Skip to content

test(agents): inline child follow-up cases fail intermittently when the registry wait lands during teardown - #183244

Merged
steipete merged 1 commit into
mainfrom
fix/inline-child-followup-registry-wait
Oct 25, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/inline-child-followup-registry-wait

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: the inline child follow-up cases in openclaw-tools.sessions-send-child-coordination.test.ts fail intermittently in the Linux Bun shard core-runtime-infra-storage-state-hosted-10 when the runner is loaded. This blocked #183052 twice: (timeout) failed with Subagent terminal execution changed, then (ok) failed with Subagent lifecycle event lost its original run.

User Impact

No user-visible change; this is a test-only change. CI stops failing these cases at random, and the cases now deterministically cover the registry seeing a child's ending after the requester has already consumed the result inline.

Why This Change Was Made

The fixture's agent.wait mock answered every wait for the child run. That included the registry's own background completion wait, which holds no Gateway root work while its RPC is pending. In the ok case the mock also wrote the final reply again and emitted a second lifecycle end for that call. Under load, that second observation could land after the test's settleSessionWork() returned. It then raced resetSubagentRegistryForTests(), which deletes the row. The in-flight completion or lifecycle listener rejected its root, and observeRootWork reported that rejection as a test failure.

Production already tolerates this ordering: waitForSubagentCompletion and completeSubagentRunWithRecovery return quietly once their owner is gone. So the fix is in the fixture, using the pattern the queued-followup cases in this file already use. The registry wait (any wait whose timeoutMs is not the inline 1000) is held on a deferred:

  • error and timeout: the wait is released after the inline result is consumed, and the test waits for cleanupCompletedAt before settling. The registry's own observation is still exercised, now in a fixed order.
  • ok: the lifecycle event already ended the child, so the redundant wait is released after teardown, where it finds no row and returns.

#183052 is unrelated. Its production code was identical between the passing and failing heads; the extra load in the shard only widened the timing window.

Evidence

  • Reproduced locally. Pure CPU stress (30 busy loops, inline cases ×15) did not reproduce the failure. I then added random 0–40 ms delays at existing await points (registry mutation after predecessors, terminal completion lock, after waitForAgentRun, listener after terminal observation). With the original fixture that reproduced 7/45 and 8/45 failures under Bun. Instrumentation showed the row deleted by the reset's publishRows, and the subagent-wait completion starting after the test had settled.
  • Fixed under the same delays: 51/51, with zero ownership-check rejections logged, including swallowed ones. Every error and timeout case completed exactly once through subagent-wait; ok completed through lifecycle-completed-event.
  • Plain Bun, after removing the instrumentation: 72/72 for the full file with the inline cases ×15 under 30 busy loops, then 30/30 under Bun and 30/30 under Node for the committed file.
  • Lint and review: oxfmt and the type-aware oxlint core shard pass. Codex autoreview (P2) came back scoped-clean.

The inline child follow-up fixture answered every agent.wait for the child run,
including the registry's own background completion wait. That wait holds no
Gateway root work while pending, so under CI load its completion (and, in the ok
case, a second lifecycle end) could land after the test settled and race
resetSubagentRegistryForTests deleting the row. The rejected root then failed the
case with "Subagent terminal execution changed" or "Subagent lifecycle event lost
its original run".

Hold the registry wait on a deferred: error and timeout release it after the
inline result is consumed and wait for cleanup, so the registry's observation is
still exercised deterministically; ok releases it after teardown because its
lifecycle event already ended the child.
@clawsweeper

clawsweeper Bot commented Oct 25, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T04:27:28.823543Z f8199f8 PR opened
ℹ️ 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 agents Agent runtime and tooling size: XS labels Oct 25, 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. 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 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 Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR controls the registry’s background wait separately from the inline requester wait in child follow-up tests.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported fixture repair with preserved regression coverage; validation consists of reported test executions and CI rather than shipped-entry-point proof.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored fixture repair changes no shipped behavior; the supplied validation exercises the affected test file under delayed completion, Bun stress, and Node, supported by successful exact-head CI.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes · Fix scope: Complete
User problem: Intermittent child-coordination fixture failures block otherwise unrelated CI work.
Reason: The maintainer-authored direction is established, and the patch repairs a specific scheduling defect without changing runtime behavior or weakening assertions.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR makes a demonstrated fixture race deterministic while preserving the cleanup regression coverage; no actionable defect was found.

Priority: P2
Reviewed head: f8199f86b2078ba7d043bf9e863fc1f9eca5b611

Before merge

None.

Findings

None.

Agent review details

How this fits together

The sessions-send coordination suite exercises native child completion through real registry and persistence owners with mocked Gateway responses, checking inline results, cleanup, and requester delivery.

flowchart TD
  A[Coordination test] --> B[Sessions send tool]
  B --> C[Inline requester wait]
  B --> D[Subagent registry]
  D --> E[Background completion wait]
  A --> F[Deferred Gateway fixture]
  C --> F
  E --> F
  D --> G[Cleanup and delivery assertions]
Loading

Technical review

Best possible solution:

Keep the existing fixture and registry owners, explicitly order their waits, and retain cleanup assertions for all three terminal outcomes.

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

Source confirms that the original fixture answers both waits and can emit duplicate lifecycle endings; the author reports reproducing teardown failures with injected delays, but this read-only review ran no tests.

Is this the best way to solve the issue?

The patch fixes the fixture’s uncontrolled completion producer using the deferred pattern already present in sibling cases, preserving the original success regression and strengthening error and timeout cleanup coverage.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Inline success, error, and timeout consumption cases keeps the original intent (a8a3680: Preserve durable restart custody and consume inline terminal results without a second requester delivery.)
  • Lifecycle completion before inline acknowledgement and descendant cleanup keeps the original intent (afd591f: Protect against a child remaining an unfinished descendant after its inline result is consumed.)
  • Consolidated follow-up fixture keeps the original intent (3908f5c: Consolidate repeated fixtures while preserving production behavior and distinct regression assertions.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit a8a3680 adds src/agents/openclaw-tools.sessions-send-child-coordination.test.ts:589 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a8a3680f3749; files: src/agents/openclaw-tools.sessions-send-child-coordination.test.ts)
  • Josh Lehman: Raw commit afd591f adds src/agents/openclaw-tools.sessions-send-child-coordination.test.ts:585 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: afd591f79f7f; files: src/agents/openclaw-tools.sessions-send-child-coordination.test.ts)

PR surface

Tests +18. Total +18 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 31 13 +18
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 31 13 +18

Labels

Label changes:

  • add P2: Repeated fixture failures blocked unrelated CI work; this focused repair improves validation reliability without changing production behavior.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Repeated fixture failures blocked unrelated CI work; this focused repair improves validation reliability without changing production behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • 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.

Reviewed October 25, 2026, 12:39 AM ET / 04:39 UTC.

@steipete
steipete merged commit 8bf4026 into main Oct 25, 2026
119 of 120 checks passed
@steipete
steipete deleted the fix/inline-child-followup-registry-wait branch October 25, 2026 20:21
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…openclaw#183244)

The inline child follow-up fixture answered every agent.wait for the child run,
including the registry's own background completion wait. That wait holds no
Gateway root work while pending, so under CI load its completion (and, in the ok
case, a second lifecycle end) could land after the test settled and race
resetSubagentRegistryForTests deleting the row. The rejected root then failed the
case with "Subagent terminal execution changed" or "Subagent lifecycle event lost
its original run".

Hold the registry wait on a deferred: error and timeout release it after the
inline result is consumed and wait for cleanup, so the registry's observation is
still exercised deterministically; ok releases it after teardown because its
lifecycle event already ended the child.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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