Skip to content

fix(gateway): keep chat subscriptions stable during unrelated approvals - #158633

Merged
steipete merged 1 commit into
mainfrom
codex/faster-session-subscriptions
Sep 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/faster-session-subscriptions

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: chat message subscriptions repeat approval queries or fail during approval activity in unrelated sessions.

User Impact

Concurrent chat viewers can subscribe without unrelated approval changes discarding their shared replay. Relevant approval changes and revoked access still prevent stale acknowledgements. No configuration, permissions, schema, or migration changes are required.

Why This Change Was Made

Approval replay used one global publication revision, so every lifecycle event invalidated every in-flight replay. Revisions now follow the exact session audience and reviewer binding. Each caller retains that scope until its response or failure, then releases it; completed snapshots are not cached. Expiry reconciliation, durable writes, and authorization checks keep their existing owners and ordering.

Evidence

  • The real subscription-handler regression failed before the fix with UNAVAILABLE under unrelated approval publications. With the fix, 64 concurrent subscribers share one pending-approval read and all receive the expected 200 approvals.
  • 28 focused tests passed, including matching-publication races, per-client revocation, expiry/waiter reconciliation, and timeout recovery. A matching publication still invalidates a replay after its worker reply settles; releasing one caller does not retire another caller's scope.
  • Isolated stress measurement: 1,920 measured acknowledgements at concurrency 64, median 33.5 ms and p90 53.7 ms; one expiry operation and one pending read per group of 64. These are handler/storage measurements, not end-to-end production latency.
  • The extracted owner suite passed all 13 tests again. All changed-code gates passed on Blacksmith Testbox (production and test typechecks, lint, documentation and runtime guards). The one-shot lease was stopped successfully.
  • Initial validation exposed two unrelated base defects: the task-runtime error repaired by fix(tasks): restore async harness task completion #158520 and the retained-assets test import repaired by da8149b8ba7d. Both repairs are incorporated. The subscription production and test files remain byte-identical to the tested revision; exact-head hosted CI passed: 124 successful jobs, 20 inapplicable jobs skipped, no failures (run 36219893761).
  • Independent review completed with no actionable P0–P2 findings, and ClawSweeper completed its exact-head review without actionable defects. A subsequent mechanical extraction moves unchanged fixture builders into a test-support module to satisfy the line-cap gate.
  • Post-merge: the 64-subscriber stress regression passed again on main 47a9e77007f7 (41.7 s command wall), which contains merge commit 970de8701da3.
  • Live production tracing was unavailable, so this PR fixes the reproduced invalidation mechanism without claiming to identify every cause of a reported 30-second subscription timeout.
Test cost

Measured with pnpm test <file> --maxWorkers=1 on macOS/Node 26.9.0:

File Command wall time
src/gateway/operator-approval-session-events.test.ts 113.6 s after fixture extraction
src/gateway/server-methods/sessions.messages-subscribe-approvals.test.ts 145.1 s
src/gateway/server-methods/sessions.messages-subscribe-perf.test.ts 118.2 s (9.86 s test execution)

Command wall time includes the repository's worker preparation and transformation. The existing database-backed owner suite preserves durable approval transitions and waiter reconciliation; the existing stress test now covers 64 subscribers and unrelated publications rather than adding a duplicate suite. Hosted CI completed in 880 seconds of total run wall time. The run did not publish per-file timing artifacts; this is whole-run time, not time attributed to these three files.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 26, 2026
@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 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 1:20 AM ET / 05:20 UTC (Revision 3).

ClawSweeper review

What this changes

The branch makes Gateway chat subscriptions share pending approval reads while unrelated sessions or reviewers change, and adds regression coverage and protocol documentation.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still invalidates every approval replay after any approval publication. The branch addresses that failure with scoped invalidation, and this review found no actionable introduced defect.

Priority: P2
Reviewed head: efca66954ba3e86fc0097c453ae10b420619f255

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair has strong handler and storage regression evidence, with no actionable defect found in this review.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The supplied MEMBER classification exempts this PR from the external-contributor proof gate. Its production replay owner and subscription handler are exercised against SQLite with an injected unrelated publication and mocked clients; the PR reports successful acknowledgments for all 64 clients but supplies no live WebSocket trace. 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 supplied MEMBER classification exempts this PR from the external-contributor proof gate. Its production replay owner and subscription handler are exercised against SQLite with an injected unrelated publication and mocked clients; the PR reports successful acknowledgments for all 64 clients but supplies no live WebSocket trace. No stored-data contract changes.
Evidence reviewed 7 items Current main behavior: Current main increments one global publication revision and clears all pending replay preparations for every approval lifecycle event.
Introduced scope: The PR head advances replay revisions only when a publication matches the retained session audience and reviewer binding.
Durable query contract: The pending-approval reader applies the same audience and reviewer-binding predicates to stored records.
Findings None None.
Security None None.

How this fits together

The Gateway accepts chat subscription requests, reads pending approvals from SQLite, and returns a replay before delivering live approval events. Approval lifecycle publications determine whether an in-flight replay remains current.

flowchart LR
A[Chat viewer] --> B[Gateway subscription]
B --> C[Session access check]
C --> D[Approval replay]
E[Approval lifecycle events] --> F[Scoped freshness check]
D --> F
F --> G[Subscription response]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +44, Tests +51, Docs 0. Total +95 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 72 28 +44
Tests 4 156 105 +51
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 229 134 +95

Review metrics

Metric Value Why it matters
Production and test growth production +44 net lines, tests +51 net lines The runtime growth implements retained replay lifetimes, while the test changes cover the subscription and publication races.
Focused test wall time 113.6 s, 145.1 s, and 118.2 s The PR body records single-worker timings for all three affected test files; hosted CI timing was still pending in the supplied evidence.

Technical review

Best possible solution:

Keep one Gateway replay owner that shares only in-flight reads, invalidates matching session and reviewer scopes, and preserves final-response access checks.

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

Yes. Current main's global revision gives a clear source-level reproduction path: publish an unrelated approval while a subscription waits for its pending-approval read. The PR reports a before-fix handler failure, but this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Scoping replay invalidation to the audience and reviewer predicates already used by the durable reader is a focused repair, and the handler retains the scope through its response.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Unrelated approval activity can interrupt concurrent chat subscription setup, but the demonstrated failure has a limited scope.
  • 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. Not applicable: The supplied MEMBER classification exempts this PR from the external-contributor proof gate. Its production replay owner and subscription handler are exercised against SQLite with an injected unrelated publication and mocked clients; the PR reports successful acknowledgments for all 64 clients but supplies no live WebSocket trace. 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)
  • Josh Lehman: 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 (2 earlier review cycles)
  • reviewed 2026-09-26T04:03:10.317Z sha b7fd4951d5789d36447409b5802c2dce29283964 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T04:16:37.270Z sha b7fd4951d5789d36447409b5802c2dce29283964 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 26, 2026 04:11
@steipete
steipete force-pushed the codex/faster-session-subscriptions branch from b7fd495 to efca669 Compare September 26, 2026 05:08
@steipete
steipete merged commit 970de87 into main Sep 26, 2026
208 checks passed
@steipete
steipete deleted the codex/faster-session-subscriptions branch September 26, 2026 05:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 26, 2026
* commit '66b812f26e725cd709e08860d2cb46ba496cd308': (70 commits)
  fix(gateway): preserve typed boxed-number coercion
  chore(ui): refresh control ui locales (#158689)
  fix(gateway): reset staged headers on authority errors (#158669)
  fix(workers): keep inbound staging stable during quota scans
  fix: preserve Telegram delivery after bot identity changes (#158612)
  fix(ui): keep automation starter prompts out of startup (#158482)
  fix(cli): distinguish configuration read failures from invalid input (#158671)
  test: remove retired progress coercion suppression allowance
  refactor(gateway): schedule worker placement maintenance (#158662)
  fix(daemon): keep native service checks within their timeout (#154565)
  fix(test): restore gateway steering fixture contracts (#158478)
  fix(acpx): use SDK filesystem publication boundary
  fix(agentsapi): load OpenClaw persona and workspace context (#158328)
  fix(gateway): drop progress snapshot coercion suppression
  fix(qa): accept native Codex truncation in cache evidence (#158454)
  fix(gateway): keep chat subscriptions stable during unrelated approvals (#158633)
  perf(gateway): release event payloads from live text guards (#158643)
  perf(sessions): reduce stalls when saving large chat messages (#158402)
  fix(qa): reject history-bearing utility requests without session affinity (#158496)
  test: allow intentional progress snapshot coercion
  ...
vincentkoc added a commit that referenced this pull request Sep 26, 2026
* fix(test): verify followup completion ordering

Exercise the real presentation settlement helper with asynchronous cleanup, preserve continuation and admission semantics, and unconditionally release and join the held work. Remote proof covers the strengthened ordering contract and both missing-await faults.

* fix(test): verify followup completion ordering

* chore: retain followup test branch ancestry

The current-main reconstruction preserves the original reviewed scope and supersedes its stale base. Keep the remotely qualified candidate tree unchanged while retaining the original PR ancestry for a non-force branch update.

* commit 'ff35145de21cf6296bec05e86bee37b5ed53bcb8':
  fix(test): verify followup completion ordering

* test(auto-reply): signal queued presentation entry

* chore: refresh followup test on boundary fix

* commit '66b812f26e725cd709e08860d2cb46ba496cd308': (70 commits)
  fix(gateway): preserve typed boxed-number coercion
  chore(ui): refresh control ui locales (#158689)
  fix(gateway): reset staged headers on authority errors (#158669)
  fix(workers): keep inbound staging stable during quota scans
  fix: preserve Telegram delivery after bot identity changes (#158612)
  fix(ui): keep automation starter prompts out of startup (#158482)
  fix(cli): distinguish configuration read failures from invalid input (#158671)
  test: remove retired progress coercion suppression allowance
  refactor(gateway): schedule worker placement maintenance (#158662)
  fix(daemon): keep native service checks within their timeout (#154565)
  fix(test): restore gateway steering fixture contracts (#158478)
  fix(acpx): use SDK filesystem publication boundary
  fix(agentsapi): load OpenClaw persona and workspace context (#158328)
  fix(gateway): drop progress snapshot coercion suppression
  fix(qa): accept native Codex truncation in cache evidence (#158454)
  fix(gateway): keep chat subscriptions stable during unrelated approvals (#158633)
  perf(gateway): release event payloads from live text guards (#158643)
  perf(sessions): reduce stalls when saving large chat messages (#158402)
  fix(qa): reject history-bearing utility requests without session affinity (#158496)
  test: allow intentional progress snapshot coercion
  ...

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
* fix(test): verify followup completion ordering

Exercise the real presentation settlement helper with asynchronous cleanup, preserve continuation and admission semantics, and unconditionally release and join the held work. Remote proof covers the strengthened ordering contract and both missing-await faults.

* fix(test): verify followup completion ordering

* chore: retain followup test branch ancestry

The current-main reconstruction preserves the original reviewed scope and supersedes its stale base. Keep the remotely qualified candidate tree unchanged while retaining the original PR ancestry for a non-force branch update.

* commit 'ff35145de21cf6296bec05e86bee37b5ed53bcb8':
  fix(test): verify followup completion ordering

* test(auto-reply): signal queued presentation entry

* chore: refresh followup test on boundary fix

* commit '622be54be3ffe0fce27d6a4b147c76d4b19c528c': (70 commits)
  fix(gateway): preserve typed boxed-number coercion
  chore(ui): refresh control ui locales (openclaw#158689)
  fix(gateway): reset staged headers on authority errors (openclaw#158669)
  fix(workers): keep inbound staging stable during quota scans
  fix: preserve Telegram delivery after bot identity changes (openclaw#158612)
  fix(ui): keep automation starter prompts out of startup (openclaw#158482)
  fix(cli): distinguish configuration read failures from invalid input (openclaw#158671)
  test: remove retired progress coercion suppression allowance
  refactor(gateway): schedule worker placement maintenance (openclaw#158662)
  fix(daemon): keep native service checks within their timeout (openclaw#154565)
  fix(test): restore gateway steering fixture contracts (openclaw#158478)
  fix(acpx): use SDK filesystem publication boundary
  fix(agentsapi): load OpenClaw persona and workspace context (openclaw#158328)
  fix(gateway): drop progress snapshot coercion suppression
  fix(qa): accept native Codex truncation in cache evidence (openclaw#158454)
  fix(gateway): keep chat subscriptions stable during unrelated approvals (openclaw#158633)
  perf(gateway): release event payloads from live text guards (openclaw#158643)
  perf(sessions): reduce stalls when saving large chat messages (openclaw#158402)
  fix(qa): reject history-bearing utility requests without session affinity (openclaw#158496)
  test: allow intentional progress snapshot coercion
  ...

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

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. 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