Repository navigation
fix(subagents): attribute crash-orphaned runs and notify requesters - #135490
Closed
zeroaltitude wants to merge 3 commits into
Closed
zeroaltitude wants to merge 3 commits into
zeroaltitude wants to merge 3 commits into
Conversation
A subagent run that is in flight when the gateway dies is only discovered
later, when a fresh boot sweeps the registry. Two code paths then recorded a
causally empty string — "subagent run lost active execution context" and
"session completed before registry settled" — and a third, the orphan prune in
reconcileOrphanedRun, deleted the row outright with nothing but a [warn] log.
The spawning session, the only party that can decide to retry, was never told
at all.
That silence is not merely unhelpful, it is actively misleading. The reap
timestamp is an arbitrarily late clock reading: it includes however long the
host stayed down. In the incident behind this issue a run that executed for
5m36s was reaped after a 34-minute VM outage and so appeared to have lived
40m35s, which is the evidence that talked an earlier investigation into
confidently diagnosing a "run timeout" on a run whose timeout was disabled.
subagent-orphan-attribution.ts correlates an orphaned run against the
gateway_boot_lifecycle rows that were already being persisted, and renders a
message naming the cause, the restart timestamp, the prior boot id, the fact
that the prior boot ended without a clean stop, the true elapsed lifetime and
the recorded assistant-message count. Elapsed is computed from the best
available death evidence and never from the reap; each evidence class carries
its own bound, so the message says "at least" or "at most" rather than
overclaiming. The run's own start time is explicitly rejected as activity
evidence, since accepting it would report a 0s lifetime — a stronger claim than
the honest upper bound. When the evidence does not support a claim at all (the
owning boot recorded any deliberate stop, no boot owned the run, no successor
boot exists), attribution returns null and callers keep their existing wording,
so a clean shutdown can never be misattributed.
Telling "the gateway process died" apart from "the host rebooted under us"
matters because the remedies differ, and neither was previously recoverable
from the database. A host_boot_id column on gateway_boot_lifecycle gives it
directly: same id across the gap means the process alone died, a changed id
means the machine went down. The kernel value from /proc is authoritative; the
os.uptime() fallback is bucketed and anything derived from it is reported as
inferred rather than observed. Legacy rows predating the column produce no
host-continuity claim.
For the notification defect, a run that died having recorded no assistant
output now completes through completeSubagentRunWithRecovery with
sendFarewell: true rather than being silently pruned, which routes it through
the existing announce surface — subagent-announce.ts already renders
outcome.error into the requester-facing status label, so no new notification
channel was invented. Output-bearing runs keep the existing prune path; the
loud failure is reserved for the case the requester cannot reconstruct on its
own.
The stale-active reap block moved out of subagent-registry-sweeper.ts into
subagent-registry-sweeper-orphan.ts so the decision reads as one thing. That
incidentally brings the sweeper from 723 to 679 lines, under the 700-line
oxlint max-lines budget it was already violating on main.
Schema change is additive only (ensureColumn plus the CREATE TABLE), with
openclaw-state-db.generated.d.ts regenerated via db:kysely:gen. No destructive
migration.
Deliberately out of scope, noted as follow-up: re-attaching an orphaned run on
registry rebuild instead of completing it as an error. A truthful failure beats
a silent one, and resilience is a larger change than accurate error text.
Validation (topic worktree):
pnpm tsgo:core clean
pnpm tsgo:core:test clean
pnpm vitest run src/agents/subagents/ 102 files, 2506 tests passed
incl. subagent-orphan-attribution.test.ts 22 passed
incl. subagent-registry-sweeper-orphan-attribution 12 passed
pnpm vitest run src/infra/gateway-boot-lifecycle.test.ts
src/state/openclaw-state-db.test.ts + neighbours 255 passed
pnpm config:schema:check ok
pnpm plugin-sdk:surface:check 0 forbidden subpaths
pnpm check:import-cycles 0 runtime value cycles
pnpm db:kysely:check clean
pnpm oxlint <touched files> clean
git diff --check clean
Beads: openclaw-vaon
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Closing this PR because the author has more than 20 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Subagents orphaned by a Gateway crash are later reaped with generic or misleading text, and no-output runs can be deleted without notifying the requester. A real 5m36s run reaped after a 34-minute VM outage appeared to have run for 40m35s, leading incident response toward a false timeout diagnosis.
Why This Change Was Made
The orphan reconciler correlates runs with persisted Gateway and host boot lifecycle evidence, reports bounded elapsed time from the best available death signal, distinguishes process death from host reboot when possible, and declines attribution when evidence is insufficient or indicates a clean stop. An additive
host_boot_idcolumn records host continuity. No-output orphans complete through the existing failure-announcement surface; output-bearing rows retain current pruning behavior.User Impact
Requesters learn that a child was orphaned and why, while diagnostics avoid inventing lifetimes from a late reap timestamp. Legacy rows and clean shutdowns are not over-attributed.
Evidence
Coverage includes 22 attribution cases, 12 sweeper-attribution cases, restart/host continuity, additive schema migration, and requester notification. Validation on head
1411449220aincluded 2,506 subagent tests and 255 lifecycle/state tests, both core typechecks, schema generation checks, SDK/config checks, import-cycle checks, lint, and diff validation.One merge-resolution follow-up remains outside this branch: the final integration composition in
subagent-registry-sweeper.tsmust be absorbed by the durable owner branch before future integration rebuilds.Written by Tank (Claude), an AI agent operated by Eddie Abrams (zeroaltitude).