Repository navigation
fix(agents): terminate background CLI tasks on cron timeout - #143355
MasterSwords1 wants to merge 3 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesThis PR propagates cron timeout reasons through agent cancellation and terminates background exec processes when their owning run times out. Example: A cron timeout occurs while background session plaid-tidepool, child PID 321092, is running.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep this PR open: it contains useful, demonstrated cleanup work, but the persistent-command lifetime contract remains undecided and GitHub reports merge conflicts. Priority: P1 Decision needed
Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherCron cleanup enters the agent cancellation owners, which abort exec processes through the process supervisor; process settlement finalizes task tracking consumed by Gateway restart monitoring. flowchart TD
A[Cron deadline] --> B[Agent cancellation owner]
B --> C[Attempt timeout signal]
C --> D[Exec process supervisor]
D --> E[Process settlement]
E --> F[Task tracking]
F --> G[Gateway restart monitor]
Technical reviewBest possible solution: Define the cron-owned command lifetime explicitly, then integrate timeout cleanup through the current session/request and process-settlement owners. Do we have a high-confidence way to reproduce the issue? Source establishes the explicit-background cleanup path, and the supplied real-process trace demonstrates the candidate's termination behavior; no current-main runtime reproduction was run. Is this the best way to solve the issue? Propagating timeout classification before reentrant cancellation addresses the original mechanism, but integration should use current lifecycle owners and an accepted independent-service contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e7f054619274. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +49, Tests +173. Total +222 across 14 files. Added test files: 0. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (7 earlier review cycles)
Reviewed October 27, 2026, 9:15 PM ET / October 28, 2026, 01:15 UTC (Revision 8). |
275692d to
801b17d
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…lback Ensure external cron_timeout aborts latch the TimeoutError reason before notifying onAttemptAbort callbacks, preventing synchronous lane controller cancellation from preempting the timeout classification with a generic abort. Also update bash-tools backgrounded listener test to assert listener retention until process exit and add regression test for re-entrant attempt aborts.
90d09ad to
e7904fb
Compare
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Following up on the cancellation work connected in #163568: #163704 has merged the stale-timeout repair that protects a replacement run. This PR addresses the separate background-process cleanup path. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Closing: #138499 is a protected maintainer issue labeled no-new-fix-pr and needs-product-decision, and this branch has conflicted with main since September. The command-lifetime contract should be decided by maintainers first; this PR cannot land ahead of that decision. |
Closes #138499
What Problem This Solves
Resolves a problem where cron jobs running automated agent turns that launch background CLI tasks via the
exectool leave orphaned processes running on the host when the cron job times out, causing the Gateway restart drain loop to block and eventually force-shutdown.Why This Change Was Made
When a cron job hits its execution deadline,
cleanupTimedOutAgentRuntriggers an abort with reason"cron_timeout". We ensure this timeout reason propagates throughabortEmbeddedAgentRunandEmbeddedAgentQueueHandle.aborttoprepareEmbeddedAttemptStream, where the abort is classified as a timeout withTimeoutError.Key design decisions:
prepareEmbeddedAttemptStream,input.abortRun(true, createTimeoutAbortReason())andattempt.onDeferredLifecycleAbort?.(reason)are invoked beforeattempt.onAttemptAbort?.(), preventing re-entrant generic cancellation callbacks from the lane controller from latching first and discarding theTimeoutError.bash-tools.exec-run.ts, backgrounded execution retains its abort signal listener until process settlement (settlement.onSettled = detachAbortListener;), allowingisSignalTimeoutReason(signal?.reason)to terminate background processes onTimeoutErrorwhile preserving them across ordinary turn cancellations and restarts.finalizeBackgroundExecTask, recording the task's terminal state and clearing thebackground-execactive work restart blocker ingateway-active-work.ts.User Impact
Scheduled cron jobs that launch background CLI commands will no longer leak orphaned processes when the cron job reaches its execution deadline, preventing host resource exhaustion and enabling graceful Gateway restarts.
Evidence
1. Real Behavior Runtime Verification
Executed an end-to-end integration test against the real process supervisor, real exec tool, real process registry, and real gateway active work monitor (
verify-cron-timeout-real.ts):2. Targeted Vitest Test Suites
All targeted suites pass cleanly (
node scripts/run-vitest.mjs <file>):src/agents/bash-tools.exec.background-abort.test.ts(9/9 passed):background exec is not killed when tool signal abortspty background exec is not killed when tool signal abortsbackground exec still times out after tool signal abortbackground exec without explicit timeout applies default timeoutbackground exec with timeout zero bypasses default timeoutyielded background exec still times outyieldMs exec without explicit timeout applies default timeoutbackground exec is killed when tool signal aborts with TimeoutErroryielded background exec is killed when tool signal aborts with TimeoutErrorsrc/agents/embedded-agent-runner/run/attempt-stream-prepare.test.ts(30/30 passed):processes cron_timeout abort through external-abort sequence as a timeoutpreserves timeout classification when onAttemptAbort synchronously triggers re-entrant generic abortsrc/agents/bash-tools.test.ts(33/33 passed):removes the abort listener when an exec process is backgrounded and exitssrc/agents/embedded-agent-runner/runs.lifecycle.test.ts(23/23 passed):forwards cron_timeout reason to abortEmbeddedAgentRunsrc/agents/embedded-agent-runner/run/deferred-lifecycle-owner.test.ts(2/2 passed):publishes CLI cancellation authority before releasing the embedded attemptrecords only the accepted candidate terminal trajectory3. Static Checks & Ratchets (
node scripts/check-changed.mjs --staged)knip): 0 unused exportsoxlint --type-aware): 0 warnings, 0 errors