Skip to content

fix: recover child results when restart interrupts requester delivery - #199488

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-restart-announce-custody-20260919
Nov 15, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-restart-announce-custody-20260919

Conversation

@steipete

@steipete steipete commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Related: #198905

What Problem This Solves

Fixes a captured child result being lost when a Gateway restart interrupts the requester’s settle/announce turn before it replies.

User Impact

A retained successful child result is handed back to its requester once after restart, without a duplicate recovery turn or a false “completion agent did not produce a visible reply” outcome. Intentional Stop still ends the obligation. No configuration, database schema, or retention policy changes.

Why This Change Was Made

The shutdown controller already distinguishes restart interruption from Stop, but two consumers discarded that distinction: the announce observer retired its wake, and the input observer sealed a non-retryable Stop receipt. Both now consume the existing typed restart reason. The restart owner recognizes that the surviving settle input owns continuation, so it does not also enqueue a generic recovery turn.

This adds 29 production lines across the existing owners. The growth is needed to recognize the previously missing interrupted-announce state; it adds no cache, state store, schema, or independent lifecycle manager. The lookup uses the existing requester index and exact settle identity. An earlier additional replay flag was removed in favor of correcting the input receipt at its producer.

Evidence

The new real-Gateway graceful-restart regression fails on base 3c6bb67f82aec52a12644933434a9d5ed7e6ed01: the successful child changes from pending to failed and loses its wake. With the fix, graceful shutdown and SIGKILL both preserve one input and produce one completed requester response; a second restart does not duplicate either. The provider is synthetic; the Gateway, SQLite, controller, and process restarts are real.

The native input-owner tests prove that restart reopens the consumed input and retains deduplication, while existing intentional Stop tests remain green. The stopped-child case verifies the parent receives actionable recovery guidance and the child is not independently rerun. The six-minute retention characterization verifies failed session-run rows can expire while suspended rows remain.

Local proof: 11 real custody/yield restart cases, five ordinary restart cases, 16 native input-owner tests, 131 focused sibling tests, and six sweeper lifecycle tests passed. pnpm check:changed passed, followed by a passing changed-file check for the five-line yielded-test fixture correction. Final local Codex autoreview against base 3c6bb67f was scoped-clean through P2, with no accepted/actionable findings. The original parked-message fixture held the now-retained pause-notice model request indefinitely; it now acknowledges that notice while preserving every lifecycle and continuation assertion. Its unchanged version passed on the exact main parent, so this is not being labeled an inherited red.

Synthetic btrfs measurement completed on an isolated 8-CPU / 16-GB VM with Node 24.22.1: 50.82 GiB agent SQLite DB, 10,800 session records, 289,998 transcript rows across 3,820 populated sessions, 4,300 retained runs, and 62,000 workspace files totaling 1.10 GiB. No Team data was used. Transcript generation was bounded after the physical DB exceeded the requested scale; the original logical-text estimate would have exhausted the volume. SQLite quick_check returned ok, then the canonical fixture owner completed retained runs and workspace data.

Five interleaved process pairs, 20 warmups and 20 measured passes per process; each pass classifies 10,800 sessions. Separate allocation sampling used two processes per arm, 1-KiB sampling, including collected allocations. Imports, metadata loading, and workspace I/O are outside owner timing.

Workload Median wall ms Median thread CPU ms Sampled allocated MiB/pass
Interrupted announce, parent baseline 2.506 3.000 4.261
Interrupted announce, fixed owner 5.233 5.000 8.396
Identical baseline A/A control A1 2.468 3.000 4.265
Identical baseline A/A control A2 2.482 3.000 4.252
Ordinary-run baseline 2.685 3.000 not sampled
Ordinary-run candidate 2.628 3.000 not sampled

The fixed owner correctly parks all 2,150 interrupted cohorts; the broken baseline parks none. The added 2.73 ms and approximately 4.14 MiB per all-interrupted pass buy the missing correctness work; this is not a speedup claim. Ordinary-run timing is unchanged within process variation. No scan, new I/O, or new cache was added. The read-only metadata pass left the fixture DB size and modification time unchanged. These numbers characterize the indexed owner, not full Gateway startup.

Final head is 82a92ced7bcd022c14f2fb69a374da360485872f; CI run 43686829245 targets that head. Prior runtime-identical head 7f464028 passed CI run 43682515506 with native watcher GREEN. The sole follow-up aligns the benchmark fixture's lifecycleRunId and lastRunId; its smoke run covered all 2,150 cohorts, changed-file checks passed, and fresh Codex autoreview was scoped-clean through P2. Existing pending-input and legacy-main-session input-handoff compatibility suites additionally passed 16/16. Final-head CI and zero-open-item ClawSweeper review remain required before merge.

Reported live evidence and related investigations

The repository maintainer explicitly requested publication of the following incident evidence and run IDs in this PR. Read-only evidence supplied from Team r333 (5fbdf698), deployed 2026-11-15 04:20Z:

  • Child 73b346e7 completed successfully and its result was captured at 04:16:15Z, pending delivery. Its requester-settle run announce:dashboard:5a1fa3ac…:73b346e7…:yield-1, created 04:16:16Z, ended with Gateway stopped at 04:19:51Z and delivery not_required. After restart the child was suspended with permanent_failure / store replaced.
  • Other captured pending results without a dying announce—f0d74c47, announce:subagent:04ee1ba0, and ae2c7c6f—were delivered at 04:26:21Z. This distinguishes the missing path from fix: deliver retained child results after Gateway restart #198905’s retained-result recovery.
  • Interrupted children c8a0d37f (running 26 minutes), c725603d, and faffe7d7 ended with Gateway stopped. The restart contract intentionally stops child executions and recovers their top-level requester to inspect saved work and issue further instructions. It does not independently resume every child execution. The real restart test proves that visible parent recovery path.
  • Rows b05d48cd, b9e5ac55, 0a4cb605, and faffe7d7 reportedly disappeared within roughly six minutes. The sweeper has an existing five-minute TTL for completed session-run bookkeeping without an archive deadline, while suspended rows have a separate seven-day retention guard. Confirmed killed rows can also retire when their requester obligation settles. These are bookkeeping rows, not a durable audit log. The store replaced reason denotes retired in-memory completion authority and does not by itself prove that a physical database was replaced. Exact historical deletion cannot be attributed from the supplied IDs alone; no retention change is included.

No Team data was copied and no live deployment, restart, or configuration change was performed. This change prevents new restart interruptions from being recorded as intentional Stop; it does not reinterpret old ambiguous Stop receipts.

@clawsweeper

clawsweeper Bot commented Nov 15, 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 scripts Repository scripts agents Agent runtime and tooling size: M labels Nov 15, 2026
@steipete
steipete marked this pull request as ready for review November 15, 2026 05:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T05:49:18.102749Z 7f46402 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.

@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. 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 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserves captured child results when restart interrupts their requester’s delivery turn and prevents a duplicate recovery turn.

Example: Gateway restarts while processing CAPTURED_CUSTODY_RESULT for agent:main:dashboard:restart-hub.

  • Before: The interruption can become a terminal Stop receipt and strand the successful child result.
  • After: The same retained input resumes once and completes delivery without a second generic recovery turn.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused production changes, meaningful restart regressions and passing exact-head CI support the implementation.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A successful delegated result can remain undelivered after Gateway restart interrupts its requester’s response.
Reason: The maintainer-approved direction restores the documented restart-delivery contract through existing owners.

Merge readiness

✅ Ready for maintainer review

Keep open: main still mishandles interrupted requester delivery, and this PR repairs the existing owners without an identified code defect.

Priority: P2
Reviewed head: 82a92ced7bcd022c14f2fb69a374da360485872f

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply a redacted production-boundary recovery trace showing interrupted announce delivery, one resumed reply and no duplicate after another restart.
Agent review details

How this fits together

Subagent completion passes captured results through the requester’s controller mailbox; restart recovery reconstructs pending obligations and admits their continuation under current authority.

flowchart LR
  A[Completed child] --> B[Captured result and wake]
  B --> C[Requester controller input]
  C --> D[Restart interruption receipt]
  D --> E[Fresh restart admission]
  E --> C
  C --> F[Requester reply and delivery receipt]
Loading

Technical review

Best possible solution:

Keep restart interruption retryable at the existing receipt producer and let the existing completion owner resume the same input once.

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

Source exposes the terminal Stop receipt and wake-retirement paths, and the supplied regression reports failure on the exact base; no target code was executed during this review.

Is this the best way to solve the issue?

The patch corrects the recorded cause and reuses exact settle identity, current requester admission and existing replay deduplication without adding a parallel recovery owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Requester input cancellation receipt keeps the original intent (84e555b: Preserve intentional cancellation while allowing the timeout producer to publish its actual terminal outcome.)
  • Announce observer settlement keeps the original intent (36e277d: Centralize session turn, queue and Stop ownership while retaining unfinished durable obligations.)
  • Restart wait classification keeps the original intent (bbf0d73: Preserve reachable yielded requesters while routing stopped descendants through ordinary recovery.)
  • Existing restart regression fixtures keeps the original intent (ad6738d: Exercise retained child results through public sessions, real persistence and repeated Gateway restarts.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced change and current main: The introduced diff changes three existing production owners; fetched main retains their pre-fix behavior, with no changes to these files since the pinned merge base. (src/gateway/agent-turn/agent-run-user-turn.ts:465, 82a92ced7bcd)
  • Existing restart-compatible receipt: The parent already treats cancelled inputs with stopReason=restart as nonfinal; the patch corrects the outcome producer without changing the stored format or reinterpreting historical Stop receipts. (src/config/sessions/session-pending-input-value.ts:33, 3c6bb67f82ae)
  • Continuation ownership: The classifier uses exact requester incarnation and settle identity; startup recovers current completion authority before classification and resumes the retained obligation afterward. (src/agents/subagents/registry/subagent-registry-read.ts:224, 82a92ced7bcd)
  • Earlier finding resolved: The maintainer-authored PR’s follow-up explicitly confirms authorization to publish the incident evidence at this destination; the earlier disclosure finding is cleared.
  • Focused restart regressions: The regression uses public session creation, real Gateway processes, GatewayClient transport and SQLite, then interrupts announce delivery gracefully or with SIGKILL and checks one input, one reply and subsequent restart deduplication. (test/gateway-subagent-completion-restart.e2e.test.ts:322, 82a92ced7bcd)
  • Exact-head CI: The current commit status reports success for CI and applicable security requirements; both check-run pages contain no failed or pending checks. (82a92ced7bcd)

Likely related people:

  • Peter Steinberger: Raw commit bbf0d73 adds src/agents/subagents/registry/subagent-registry-read.ts:201 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bbf0d7380315; files: src/agents/subagents/registry/subagent-registry-read.ts)
  • Vincent Koc: Raw commit 7a168d3 adds src/gateway/agent-turn/agent-run-user-turn.ts:310 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7a168d3d4bdd; files: src/gateway/agent-turn/agent-run-user-turn.ts)
  • Jason (Json): Raw commit 70da467 adds src/gateway/agent-turn/agent-run-user-turn.ts:371 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 70da467c9e49; files: src/gateway/agent-turn/agent-run-user-turn.ts)

PR surface

Source +29, Tests +88, Docs +6, Other +178. Total +301 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 31 2 +29
Tests 4 93 5 +88
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 178 0 +178
Total 9 308 7 +301

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.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Repairs lost child-result delivery when restart interrupts a specific requester continuation.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-15T06:03:38.500Z sha 7f46402 :: blocked before merge. :: [P2] Anonymize private deployment details in the public evidence

Reviewed November 15, 2026, 1:58 AM ET / 06:58 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

Addressing all four open items against final code head 82a92ced7bcd022c14f2fb69a374da360485872f:

  1. Anonymize deployment evidence: the repository maintainer explicitly requested this PR include the supplied live Team evidence and run IDs. That is task-specific approval of both this content and this public PR destination. The body is intentionally limited to the supplied incident sequence, revisions, times, and correlation IDs; no credentials, authentication-bearing URLs, unrelated logs, or copied Team data are present. Please clear this item on that authorization basis. The production change itself is at the input outcome producer and uses the already-owned typed abort reason.

  2. Private operational context: this is the same explicitly approved evidence as item 1, not an additional disclosure. The review found no runtime authorization or supply-chain regression. Fresh requester authority remains unchanged; restart wait classification uses the existing exact settle identity and requester incarnation. Please clear the duplicate security concern on the same task-specific authorization.

  3. Scale characterization: Completed on the synthetic 50.82-GiB btrfs database and 1.10-GiB / 62,000-file workspace described in the updated PR body. The committed owner probe ran five interleaved process pairs with 20 warmups and 20 measured passes. Baseline → candidate per 10,800 sessions: wall 2.506 → 5.233 ms; thread CPU 3.000 → 5.000 ms; separately sampled allocation 4.261 → 8.396 MiB. The candidate parks 2,150 interrupted cohorts, baseline zero. A/A wall medians 2.468 / 2.482 ms, CPU 3.000 / 3.000 ms, allocation 4.265 / 4.252 MiB. Ordinary-run wall medians 2.685 / 2.628 ms. Added correctness work stays below the predeclared 10-ms per-pass bound; no speedup or complete-startup claim. Full method, actual fixture population, and generation adjustment are now in the body.

  4. Data-model compatibility: no stored-data format, schema, migration, reader, or config changed. cancelled/stopReason=restart already existed on the exact parent and was already replayable: parent pending-input rule. This repair corrects which existing outcome the producer records. The native persisted-input regression retains one approved input, records restart, rotates lifecycle generation, reopens that same input, completes it, and reconciles duplicate replay. Its 16-test suite passed. Additional existing compatibility tests (session-actor-memory-pending.test.ts and legacy-main-session-migration.input-handoff.test.ts) passed 16/16, covering interrupted-input replay and legacy handoff migration. The full fixture uses unchanged baseline schema/session producers; the candidate read all 10,800 existing session metadata records through the canonical read-only accessor, with DB size and modification time unchanged across the complete measurement campaign. SQLite quick_check returned ok before fixture completion. No latest-stable package upgrade was run or claimed; the introduced diff does not create the data-model incompatibility alleged by this item. Existing ambiguous Stop receipts remain terminal rather than being reinterpreted.

Inspectable real-Gateway proof is committed in the restart harness: the graceful and SIGKILL branches preserve pending captured results, assert one persisted input and one completed reply after reconstruction, and repeat the restart to assert deduplication again. The provider is synthetic; Gateway, SQLite, controller and process termination are real. Relevant sanitized local test output:

PASS recovers session completion custody through a real Gateway restart (announcing)       25448 ms
PASS recovers session completion custody through a real Gateway restart (announcing-crash) 27877 ms
Native settle-input suite: 16 passed
Existing pending-input / legacy-handoff compatibility suites: 16 passed

The captured/stopped-child case was rerun separately after moving an assertion before its expected bookkeeping retirement; all four custody cases and all seven yielded restart cases passed. The new announcing case fails on exact parent 3c6bb67f, while the fixed cases pass. Final-head CI run 43686829245 targets 82a92ced7bcd. The prior code head passed CI run 43682515506 with native watcher GREEN; the only follow-up aligns the two run-ID fields in the synthetic benchmark, with changed-file checks, a 2,150-cohort smoke run, and a fresh scoped-clean Codex review. Production code is unchanged. No failed-CI exception is requested.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. label Nov 15, 2026
@steipete
steipete merged commit 18e257d into main Nov 15, 2026
147 checks passed
@steipete
steipete deleted the steipete/perf-micro-restart-announce-custody-20260919 branch November 15, 2026 07:04
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant