Skip to content

fix: reset chat baselines when an observer unsubscribes - #169693

Merged
steipete merged 1 commit into
mainfrom
codex/chat-subscription-recovered-20261012
Oct 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/chat-subscription-recovered-20261012

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: a shared chat stream disconnects when one of several full observers on the same connection unsubscribes and another update arrives.

User Impact

Remaining observers continue receiving chat text and queued narration after another observer releases its subscription. Releasing the final observer still stops delivery, and later subscriptions receive a complete snapshot.

Why This Change Was Made

The browser retires its text baseline after an acknowledged unsubscribe. The Gateway previously invalidated its matching broadcast receipt only when aggregate interest changed, leaving it to send append-only text to a client without a baseline. The existing registry now records an explicit baseline-only reset when other observers preserve aggregate interest. Its existing live-text listener invalidates receipts; narration preserves queued snapshots because its aggregate intent has not changed. This distinction addresses a concrete sibling regression without another state owner or a public protocol/config change. Production code grows by six lines after folding the narration guard and reusing the existing listener contract.

Evidence

  • The original boundary regression failed with browser close code 4000 after releasing one of two full observers. The candidate connects the real subscriber registry and broadcaster to the production browser client and proves retained delivery, final-unsubscribe suppression, and later snapshot restoration.
  • Fresh review caught an intermediate candidate discarding pending narration after one of two observers left. Strengthening the existing narration fixture reproduced the loss before the repair: fake pacing elapsed without another frame, but the remaining observer missed both queued snapshots. The final candidate delivers them and preserves final-release/foreground cleanup.
  • 116 distinct focused cases passed without skips across subscriber state, live-text delivery, narration, and browser handling, using the maintained Vitest wrapper with one worker (39.91 s command wall). The full-stream regression took 14 ms; the strengthened narration case took 5 ms. Both use fake clocks and no Gateway boot. No separate single-file command wall time was recorded for the final three-file Gateway group.
  • Final format, source ratchets, plugin import boundary, and test-temp checks passed. Four-file targeted typed lint passed in 16.953 s; the subsequent narration-only guard reduction passed affected typed lint in 17.467 s. Original lint and narration regression failures remain retained as evidence.
  • Fresh canonical isolated P2 review of final staged tree 3dc05f57daff741d0020e4bea2aeb2cb651ff91c passed with no actionable findings (106.192 s command wall). The earlier finding, pre-fold clean review, and final review are preserved in durable task evidence.
  • Canonical core boundary passed using one native immutable API snapshot (18.582 s). Its exact file metadata selected only core-test-gateway-server, which contains both broadcaster tests and the UI imports. Production core types passed (59.250 s), followed serially by that consumer graph (48.974 s). Each launch met the coordinated memory/compiler limits; a prior capacity hold launched no compiler and is retained. Earlier graph listing exited 137 without a TypeScript diagnostic, so it is not classified as a code error or proven OOM. No all-graph compiler sweep was run; these are scoped local checks, not a complete check:changed, remote CI, or live-browser claim.

Invalidate text receipts after acknowledged unsubscribe while preserving queued narration for remaining observers.
@clawsweeper

clawsweeper Bot commented Oct 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR resets text delivery baselines when an observer unsubscribes while preserving narration queued for remaining observers.

Example: Observers first and second share agent:main:chat; first unsubscribes after receiving A, then the answer becomes AB.

  • Before: The browser retires its baseline, receives append-only B, and closes with code 4000.
  • After: The remaining observer receives the complete AB snapshot and stays connected.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, focused repair with no actionable finding; supplied behavioral validation remains an in-process harness.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored repair is outside the ordinary contributor proof gate; supplied validation exercises production owners through mocked sockets and establishes no shipped Gateway/browser claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A remaining chat observer disconnects when another observer releases a shared subscription.
Reason: The maintainer-authored repair restores the existing remaining-observer contract with a small owner-level change and meaningful regressions.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a concrete current-main disconnect through the existing subscription owner, preserves queued narration, and introduces no actionable correctness finding.

Priority: P2
Reviewed head: d499866c95fb88ae842ee7b87d6a3e41d1ccaae6

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied regressions use mocked sockets and direct registry operations rather than a running Gateway and browser unsubscribe flow.
Agent review details

How this fits together

The Gateway subscriber registry aggregates observer interests per connection and session, notifying text receipt and narration owners before the broadcaster delivers events to clients.

flowchart LR
  A[Browser observers] --> B[Subscription RPC]
  B --> C[Subscriber registry]
  C --> D[Text receipts]
  C --> E[Narration queue]
  D --> F[Gateway broadcaster]
  E --> F
  F --> G[Browser text projection]
Loading

Technical review

Best possible solution:

Land the focused registry notification repair with narration preservation and the boundary regressions.

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

Current-main registry notifications, receipt invalidation, and browser baseline retirement establish the failure path; the PR reports a matching failing-before regression, but this read-only review executed no code.

Is this the best way to solve the issue?

The repair corrects stale receipts at their producer and distinguishes baseline retirement from subscription-intent changes without adding another state owner or public option.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Per-recipient append baselines keeps the original intent (2f58ead: Reduce repeated full-answer serialization while retaining complete snapshots when recipient continuity is unavailable.)
  • Independent observer ownership and narration retirement keeps the original intent (d769e31: Pace background narration while preserving independent full-stream interests across unrelated releases.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d769e31 adds src/gateway/server-chat-state.ts:549 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d769e31af2b9; files: src/gateway/server-chat-state.ts)

PR surface

Source +6, Tests +101, Docs +2. Total +109 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 15 9 +6
Tests 2 105 4 +101
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 123 14 +109

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +15/-9; tests +105/-4 Six net production lines reuse existing owners; the test growth covers browser reconstruction and queued narration as separate observable contracts.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The repair prevents a chat disconnect when independently identified observers share one connection and session.
  • 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.

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-10-12T06:57:37.340Z sha d499866 :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 3:07 AM ET / 07:07 UTC (Revision 2).

@steipete
steipete marked this pull request as ready for review October 12, 2026 07:02
@steipete
steipete merged commit 13f4924 into main Oct 12, 2026
193 of 195 checks passed
@steipete
steipete deleted the codex/chat-subscription-recovered-20261012 branch October 12, 2026 08:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
)

Invalidate text receipts after acknowledged unsubscribe while preserving queued narration for remaining observers.
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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