Skip to content

fix: give a subagent result's restart wake the requester's original access - #203479

Merged
obviyus merged 2 commits into
mainfrom
fix/restart-custody-requester-source
Nov 22, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/restart-custody-requester-source

Conversation

@obviyus

@obviyus obviyus commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #203466, #198905

What Problem This Solves

When the Gateway restarts while a parent chat still owes a subagent result, restart recovery rebinds the result so that the parent chat is woken to receive it. Since #203466, a parent chat with no recorded owner wakes with the System write baseline, so an admin requester can lose admin after a restart. A parent chat whose owner profile has no current role-based grant (for example, someone who connected with a device token) fails recovery completely: the log shows "Session principal has no current run authority", and the child result is not delivered.

User Impact

After a restart, the woken settlement turn has the access of the person who spawned the subagent, checked against current policy: an owner keeps admin, a writer gets write and never admin. The child result is delivered. Subagent runs started before this change keep the earlier behavior (the session owner's access, else the System write baseline, never admin).

Why This Change Was Made

Subagent spawn now saves the requester's operator recovery source (requesterOperatorSource) on the subagent run. This is the same bounded codec and the same capture (captureQueuedOperatorRecoverySource) that queued inputs use. Unavailable sources are not stored. At restart, recoverRequesterCompletionCustody re-admits that source through restoreGatewayQueuedOperatorRecovery, the one admission that queued work also uses. The woken turn's own admission still checks session access when it starts. A refused source leaves the result unbound, as any failed recovery does.

Storage (schema change approved by Ayaan): one optional property inside the existing subagent_runs.payload_json. No table, column, index, schema version or backfill. Older builds ignore the property and use their own fallback (docs/reference/database-schemas/storage-changes.md has the entry).

Evidence

  • session-restart-resume-custody.test.ts, "wakes the parent with the saved owner/writer requester's scopes after a restart". These tests drive restart store discovery and custody recovery, then settle the interrupted child through the real lifecycle controller.
    • Base e9f29990130b: red. Recovery fails with "Session principal has no current run authority", and the result is not delivered.
    • Head: green. The owner wakes with operator.admin. The writer wakes with operator.write and without admin. The result is delivered (delivery.status === "delivered").
  • Older rows: "delivers a restored ... child's owed notice after its legacy profile/unattributed requester settled" (session owner, else [operator.write]).
  • Spawn: subagent-registry.requester-source.test.ts. registerSubagentRun persists the requester's gateway source in the SQLite row.
  • Touched and importer tests: 17 files, 226 tests pass.

Production code grows by about 25 lines: one capture at spawn and per-child re-admission at restart. This is the approved stored-source design. It removes the single session-principal admission that every restored child shared.

Each restored child re-admits its own saved requester. A refused source (for example, a revoked device) is logged and leaves only that child unbound. Its siblings are still recovered and resumed (test: "recovers a sibling child when another child's saved requester is refused"). Shutdown or a changed requester chat still stops recovery for every child.

…iginal scopes

Save the spawning requester's recovery source on the subagent run. After a Gateway restart, completion recovery re-admits that source, so the woken parent turn keeps the requester's scopes (an owner keeps admin, a writer gets write). Rows without the field keep the session principal or System write baseline.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 22, 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: M labels Nov 22, 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. labels Nov 22, 2026
…er is refused

Each restored child re-admits its own saved requester, so one refused source no longer stops its siblings or drops already-bound children from the resume list. Shutdown and a changed requester chat still stop every child.

Co-authored-by: obviyus <[email protected]>
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 22, 2026
@obviyus
obviyus merged commit 450441b into main Nov 22, 2026
130 checks passed
@obviyus
obviyus deleted the fix/restart-custody-requester-source branch November 22, 2026 12:05
@clawsweeper

clawsweeper Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR saves each subagent requester's recovery source and re-admits it when restoring parent completion delivery after a Gateway restart.

Example: A device-authenticated writer spawns a child from agent:main:dashboard:settled-requester, then the Gateway restarts.

  • Before: Recovery can reject the session principal with “Session principal has no current run authority,” leaving the child result undelivered.
  • After: Recovery re-admits the saved device-backed requester with operator.write, without operator.admin, and restores completion custody.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and has no identified code defect, but shipped-entry-point proof and a v2026.11.6 upgrade demonstrating intact settings, existing obligations, and requesterOperatorSource compatibility are missing.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: After a Gateway restart, an owed child result can fail delivery or wake its parent with less access than the spawning requester had.
Reason: The maintainer-authored direction repairs requester continuity without adding a public option or replacing the established admission owner.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this maintainer-authored PR addresses a current-main restart recovery defect, and no discrete introduced code bug was found.

Priority: P2
Reviewed head: 2ce163ba8641410017bf58f5b866d97ce8e4d795

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide an isolated running-Gateway scenario using public sessions.create, real spawn, restart, and parent delivery showing owner access retained and writer access never widened; redact credentials, IPs, phone numbers, and non-public endpoints.
Agent review details

How this fits together

The subagent registry retains child-result obligations in SQLite; Gateway startup restores their requester custody before completion delivery starts a parent turn.

flowchart TD
  A[Requester spawns child] --> B[Registry captures recovery source]
  B --> C[SQLite subagent run]
  C --> D[Gateway restart recovery]
  D --> E[Current operator admission]
  E --> F[Restored completion custody]
  F --> G[Parent turn admission and delivery]
Loading

Technical review

Best possible solution:

Retain the existing registry and operator-admission owners, saving bounded requester facts and restoring each child's custody independently while preserving legacy fallback behavior.

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

Current main re-admits only the session principal or uses the write baseline, losing the spawning requester's device-backed authority; the PR reports base-red/head-green owner and writer regressions, which were inspected but not executed during this read-only review.

Is this the best way to solve the issue?

The patch is a focused owner-level repair: one optional registry field uses the existing bounded codec and admission path, and per-child failure handling prevents a refused requester from blocking siblings.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Session-principal restart custody changes intended behavior with a stated reason (ad6738d: Restore retained child obligations only after fresh requester admission and exact session-incarnation validation.)
  • Unattributed write baseline keeps the original intent (e9f2999: Prevent unattributed restart wakes from gaining admin; loss of original admin access was explicitly accepted pending stored-source support.)
  • Retired operatorRecoverySource changes intended behavior with a stated reason (9344233: Simplify graceful restart by removing reconstruction and old requester snapshots; the new field serves retained completion custody and leaves the retired field ignored.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 8d581e9 adds src/gateway/session-restart-resume-custody.ts:116 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8d581e98c5b5; files: src/gateway/session-restart-resume-custody.ts)
  • Peter Steinberger: Raw commit ad6738d adds src/gateway/session-restart-resume-custody.ts:122 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ad6738d48408; files: src/gateway/session-restart-resume-custody.ts)

PR surface

Source +33, Tests +198, Docs +12. Total +243 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 72 39 +33
Tests 2 297 99 +198
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 381 138 +243

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 LOC Production +72/-39; tests +297/-99 The production growth adds capture and per-child recovery using existing owners; tests cover persistence, owner/writer scopes, legacy behavior, and sibling isolation.

Labels

Label changes:

  • add P2: Restart recovery can strand child results or narrow requester access, with a limited trigger involving retained subagent work.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.

Label justifications:

  • P2: Restart recovery can strand child results or narrow requester access, with a limited trigger involving retained subagent work.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.

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 22, 2026, 7:04 AM ET / 12:04 UTC.

@obviyus

obviyus commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 450441b. Subagent spawn now saves the requester's recovery source. After a Gateway restart, the woken parent turn re-admits that source: an owner keeps admin, a writer gets write and never admin, and the child result is delivered. Older runs keep the session owner, else the System write baseline. One refused source no longer blocks its siblings. Proof: the saved-source restart tests are red on base (recovery refused, result undelivered) and green on head; CI is green; review round 2 is clean; the one-admission E2E checks R and S pass.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 23, 2026
…ccess (openclaw#203479)

Related: openclaw#203466, openclaw#198905

## What Problem This Solves

When the Gateway restarts while a parent chat still owes a subagent result, restart recovery rebinds the result so that the parent chat is woken to receive it. Since openclaw#203466, a parent chat with no recorded owner wakes with the System write baseline, so an admin requester can lose admin after a restart. A parent chat whose owner profile has no current role-based grant (for example, someone who connected with a device token) fails recovery completely: the log shows "Session principal has no current run authority", and the child result is not delivered.

## User Impact

After a restart, the woken settlement turn has the access of the person who spawned the subagent, checked against current policy: an owner keeps admin, a writer gets write and never admin. The child result is delivered. Subagent runs started before this change keep the earlier behavior (the session owner's access, else the System write baseline, never admin).

## Why This Change Was Made

Subagent spawn now saves the requester's operator recovery source (`requesterOperatorSource`) on the subagent run. This is the same bounded codec and the same capture (`captureQueuedOperatorRecoverySource`) that queued inputs use. Unavailable sources are not stored. At restart, `recoverRequesterCompletionCustody` re-admits that source through `restoreGatewayQueuedOperatorRecovery`, the one admission that queued work also uses. The woken turn's own admission still checks session access when it starts. A refused source leaves the result unbound, as any failed recovery does.

Storage (schema change approved by Ayaan): one optional property inside the existing `subagent_runs.payload_json`. No table, column, index, schema version or backfill. Older builds ignore the property and use their own fallback (`docs/reference/database-schemas/storage-changes.md` has the entry).

## Evidence

- `session-restart-resume-custody.test.ts`, "wakes the parent with the saved owner/writer requester's scopes after a restart". These tests drive restart store discovery and custody recovery, then settle the interrupted child through the real lifecycle controller.
  - Base `7a9ad62bfc9e`: red. Recovery fails with "Session principal has no current run authority", and the result is not delivered.
  - Head: green. The owner wakes with `operator.admin`. The writer wakes with `operator.write` and without admin. The result is delivered (`delivery.status === "delivered"`).
- Older rows: "delivers a restored ... child's owed notice after its legacy profile/unattributed requester settled" (session owner, else `[operator.write]`).
- Spawn: `subagent-registry.requester-source.test.ts`. `registerSubagentRun` persists the requester's `gateway` source in the SQLite row.
- Touched and importer tests: 17 files, 226 tests pass.

Production code grows by about 25 lines: one capture at spawn and per-child re-admission at restart. This is the approved stored-source design. It removes the single session-principal admission that every restored child shared.

Each restored child re-admits its own saved requester. A refused source (for example, a revoked device) is logged and leaves only that child unbound. Its siblings are still recovered and resumed (test: "recovers a sibling child when another child's saved requester is refused"). Shutdown or a changed requester chat still stops recovery for every child.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…ccess (#203479)

Related: #203466, #198905

When the Gateway restarts while a parent chat still owes a subagent result, restart recovery rebinds the result so that the parent chat is woken to receive it. Since #203466, a parent chat with no recorded owner wakes with the System write baseline, so an admin requester can lose admin after a restart. A parent chat whose owner profile has no current role-based grant (for example, someone who connected with a device token) fails recovery completely: the log shows "Session principal has no current run authority", and the child result is not delivered.

After a restart, the woken settlement turn has the access of the person who spawned the subagent, checked against current policy: an owner keeps admin, a writer gets write and never admin. The child result is delivered. Subagent runs started before this change keep the earlier behavior (the session owner's access, else the System write baseline, never admin).

Subagent spawn now saves the requester's operator recovery source (`requesterOperatorSource`) on the subagent run. This is the same bounded codec and the same capture (`captureQueuedOperatorRecoverySource`) that queued inputs use. Unavailable sources are not stored. At restart, `recoverRequesterCompletionCustody` re-admits that source through `restoreGatewayQueuedOperatorRecovery`, the one admission that queued work also uses. The woken turn's own admission still checks session access when it starts. A refused source leaves the result unbound, as any failed recovery does.

Storage (schema change approved by Ayaan): one optional property inside the existing `subagent_runs.payload_json`. No table, column, index, schema version or backfill. Older builds ignore the property and use their own fallback (`docs/reference/database-schemas/storage-changes.md` has the entry).

- `session-restart-resume-custody.test.ts`, "wakes the parent with the saved owner/writer requester's scopes after a restart". These tests drive restart store discovery and custody recovery, then settle the interrupted child through the real lifecycle controller.
  - Base `e9f29990130b`: red. Recovery fails with "Session principal has no current run authority", and the result is not delivered.
  - Head: green. The owner wakes with `operator.admin`. The writer wakes with `operator.write` and without admin. The result is delivered (`delivery.status === "delivered"`).
- Older rows: "delivers a restored ... child's owed notice after its legacy profile/unattributed requester settled" (session owner, else `[operator.write]`).
- Spawn: `subagent-registry.requester-source.test.ts`. `registerSubagentRun` persists the requester's `gateway` source in the SQLite row.
- Touched and importer tests: 17 files, 226 tests pass.

Production code grows by about 25 lines: one capture at spawn and per-child re-admission at restart. This is the approved stored-source design. It removes the single session-principal admission that every restored child shared.

Each restored child re-admits its own saved requester. A refused source (for example, a revoked device) is logged and leaves only that child unbound. Its siblings are still recovered and resumed (test: "recovers a sibling child when another child's saved requester is refused"). Shutdown or a changed requester chat still stops recovery for every child.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 450441b)

Release adaptation: restore through the stable queued-source API without the newer agentId parameter; keep stable restart-store discovery proof and omit main-only restart-scope cases because stable has no restart-scope classifier. Carry upstream least-privilege System write fallback. #203521 deliberately does not turn completion custody into a fresh chat grant check. #203222 settlement already staged; later parent-history redesign is not a prerequisite.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit b3231a69dd6ead5d34ee7cba31b58aaaea29308a)
tideclaw-bot added a commit that referenced this pull request Nov 24, 2026
Release adaptation for #203479: stable recovery fixture releases its live authority before returning; exercise the persisted snapshot instead of recapturing a released handle. Spawn persistence has its own owning-boundary regression.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 6f3cc9de265f8a8a0c062bf95bd67fee234a2a58)
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 P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant