Skip to content

fix(ui): enforce authoritative Gateway observer lifecycle - #117017

Merged
steipete merged 1 commit into
mainfrom
codex/wave3-real-gateway-browser-proof
Jul 31, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/wave3-real-gateway-browser-proof

Conversation

@steipete

@steipete steipete commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A faulty Control UI observer could turn a successful Gateway hello into a failed connection, corrupt snapshot or event-log fanout, or publish retired connection state. More subtly, a presence observer could replace its client before that client's event was logged, while connecting and event-gap observers could synchronously replace or stop a client that stale producer code then started or reconnected anyway.

These failures caused missing UI updates, cross-connection history pollution, ghost WebSockets, duplicate reconnects, and explicitly stopped Gateways unexpectedly restarting.

Why This Change Was Made

The existing Gateway store is the authoritative owner of snapshot, event, event-log, and browser-client lifecycle delivery. The repair replaces three divergent mutable fanout loops with one isolated observer-delivery path, then applies one canonical current-client-plus-not-stopped predicate to producer continuations, presence projection, gap recovery, and event delivery.

This preserves existing diagnostic labels and public behavior while fixing ownership where it changes. The existing 777-line owner suite stays untouched; 10 original-order regressions live in a focused new 305-line suite. The justified production delta is 38 added / 27 removed / net +11.

User Impact

  • Successful Gateway handshakes survive failing snapshot or event-log observers.
  • Healthy observers receive the correct current publication despite callback failures or membership changes.
  • Replaced connections cannot leak stale snapshots, presence records, or event deliveries into the active session.
  • Reentrant connection replacement creates exactly one fresh browser socket; stopping during startup or gap handling creates none and stays stopped.
  • Authentication, public Gateway protocols, SDK contracts, configuration, persistence, SQLite, and operator Gateway processes are unchanged.

Evidence

  • Frozen baseline: 36b80ada3ceae2de21b3d8710b883d778e4c4578.
  • Final immutable single-commit PR head: 74ee66be3cd2347f6efb835b6a03cb977e645cd3.
  • All 10 focused owner cases were observed red before their corresponding repair; the four connecting/gap stop-or-replace permutations correctly deduplicate to one lifecycle root cause.
  • Exact immutable candidate proof:
$ node scripts/run-vitest.mjs \
    ui/src/app/gateway-store.test.ts \
    ui/src/app/gateway-store.observers.test.ts
Test Files  2 passed
Tests       43 passed, 0 failed
Existing owner cases: 33
Original red-to-green regressions: 10
exit 0
  • Real Google Chrome 150.0.7871.187, isolated localhost Vite, the actual GatewayBrowserClient, actual browser WebSocket adapter, and a deterministic local Gateway peer exercised the exact PR head. Throwing snapshot and event-log observers remained isolated, healthy observers received their event/log, and forced disconnect reconnected across three real sockets.
  • Redacted real-browser presence-owner output from the exact PR head:
{
  "candidateSha": "74ee66be3cd2347f6efb835b6a03cb977e645cd3",
  "browser": "Google Chrome 150.0.7871.187",
  "repaired": true,
  "invariant": "retired presence cannot enter the replacement Gateway event log",
  "results": { "replaced": true, "staleLogs": [], "staleEvents": [] }
}
  • Redacted real-browser lifecycle output from the exact PR head; client IDs are intentionally omitted:
{
  "candidateSha": "74ee66be3cd2347f6efb835b6a03cb977e645cd3",
  "browser": "real-system-google-chrome",
  "ok": true,
  "results": [
    { "variant": "connecting-replace", "handled": true, "socketDelta": 1, "phase": "connected" },
    { "variant": "connecting-stop", "handled": true, "socketDelta": 0, "phase": "stopped" },
    { "variant": "gap-replace", "handled": true, "socketDelta": 1, "phase": "connected" },
    { "variant": "gap-stop", "handled": true, "socketDelta": 0, "phase": "stopped" }
  ]
}
  • Thus both replacement variants opened exactly one fresh socket and both stopped variants opened zero; none resurrected the retired connection. The same presence scenario produced staleLogs=["presence"] before repair and staleLogs=[] after.
  • The Chrome scenarios use the real browser, real browser Gateway client, and real browser WebSockets. The Gateway peer is deterministic and isolated; no operator Gateway, live credentials, or private user state are involved. Screenshot/JSON files remain external; no proof assets are committed and no unavailable recording is claimed.
  • Independent strict immutable-source review inspected the complete exact owner modules, 40+ callers, lifecycle siblings, and real browser/protocol contracts: zero P0/P1/P2 findings.
  • Official complete-branch Codex autoreview explicitly used --max-priority P3 with genuine TruffleHog 3.96.0: zero findings, patch is correct, confidence 0.90.
  • Final production delta: 38 added / 27 removed / net +11. Existing oversized tests, public protocols, SDKs, authentication, configuration, and persistence are unchanged.

Distinct root causes (7):

  1. Snapshot observer exceptions escaped successful Gateway hellos.
  2. Mutable snapshot membership corrupted active fanout.
  3. Reentrant replacement allowed retired snapshots to continue delivery.
  4. Event-log observer exceptions starved healthy consumers.
  5. Mutable event-log membership corrupted active fanout.
  6. Presence-driven replacement allowed a retired event into the active owner's log.
  7. Lifecycle producers continued after synchronous snapshots replaced or stopped their owner.

ClawSweeper rank-up moves

  1. Attach redacted exact-head browser diagnostics, terminal output, logs, or a recording for healthy delivery, replacement, and stop scenarios — addressed. The exact-head 43-test terminal output, real Google Chrome version, presence JSON, all four real connecting/gap replacement/stop socket measurements, and healthy three-socket reconnect proof are embedded above. A video is not claimed because Playwright FFmpeg is unavailable; the already-generated real-browser screenshot remains external and is not committed.
  2. Refresh review against the current three-way merge result once exact branch blobs are available — addressed. The exact branch blobs for ui/src/app/gateway-store.ts and ui/src/app/gateway-store.observers.test.ts were independently inspected at 74ee66be3cd2347f6efb835b6a03cb977e645cd3; the pull request is mergeable, exact-head hosted CI is green, and the complete exact-head owner suite plus full-branch P3 review both passed. The repository-native maintainer review/prepare workflow checks the current merge result before landing.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: M maintainer Maintainer-authored PR labels Jul 31, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 31, 2026
@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 31, 2026, 3:54 PM ET / 19:54 UTC.

ClawSweeper review

What this changes

This PR centralizes Control UI Gateway observer delivery and prevents replaced or stopped browser clients from continuing to publish state, reconnect, or start sockets.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 6 items remain

Keep this PR open for protected human review. Current main still directly invokes snapshot and event-log observers, while the supplied branch targets the remaining observer and lifecycle-authority hazards; however, the exact PR blobs and claimed real-browser artifacts were not independently accessible in this read-only environment, and the maintainer label requires an explicit owner decision before merge.

Priority: P1
Reviewed head: 74ee66be3cd2347f6efb835b6a03cb977e645cd3
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has a focused owner-boundary rationale and targeted regression plan, but real behavior proof remains uninspectable and is a merge gate.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The PR body describes real-Chrome after-fix scenarios, but no accessible artifact and no complete exact-head source were available to independently connect that behavior to the proposed commit; attach redacted browser diagnostics, terminal output, logs, or a recording before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body describes real-Chrome after-fix scenarios, but no accessible artifact and no complete exact-head source were available to independently connect that behavior to the proposed commit; attach redacted browser diagnostics, terminal output, logs, or a recording before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current observer delivery remains unguarded: Current main iterates snapshot observers directly, so a throwing or reentrant snapshot callback can escape the state publisher; event-log observers are likewise invoked directly before raw event listeners are reached.
Current lifecycle callbacks establish the affected owner boundary: onHello, onGap, and onEvent all operate through the Gateway store; onHello publishes a connected snapshot, onGap immediately reconnects, and raw events already stop delivery when a client replacement occurs during listener iteration.
Existing current-main tests cover related event invariants: The owner suite already verifies snapshot membership for raw event listeners, isolation of throwing event subscribers, isolation of throwing event-log subscribers, replacement during event delivery, and ignored events after stop; the proposed branch adds coverage for the remaining observer/lifecycle orders.
Findings None None.
Security None None.

How this fits together

The Control UI Gateway store creates and owns the browser WebSocket client, then publishes connection snapshots, raw events, and event-log updates to application subscribers. Gateway callbacks update this store and may start, replace, reconnect, or stop the browser client that powers the UI session.

flowchart LR
  A[Gateway Browser Client] --> B[Control UI Gateway Store]
  B --> C[Current Client Check]
  C --> D[Snapshot and Event Log]
  D --> E[UI Observers]
  C --> F[Start Reconnect or Stop]
  F --> A
Loading

Decision needed

Question Recommendation
Should the Control UI owner approve this protected lifecycle change after the exact PR head and its real-browser proof are independently inspectable? Refresh source and proof, then approve: Make the exact-head source and redacted real-browser diagnostic evidence available, compare the clean three-way merge result, and have the Control UI owner approve the lifecycle invariant.

Why: The maintainer label blocks automated cleanup, and this patch changes the authority boundary for active browser clients; the missing branch blob/artifact prevents a safe automated merge recommendation.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body describes real-Chrome after-fix scenarios, but no accessible artifact and no complete exact-head source were available to independently connect that behavior to the proposed commit; attach redacted browser diagnostics, terminal output, logs, or a recording before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The lifecycle change is merge-sensitive because a missed current-client or stopped-state continuation can publish stale UI state, reconnect unexpectedly, or create an extra browser WebSocket.
  • Resolve merge risk (P1) - The PR body describes real Chrome proof, but no inspectable artifact or complete exact-head source was available here to verify that the recorded scenarios match commit 74ee66be3cd2347f6efb835b6a03cb977e645cd3.
  • Resolve merge risk (P1) - GitHub reports the branch as clean but behind main; review should refresh against the actual three-way merge result rather than infer a regression from base drift alone.
  • Complete next step (P2) - The protected maintainer label plus unavailable exact-head source and proof require a Control UI owner’s review; there is no discrete mechanical repair finding to dispatch.
Agent review details

Security

None.

PR surface

Source +11, Tests +305. Total +316 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 38 27 +11
Tests 1 305 0 +305
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 343 27 +316

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: ui/src/app/gateway-store.observers.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Refresh exact-head lifecycle proof (recommended)
    Before merge, attach or link redacted browser diagnostics, logs, terminal output, or a recording for the claimed replacement and stop scenarios, then review the actual merge result.
  2. Pause until the owner boundary is reproducible
    Pause this branch if the exact-head artifact cannot be recovered, because this lifecycle-sensitive change should not merge on uninspectable proof alone.

Technical review

Best possible solution:

Retain one canonical observer-delivery and current-client predicate in the Gateway store, then obtain a Control UI owner’s approval after an exact-head, redacted browser diagnostic or recording demonstrates the stop, replacement, and healthy-delivery scenarios.

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

Yes, from source: on current main, a snapshot listener is called directly from setSnapshot, and an event-log listener is called directly from publishEventLog; a focused fake-client regression can synchronously throw, stop, or replace the client during those callbacks. No local execution was performed because this review must not write test artifacts.

Is this the best way to solve the issue?

Yes, provisionally: consolidating notification isolation and checking whether the publishing client remains authoritative matches the Gateway store’s owner boundary, rather than compensating in individual UI consumers. Exact-head source and proof still need inspection before treating this as the final merge solution.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The reported defect affects active Control UI Gateway sessions and can result in missing updates or duplicate browser connection activity.
  • merge-risk: 🚨 session-state: The patch changes observer publication and client replacement ordering for snapshots and event-log state associated with the active UI session.
  • merge-risk: 🚨 availability: The patch changes stop, start, reconnect, and gap-recovery continuations that control browser WebSocket lifecycle.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body describes real-Chrome after-fix scenarios, but no accessible artifact and no complete exact-head source were available to independently connect that behavior to the proposed commit; attach redacted browser diagnostics, terminal output, logs, or a recording before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current observer delivery remains unguarded: Current main iterates snapshot observers directly, so a throwing or reentrant snapshot callback can escape the state publisher; event-log observers are likewise invoked directly before raw event listeners are reached. (ui/src/app/gateway-store.ts:88, 8b5871e1b703)
  • Current lifecycle callbacks establish the affected owner boundary: onHello, onGap, and onEvent all operate through the Gateway store; onHello publishes a connected snapshot, onGap immediately reconnects, and raw events already stop delivery when a client replacement occurs during listener iteration. (ui/src/app/gateway-store.ts:296, 8b5871e1b703)
  • Existing current-main tests cover related event invariants: The owner suite already verifies snapshot membership for raw event listeners, isolation of throwing event subscribers, isolation of throwing event-log subscribers, replacement during event delivery, and ignored events after stop; the proposed branch adds coverage for the remaining observer/lifecycle orders. (ui/src/app/gateway-store.test.ts:451, 8b5871e1b703)
  • Browser-client callback contract: The browser client accepts synchronous onHello, onEvent, onClose, and onGap callbacks, making exception isolation and reentrant ownership checks the store’s responsibility. (ui/src/api/gateway.ts:167, 8b5871e1b703)
  • Current-path provenance: The relevant current-main store lines trace to the same recent source introduction by Vincent Koc, so this person is the best available routing candidate for the existing owner boundary. (ui/src/app/gateway-store.ts:84, 11edc89613d9)
  • Exact-head inspection limitation: The PR commit and its changed blob identifiers are present locally, but the partial checkout could not hydrate the missing gateway-store.ts blob because GitHub DNS resolution failed; the supplied GitHub diff was therefore the only branch-source evidence available. (ui/src/app/gateway-store.ts, 74ee66be3cd2)

Likely related people:

  • Vincent Koc: Blame attributes the current Gateway store observer sets, direct publishers, and lifecycle callback body to this recent source introduction; the branch changes that same owner boundary. (role: current lifecycle implementation author; confidence: medium; commits: 11edc89613d9; files: ui/src/app/gateway-store.ts, ui/src/app/gateway-store.test.ts)

Rank-up moves

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

  • Attach redacted exact-head browser diagnostics, terminal output, logs, or a recording for the healthy-delivery, replacement, and stop scenarios.
  • Refresh review against the current three-way merge result once the exact branch blobs are available.

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 (1 earlier review cycle)
  • reviewed 2026-07-31T19:36:58.578Z sha 74ee66b :: needs real behavior proof before merge. :: none

@steipete
steipete marked this pull request as ready for review July 31, 2026 19:46
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 31, 2026
@steipete
steipete merged commit e4568f6 into main Jul 31, 2026
159 of 171 checks passed
@steipete
steipete deleted the codex/wave3-real-gateway-browser-proof branch July 31, 2026 21:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 31, 2026
* origin/main: (22 commits)
  fix(cron): preserve lazy ownership and bounded notification lifetimes (#117018)
  fix: live updater no-op restarts healthy gateways (#117038)
  fix(bedrock): release streaming clients (#117039)
  fix(google): restore canonical Gemini and Vertex provider invariants (#117042)
  fix(channels): preserve accepted LINE and Mattermost delivery (#117024)
  fix(feishu): unify truthful delivery and media ownership (#117023)
  fix(ui): isolate gateway observer lifecycles (#117017)
  fix(tui): keep reset transitions isolated from stale input (#116873)
  fix(gateway): centralize streamed media descriptor ownership (#117000)
  feat(plugins): externalize OpenCode provider (#117035)
  fix(onboarding): restore skill dependency consent (#116644)
  fix(streaming): preserve incomplete bracket tails in final replies (#116983)
  fix: allow slower gateway readiness after updates (#117032)
  fix(plugin-state): avoid shared SQLite corruption when CLI starts during gateway runtime (#113204)
  fix(cli): keep config file output raw under JSON logging (#116968)
  fix(ai): malformed Anthropic stream frames expose raw event payloads (#116938)
  fix(qa): authenticate actual scenario execution evidence (#117004)
  feat(plugins): externalize NovitaAI provider (#117007)
  fix(text): preserve fenced tool markers in visible-text sanitizer (#116939) (#116971)
  fix(channels): reset metadata memos with plugin lifecycle (#117005)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant