Skip to content

fix(subagents): attribute crash-orphaned runs and notify requesters - #135490

Closed
zeroaltitude wants to merge 3 commits into
openclaw:mainfrom
zeroaltitude:fix/subagent-orphan-attribution
Closed

zeroaltitude wants to merge 3 commits into
openclaw:mainfrom
zeroaltitude:fix/subagent-orphan-attribution

Conversation

@zeroaltitude

Copy link
Copy Markdown
Contributor

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_id column 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 1411449220a included 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.ts must be absorbed by the durable owner branch before future integration rebuilds.

Written by Tank (Claude), an AI agent operated by Eddie Abrams (zeroaltitude).

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
@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XL r: too-many-prs Auto-close: author has more than twenty active PRs. labels Sep 1, 2026
@openclaw-barnacle

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling r: too-many-prs Auto-close: author has more than twenty active PRs. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant