Skip to content

fix(agents): release requester wake reservations and preparation capacity after restarts - #182285

Merged
steipete merged 2 commits into
mainfrom
steipete/requester-mailbox-after-restart
Oct 24, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/requester-mailbox-after-restart

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

After Gateway restarts, yielded fleet parents could stay asleep forever even though their children had finished or been interrupted. In live stress runs on main d355f2f (12 fleets per Gateway, Gateway killed -9 at +60 s and +240 s), 2/12 embedded and 5/12 Codex-runtime parents never merged anything; 40+ minutes later they were still idle. Durable state showed three shapes:

  • the requester's cohort wake sitting queued in session_pending_inputs and never consumed, accepted 8 minutes after the last boot;
  • parents that yielded before the kill, whose interrupted children's completions never woke them;
  • Codex parents whose settle wake was never enqueued after recovery.

User Impact

Yielded parents can resume after Gateway restarts when their child completions are ready. FIFO order and exactly-once delivery are unchanged, with no new timers or configuration.

Why This Change Was Made

Root cause

Two coupled defects in the subagent registry lifecycle:

  1. Leaked reservation. When a wave's requester wake settled quietly, the wake was cleared, but a restored, unbound mailbox reservation for it was never retired. FIFO dispatch (session-controller.mailbox-dispatch.ts) then waited indefinitely on that preparing head (subagent-announce.requester-settle-wake.ts).
  2. Circular wait on preparation capacity. runBackgroundWork held the background preparation slot until a delivery fully finished (subagent-registry-lifecycle.ts). After a restart, accepted deliveries held every slot while waiting in the requester's FIFO behind earlier reservations, and those earlier reservations needed the same slots to prepare (cleanup in subagent-registry-lifecycle-cleanup.ts, wake preparation in subagent-registry-lifecycle-wake.ts). Neither side could progress. Embedded and Codex parents share this owner.

Fix

  • Capture the exact controller inputs before quiet settlement erases their identity, and retire them after acknowledged publication. Claimed turns keep their owner.
  • Release preparation capacity when a delivery is accepted; delivery settlement stays with the existing lifecycle owner.

FIFO order and exactly-once delivery are unchanged, with no new timers or configuration. docs/concepts/subagent-yield-handoff.md and docs/tools/subagents/operations.md are updated.

Evidence

  • Three regressions in subagent-registry.requester-wake.e2e.test.ts (via subagent-registry.requester-wake-settlement.test-support.ts): a yielded cohort dispatched once after a second restart retires an already-delivered wave, and a restored cohort and a restored individual each drained before later cohorts when registry order differs. All three time out (120 s, the deadlock) on base, both on d355f2f and on today's main 7c374d4, and pass twice with the fix. Also green: lifecycle (234, twice), completion replay (3, twice), main-session recovery (193), subagent recovery (85), spawn (32) and mailbox (29).
  • Live on a Crabbox AWS host with real OpenAI models: the stalls above were observed on main d355f2f (embedded 2/12, Codex 5/12; a first version of this branch still stalled 3/12 and 8/12, which led to the capacity fix). On a later main (4f2b1be) two A/B runs (8 and 12 fleets per Gateway, kills at +60/+240 s and +60/+150 s) completed 100% on both main and this branch (80/80 and 80/80 fleets, 0 lane errors). The race window didn't recur there, so the deterministic regressions above are the proof that the deadlock still exists on main and is fixed here.

Release restored requester-settle reservations after their durable wave
settlement is acknowledged so later yielded cohorts can dispatch in FIFO order.
Capture exact input identities before settlement clears frozen batch membership,
preserve them across publication retries, and leave claimed turns with their owner.

Add a two-restart registry/controller regression and document the ownership
contract. The regression fails on the base and passes twice with the fix;
focused requester-settle, restart recovery, mailbox, and spawn checks pass.
Restored child deliveries could exhaust the shared preparation budget while
waiting behind earlier FIFO sources that needed the same budget to prepare.
This left yielded parents with queued or never-enqueued completion wakes.

Release preparation capacity when the Gateway accepts a delivery, including
execution-start replays, while retaining its result under the existing lifecycle
owner until settlement. Keep the concurrency bound, FIFO, and idempotency intact.

Cover restored cohort and individual completions whose creation order differs
from completion order. Both cases time out on the parent commit and pass twice
with this change. Model acceptance in the test adapter before its mailbox wait.
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review October 24, 2026 05:57
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T05:59:45.934383Z 904293f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Oct 24, 2026
@steipete
steipete enabled auto-merge (squash) October 24, 2026 06:07
@steipete
steipete merged commit 5d47168 into main Oct 24, 2026
202 of 203 checks passed
@steipete
steipete deleted the steipete/requester-mailbox-after-restart branch October 24, 2026 06:08
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 25, 2026
Absorb openclaw/openclaw main at 9629838
(967 commits past 7ab6453) into P ea81534. 39 textual conflicts,
resolved upstream-first; every ours/combined resolution keeps a continuation
or carried-fleet symbol and is listed with its reason in the lane's
table.tsv / RESOLUTION.md.

Schema: upstream took agent schema 32-34 (PostgreSQL-only vector decoder,
binary vector projection, index ordering; SQLite advances metadata only) and
state 32. The continuation recipient-authority step moves from 32 to 35,
above upstream's steps; on SQLite a P-era 32 database is upstream's 32 plus
the authority table, which the idempotent step admits.

Ports into upstream's new owners:
- agent-runner-result-complete.ts deleted upstream (openclaw#181917, inlined into
  agent-runner-result.ts); the continuation delta moves onto the inlined block.
- subagent registry activation returns AgentRecoveryProgress (openclaw#181428); the
  continuation activation latch follows progress.settled.
- announce reply-instruction / params moved by the fork receive upstream's
  requesterOrigin (openclaw#182124) and onAccepted (openclaw#182285).
- diagnostic trace context moved to the shared AsyncContext carrier (openclaw#181780);
  the fork's test reset clears only its own field.

Generated files regenerated with their generators (postgres schema, config
doc baseline).

Refs karmaterminal/openclaw-bootstrap#1727

Co-Authored-By: Claude Opus 5.5 <[email protected]>
steipete added a commit that referenced this pull request Oct 25, 2026
#182285 changed the restored requester-settle budget to cover delivery
preparation only until the Gateway accepts the input, documented in the
subagent yield handoff and operations docs. The Gateway e2e still asserted
the earlier contract that at most two restored wakes reach the model at
once, so all three arrived together and it failed deterministically on main.

Assert the documented contract instead: every restored wake proceeds once
earlier wakes are accepted, a live turn is not delayed behind them, and all
requesters settle after release. The two-slot preparation bound stays
covered by the registry persistence and lifecycle tests.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…city after restarts (openclaw#182285)

* fix(agents): release settled requester wake reservations

Release restored requester-settle reservations after their durable wave
settlement is acknowledged so later yielded cohorts can dispatch in FIFO order.
Capture exact input identities before settlement clears frozen batch membership,
preserve them across publication retries, and leave claimed turns with their owner.

Add a two-restart registry/controller regression and document the ownership
contract. The regression fails on the base and passes twice with the fix;
focused requester-settle, restart recovery, mailbox, and spawn checks pass.

* fix(agents): release recovery capacity on delivery admission

Restored child deliveries could exhaust the shared preparation budget while
waiting behind earlier FIFO sources that needed the same budget to prepare.
This left yielded parents with queued or never-enqueued completion wakes.

Release preparation capacity when the Gateway accepts a delivery, including
execution-start replays, while retaining its result under the existing lifecycle
owner until settlement. Keep the concurrency bound, FIFO, and idempotency intact.

Cover restored cohort and individual completions whose creation order differs
from completion order. Both cases time out on the parent commit and pass twice
with this change. Model acceptance in the test adapter before its mailbox wait.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
openclaw#182285 changed the restored requester-settle budget to cover delivery
preparation only until the Gateway accepts the input, documented in the
subagent yield handoff and operations docs. The Gateway e2e still asserted
the earlier contract that at most two restored wakes reach the model at
once, so all three arrived together and it failed deterministically on main.

Assert the documented contract instead: every restored wake proceeds once
earlier wakes are accepted, a live turn is not delayed behind them, and all
requesters settle after release. The two-slot preparation bound stays
covered by the registry persistence and lifecycle tests.
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 size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant