Skip to content

fix(worker-runtime): reserve a class-0 lane for access checks - #199564

Merged
obviyus merged 1 commit into
mainfrom
fix/worker-reserved-point-read-lane
Nov 15, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/worker-reserved-point-read-lane

Conversation

@obviyus

@obviyus obviyus commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Access checks read session facts through the shared session store worker pool. Bulk reads use the same pool. When bulk reads filled the pool's pending cap (128 tasks), the pool refused the access check with worker task capacity reached. The Gateway then failed the request with SessionMutationFactsUnavailableError.

One production Gateway logged 2,455 of these refusals in one episode on 2026-11-11 (sessions.messages.subscribe, sessions.viewers.set, progressCard.get, artifacts.download, Web Push authority and others). The requests also waited up to about 20 minutes before the refusal.

The pool had one FIFO queue and one cap. It had no caller class.

Fix

The worker pool core now has two lanes:

  • Class 0 (pointRead: true): access checks and other point reads.
    • The pending caps never refuse it.
    • It queues ahead of all queued bulk work, in its own arrival order.
    • It does not wait for a shared compute permit.
    • It can use one worker above the bulk worker limit. Bulk work cannot use that worker.
    • Its input must carry every fact it needs. The pool refuses a point read that asks for host callbacks (onRequest or onRequestSync).
  • Everything else: no change.

The session access fact reads use class 0: the store inventory read, the store target read and the exact entry read in prepareSessionMutationFacts. These reads already sent no host callbacks. The access check therefore no longer has an overload refusal path.

Small related changes:

  • The session history request runner takes { timeoutMs, pointRead } as one options object instead of a positional timeoutMs.
  • The pointRead field never goes to the worker. The transport removes it before it sends the request.

This is step 1 of the runtime design (E2): a reserved class-0 lane. It does not add more classes or change other pools.

Proof

Check Tier Base (33a1413e7be4) Head
New: access check after 128 bulk reads fill the session store pool (session-sharing-preparation.test.ts) vitest-source Fails: SessionMutationFactsUnavailableError caused by worker task capacity reached [task=sessionTranscript.session-target-inventory pool pending tasks: pendingTasks=128 maxPendingTasks=128] Passes in 674 ms; the pool call has pointRead: true
New: point reads run on the reserved worker, ahead of queued bulk work, while the pool is full (worker-task-pool.preparation.test.ts) vitest-source Fails: worker task capacity reached [... pendingTasks=2 maxPendingTasks=2] Passes
New: a point read that asks for host callbacks is refused vitest-source Fails (the read runs) Passes
27 affected test files: worker pool, worker runtime, session entry reads, store target inventory, session sharing, compaction source, startup vitest-source — 380 tests pass
pnpm tsgo:core, pnpm check:test-types, pnpm tsgo:scripts, oxlint, oxfmt typecheck / lint — Pass
Real Gateway, 32 clients, 1,000 access checks on uncached session keys plus 100 sessions.list reads source (ocx src) 0 capacity refusals, 929 correct unknown session answers, 72 server is busy 0 capacity refusals, 932 correct answers, 69 + 6 server is busy
Real Gateway from dist/ on Node, 200 access checks dist (after ocx build --dts) — 200 correct answers, 0 capacity refusals
ocx build --dts, then npm pack with the bundled channel entry smoke full — Pass

Note about the real Gateway run: the Gateway request admission refuses extra RPCs (server is busy) before they can fill the session store pool. So RPC load alone does not reproduce the refusal on base. In production, internal work filled the pool. The run shows that the head has no regression on the real Gateway. The vitest proof shows the fix.

Known unrelated failure: src/config/sessions/session-transcript-worker-lanes.test.ts ("releases pressure subscriptions after native settlement and rearms reopened lanes") fails and then hangs on the base too.

Net lines

git diff --stat origin/main...HEAD: 17 files, +151 / −21.

  • Source: +77 / −20.
  • Tests: +74 / −1.

@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.

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Nov 15, 2026
@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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 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

This PR reserves priority admission and one additional worker slot for session access-fact reads.

Example: An access check starts while 128 bulk tasks fill the session-store pool.

  • Before: The pool rejects the check with worker task capacity reached, producing SessionMutationFactsUnavailableError.
  • After: The check bypasses pending caps and runs ahead of queued bulk work using the additional worker capacity.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation and reported regression results support correctness, but the supplied runtime evidence does not exercise the changed saturation behavior.
Proof confidence 🧂 unranked krab (1/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: Session requests fail when background reads exhaust the worker admission budget needed for their access checks.
Reason: The production incident establishes user impact, and collaborator authorship supplies the owner decision for the reserved-lane tradeoff.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a concrete access-check availability failure that remains on main; source review found no actionable correctness defect.

Priority: P1
Reviewed head: 9e406e144415eb41f36fb3621a74306de70191e7

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted logs or terminal output showing an affected Gateway RPC completing while internal bulk work actually saturates the session-store pool.
Agent review details

How this fits together

Gateway access preparation discovers session stores and reads exact membership facts through the shared worker scheduler, then supplies those facts to the existing authorization owner.

flowchart TD
  A[Gateway request] --> B[Session fact preparation]
  B --> C[Priority worker admission]
  D[Bulk reads] --> E[Bounded bulk admission]
  C --> F[Existing worker scheduler]
  E --> F
  F --> G[Session store reads]
  G --> H[Authorization facts]
Loading

Technical review

Best possible solution:

Keep priority admission in the existing scheduler and preserve the current authorization, cancellation, and cleanup owners.

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

Main rejects the next ordinary task once 128 tasks are admitted, and access-fact preparation uses that pool; the PR supplies a focused saturation regression and reports its expected failure on the pinned base.

Is this the best way to solve the issue?

The change repairs admission at its existing owner, threads classification through the affected reads, and preserves ordinary callers without introducing another pool, cache, or authorization path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Worker reuse and exact-slot custody keeps the original intent (fix: avoid repeated worker startup for Node state reads #151929: Reuse bounded execution workers while retaining each task's slot through result acceptance and native cleanup.)
  • Admission budgets and refusal diagnostics changes intended behavior with a stated reason (c686c16: Expose which existing task or byte budget refused admission without changing limits; this PR explicitly exempts access point reads to address observed availability failures.)
  • Retained reader adapters keeps the original intent (83fd5dd: Share stateless adapters while keeping each retained read's request runner and lifecycle context.)
  • Compaction request deadlines keeps the original intent (c9ee264: Use short planning and rendering tasks without holding a worker during summary requests; the options-object conversion preserves those tasks and deadlines.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +57, Tests +72. Total +129 across 17 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 15 77 20 +57
Tests 2 72 0 +72
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 149 20 +129

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:

No label changes.

Label justifications:

  • P1: The reported production saturation prevents access checks across active session subscriptions, viewer updates, artifact downloads, and other Gateway workflows.
  • merge-risk: 🚨 compatibility: The plugin-visible WorkerTaskPool.run contract gains an optional classification with different admission and concurrency semantics; the maintainer-authored direction accepts that opt-in tradeoff.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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-15T10:22:48.422Z sha d038058 :: needs maintainer review before merge. :: none

Reviewed November 15, 2026, 5:36 AM ET / 10:36 UTC (Revision 2).

Access checks read session facts through the shared session store worker
pool. When bulk reads filled the pool's pending cap, the pool refused the
access check with "worker task capacity reached", and the Gateway reported
SessionMutationFactsUnavailableError for every request that needed it.

The worker pool core now has two lanes. A task marked `pointRead` (class 0)
is never refused by the pending caps, queues ahead of bulk work, skips the
shared compute permit, and can use one worker above the bulk limit. A point
read must carry every fact in its input, so the pool refuses one that asks
for host callbacks. Session access fact reads (inventory, store target and
exact entries) use this lane.

Co-authored-by: obviyus <[email protected]>
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@obviyus
obviyus force-pushed the fix/worker-reserved-point-read-lane branch from d038058 to 9e406e1 Compare November 15, 2026 10:30
@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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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
@obviyus
obviyus merged commit 8f9bd10 into main Nov 15, 2026
147 of 148 checks passed
@obviyus
obviyus deleted the fix/worker-reserved-point-read-lane branch November 15, 2026 11:02
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 8f9bd10.

  • Bug: access checks shared the session store worker pool with bulk reads. When bulk work filled the 128-task cap, access checks were refused with worker task capacity reached; one production Gateway logged 2,455 of these refusals on 2026-11-11.
  • Fix: access checks and other point reads use a reserved lane. The pending caps never refuse them, and they run ahead of queued bulk work.
  • Proof:
    • A real-pool test fails on base and passes on head.
    • A real-Gateway run under load showed no regression.

roboclaw-bot added a commit that referenced this pull request Nov 15, 2026
Merge main 8f9bd10 to resolve the
three conflicts introduced by #199564. Keep the retired compaction-source
module deleted and the request runner owned by the reader factory.
Preserve main's options object, explicit trajectory timeout, transport-only
pointRead classification, reserved-lane dispatch, and unrelated changes.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: jalehman <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 16, 2026
Backport the P1 access-check starvation fix to beta.4 using its existing
targetDiscoveryLane and boolean admission owner. Keep the retired compaction
source deleted; do not import the main-only reader-pool or diagnostic migration.
Preserve bulk caps, FIFO within point reads, and the callback prohibition.

The real preparation boundary and pool regressions fail on the prior candidate.
All 16 affected consumer suites pass (220 tests), as do core types, touched-file
lint and the assertion ratchet. Local autoreview is unavailable and skipped
under the release authorization; this is not independent review evidence.

(cherry picked from commit 8f9bd10)

Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 16, 2026
Honor the explicit hosted runner choice in the aggregate source check introduced by #199836 after #199785. Verify refreshed workspace instructions in history while preserving the pinned prompt required by the approved prompt fixes. Drop a main-only diagnostic option from the #199564 regression fixture instead of importing its unrelated prerequisite.

Proof: hosted/workflow and prompt boundary suites pass (109 executions); access preparation passes 23 tests; all core test-type shards and touched lint pass. Local autoreview unavailable and skipped under release authorization.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…aw#199564)

## Problem

Access checks read session facts through the shared session store worker pool. Bulk reads use the same pool. When bulk reads filled the pool's pending cap (128 tasks), the pool refused the access check with `worker task capacity reached`. The Gateway then failed the request with `SessionMutationFactsUnavailableError`.

One production Gateway logged 2,455 of these refusals in one episode on 2026-11-11 (`sessions.messages.subscribe`, `sessions.viewers.set`, `progressCard.get`, `artifacts.download`, Web Push authority and others). The requests also waited up to about 20 minutes before the refusal.

The pool had one FIFO queue and one cap. It had no caller class.

## Fix

The worker pool core now has two lanes:

- **Class 0 (`pointRead: true`)**: access checks and other point reads.
  - The pending caps never refuse it.
  - It queues ahead of all queued bulk work, in its own arrival order.
  - It does not wait for a shared compute permit.
  - It can use one worker above the bulk worker limit. Bulk work cannot use that worker.
  - Its input must carry every fact it needs. The pool refuses a point read that asks for host callbacks (`onRequest` or `onRequestSync`).
- **Everything else**: no change.

The session access fact reads use class 0: the store inventory read, the store target read and the exact entry read in `prepareSessionMutationFacts`. These reads already sent no host callbacks. The access check therefore no longer has an overload refusal path.

Small related changes:
- The session history request runner takes `{ timeoutMs, pointRead }` as one options object instead of a positional `timeoutMs`.
- The `pointRead` field never goes to the worker. The transport removes it before it sends the request.

This is step 1 of the runtime design (E2): a reserved class-0 lane. It does not add more classes or change other pools.

## Proof

| Check | Tier | Base (`312d29fad005`) | Head |
|---|---|---|---|
| New: access check after 128 bulk reads fill the session store pool (`session-sharing-preparation.test.ts`) | vitest-source | Fails: `SessionMutationFactsUnavailableError` caused by `worker task capacity reached [task=sessionTranscript.session-target-inventory pool pending tasks: pendingTasks=128 maxPendingTasks=128]` | Passes in 674 ms; the pool call has `pointRead: true` |
| New: point reads run on the reserved worker, ahead of queued bulk work, while the pool is full (`worker-task-pool.preparation.test.ts`) | vitest-source | Fails: `worker task capacity reached [... pendingTasks=2 maxPendingTasks=2]` | Passes |
| New: a point read that asks for host callbacks is refused | vitest-source | Fails (the read runs) | Passes |
| 27 affected test files: worker pool, worker runtime, session entry reads, store target inventory, session sharing, compaction source, startup | vitest-source | — | 380 tests pass |
| `pnpm tsgo:core`, `pnpm check:test-types`, `pnpm tsgo:scripts`, `oxlint`, `oxfmt` | typecheck / lint | — | Pass |
| Real Gateway, 32 clients, 1,000 access checks on uncached session keys plus 100 `sessions.list` reads | source (`ocx src`) | 0 capacity refusals, 929 correct `unknown session` answers, 72 `server is busy` | 0 capacity refusals, 932 correct answers, 69 + 6 `server is busy` |
| Real Gateway from `dist/` on Node, 200 access checks | dist (after `ocx build --dts`) | — | 200 correct answers, 0 capacity refusals |
| `ocx build --dts`, then `npm pack` with the bundled channel entry smoke | full | — | Pass |

Note about the real Gateway run: the Gateway request admission refuses extra RPCs (`server is busy`) before they can fill the session store pool. So RPC load alone does not reproduce the refusal on base. In production, internal work filled the pool. The run shows that the head has no regression on the real Gateway. The vitest proof shows the fix.

Known unrelated failure: `src/config/sessions/session-transcript-worker-lanes.test.ts` ("releases pressure subscriptions after native settlement and rearms reopened lanes") fails and then hangs on the base too.

## Net lines

`git diff --stat origin/main...HEAD`: 17 files, +151 / −21.
- Source: +77 / −20.
- Tests: +74 / −1.

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

gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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