Skip to content

fix(tests): prevent session-send callbacks from outliving fixtures - #147167

Merged
steipete merged 11 commits into
mainfrom
codex/agent-step-canonical-command-20260912
Sep 21, 2026
Merged

steipete merged 11 commits into
mainfrom
codex/agent-step-canonical-command-20260912

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session-send tests could reset shared fixtures while an accepted background callback was still waiting on an RPC.

User Impact

Test teardown now waits for that work before resetting fixtures. There is no user-visible runtime change.

Why This Change Was Made

The production test-registry cleanup already landed in #155125. This refresh addresses the remaining, independently reproduced fixture-lifetime bug.

Observe the actual returned session-send continuation promises and join them through the existing QA cleanup owner before resetting admission, system events, adjusted tool parameters, and the command mock. The synthetic pending-error run becomes terminal only during cleanup, after its original timeout assertions. Its test stays in the same registration position, using the existing timeout fixture module. The current async mock setter and fresh inline plugin fixtures retain their contracts.

Evidence

  • Baseline: a temporary ordered probe called the real tool through unchanged hooks. The first case admitted one root and held its RPC; the next case saw zero roots and an aborted signal while the same continuation promise remained unsettled. The exact failure was prior case continuation must settle before fixture reset: expected false to be true. The diagnostic then released and joined the callback. One probe passed and one failed; 82 original cases were intentionally filtered. All 22 recorded source hashes were restored, with a clean remote worktree/index.
  • Candidate: an external handshake released the held RPC only after real cleanup entered its wait. At that checkpoint the root remained active, the callback and fixture settlement were pending, and the signal was not aborted. The next case began only after the callback settled and the root retired. Both temporary probes passed; neither is added as a permanent test.
  • Existing coverage: all 82 original sessions cases passed with identical names and order, plus 5 AgentStep and 33 child-coordination cases, with no failures or skips.

Measured Linux command costs, including default and JUnit reporters:

Command Passed Wall time
pnpm test src/agents/openclaw-tools.sessions.test.ts --maxWorkers=1 82 23.479 s
pnpm test src/agents/tools/agent-step.test.ts --maxWorkers=1 5 26.222 s
pnpm test src/agents/openclaw-tools.sessions-send-child-coordination.test.ts --maxWorkers=1 33 35.496 s

Fresh managed P2 review found no actionable findings on the exact two-file patch. All 21 selected changed checks passed in 1,668.345 s, including all 25 core-test typechecking groups, all three Knip scans with zero entries, and typed lint with no warnings or errors. These are private development results, not a performance comparison.

Published-head CI passed for 9a8f935bd4314cc5703a110832bb0998d27e4231, testing merge 42f95e4d7a2c30755fa01e2cb57012480b874486 over 06ce6c415dd293f139181085c9518abe5d47ce36. Both changed file blobs match the reviewed candidate and the package/lock resolve fs-safe 0.18.0, matching private proof. Hosted selection passed 82 primary cases and 142 boundary cases; the other 38 sibling cases were not selected and remain private proof. Primary cases totaled 3.965s reported test time, with 75.80s Vitest duration and 80.09s wrapper wall on two CPUs. These are CI costs, not pnpm command timing or a performance comparison. The run finished with 27 successful jobs and 19 skipped jobs; no failures.

The Blacksmith Testbox lifecycle run identifies the environment, not a PR-CI result. Candidate proof binds main 15201542a5356ce563cbaec3c2e0e9847aeffe8c plus the two-file patch to tree d92689552e5bfc5d8bcc703b6ebeb75c9502df70, preserved exactly in commit 9a8f935bd4314cc5703a110832bb0998d27e4231. All 23 recorded source hashes matched before and after proof and after the normal-hook commit; the original af1b7126 PR ancestry is retained. The Testbox is stopped and both temporary source capsules are retired.

The baseline reporting script encountered a parser error after restoring source; its retained logs were reparsed without rerunning the test. Optional runner-portal synchronization timed out after the successful candidate workload; the candidate wrapper exited zero and its downloaded artifacts were verified independently.

Gateway normal release is already protected. Failure-only shared-suite reset isolation remains a separate source-confirmed, unexecuted follow-up outside this primary-suite repair.

Use the canonical lazy command owner instead of a mutable test dependency bag and global publication.

Bind tests to the existing command module and settle returned session-send continuations before fixture cleanup, retaining native failure reporting through the existing QA cleanup owner.
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 13, 2026 15:58
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 13, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 7:30 PM ET / 23:30 UTC (Revision 7).

ClawSweeper review

What this changes

Session-send tests now wait for background callbacks before resetting shared fixtures and explicitly complete the synthetic pending-error run during cleanup.

Merge readiness

✅ Ready for maintainer review

The fixture-lifetime repair remains necessary on current main. The refreshed patch resolves the earlier merge-conflict concern, preserves existing coverage, and has no actionable correctness findings.

Priority: P3
Reviewed head: 9a8f935bd4314cc5703a110832bb0998d27e4231

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused fixture repair with preserved assertions, relevant reported boundary validation, and no identified correctness or security blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: The contributor-proof gate is exempt for this maintainer-authored test-only repair. The supplied Testbox account specifically exercises actual session-send callbacks and fixture cleanup ordering, with before/after observations; no live channel behavior changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The contributor-proof gate is exempt for this maintainer-authored test-only repair. The supplied Testbox account specifically exercises actual session-send callbacks and fixture cleanup ordering, with before/after observations; no live channel behavior changes.
Evidence reviewed 7 items Pinned introduced change: The merge-base-to-head patch changes only session test setup and timeout test support. The observer forwards the original continuation call and retains its returned promise; cleanup joins retained promises before resetting admission, events, adjusted parameters, and the command spy.
Remaining current-main defect: Current main still registers admission and system-event resets without joining session-send continuations. The production reset aborts the restart signal and retires active roots without waiting for their callbacks, supporting the reported fixture-lifetime failure.
Existing cleanup owner preserves failures: The shared cleanup helper awaits each phase in order, continues subsequent cleanup after rejection, and preserves body and cleanup errors. The patch reuses this owner instead of suppressing callback failures.
Findings None None.
Security None None.

How this fits together

Session-send tools can return while background reply handling continues. These test fixtures provide simulated Gateway responses and must remain intact until that background work finishes.

flowchart TD
  A[Session-send test] --> B[Real session-send tool]
  B --> C[Simulated Gateway responses]
  B --> D[Background reply callback]
  D --> E[Observe completion promise]
  E --> F[Join callbacks during cleanup]
  F --> G[Reset shared fixtures]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +100. Total +100 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 154 54 +100
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 154 54 +100

Review metrics

None.

Technical review

Best possible solution:

Keep callback settlement within the existing fixture cleanup lifecycle, preserving production admission behavior and the original test inventory.

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

Yes: hold a session-send background RPC across test completion and observe whether fixture reset precedes callback settlement. Current source supports that failure path, and the body reports a failing ordered probe; this review did not execute it.

Is this the best way to solve the issue?

Yes: observing the original completion promises and joining them through the existing cleanup owner fixes the fixture boundary without adding a production test seam.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This focused test-fixture reliability repair changes no user-facing runtime behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The contributor-proof gate is exempt for this maintainer-authored test-only repair. The supplied Testbox account specifically exercises actual session-send callbacks and fixture cleanup ordering, with before/after observations; no live channel behavior changes.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head patch changes only session test setup and timeout test support. The observer forwards the original continuation call and retains its returned promise; cleanup joins retained promises before resetting admission, events, adjusted parameters, and the command spy. (src/agents/openclaw-tools.sessions-timeout.test-support.ts:21, 9a8f935bd431)
  • Remaining current-main defect: Current main still registers admission and system-event resets without joining session-send continuations. The production reset aborts the restart signal and retires active roots without waiting for their callbacks, supporting the reported fixture-lifetime failure. (src/agents/openclaw-tools.sessions.test.ts:279, 23eb2a6f01a7)
  • Existing cleanup owner preserves failures: The shared cleanup helper awaits each phase in order, continues subsequent cleanup after rejection, and preserves body and cleanup errors. The patch reuses this owner instead of suppressing callback failures. (test/helpers/qa-gateway-cleanup.ts:5, 9a8f935bd431)
  • Earlier conflict concern resolved: The inspected test-merge commit records exactly the pinned base followed by the reviewed head as parents. Its result changes only the same two test files; the earlier review's conflict warning does not remain a blocker for this recorded merge candidate. (42f95e4d7a2c)
  • Merged related work covers a different responsibility: GitHub confirms refactor: remove agent-step test registry #155125 merged at 2026-09-21T20:23:48Z. It removes the production AgentStep test registry; the remaining callback-joining repair is distinct. Commit metadata and its test-support patch also establish steipete as a relevant recent area contributor beyond this proposed branch. (src/agents/tools/agent-step.test-support.ts:12, 24b9d0f49d37)
  • Captured validation evidence: The supplied PR body reports an ordered actual-tool baseline failure and an after-fix handshake that holds the RPC until cleanup waits, then observes callback settlement before the next case. It reports all 82 original session cases, 5 AgentStep cases, and 33 child-coordination cases passing. The declared candidate tree d92689552e5bfc5d8bcc703b6ebeb75c9502df70 matches the inspected head tree. These are contributor-reported results, not tests executed during this review. (9a8f935bd431)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-13T16:06:00.400Z sha a8265e9 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-14T23:35:51.513Z sha 436af2d :: blocked before merge. :: none
  • reviewed 2026-09-15T14:36:45.645Z sha 644f736 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T09:57:14.115Z sha 1b0e129 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T01:16:10.039Z sha c2eda4d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-18T09:15:14.831Z sha af1b712 :: blocked before merge. :: none

Merge current main and bind session-send test cleanup to its detached continuation owner. Retain the late-reply variants and pending-callback regression.
Merge current main while retaining canonical agent-step dispatch and owned continuation cleanup. Preserve notification, steering, followup, and late-reply test cases.
Merge the pinned main changes while preserving canonical command mocks and
completing the pending-run fixture before its continuation cleanup.
Merge pinned main 7034b4a to inherit the QA fixture fix that preserves
native process hooks. Keep the reviewed AgentStep command forwarding
and continuation-cleanup changes unchanged.
Merge pinned main 4bba146 to inherit the canonical emoji dependency,
alias and yield fixture fixes, and archive-read ownership repair.
Preserve the reviewed AgentStep command forwarding and continuation
cleanup changes, with the required-close retention invariant documented.
Keep the complete sessions case inventory and original import/setup order.
Construct the two-channel fixture through its pure sibling factory while
leaving registry activation at the existing beforeEach boundary.
Merge pinned main 9a44681 to inherit the canonical UI startup-budget,
skill bounded-read, and cold native-fixture dependency fixes.
Preserve AgentStep command ownership and the complete sessions registry
case inventory with its extracted pure fixture factory.
Merge pinned main 448b774 while preserving canonical AgentStep command
ownership and the extracted fresh-per-test registry factory.
Compose the full child, peer, and Cron late-reply matrix with tracked
continuation settlement and ordered fixture cleanup.
Retain the real A2A completion promises until fixture cleanup can join them,
then reset admission, system events, adjusted tool parameters, and the command
spy. Finish the synthetic pending-error run during cleanup after its timeout
assertions. Keep all 82 sessions cases in their original registration order.

The production registry cleanup landed in #155125. This commit preserves the
original #147167 ancestry and addresses its remaining primary-suite lifetime
bug through the existing test fixture owners.

Proof: the actual-tool baseline exposed an unsettled callback after fixture
reset. The candidate handshake passed, as did all 82 original sessions cases,
5 AgentStep cases, and 33 child-coordination cases. All 21 selected checks,
including all 25 core-test type graphs, passed on Blacksmith Testbox. Fresh
Codex P2 review found no actionable findings.
@steipete
steipete requested review from a team as code owners September 21, 2026 23:19
@steipete steipete changed the title refactor(agents): remove agent-step test dependency seam fix(tests): prevent session-send callbacks from outliving fixtures Sep 21, 2026
@steipete
steipete merged commit a3815a8 into main Sep 21, 2026
110 of 112 checks passed
@steipete
steipete deleted the codex/agent-step-canonical-command-20260912 branch September 21, 2026 23:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…penclaw#147167)

* refactor(agents): remove agent-step test dependency seam

Use the canonical lazy command owner instead of a mutable test dependency bag and global publication.

Bind tests to the existing command module and settle returned session-send continuations before fixture cleanup, retaining native failure reporting through the existing QA cleanup owner.

* test(sessions): extract registry fixture owner

Keep the complete sessions case inventory and original import/setup order.
Construct the two-channel fixture through its pure sibling factory while
leaving registry activation at the existing beforeEach boundary.

* test(agents): use command mock for child coordination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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