Skip to content

fix: Gateway fixture cleanup races participant persistence - #156172

Merged
roboclaw-bot merged 2 commits into
mainfrom
openclaw/fix-gateway-test-write-queue-drain-joining
Sep 23, 2026
Merged

roboclaw-bot merged 2 commits into
mainfrom
openclaw/fix-gateway-test-write-queue-drain-joining

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes Gateway fixture cleanup racing accepted participant writes after a request has finished.

User Impact

No user-visible feature or configuration change. Best-effort participant bookkeeping no longer keeps a completed Gateway request active, while shutdown and test cleanup still join the persistence they own. Schemas, retention, and write authorization are unchanged.

Why This Change Was Made

Request-root completion is not a storage completion signal. Participant persistence remains tracked by its async work scope; fixture retirement now joins the canonical agent writer queue without rejecting pending writes. Directory-scoped cleanup drains only its own stores, keeps their selectors until writes settle, and preserves the existing read-context disposal. The drain lives in test support rather than adding a test-only production export.

Evidence

Observed after-change behavior

Proof is applicable and executed, using isolated Gateway state rather than a live operator deployment. At this PR head, the real SQLite retirement regression passed with these observations:

  1. Hold the canonical agent writer, queue a real participant write, and start fixture retirement.
  2. While that write is blocked, the Gateway root count is 0, and both store selectors still point to the original store.
  3. Release the writer. The persistence result is fulfilled / inserted; retirement then leaves the selector unset and the database absent from the open-handle registry.

The participant lifetime regression separately proves root release while its tracked async scope still waits, for both persistence success and rejection. Its persistence callback is mocked; the retirement regression above uses the real SQLite path.

Latest local execution excerpts:

PASS participant persistence resolves without retaining caller root (65 ms)
PASS participant persistence rejects without retaining caller root (1 ms)
PASS fixture release joins queued participant persistence before deselecting its store (689 ms)

Exact-head CI completed successfully: 144 successful jobs, with 17 skipped jobs excluded from passing proof. The required CI/security gate also completed successfully. CodeQL was neutral, not counted as success.

Regression coverage and static checks

  • Both regression checks failed before the fix: participant work retained a request root after its caller released it; fixture retirement deselected a store with a real participant write still queued.
  • Current integrated candidate: 154 focused tests pass, including the participant regression, Gateway storage-retirement tests, and the larger chat fixture suite.
  • Full agentic-control-plane-agent-chat plan through scripts/ci-run-node-test-shard.mts, default scheduling/forks: 81 files / 1,165 tests pass twice, in 230.79 s and 220.86 s. No timeout increases or worker-policy changes.
  • Earlier focused agent-a/chat/auth-refresh trio: 105 tests pass. Persistence/queue sibling selection: 37 tests pass.
  • New real-write regression measured 0.942 s in the existing Gateway suite; the 12-test fixture file took 13.42 s with one worker. Participant resolve/reject cases took 2 ms / 1 ms. No extra Gateway boot was added per case.
  • Fresh independent review: no actionable P0–P2 findings. Line-cap and dead-export guards pass. The full current-base pnpm check:changed --base 0e79899fedc26ae9a90a196a8bc41b97fd39d7e5 run passed, including all selected typechecks, lint, dead-export scans, and guards. GitHub CI and review remain enforced merge gates.

Local proof ran on Linux/Node 26 in the isolated task worktree. Initial unrelated mock-provider/CLI failures reproduced with ambient host settings: proxying loopback returned HTTP 502, and an inherited Gateway password changed token-only CLI auth-mode classification. The controlled rerun passed all nine affected tests after removing that password only from the test process and setting NO_PROXY/no_proxy to 127.0.0.1,localhost; external proxy settings and authorization checks remain intact. No unrelated production workaround was added.

Worked on by

Work sessions


View the OpenClaw team session

roboclaw-bot and others added 2 commits September 23, 2026 04:35
Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 5e11a06e-7704-46e5-b79b-c0583b263950
@clawsweeper

clawsweeper Bot commented Sep 23, 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 gateway Gateway runtime size: M labels Sep 23, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 23, 2026 04:37
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 23, 2026, 2:12 AM ET / 06:12 UTC (Revision 2).

ClawSweeper review

What this changes

The PR lets background participant recording outlive completed Gateway requests while making test cleanup wait for accepted database writes before releasing their stores.

Merge readiness

✅ Ready for maintainer review

The PR remains useful: current main still retains request roots during participant persistence and lacks the fixture queue joins. The updated evidence resolves the previous proof concern. No actionable correctness or security findings remain.

Priority: P2
Reviewed head: 0f7d8db39f62c49f64f6bfebfc9556905f7aaa1f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant real SQLite boundary proof, supporting CI, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The updated body reports an executed Linux/Node 26 scenario through the real participant SQLite worker and fixture-retirement owners: selectors remain bound while the writer is blocked, persistence finishes as inserted, and retirement then closes the database. Source matches those observations; mocked root-lifetime cases are supplemental. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The updated body reports an executed Linux/Node 26 scenario through the real participant SQLite worker and fixture-retirement owners: selectors remain bound while the writer is blocked, persistence finishes as inserted, and retirement then closes the database. Source matches those observations; mocked root-lifetime cases are supplemental. No stored-data contract changes.
Evidence reviewed 9 items Pinned introduction and merge scope: Reviewed the merge-base-to-head introduced diff. Raw test-merge parents match the pinned base followed by the original PR head; its changes against that base are confined to the introduced paths. Unrelated endpoint drift is not attributed to this PR.
Current main still needs the repair: Fetched main still wraps participant persistence in runWithRetainedGatewayRootWork. Its directory-retirement helper clears store selectors without first joining the canonical agent writer queue.
Request accounting remains separate from persistence ownership: The changed wrapper exits only Gateway request-root accounting. trackAsyncWork remains intact, and the unchanged persistence owner retains FIFO admission, captured database identity, currentness checks, worker execution, and publication. No stored format, permission, or dependency contract changes.
Findings None None.
Security None None.

How this fits together

Gateway participant recording saves who contributed to a session through the agent database writer queue. Request accounting and background-work tracking govern different lifetimes; test fixtures must wait for persistence before closing storage.

flowchart TD
  A[Accepted session input] --> B[Background participant recording]
  B --> C[Request root released]
  B --> D[Tracked async work]
  D --> E[Agent database writer queue]
  E --> F[Participant history persisted]
  G[Fixture cleanup] --> E
  F --> H[Store selectors cleared and database closed]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +76. Total +84 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 4 32 24 +8
Tests 7 124 48 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 156 72 +84

Review metrics

Metric Value Why it matters
Production versus test growth Production net 0 lines; tests and test support net +84 The added code stays in fixture drainage and regression coverage, without adding a test-only production API.

Technical review

Best possible solution:

Keep participant persistence under its async-work owner and retire fixtures only after their canonical writer queues settle.

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

Yes, source provides a high-confidence path: hold participant persistence after request completion, then observe retained roots or retire its fixture while the write remains queued. The contributor reports failing-before regressions; this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. The patch uses the existing async-work and writer-queue owners, preserves persistence checks, and repairs cleanup ordering without changing timeouts, schemas, or user settings.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The updated body reports an executed Linux/Node 26 scenario through the real participant SQLite worker and fixture-retirement owners: selectors remain bound while the writer is blocked, persistence finishes as inserted, and retirement then closes the database. Source matches those observations; mocked root-lifetime cases are supplemental. No stored-data contract changes.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The updated body reports an executed Linux/Node 26 scenario through the real participant SQLite worker and fixture-retirement owners: selectors remain bound while the writer is blocked, persistence finishes as inserted, and retirement then closes the database. Source matches those observations; mocked root-lifetime cases are supplemental. No stored-data contract changes.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded request-lifetime and test-storage cleanup repair with no demonstrated urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The updated body reports an executed Linux/Node 26 scenario through the real participant SQLite worker and fixture-retirement owners: selectors remain bound while the writer is blocked, persistence finishes as inserted, and retirement then closes the database. Source matches those observations; mocked root-lifetime cases are supplemental. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The updated body reports an executed Linux/Node 26 scenario through the real participant SQLite worker and fixture-retirement owners: selectors remain bound while the writer is blocked, persistence finishes as inserted, and retirement then closes the database. Source matches those observations; mocked root-lifetime cases are supplemental. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction and merge scope: Reviewed the merge-base-to-head introduced diff. Raw test-merge parents match the pinned base followed by the original PR head; its changes against that base are confined to the introduced paths. Unrelated endpoint drift is not attributed to this PR. (0f7d8db39f62)
  • Current main still needs the repair: Fetched main still wraps participant persistence in runWithRetainedGatewayRootWork. Its directory-retirement helper clears store selectors without first joining the canonical agent writer queue. (src/sessions/session-participant-recording.ts:17, cb6ef2b3e9ed)
  • Request accounting remains separate from persistence ownership: The changed wrapper exits only Gateway request-root accounting. trackAsyncWork remains intact, and the unchanged persistence owner retains FIFO admission, captured database identity, currentness checks, worker execution, and publication. No stored format, permission, or dependency contract changes. (src/sessions/session-participant-recording.ts:16, 0f7d8db39f62)
  • Real SQLite retirement proof: The supplied body snapshot, sourceRevision decac8102847b83a3c1e456e2b786c7aa69e97d2a5315f0f861428722506ec29, reports execution on Linux/Node 26 at the reviewed head. Source confirms that the scenario holds the real writer, queues recordSessionParticipant through its SQLite worker path, starts retirement, verifies both selectors remain bound, and observes fulfilled/inserted persistence before database retirement. The reported run passed in 689 ms. Separate mocked resolve/reject cases supplement this by checking async-scope ownership after root release. (src/gateway/test-helpers.server-rpc.test.ts:202, 0f7d8db39f62)
  • Review continuity: The earlier completed review recorded no code findings and requested relevant after-change evidence in the main PR body. That body now contains the actual SQLite scenario, observed outcomes, execution excerpts, environment, and focused validation. The contributor's follow-up correctly distinguishes this boundary proof from live operator deployment testing. (0f7d8db39f62)
  • Exact-head CI and read-only validation: GitHub confirms run 35819090116 completed successfully on the reviewed head. The separate gate workflow has a different workflow head and is not treated as execution proof for this patch. git diff --check passed and the checkout remained clean; this review did not execute repository tests. (0f7d8db39f62)

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 (1 earlier review cycle)
  • reviewed 2026-09-23T04:54:32.326Z sha 0f7d8db :: needs real behavior proof before merge. :: none

@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

The main PR body now spells out the observed after-change behavior and links the completed exact-head CI and required CI/security gate. The real SQLite regression keeps both selectors bound while the write is blocked, then observes fulfilled/inserted persistence and database retirement. Separate resolve/reject cases show root count zero while AsyncWorkScope drainage still waits.

Review disposition: the recorded “not applicable” proof classification is incorrect; this is applicable, executed owner-boundary proof, not a claim of live operator-Gateway testing. The durable review itself recognizes the real queued-write coverage, unchanged authority, the bot-published exemption, and no actionable code or security findings. No source change or waiver of enforced checks is needed for that classification discrepancy. Proceeding through the normal native maintainer gates under the existing repair-and-land request.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 23, 2026
@roboclaw-bot
roboclaw-bot merged commit f63d91e into main Sep 23, 2026
305 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/fix-gateway-test-write-queue-drain-joining branch September 23, 2026 06:22
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 23, 2026
* fix(gateway): join participant writes before test cleanup

Co-authored-by: steipete <[email protected]>

* fix: Gateway fixture cleanup races participant persistence

Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 5e11a06e-7704-46e5-b79b-c0583b263950

---------

Co-authored-by: steipete <[email protected]>
(cherry picked from commit f63d91e)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
…156172)

* fix(gateway): join participant writes before test cleanup

Co-authored-by: steipete <[email protected]>

* fix: Gateway fixture cleanup races participant persistence

Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 5e11a06e-7704-46e5-b79b-c0583b263950

---------

Co-authored-by: steipete <[email protected]>
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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