← Back to Pull requests

factory(watch): nudge linked workflows when an issue's sandbox is collected #1691

Closed
unknown closed this pull request without merging on Oct 01, 2026 17:39 UTC
View on GitHub
unknown unknown commented on Oct 01, 2026 16:16 UTC
Author

Why

A workflow issue (e.g. KCC's kcc-greenfield) hands its steps out as issues of their own and checks on them each run, sitting out its cooldown (2h for greenfield) in between. When a step closes, the workflow only notices on its next cooldown-gated run.

Example: merging PR #13570 closes step issue #13565. Parent issue #13254 has wf-issue-13254 and tracks #13565 in a progress comment. Nothing on #13565 or its sandbox points back at #13254. The link only shows up as a cross-referenced event on #13565's timeline.

A second problem made this worse: the PR's tasks ran in fix-k8s-config-connector-13565 (labelled pr=13570). The open-issue cache keeps every issue the watcher has ever worked on, so the closed-issue GC never noticed the merge, and the sandbox stayed around indefinitely.

What

  • sandbox.Reconciler

  • - When it confirms an issue closed, it calls a new LinkedWork hook before deleting the sandbox, including in dry-run mode. The reconciler still cannot touch the queue itself.
    - An issue sandbox whose factory.gemini.google.com/pr label names a PR that has left the open-PR cache is now confirmed against GitHub, even though the issue cache still lists the issue as open.
  • issues.Nudger (new, stateless, so safe to call from the reconciler's goroutine):

  • - It gathers the issues that cross-reference the closed one on its timeline, plus the issues its body names.
    - For each that has a wf-issue-N sandbox, is open, has no stop label and still names a workflow, it queues the workflow run.
    - The task uses the scanner's own file name (task-workflow-<slug>-issue-N.yaml), so the queue dedupes against the scanner.
    - It skips the cooldown and records the new trigger reason LinkedIssueClosed.
    - It honours MinNumber and DryRun.
    - It is wired in only when the watcher scans issues.
  • Shared helpers: the scanner's workflow resolution, task-file naming and task builder are factored out so the scanner and the nudger share them.

  • sandbox.Service.Exists: new.
  • Behaviour change

  • A fix-* sandbox that a PR ran in is now deleted about 15 minutes after the PR merges and closes its issue. The first GC after deploy will delete the ones whose PR is already merged.

  • A PR closed without merging, with its issue still open, costs one issue fetch per GC sweep. Nothing is deleted.
  • Latency from merge to nudge: at most about 15 minutes (up to 10 for the PR sweep, up to 5 for GC). Previously the wait was up to the workflow's cooldown.

    Not covered

  • If the workflow's run is already queued or in progress, no nudge is queued; its next run after the cooldown picks the closure up.

  • An issue closed without a PR is still hidden by the open-issue cache keeping worked-on issues.
  • Tests

  • issues/nudge_test.go covers:

  • - the cross-referencing parent is queued with the right task;
    - the near misses are not queued: the PR itself, a closed issue, an issue with no workflow, and an issue with no sandbox;
    - an already-queued run is left alone;
    - the cooldown is skipped;
    - dry-run queues nothing;
    - MinNumber is honoured.
  • sandbox/reconciler_test.go covers:

  • - the sandbox is collected and reported once its PR leaves the open-PR cache (this test fails without the new check);
    - the sandbox is kept, with no GitHub calls, while the PR is open;
    - the hook is called in dry-run mode.

    Diff: 424 lines (+318 / -106) across 5 files Reviewer: sdowell Review duration: 83m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 424 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.362
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1691"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.1% (MEDIUM) · Higher = larger blast radius
    45.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%