Skip to content

perf(gateway): avoid display-row waits in message subscriptions - #162013

Merged
steipete merged 4 commits into
mainfrom
steipete/perf-micro-subscribe-wait-attribution-20260919
Sep 30, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/perf-micro-subscribe-wait-attribution-20260919

Conversation

@steipete

@steipete steipete commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

sessions.messages.subscribe could wait for a dirty session display row before entering its otherwise fast handler. The router joined the transcript worker's display refresh even when committed sharing facts were already available.

The required CI run also exposed a deterministic, pre-existing updater bug: SIGINT during Windows task suspension made recovery settlement use the forward-work guard and fail with requester-revoked.

User Impact

Message subscriptions can acknowledge while display facts refresh. Visibility, membership, retained session/caller authority, incognito preparation, and authoritative approval replay remain enforced. Slow requests now report where they waited.

The bounded updater repair lets interruption finish owned autostart restoration and cancellation settlement, while preserving live executor, native task, and repair checks.

Why This Change Was Made

Subscription authorization now prepares committed access facts through their existing owner, without requiring display materialization. Approval replay still completes before acknowledgment and retains its retry and rollback checks.

slow session messages subscribe uses the shared one-second threshold and phaseDurationsMs, starting in the router. Phases cover access facts, projection readiness, handler preparation, retained-read admission, replay preparation, observer commit, response, and cleanup. It records no session keys or message contents.

The updater repair forwards its existing restore phase through recovery guards. The overlapping Windows task repair landed independently in #161990; this PR retains the additional service-maintenance compensation guard, with zero net production LOC. Initial disable, mutation admission, and handoff retain forward checks. This belongs to the running updater; older drivers already in progress retain their behavior.

Evidence

The subscription regression uses the registered router/handler, a real SQLite transcript worker, an active turn writing a row, and plain plus approval observers. It holds delivery of display facts with a deferred signal. Both the one-session and 8,000-session fixtures failed on the old path and pass with this change.

Measurement Before After
Controlled display-worker delay, 1 session 1,500 ms inherited wait 0 ms inherited wait; acknowledgment before worker release
Controlled display-worker delay, 8,000 sessions 1,500 ms; diagnostic attributes all of it to projectionReadiness 0 ms inherited wait; acknowledgment before worker release

The 1,500 ms interval is an injected clock measurement. Production tail latency remains unverified. Cold approval preparation remains: the corrected 8,000-session response pair took 927 ms wall time. The final warm 160k-token run measured 1.96 ms mean without approval replay and 10.97 ms with replay; wall samples varied under load.

Validation passed:

  • Final-head CI: success, head df91ac87102f7592346755df02e32dc8880dc7ce. The superseded 4828430d8d73 run was cancelled after the conflict-resolution push; it is not claimed as passing CI.

  • 68 focused subscription, approval, visibility, retained-authority, and diagnostic tests across scoped runs.

  • Four canonical-validation cases. CI caught an old assertion against pre-dispatch timing; the updated test requires the actual registered subscription to reject corrupt storage before any observer registration.

  • All 52 focused updater lifecycle/recovery/authority cases. The existing SIGINT regression failed before the guard repair and passes afterward.

  • The exact original 36-file updater CI group: 772 passed after repair, versus 771 passed and the same SIGINT failure before it. Core and updater test types, targeted lint, runtime guards, and docs checks passed.

  • After resolving the overlap with fix(update): restore Windows task autostart after cancellation #161990 against main 8eadb661cdfb, all 102 tests across five Windows lifecycle, service-authority, maintenance, and recovery files passed in 153.44 s. The resolution uses main’s existing helper; subscription code is unchanged.

  • Independent reviews through P2: scoped-clean, no actionable findings.

  • Full candidate build, SDK export checks, tarball integrity/import-graph checks, and the existing published [email protected] → candidate 4828430d8d73 Linux Docker upgrade cell. It verified preserved synthetic operator state, installed candidate payload, and Gateway readiness. The upgrade scenario passed in 369 s; build/package preparation took 525 s.

The updater unit proof uses mocked Windows service APIs on Linux. Native Windows interruption was not exercised. No live operator Gateway was changed.

Test cost

Measured with pnpm test <file> --maxWorkers=1:

File Test time Command wall
sessions.messages-subscribe-wait.test.ts 3.892 s 63.47 s, including 45.47 s cold worker compilation
sessions.messages-subscribe-latency.benchmark.test.ts 19.25 s 38.39 s
slow-request-diagnostics.test.ts 0.048 s 2.45 s
server-methods.canonical-validation.test.ts 4.201 s 55.24 s with cold worker preparation

The ordinary regression uses one session. The larger benchmark exercises the requested inventory and real worker dependency. The original canonical-validation file consumed 3.170 s in the first CI run, including its stale assertion.

Testbox commands, identities, and recovery

Every heavy command ran through crabbox, provider blacksmith-testbox, profile openclaw-check, with native sync and one active command per lease. All leases were stopped.

Lease Commands / result
tbx_01m3sj82qmqg8eg45skf6df42h (run) Baseline and candidate Gateway tests, node scripts/check-changed.mjs, scoped lint/guard recovery, and pnpm check:docs. Initial missing dependencies were repaired with one frozen-lockfile install. All typecheck lanes passed; test-only lint issues were corrected and the affected lint/tests rerun clean. Docs: 14,646 links, zero broken links.
tbx_01m3spf2wwhfbn25c7zaexk42x (run) Canonical-validation test, targeted lint, and tsconfig.core.test.gateway-server.json: passed.
tbx_01m3sq4szsp3tg61bjkvs6ye52 (run) Reproduced the Windows failure in its original CI group and standalone; diagnostics identified the wrong guard phase. After repair: 52 focused cases, original 772-case group, core/updater test types, lint, and changed docs MDX passed.
tbx_01m3sryw91t6swtdae6dyqxfrn Source-head preflight refused a newer-main Git checkout with overlaid files; no upgrade proof ran. Stopped and replaced with an exact-branch lease.
tbx_01m3ssb8n9tpb5vyf65rydwkr2 (run) Exact candidate head verified; published-driver Docker cell passed, exit 0.
tbx_01m3stsqkj7vnyrap1paxyhvyj (run) Conflict resolution: source checksums verified. First command stopped for missing dependencies; one pnpm install --frozen-lockfile repaired the lease. Focused command below: 102 passed, exit 0; 153.44 s test runner, 168.40 s command wall including installation and transport.

Focused subscription command:

node scripts/run-vitest.mjs \
  src/gateway/server-methods/sessions.messages-subscribe-wait.test.ts \
  src/gateway/server-methods/sessions.messages-subscribe-latency.benchmark.test.ts \
  src/gateway/server-methods/sessions.messages-subscribe-approvals.test.ts \
  src/gateway/server-methods.session-scoped-reads.test.ts \
  src/gateway/session-sharing-committed-read.test.ts \
  src/gateway/slow-request-diagnostics.test.ts \
  src/gateway/server-methods/cron-list-diagnostics.test.ts \
  src/gateway/server-methods/sessions-read-diagnostics.test.ts --maxWorkers=1

Conflict-resolution command:

node scripts/run-vitest.mjs \
  src/cli/update-cli.windows-lifecycle.test.ts \
  src/cli/update-cli/update-command-windows-task.test.ts \
  src/cli/update-cli/update-command-service-maintenance.windows-recovery.test.ts \
  src/cli/update-cli/update-command-service-maintenance.test.ts \
  src/cli/update-cli.service-authority.test.ts --maxWorkers=1

Published-driver cell:

OPENCLAW_DOCKER_E2E_SELECTED_SHA=4828430d8d73343f301c13b5f49081a6195d6403 \
[email protected] \
OPENCLAW_UPGRADE_SURVIVOR_SCENARIOS=base \
OPENCLAW_UPGRADE_SURVIVOR_UPDATE_RESTART_MODE=manual \
OPENCLAW_UPGRADE_SURVIVOR_LIVE_MODELS= \
OPENCLAW_UPGRADE_SURVIVOR_LIVE_OPENAI=0 \
pnpm test:docker:published-upgrade-survivor

The baseline version, registry tarball, and integrity were verified before execution. No live model calls were selected.

Related: #161555.

Authorize message observers from committed sharing and membership facts while retaining incognito preparation, session authority, and approval replay guards. Attribute slow subscriptions from router entry through observer commit with bounded phase timings.
@clawsweeper

clawsweeper Bot commented Sep 30, 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 docs Improvements or additions to documentation gateway Gateway runtime size: M labels Sep 30, 2026
@steipete
steipete marked this pull request as ready for review September 30, 2026 17:26
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: df91ac87102f7592346755df02e32dc8880dc7ce
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-methods.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@steipete
steipete enabled auto-merge (squash) September 30, 2026 17:30
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 30, 2026, 3:15 PM ET / 19:15 UTC (Revision 4).

ClawSweeper review

What this changes

The branch lets Gateway message subscriptions authorize from committed session facts while display rows refresh, adds slow-request timing and regression coverage, and adjusts Windows updater recovery after interruption.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open. Current main still waits for display-row preparation during message subscriptions, and the merged related work addresses different bottlenecks. The remaining review gap is native Windows evidence for the added cancellation-recovery catch.

Priority: P2
Reviewed head: df91ac87102f7592346755df02e32dc8880dc7ce

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has focused owner-boundary coverage and no established defect, with confidence limited by the unobserved native Windows recovery outcome.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: The maintainer-authored PR is exempt from the ordinary contributor proof gate. Its reported real SQLite-worker subscription scenario covers the changed Gateway entry point; the Linux published-driver upgrade cell covers general update compatibility, while native Windows settlement through the added catch remains unobserved. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the ordinary contributor proof gate. Its reported real SQLite-worker subscription scenario covers the changed Gateway entry point; the Linux published-driver upgrade cell covers general update compatibility, while native Windows settlement through the added catch remains unobserved. No stored-data contract changes.
Evidence reviewed 9 items Current main still waits: Current main awaits exact-row preparation before subscription authorization; the branch adds a committed-facts path for ordinary subscriptions.
Introduced Gateway path: The introduced branch prepares membership, then authorizes ordinary message subscriptions without awaiting display-row preparation; incognito requests retain the exact-row path.
Final observer checks: The subscription handler rechecks retained reads and session authorization before committing plain or approval observers; approval replay is prepared before acknowledgment.
Findings None None.
Security None None.

How this fits together

The Gateway authorizes a client's session subscription before registering an observer for live messages. Separately, the updater temporarily changes Windows Scheduled Task autostart and must restore it when an update is interrupted.

flowchart LR
A[Client subscription] --> B[Gateway authorization]
B --> C[Committed session facts]
C --> D[Observer registration]
D --> E[Live messages]
F[Update interruption] --> G[Updater recovery]
G --> H[Windows task autostart]
Loading

Before merge

  • Resolve merge risk (P1) - The added service-maintenance catch has not been observed through a native Windows interruption and cancellation settlement. Linux tests mock Windows service APIs, while the related merged PR's native proof covers the Scheduler restoration component rather than this added catch.
  • Complete next step (P2) - Capture a native Windows SIGINT or SIGBREAK run through the added service-maintenance catch, showing original task autostart restored and cancellation settled.
Agent review details

Security

None.

PR surface

Source +121, Tests +351, Docs +16. Total +488 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 9 138 17 +121
Tests 5 356 5 +351
Docs 2 16 0 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 510 22 +488

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Verify Windows cancellation settlement (recommended)
    Capture a native Windows interruption through the added service-maintenance catch, including original task autostart and the final cancellation outcome.

Technical review

Best possible solution:

Subscriptions should acknowledge from current committed access facts with final observer authority checks; interrupted Windows updates should restore only the original task and settle cancellation under the retained executor.

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

Yes, current-main source shows the display-row await and the branch contains a registered-router, real-worker regression with a reported failing baseline. This read-only review did not execute the test.

Is this the best way to solve the issue?

Yes for the Gateway path: committed sharing facts and final authority checks address the wait at its owner. The Windows catch has a narrow code shape, with native settlement proof still outstanding.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e6d8dae5c200.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The PR addresses a bounded Gateway subscription latency problem and a Windows update recovery path.
  • merge-risk: 🚨 availability: An incorrect Windows recovery outcome could leave task autostart disabled or prevent interrupted update settlement.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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 maintainer-authored PR is exempt from the ordinary contributor proof gate. Its reported real SQLite-worker subscription scenario covers the changed Gateway entry point; the Linux published-driver upgrade cell covers general update compatibility, while native Windows settlement through the added catch remains unobserved. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add a native Windows interruption trace that reaches the service-maintenance catch and records task autostart plus cancellation settlement.

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 (3 earlier review cycles)
  • reviewed 2026-09-30T17:33:23.446Z sha b1d3e5e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-30T18:36:53.109Z sha 4828430 :: blocked before merge. :: none
  • reviewed 2026-09-30T18:56:02.261Z sha 4828430 :: blocked before merge. :: none

@steipete
steipete marked this pull request as draft September 30, 2026 18:28
auto-merge was automatically disabled September 30, 2026 18:28

Pull request was converted to draft

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: L and removed size: M labels Sep 30, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. labels Sep 30, 2026
@steipete
steipete marked this pull request as ready for review September 30, 2026 18:50
@steipete
steipete enabled auto-merge (squash) September 30, 2026 18:50
@steipete
steipete merged commit 49576e2 into main Sep 30, 2026
198 checks passed
@steipete
steipete deleted the steipete/perf-micro-subscribe-wait-attribution-20260919 branch September 30, 2026 19:25
steipete added a commit that referenced this pull request Sep 30, 2026
Keep the main-owned #162013 cleanup behavior without overriding it. The remaining three-path delta is failed-disable compensation and regression coverage; all three postimages match the qualified predecessor.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
…claw#162013)

* perf(gateway): avoid display-row waits in message subscriptions

Authorize message observers from committed sharing and membership facts while retaining incognito preparation, session authority, and approval replay guards. Attribute slow subscriptions from router entry through observer commit with bounded phase timings.

* test(gateway): enforce subscription integrity at observer admission

* fix(update): retain restoration authority after interruption
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: L 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