Skip to content

fix: keep I/O responsive during queued session writes - #146491

Merged
steipete merged 4 commits into
mainfrom
codex/swarm-writer-fairness
Sep 13, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/swarm-writer-fairness

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Related: #130741

What Problem This Solves

Ready session writes can drain as an uninterrupted microtask backlog, delaying Gateway I/O even after each individual write has finished.

User Impact

I/O gets a turn while queued writes remain pending. Writes keep their FIFO order, and an active write retains ownership until it settles.

Why This Change Was Made

The existing queue now yields between completed writers after four completions or four milliseconds. Idle and explicitly reentrant writes still start immediately, and queued callbacks retain their caller context and exact results or rejection values.

Evidence

The four fairness regressions fail on the main implementation because all queued writes finish before the I/O turn. 61 focused tests passed across queue, SQLite diagnostics, and session lifecycle coverage, including ordering, caller context, rejection, cancellation, and bulk identity locks. This change does not establish the full Swarm latency target.

Canonical changed gates pass on the refreshed base. The full Telegram bot test file also passes (167 tests); its debounce fixtures now await their existing deferred-work promises before checking completed replies, preserving every timer boundary and message assertion.

Earlier CI hit the Gateway profile lifetime fixture's 120-second timeout. This branch now inherits main's fresh-handler-factory repair from #146390, keeping that test change out of the writer slice. The original timeout was not reproduced locally, and replacement-head CI remains required. No timeout or assertion was relaxed.

CI also exposed an intermittent compiler-launch ETXTBSY failure in the test fixture. A controlled Linux comparison reproduced Node 24.19's recursive copy leaking a writable descriptor into a concurrently spawned process. The fixture now uses the documented filter option, selecting libuv's close-on-exec copy path. Complete copying and the existing compiler launch remain unchanged.

The unchanged TypeScript compiler failed while the inherited descriptor remained open, then ran after it closed. With the filtered copy it ran while the other process remained alive. All 19 real-compiler tests, the fixture's complete changed gate, and fresh independent P1 review pass. This proves the mechanism and prevention; the holder in the original CI run was not identified. Exact final-head CI remains required.

The next CI run stopped during a Matrix binary download connection reset and exposed a separate Signal test race. After closing its listener, that test assumed the released port remained free. A controlled TCP competitor reproduced the assumption's failure. The positive probe now lets the kernel allocate its port; occupied-port refusal, error guidance and listener cleanup stay intact. This changes only the fixture, not operator Signal configuration. All 10 daemon tests and four port-probe siblings pass (one existing alternate-loopback case skips on this host), with full changed checks and fresh P1 review. The failed run remains recorded; validation proceeds on the corrected head.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 21:28
@clawsweeper

clawsweeper Bot commented Sep 12, 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.

@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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 11:13 PM ET / September 13, 2026, 03:13 UTC (Revision 7).

ClawSweeper review

What this changes

The PR gives I/O opportunities between queued session writes and updates completion-sensitive, compiler-copy, and port-probe test fixtures.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main still permits uninterrupted ready-write backlogs. No introduced correctness or security defect was found, and the latest Signal fixture correction preserves the meaningful assertions.

Priority: P2
Reviewed head: 021b9f75759c80ab14fa6c6b334cb5e563413c39

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no actionable introduced defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies maintainer authorship, so the external-contributor proof gate does not apply. Queue regressions support bounded scheduling; reported native-copy and TCP experiments cover the fixture repairs, while historical Swarm media does not establish current latency.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies maintainer authorship, so the external-contributor proof gate does not apply. Queue regressions support bounded scheduling; reported native-copy and TCP experiments cover the fixture repairs, while historical Swarm media does not establish current latency.
Evidence reviewed 10 items Introduced scheduling change: The complete merge-base-to-head patch changes the existing drain. It retains drain ownership during setImmediate, settles each writer before yielding, and preserves the async wrapper that converts synchronous callback failures into rejected promises.
Still needed on current main: Direct inspection of the fetched main revision shows the drain still loops through ready writers without an event-loop yield; the fairness change is absent.
Latest release comparison: GitHub contents inspection at v2026.9.4 also shows the uninterrupted drain. The local release object was unavailable, so the released source was inspected through GitHub instead.
Findings None None.
Security None None.

How this fits together

The shared writer queue serializes session storage and lifecycle operations within a process. Its scheduling determines when waiting writes execute and when the Gateway event loop can service I/O.

flowchart TD
  A[Session and lifecycle operations] --> B[Per-store FIFO queue]
  B --> C[Run writer in caller context]
  C --> D[Settle result or failure]
  D --> E{Backlog and turn budget reached?}
  E -->|Yes| F[Give event loop an I/O turn]
  F --> B
  E -->|No| B
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +4, Tests +113. Total +117 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 1 18 14 +4
Tests 5 125 12 +113
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 143 26 +117

Review metrics

None.

Technical review

Best possible solution:

Keep bounded yielding in the existing queue owner while preserving FIFO execution, caller context, exact outcomes, and complete writer settlement.

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

Yes, from source: a blocked writer followed by ready writes drains through microtasks before I/O on current main. The PR provides focused regressions for that mechanism; this review did not execute them.

Is this the best way to solve the issue?

Yes. Yielding between settled writers repairs scheduling at its existing owner without adding another queue, changing public configuration, or interrupting active writes.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded Gateway responsiveness improvement under queued session-write load.
  • 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 supplied repository state identifies maintainer authorship, so the external-contributor proof gate does not apply. Queue regressions support bounded scheduling; reported native-copy and TCP experiments cover the fixture repairs, while historical Swarm media does not establish current latency.

Evidence

What I checked:

  • Introduced scheduling change: The complete merge-base-to-head patch changes the existing drain. It retains drain ownership during setImmediate, settles each writer before yielding, and preserves the async wrapper that converts synchronous callback failures into rejected promises. (src/shared/store-writer-queue.ts:97, 021b9f75759c)
  • Still needed on current main: Direct inspection of the fetched main revision shows the drain still loops through ready writers without an event-loop yield; the fairness change is absent. (src/shared/store-writer-queue.ts:97, bd002c80a15f)
  • Latest release comparison: GitHub contents inspection at v2026.9.4 also shows the uninterrupted drain. The local release object was unavailable, so the released source was inspected through GitHub instead. (src/shared/store-writer-queue.ts, 3a9d69db306c)
  • Regression coverage and caller contracts: Four added fairness cases cover fulfilled writes, rejection including undefined, and expensive writers. Existing tests retain caller context, explicit reentrancy, and nested-write ordering; SQLite diagnostics now observe completion before the successor starts. Tests were inspected, not executed during this read-only review. (src/shared/store-writer-queue.test.ts:60, 021b9f75759c)
  • Latest revision and review continuity: Comparison with the previous reviewed head shows only the Signal available-port probe changed. The occupied-port refusal, actionable error text, and listener cleanup remain intact. The previous completed review retained no findings or published rank-up moves. (extensions/signal/src/daemon.test.ts:83, 021b9f75759c)
  • Dependency signal: The compiler fixture directly calls Node fs.cpSync with an always-true filter, and the PR explicitly attributes its ETXTBSY repair to Node 24.19 copy behavior. This establishes a Node dependency contract; the patch does not depend on the Codex harness. (test/scripts/native-boundary-fixture.ts:32, 021b9f75759c)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • gaoanze888: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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-12T21:36:35.627Z sha ac8acd6 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-12T22:00:15.814Z sha 08c6c8b :: needs maintainer review before merge. :: none
  • reviewed 2026-09-12T22:52:45.635Z sha 932f573c4f3ac061fffb4a2c9317a29835344c99 :: needs changes before merge. :: none
  • reviewed 2026-09-12T23:27:34.321Z sha 40cb04f :: needs changes before merge. :: none
  • reviewed 2026-09-13T00:12:46.367Z sha af1811f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-13T02:31:32.674Z sha 476ed72 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/swarm-writer-fairness branch from 40cb04f to af1811f Compare September 13, 2026 00:06
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed app: web-ui App: web-ui scripts Repository scripts size: M labels Sep 13, 2026
@openclaw-barnacle openclaw-barnacle Bot added the channel: signal Channel integration: signal label Sep 13, 2026
@steipete
steipete merged commit fe55a3a into main Sep 13, 2026
190 of 191 checks passed
@steipete
steipete deleted the codex/swarm-writer-fairness branch September 13, 2026 03:31
@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 13, 2026
* fix: keep I/O responsive during queued session writes

* test(telegram): await debounced dispatch completion

* test: prevent inherited writable compiler descriptors

* test(signal): allocate the available-port probe through the kernel
obviyus added a commit that referenced this pull request Sep 15, 2026
)

## What Problem This Solves
Multiline `/steer` and `/tell` messages lose later lines when incoming command text still contains newlines. A command-only first line returns usage. Closes #146007.

## Why This Change Was Made
Extend the existing argument-preservation policy from goal to steer. Normalized command text has one writer. Match whitespace consistently in the reset reader so a configured `/steer` trigger still resets with newline or tab separators; authorization and anchored payload extraction stay unchanged.

Production: `commands-registry-normalize.ts` +7/-2; `session-reset-command.ts` +2/-1. Tests: `commands-steer.test.ts` +17; `session.test.ts` +39. No new owner or configuration key.
Growth accepted under the owner's standing acceptance (2026-09-15).

## User Impact
Complete instructions reach the active run or normal idle fallback. Configured reset commands keep resetting the conversation with the complete payload.

## Evidence
Raw WebChat `chat.send` reproduced truncation on main `3869ac66de02`. Retained real-Gateway recordings at `26d6274c2d67` passed three active-run and three idle cases with a deterministic provider. Each active case was matched to the original held task, and its complete current instruction was inspected at the provider boundary. Empty usage stayed correct. The Control UI's local steering shortcut removes the command prefix and is a separate path.

The reset regression fails on `26d6274c2d67` for newline and tab delimiters, then passes with this correction. The non-boundary `/steering` case keeps the existing conversation. These tests call `initSessionState` with seeded state and check the reset revision and complete payload.

## Compatibility
No configuration, schema, dependency, or API shape change. Group mention processing and some adapters flatten newlines before normalization; that separate formatting issue is outside this change. Per-channel scope comes from source inspection unless a runtime capture is cited.

## Consumers
Shared text-command callers with newline-preserving ingress, plus configured reset detection during admission and session initialization.

## Invalidation
No cache lifecycle change.

## Tests
The three steering regressions exercise the real command-context builder and registered handler; the retained Gateway proof establishes delivery beyond that boundary. The pinned merge includes main `3869ac66de02`, where 79 focused tests passed before this correction. All 259 tests passed across session initialization, steering, and reset-model suites. After correcting two fixture typing errors, the three seeded-session cases passed again on `d86aebfa4701`. The existing session test file is selected once by the hosted test command.

Historical CI failures have retained timing/compiler-launch evidence and passing focused checks with upstream repairs #148107 and #146491. Historical base/parent reruns and full current hosted CI are not claimed.

| Before | After |
| --- | --- |
| ![Before](https://github.com/user-attachments/assets/0474c4a2-1f19-4be8-b644-68db0c01a0e8) | ![After](https://github.com/user-attachments/assets/0aa13924-364d-4af5-9484-497b2cb9cbd0) |

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
…claw#146009)

## What Problem This Solves
Multiline `/steer` and `/tell` messages lose later lines when incoming command text still contains newlines. A command-only first line returns usage. Closes openclaw#146007.

## Why This Change Was Made
Extend the existing argument-preservation policy from goal to steer. Normalized command text has one writer. Match whitespace consistently in the reset reader so a configured `/steer` trigger still resets with newline or tab separators; authorization and anchored payload extraction stay unchanged.

Production: `commands-registry-normalize.ts` +7/-2; `session-reset-command.ts` +2/-1. Tests: `commands-steer.test.ts` +17; `session.test.ts` +39. No new owner or configuration key.
Growth accepted under the owner's standing acceptance (2026-09-15).

## User Impact
Complete instructions reach the active run or normal idle fallback. Configured reset commands keep resetting the conversation with the complete payload.

## Evidence
Raw WebChat `chat.send` reproduced truncation on main `0da26ff6b4cc`. Retained real-Gateway recordings at `26d6274c2d67` passed three active-run and three idle cases with a deterministic provider. Each active case was matched to the original held task, and its complete current instruction was inspected at the provider boundary. Empty usage stayed correct. The Control UI's local steering shortcut removes the command prefix and is a separate path.

The reset regression fails on `26d6274c2d67` for newline and tab delimiters, then passes with this correction. The non-boundary `/steering` case keeps the existing conversation. These tests call `initSessionState` with seeded state and check the reset revision and complete payload.

## Compatibility
No configuration, schema, dependency, or API shape change. Group mention processing and some adapters flatten newlines before normalization; that separate formatting issue is outside this change. Per-channel scope comes from source inspection unless a runtime capture is cited.

## Consumers
Shared text-command callers with newline-preserving ingress, plus configured reset detection during admission and session initialization.

## Invalidation
No cache lifecycle change.

## Tests
The three steering regressions exercise the real command-context builder and registered handler; the retained Gateway proof establishes delivery beyond that boundary. The pinned merge includes main `0da26ff6b4cc`, where 79 focused tests passed before this correction. All 259 tests passed across session initialization, steering, and reset-model suites. After correcting two fixture typing errors, the three seeded-session cases passed again on `d86aebfa4701`. The existing session test file is selected once by the hosted test command.

Historical CI failures have retained timing/compiler-launch evidence and passing focused checks with upstream repairs openclaw#148107 and openclaw#146491. Historical base/parent reruns and full current hosted CI are not claimed.

| Before | After |
| --- | --- |
| ![Before](https://github.com/user-attachments/assets/0474c4a2-1f19-4be8-b644-68db0c01a0e8) | ![After](https://github.com/user-attachments/assets/0aa13924-364d-4af5-9484-497b2cb9cbd0) |

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: signal Channel integration: signal channel: telegram Channel integration: telegram maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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