Repository navigation
Description
Summary
restart_agent deletes the role's live one-shot Job and delegates the respawn to the event
loop. Kubernetes Job deletion is asynchronous, so the Job sits in Terminating for a few
seconds. If the event loop's next poll lands inside that window, it matches the still-terminating
Job on its dedupe-key label, logs Adopting existing live Job for event (dedupe hit), and
declines to spawn a replacement. The adopted Job then finishes terminating.
Net result: the role silently vanishes. No pod, no Job, pipeline state still reporting
status: running with container_id: null, indefinitely.
Observed 2026-07-25 on pipeline issue-3596-v2 while recovering a livelocked task_planner.
Evidence
First restart, respawn never happened:
01:49:08 restart_agent: invalidated event-loop arms for role
pipeline_id=issue-3596-v2 agent_role=task_planner invalidated_keys=1
01:49:08 Agent restart requested (respawn delegated to event loop) restart_count=1
01:49:11 Adopting existing live Job for event (dedupe hit)
role=task_planner action=propose dedupe_key=15de0e9451fc81f2...
Three seconds. The event loop adopted the Job restart_agent had just deleted.
For the next ~2 minutes there was no task_planner Job and no pod, while get_status reported:
{"role": "task_planner", "status": "running", "container_id": null, "elapsed_seconds": 73}Second, identical restart — old Job now fully reaped, so no dedupe hit, and it spawned normally:
01:51:10 restart_agent: deleted live one-shot Job(s) for role ... removed=0
01:51:10 Reset consensus state for agent
01:51:10 Agent restart requested (respawn delegated to event loop) restart_count=2
01:51:11 Event spawn: worktree re-attach succeeded
01:51:11 Agent Job created job_name=egg-agent-issue-3596-v2-task-planner-15de0e94
01:51:11 event-loop spawn dispatched action=propose
Note removed=0 on the second call: nothing left to delete. The only difference between the two
calls was how much wall-clock had passed since the delete.
Root cause
orchestrator/kubernetes_spawner/_events.py:22 — _event_dedupe_key_live counts a Job as live
purely by status:
return any(getattr(j, "status", None) in LIVE_POD_STATUSES for j in jobs)A Job under deletion still reports RUNNING/PENDING until its pod actually terminates, so it
satisfies LIVE_POD_STATUSES and is adopted. The predicate has no notion of "this Job is on its
way out".
The docstring already reasons carefully about terminal Jobs (EXITED/FAILED must not adopt,
per #3181) but not about terminating ones. Deletion-in-progress is a third state the predicate
does not model.
orchestrator/routes/pipelines/_routes_restart.py:348-391 deletes best-effort with force=True
and returns immediately; nothing waits for the delete to be observed.
Impact
- The documented recovery path for a wedged agent is unreliable, failing exactly when it is
needed. The caller cannot tell: the response is{"restarted": true, "container_id": "", "message": "Agent task_planner restarted successfully"}in both the working and the
vanished case. - The resulting hole is invisible to monitoring, for two compounding reasons filed separately in
Repetition-trapped agent is invisible to every progress detector: 94 min / 613 calls / 162M tokens, zero output #3595: the health monitor's heartbeat anchor is reset to0by the restart (yielding
elapsed_seconds=1784944189, an epoch timestamp used as a duration), and the peer-progress
gate then suppresses the alert anyway because a different agent heartbeated recently. So an
agent that does not exist, with an impossible timer, produces no alert. - Operators are likely to do what the reporter did: call
restart_agentagain and have it work,
concluding the first call was a fluke rather than a race.
Suggested fixes
Either would close it; the first is narrower.
- Exclude terminating Jobs from adoption. In
_event_dedupe_key_live, treat a Job with a
non-nullmetadata.deletionTimestampas not-live. Matches the predicate's existing intent
("only Jobs whose pod is still doing work") and needs no change to the restart path. - Make the delete synchronous in
restart_agent. Wait for the Job to be observed gone (or
for a short bounded timeout) before returning, so the event loop's next poll cannot see it.
Worth considering alongside: restart_agent returning container_id: "" with the message
"restarted successfully" is correct per #3164 (it deliberately does not spawn; the event loop
owns respawn) but reads as a failure signal. A field distinguishing "teardown done, respawn
delegated" from "nothing to tear down" would make the delegation legible.
Reproduction
- Have a running BRC producer with a live one-shot event Job.
- Call
restart_agentfor that role. - Watch the orchestrator log for
Adopting existing live Job for event (dedupe hit)within
~5s carrying the samededupe_key. - Observe no replacement Job while
get_statusstill reports the role asrunning.
Timing-dependent: it reproduces when the event-loop poll falls inside the deletion window, which
is why an immediate second call typically succeeds.
Related
- Flip event-loop ownership to the orchestrator and retire the in-pod wait arm (gated on a live BRC proving run of #3229) #3164 — moved respawn ownership from
restart_agentto the event loop - [issue-3064][slice-3/6] Failure supervision re-homing: bounded... #3181 — established that terminal Jobs must not be adopted (same predicate, adjacent case)
- Repetition-trapped agent is invisible to every progress detector: 94 min / 613 calls / 162M tokens, zero output #3595 — the livelock incident this surfaced during, plus the heartbeat-anchor and
peer-progress-gate defects that hid the resulting hole
Activity
Address review feedback on the terminating-Job adoption fix (#3597)
Don't claim an observation the teardown wait never made (#3597)
Apply the no-observation log taxonomy to the event path too (#3597)
Report the unnameable-Job skip path instead of folding it into a count (
Don't report a failed Job delete as a clean teardown (#3597)
Merge pull request #3613 from jwbron/egg/3597-terminating-job-adoption
jwbron commentedon Jul 25, 2026
Reproduced live twice today on pipeline
issue-3596-v2, with a measured hit rate.All four
restart_agentcalls in a 19-hour orchestrator log window, and what the event-looprespawn did one to two seconds later:
Adopting existing live Job for event (dedupe hit)Agent Job createdAgent Job createdAdopting existing live Job for event (dedupe hit)Two of four lost the race. The 20:39 instance in full:
Net effect: old pod gone, no new pod, the agent still reporting WORKING with zero pods in the
namespace, and the orchestrator silent for the following 10 minutes. Nothing detected it. The MCP
call had returned
{"restarted": true}.Recovery is to wait for the deleted Job to be reaped, then re-issue the identical call: the second
attempt logs
removed=0, no adoption, and creates the Job. That is what the 01:49:08 / 01:51:10pair is, two minutes apart, and it predates the diagnosis, so at least one earlier "the model
stalled again" intervention in this run was actually this bug.
Two consequences worth noting for #3601's evaluation: the failure presents identically to a model
stall unless you read the spawner log, and it inflates the operator-intervention count that the
evaluation treats as a result. PR #3613 fixes it.
Hoist the orphan reap above the classification switch and wait for te…