Repository navigation
fix(gateway): retire worker placements without sessions - #123785
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
ad3c3a6 to
bb5fa60
Compare
|
Codex review: found issues before merge. Reviewed August 14, 2026, 4:47 PM ET / 20:47 UTC. ClawSweeper reviewWhat this changesThis PR adds canonical-session evidence checks that retire orphaned Gateway worker placements during startup, identity changes, and periodic reconciliation. Merge readinessKeep open: the final head fixes the prior shutdown-drain finding, but concurrent calls to its new sidecar stop method can resolve before worker environments finish stopping. Priority: P1 Review scores
Verification
How this fits togetherGateway worker placements durably associate an agent session with a local or remote execution environment. The new path reads the canonical per-agent session store, retains uncertain records, and fences or retires records whose session is confirmed absent. flowchart LR
A[Canonical session store] --> B[Session evidence probe]
C[Durable worker placement] --> B
B --> D{Evidence state}
D -->|Current or unknown| E[Keep placement]
D -->|Absent| F[Fence and retire]
F --> G[Worker environment cleanup]
G --> H[Gateway shutdown]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +239, Tests +434, Docs +3. Total +676 across 13 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Memoize the sidecar shutdown promise so every caller joins the same drain and environment-stop operation, with a concurrent-stop regression; the existing new evidence and retirement boundaries justify the remaining production growth because current explicit-mutation guards do not own startup or periodic orphan discovery. Do we have a high-confidence way to reproduce the issue? Yes, from source: defer reconciliation or environment shutdown, call the new sidecar stop twice, and observe the second call resolve before the first has finished stopping environments. Is this the best way to solve the issue? No: the session-evidence approach is the right owner-boundary direction, but the changed shutdown path must make repeated stop calls join one shared operation. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ae385f3c6bbd. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
bb5fa60 to
5d38b06
Compare
728350c to
685c7a0
Compare
685c7a0 to
c41cf9c
Compare
|
Merged via squash.
|
What Problem This Solves
Fixes an issue where durable worker placements could survive after their authoritative session entry was deleted or replaced outside the explicit Gateway delete/reset RPCs. Those invisible rows could keep environments and worker authority alive, pin terminal environment retention, and be re-adopted after Gateway restart.
Why This Change Was Made
The Gateway worker lifecycle now reconciles each placement against canonical per-agent session evidence at startup, after identity mutations, and during periodic placement sweeps. The session-store owner provides one strict tri-state probe using indexed exact-key and
current_session_idlookups: confirmed absence exact-CAS retires safe local or terminal rows; live or transitional placements first force-fence and destroy their environment; unreadable, ambiguous, or migration-invalid stores remainunknownand preserve the placement.Startup and mutation-triggered retirement stay inside the reconciliation promise drained before environment shutdown. The change also moves the existing dispatch coordinator to its worker-environment owner so the startup composition stays below the 700-line budget.
AI-assisted; implementation and proof were reviewed by the author.
User Impact
Sessions deleted by maintenance, cron cleanup, plugin rollback, migration, or other canonical lifecycle owners no longer leave remote execution placements behind. A deleted session's worker environment is fenced and cleaned up even across restart, while archived sessions and temporarily unreadable session stores are retained safely.
Evidence
sessions.deletetriggers placement retirement through the production Gateway startup context.unknowninstead of environment teardown.origin/main: clean, no accepted/actionable findings.