Skip to content

fix(gateway): resume the true root after restart through visible spawned children - #201970

Merged
obviyus merged 1 commit into
mainfrom
fix/restart-root-through-visible-children
Nov 19, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/restart-root-through-visible-children

Conversation

@obviyus

@obviyus obviyus commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

What problem this solves

After a Gateway restart, OpenClaw stops running subagents and resumes only their ordinary root session, which then re-instructs its children (#185730, docs/gateway/restart-recovery.md). Root discovery (resolveRootSubagentRequester) walked up the ancestry only while the session key looked like a hidden subagent (agent:…:subagent:…). A VISIBLE spawned child (a dashboard session created by sessions_spawn with visible: true) stopped the walk. Its restart marker was then rejected because it is a spawned child, and the real root was never marked.

Seen on a live Gateway: a root chat → visible coordinator → hidden workers tree stalled after a restart and needed a human message 25 minutes later.

Change

  • Follow RECORDED native spawn ownership up to the ordinary root: the session's spawnedBy, or createdVia: "spawn" with parent, controller or requester fallback. The walk now covers visible and hidden native children alike, and keeps the cycle guard, the recorded child-authority (owner) check and the session-incarnation match.
  • sessions_send also registers requester edges, but it creates no child and carries no spawn metadata. Those sessions stay independent roots, which keeps the case fix: resume running channel threads after graceful restarts #188402 narrowed the walk for: an ordinary conversation must not inherit an excluded cron requester. Run records cannot tell the two edges apart, so the walk reads the session's creation metadata in a worker, once per ancestry step. A session without a registry entry stops before any read.
  • Selection snapshots live owners before those reads, keeps the live-root-before-parked precedence, and still runs inside the existing shutdown persistence budget.
  • docs/tools/subagents/operations.md notes that visible spawned children resolve to their root.

Evidence

Proof tier: source (ocx test).

  • New session-restart-resume.ancestry.test.ts, with two cases: a hidden worker under a visible spawned coordinator, and a visible worker directly under the root. Both fail on unchanged main (resumeAfterRestart undefined on the root) and pass with the fix, through a real shutdown marker into the startup enqueue.
  • Frozen head: 11 files, 110 tests pass, including the existing cron-ownership protection.
  • session-restart-resume.workspace.test.ts timed out under heavy host load (load above 70). An instrumented run on the fix then passed in 27 s with no root-resolver calls or ancestry reads, and its close took 244 ms. It does not touch the changed path.
  • pnpm tsgo, pnpm check:test-types, type-aware oxlint, format and the line-cap ratchet: pass.

Production +50 lines, test +99 lines, docs +4 lines.

…ned children

- Restart root discovery walked ancestry only while the key looked like a hidden
  subagent, so a visible spawned coordinator (or worker) stopped the walk and its
  ordinary root was never marked to resume.
- Follow recorded native spawn ownership (session spawnedBy / createdVia spawn) up
  to the ordinary root, keeping cycle, owner and incarnation checks.
- sessions_send edges (no spawn metadata) stay independent roots, as #188402 needs.
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: S labels Nov 19, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR follows recorded spawn ancestry through visible children to resume their ordinary root after a Gateway restart.

Example: agent:main:dashboard:root has finished its turn while its visible coordinator runs a hidden worker.

  • Before: Restart discovery stops at the coordinator, leaving the root without a resume marker.
  • After: Discovery reaches the root and selects it for the ordinary restart input.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful, focused recovery repair with meaningful integration tests, but an introduced failure-isolation defect and no shipped-entry-point proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A conversation with running descendants beneath a visible spawned coordinator can stop progressing after restart until a human sends another message.
Reason: Restores documented root-only recovery through existing ownership metadata; the collaborator-authored direction needs no additional product decision.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This PR addresses a source-confirmed recovery bug, but a failed ancestry read can prevent unrelated healthy sessions from receiving restart markers.

Priority: P2
Reviewed head: 97b311a30b0829dc55a5e189a8d4dcd093afa84c

Before merge

  • Isolate ancestry-read failures from healthy restart candidates (P2) - With a healthy running root in one agent and a live child in another whose metadata read rejects, listLiveSubagentRootSessions rejects through Promise.all at this await. persistRunningSessions awaits the entire selection before starting any marker writes, so the healthy root also receives no restart marker. The reader explicitly throws for unavailable metadata; previously a store failure was isolated by the per-store Promise.allSettled writes. Handle failed ancestry candidates individually, including the later select calls, record the failure, and continue persisting healthy roots.

Findings

  • [P2] Isolate ancestry-read failures from healthy restart candidates — src/gateway/session-restart-resume-selection.ts:145-146

Tests

  • Missing end-to-end proof: Supply redacted post-fix Gateway logs or terminal output showing a root with a visible coordinator and running worker receiving its restart input and continuing after a real restart.
Agent review details

How this fits together

Shutdown selection combines live execution owners, subagent ancestry, and parked waits into persisted restart markers; startup consumes those markers through ordinary session admission.

flowchart TD
  A[Live execution owners] --> C[Restart selection]
  B[Registry and spawn metadata] --> C
  C --> D[Root restart markers]
  D --> E[Startup authority admission]
  E --> F[Ordinary root continuation]
Loading

Technical review

Best possible solution:

Keep spawn-aware traversal in the existing registry owner while isolating failed ancestry candidates so healthy roots still receive restart markers.

Do we have a high-confidence way to reproduce the issue?

Current-main traversal stops at visible session keys while persistence rejects spawned sessions; the supplied tests exercise this combination, but no target code was run during this read-only review.

Is this the best way to solve the issue?

Using recorded spawn metadata is appropriate and preserves ordinary conversation independence; the new asynchronous reads must retain fault isolation between recovery candidates.

Full review comments:

  • [P2] Isolate ancestry-read failures from healthy restart candidates — src/gateway/session-restart-resume-selection.ts:145-146
    With a healthy running root in one agent and a live child in another whose metadata read rejects, listLiveSubagentRootSessions rejects through Promise.all at this await. persistRunningSessions awaits the entire selection before starting any marker writes, so the healthy root also receives no restart marker. The reader explicitly throws for unavailable metadata; previously a store failure was isolated by the per-store Promise.allSettled writes. Handle failed ancestry candidates individually, including the later select calls, record the failure, and continue persisting healthy roots.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d23fd767e606.

Provenance checked

  • Spawn versus message ancestry changes intended behavior with a stated reason (e051130: Ordinary conversations targeted by sessions_send must retain their own recovery instead of inheriting an excluded cron requester.)
  • Root-only restart selection keeps the original intent (9344233: Replace execution reconstruction with one ordinary continuation input per eligible root.)
  • Live-owner selection and parked precedence keeps the original intent (cb04fef: Cron retains scheduled occurrences, while accepted user work and live-root precedence retain their existing recovery custody.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/session-restart-resume.ancestry.test.ts src/gateway/session-restart-resume-selection.test.ts src/gateway/session-restart-resume.test.ts --maxWorkers=1
  • pnpm tsgo:core
  • pnpm check:test-types
  • git diff --check

What I checked:

PR surface

Source +50, Tests +99, Docs +4. Total +153 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 69 19 +50
Tests 1 99 0 +99
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 172 19 +153

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test growth Production +50 LOC; tests +99 LOC The growth distinguishes spawn ancestry from message-requester edges and covers direct-visible and nested-hidden recovery.

Labels

Label changes:

  • add P2: Visible spawned children can prevent automatic root continuation after restart, requiring another user message.
  • add merge-risk: 🚨 session-state: A rejected ancestry read now prevents restart markers for unrelated healthy sessions before per-store fault isolation is reached.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Visible spawned children can prevent automatic root continuation after restart, requiring another user message.
  • merge-risk: 🚨 session-state: A rejected ancestry read now prevents restart markers for unrelated healthy sessions before per-store fault isolation is reached.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 19, 2026, 1:11 PM ET / 18:11 UTC.

@obviyus
obviyus merged commit 2420b7d into main Nov 19, 2026
151 checks passed
@obviyus
obviyus deleted the fix/restart-root-through-visible-children branch November 19, 2026 18:27
@obviyus

obviyus commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

Post-merge real-Gateway proof (isolated Gateway from source, real model, natural state, graceful restart).

Tree: finished true root → finished visible coordinator (spawned with sessions_spawn) → live worker.

Build Shutdown selection After restart
main with this PR (4eb3541) marked only the true root true root: restart input ×1, recovered; coordinator and worker: ×0
Before this PR (6ecbcf0) marked: 0, skipped: 1, reasons: {"subagent": 1} true root: no marker, no input, stayed stalled

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 20, 2026
…ned children (openclaw#201970)

Problem: after a Gateway restart, OpenClaw stops running subagents and resumes only their ordinary root, which re-instructs its children. Root discovery walked up the ancestry only while the session key looked like a hidden subagent. A visible spawned child (a dashboard session from sessions_spawn visible:true) stopped the walk, its restart marker was rejected as a spawned child, and the real root was never marked. On a live Gateway a root chat -> visible coordinator -> hidden workers tree stalled after a restart until a human wrote.

Fix: follow recorded native spawn ownership (session spawnedBy, or createdVia spawn with parent/controller/requester fallback) up to the ordinary root, for visible and hidden native children, keeping the cycle guard, the recorded child-authority check and the session-incarnation match. sessions_send edges carry no spawn metadata and stay independent roots, which keeps the case openclaw#188402 protected. Selection snapshots live owners before the worker reads, keeps live-root-before-parked precedence, and stays inside the existing shutdown persistence budget.

User impact: a root whose work runs through a visible spawned coordinator or worker is resumed after a restart and can re-instruct its children, instead of stalling until someone writes.

Proof: new ancestry regression (hidden worker under a visible coordinator; visible worker under the root) red on unchanged main and green with the fix through a real shutdown marker and startup enqueue; 11 restart-resume and registry files (110 tests); tsgo, test types, type-aware oxlint, format and the line-cap ratchet; ocx build --dts plus a packed install smoke on the head.

Co-authored-by: Ayaan Zaidi <[email protected]>
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 20, 2026
…ineage spawn records

Upstream openclaw#201970 (2420b7d) changed restart root discovery:
resolveRootSubagentRequester now follows recorded spawn ownership and
stops unless the child's session entry carries spawnedBy or createdVia
"spawn" (subagent-registry-read.ts:111-114). Before, it walked by the
hidden-subagent session-key shape. The fixture wrote the delegate's child
session without lineage, so graceful shutdown's marker selection stopped
at the child, the parent got no restart resume input, and cases 1 and 3
of the shutdown-contract pins went red on Bun and Node 24 (matrix chunk
03, f150ea9).

Production continuation delegates spawn through spawnSubagentDirect,
whose createInitialSubagentSession writes spawnedBy and parentSessionKey
on the child (subagent-spawn-session-patch.ts:147-160). The fixture now
writes the same two fields. No assertion changed: all 16 cases (graceful
items 1-3, crash pins 5 and 6, the in-process restart, inspection) pass
on Bun and Node 24, so the shutdown contract's behavior is unchanged for
a production-shaped delegate.

Refs openclaw#129388
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 20, 2026
…child session entry is gone

Upstream openclaw#201970 (2420b7d) walks the restart root by recorded spawn
lineage, which lives on the child's session entry. A continuation
delegate whose child session entry is missing therefore leads to no
root, and shutdown marked nothing for its requester. Repro at
8ba4ee8: after a graceful restart the requester got the delegate's
ordinary outcome ("any work it saved ... stays in its child session",
which is false), no root resume and no word about either. With the
requester's session also gone, the outcome stayed pending forever with
no log at all.

🌊's ruling (msg 1573423363714715731): no root inferred from the key and
no unverified root resumed; one explicit "lineage missing; election
outcome unknown" notice while a durable receipt still binds the
requester, idempotent on the election; otherwise a diagnosable
unresolved record, with no broadcast and no guess.

Gateway activation (the fork's restart-custody owner, before restart
resume and before any delivery) now checks each continuation delegate
that a restart ended with an outcome still owed. When its child session
entry is missing, the run row records continuationLineageMissing once:
- the row's recorded requester agent resolves and its session exists
  unarchived (what restart completion recovery admits through): the
  delegate's one outcome opens "lineage missing; election outcome
  unknown (election <record id>)", says no root was resumed for it and
  its saved work cannot be located, and travels its return mode. Once:
  delivery state and the recorded decision survive a replayed
  activation, a second restart and the sweeps;
- otherwise: the reason is recorded (requester agent unresolved, session
  missing or archived), a warning names the run, election, child and
  requester, and the row closes as intentional non-delivery, as a
  delegate its requester had asked to stop does.

The notice is the delegate's own outcome rather than a second message:
shutdown-contract item 3 allows each delegate one outcome. The root walk
is unchanged and is the only caller of resolveRootSubagentRequester
(selectLiveRestartResumeSessions, directly and through
listLiveSubagentRootSessions). A delegate with its lineage writes no
record, and its outcome is byte-identical.

Pins (restart-terminal-custody item 7, red at 8ba4ee8, green here on
Bun and Node 24): a graceful restart with the entry missing, per return
mode (direct, silent, silent-wake, targeted), sends one lineage-missing
outcome and no root resume input; a replayed activation, a second
restart and its sweeps add none; a crash-settled delegate gets the
interrupted variant; with no requester session, an unresolved record, a
warning, no notice and no resume. Case 1 also asserts a production
lineage records nothing. The status stays under the event's 500
character cap with UUID-sized ids (445 worst case).

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant