Skip to content

perf: streamline chat startup metadata#88825

Merged
steipete merged 3 commits into
mainfrom
perf/startup-followups
Jun 1, 2026
Merged

perf: streamline chat startup metadata#88825
steipete merged 3 commits into
mainfrom
perf/startup-followups

Conversation

@steipete

@steipete steipete commented May 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Make chat.history return enough persisted and synthetic session metadata for startup hydration so the web UI can skip the startup sessions.list follow-up.
  • Centralize UI/TUI/global-session key matching helpers so /new, /reset, chat send, run lifecycle, and gateway hydration share the same selected-agent rules.
  • Defer model auth status refresh when opening the chat tab so chat/history paint is not blocked by auth probing.
  • Preserve queued global sends until defaults/hello agent metadata is known, so they do not get pinned to main too early.

Verification

  • pnpm exec oxfmt --check ui/src/ui/session-key.ts ui/src/ui/app-chat.ts ui/src/ui/app-chat.test.ts src/routing/session-key.ts src/routing/session-key.test.ts src/tui/tui-session-actions.ts src/gateway/server.chat.gateway-server-chat-b.test.ts
  • pnpm tsgo:test:ui
  • node scripts/run-vitest.mjs ui/src/ui/app-chat.test.ts src/routing/session-key.test.ts src/tui/tui-session-actions.test.ts src/gateway/server.chat.gateway-server-chat-b.test.ts
  • /Users/steipete/Projects/agent-scripts/skills/autoreview/scripts/autoreview --mode branch --base origin/main -> clean, no accepted/actionable findings

Real behavior proof

Behavior addressed: startup and reset/new command latency from redundant session discovery and duplicate UI-side session-key logic.
Real environment tested: local gateway plus authenticated Control UI and TUI tmux sessions.
Exact steps or command run after this patch: opened http://127.0.0.1:18789/chat?session=main, inspected startup RPC traffic, then exercised /new and /reset in the TUI under tmux.
Evidence after fix: web startup used chat.history, models.list, commands.list, and deferred models.authStatus; it did not issue the startup sessions.list follow-up. TUI /new switched locally without a gateway RPC, and /reset issued only sessions.reset without follow-up chat.history or sessions.list.
Observed result after fix: chat.history carried enough session metadata for startup hydration; the TUI command path stayed single-RPC or local-only where expected.
What was not tested: full cross-platform release checks; PR CI remains the broad gate.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: M maintainer Maintainer-authored PR labels May 31, 2026
@clawsweeper

clawsweeper Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed May 31, 2026, 9:13 PM ET / 01:13 UTC.

Summary
The branch centralizes UI/TUI session-key matching, uses chat.history metadata for startup hydration, defers chat auth-status refresh, and adjusts queued global-send handling.

PR surface: Source -32, Tests +121. Total +89 across 11 files.

Reproducibility: yes. source-reproducible: the new test enqueues a disconnected global send with no agentId, then ensureQueuedSendState returns early on replay because sendRunId and sendState are already present. I did not run tests because this review was required to keep the checkout read-only.

Review metrics: none identified.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦞 diamond lobster
Patch quality: 🧂 unranked krab
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Fix queued global-send replay so a missing agentId is resolved after defaults load while preserving already-captured agent choices.
  • Refresh against current main and rerun the focused UI/routing/TUI/gateway tests listed in the PR body.

Risk before merge

  • [P1] The added queued global-send scenario is source-inconsistent: replay can still send agentId as undefined after defaults load, which can route the message to the gateway default instead of the intended selected/default agent.
  • [P1] The shared key helpers now influence Control UI chat, gateway event filtering, queued replay, session subscriptions, run lifecycle reconciliation, and TUI session rows, so alias mistakes can mis-associate session state or message/status events.
  • [P1] The branch needs a final refresh against current main's startup-send fixes before merge; this is a rebase/review risk, not proof that a clean three-way merge would delete those protections.

Maintainer options:

  1. Fix queued replay before merge (recommended)
    Update queued-send preparation so waiting global sends with no captured agent resolve the agent after defaults load, while preserving an agent that was already captured at enqueue time.
  2. Refresh against current main
    After the queued-send fix, rebase or otherwise refresh the branch and re-check the startup chat send protections from current main before maintainer approval.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Update `ui/src/ui/app-chat.ts` so retrying a waiting global queued send recomputes `agentId` when it was originally unknown after defaults load, preserves already-captured agent IDs, and makes the added `ui/src/ui/app-chat.test.ts` queued global-send test pass without changing unrelated session-key behavior.

Next step before merge

  • [P2] A narrow mechanical repair can update queued-send preparation and preserve captured agent IDs while making the added regression test pass.

Security
Cleared: The diff touches UI/gateway/session-routing code and tests, with no dependency, workflow, secret, package, or supply-chain surface changes found.

Review findings

  • [P1] Recompute missing agentId before replaying queued sends — ui/src/ui/app-chat.test.ts:1884
Review details

Best possible solution:

Merge the shared session-key/startup direction only after queued global-send replay fills a missing agentId from fresh defaults without overwriting already-captured agent choices, then refresh the branch against current main's startup-send protections.

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

Yes, source-reproducible: the new test enqueues a disconnected global send with no agentId, then ensureQueuedSendState returns early on replay because sendRunId and sendState are already present. I did not run tests because this review was required to keep the checkout read-only.

Is this the best way to solve the issue?

No, not yet: centralizing session-key/default-agent handling is the right direction, but the current patch does not implement the delayed agent selection its new test expects. The narrow fix is to recompute only missing queued agentId values at replay time after defaults are known.

Full review comments:

  • [P1] Recompute missing agentId before replaying queued sends — ui/src/ui/app-chat.test.ts:1884
    This added expectation is not produced by the current code path. handleSendChat creates the disconnected global queued item with sendRunId/sendState already set and agentId undefined; on reconnect, ensureQueuedSendState returns that item before recomputing the now-known default agent, so chat.send still receives no agentId and can route to the gateway default instead of work.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 5b0c4c04917f.

Label changes

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦞 diamond lobster and patch quality is 🧂 unranked krab.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P2: This is a normal-priority PR with useful performance/session-routing work, but the blocker is pre-merge and bounded to queued global-send routing plus review refresh.
  • merge-risk: 🚨 message-delivery: The changed queued global-send path can replay a message without the intended agent ID, causing delivery to the wrong agent/default route.
  • merge-risk: 🚨 session-state: The new shared session-key matching logic affects session hydration, subscriptions, run lifecycle reconciliation, and TUI session rows.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦞 diamond lobster and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes labeled after-fix proof from a local gateway, authenticated Control UI, and TUI tmux sessions with observed RPC traffic and /new//reset behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes labeled after-fix proof from a local gateway, authenticated Control UI, and TUI tmux sessions with observed RPC traffic and /new//reset behavior.
Evidence reviewed

PR surface:

Source -32, Tests +121. Total +89 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 8 180 212 -32
Tests 3 121 0 +121
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 301 212 +89

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs ui/src/ui/app-chat.test.ts src/routing/session-key.test.ts src/tui/tui-session-actions.test.ts src/gateway/server.chat.gateway-server-chat-b.test.ts.
  • [P1] pnpm exec oxfmt --check ui/src/ui/session-key.ts ui/src/ui/app-chat.ts ui/src/ui/app-chat.test.ts src/routing/session-key.ts src/routing/session-key.test.ts src/tui/tui-session-actions.ts src/gateway/server.chat.gateway-server-chat-b.test.ts.
  • [P1] pnpm tsgo:test:ui.

What I checked:

  • PR body and live metadata: The PR body claims local gateway, authenticated Control UI, and TUI tmux proof for skipping startup sessions.list, deferring models.authStatus, and reducing /new and /reset follow-up RPCs; live labels include maintainer, proof: sufficient, merge-risk: 🚨 session-state, and merge-risk: 🚨 message-delivery. (5c8396f8a3e1)
  • Added regression expectation: The new queued global-send test expects the replayed chat.send payload to include agentId: "work" after defaults load. (ui/src/ui/app-chat.test.ts:1884, 5c8396f8a3e1)
  • Source path contradicts the new test: On PR head, disconnected sends enqueue a queued item with sendRunId and sendState already set, and ensureQueuedSendState immediately returns such items before it can recompute a missing agentId from the now-populated defaults. (ui/src/ui/app-chat.ts:496, 5c8396f8a3e1)
  • Replay path uses the stale queued item: retryReconnectableQueuedChatSends replays the waiting item through sendQueuedChatMessage, so the early return above leaves prepared.agentId undefined for the new scenario. (ui/src/ui/app-chat.ts:1123, 5c8396f8a3e1)
  • Current-main adjacent startup-send work: Current main contains recent adjacent Control UI startup-send fixes in ui/src/ui/app-gateway.ts, so this broad session-routing PR needs a final refresh/review against those protections before merge. (ui/src/ui/app-gateway.ts:589, 49b62079f7d4)
  • Related canonical performance issue: GitHub search found the open Control UI startup RPC performance issue as related work, but it has clawsweeper:no-new-fix-pr and clawsweeper:needs-maintainer-review, so this existing PR should be repaired/reviewed rather than replaced by a new broad fix PR.

Likely related people:

  • steipete: Peter Steinberger has the largest recent history across the touched UI/gateway/session files and prior session-key normalization work appears in the path history; this is independent of being the PR author. (role: recent area contributor; confidence: high; commits: e93216080aa1, f665da8dbcf3, 4b71de384c7b; files: ui/src/ui/app-chat.ts, ui/src/ui/app-gateway.ts, ui/src/ui/session-key.ts)
  • vincentkoc: Vincent Koc landed the current-main startup chat-send protections that this PR must preserve during rebase/final review. (role: recent adjacent owner; confidence: high; commits: 49b62079f7d4, 43ced7bc4949, dbe2a97e802a; files: ui/src/ui/app-gateway.ts, ui/src/ui/controllers/chat.ts, ui/src/ui/app-chat.ts)
  • Tyler Yust: Tyler Yust has earlier merged work on chat session dropdowns, session refresh behavior, and chat session constants in the same Control UI surface. (role: session UI history contributor; confidence: medium; commits: 6372242da756, 0b7aa8cf1d2a, 57c34a324c03; files: ui/src/ui/app-chat.ts, ui/src/ui/controllers/sessions.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels May 31, 2026
@steipete
steipete force-pushed the perf/startup-followups branch from ceb2305 to 256f8c8 Compare May 31, 2026 23:47
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. labels Jun 1, 2026
@steipete
steipete force-pushed the perf/startup-followups branch from f65fbed to 2794970 Compare June 1, 2026 00:20
@steipete
steipete force-pushed the perf/startup-followups branch from 2794970 to 6e086cc Compare June 1, 2026 00:29
@steipete
steipete force-pushed the perf/startup-followups branch from 5503939 to 17f3e13 Compare June 1, 2026 00:57
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

💡 Codex Review

await retryReconnectableQueuedChatSends(host);

P2 Badge Resolve missing agentId before retrying queued sends

In this new scenario the queued item is created while disconnected with sendRunId/sendState already set and agentId undefined; when retryReconnectableQueuedChatSends calls back into the send path, ensureQueuedSendState returns early for items that already have those fields, so it never re-reads the now-populated agentsList.defaultId. The subsequent chat.send therefore goes out with no agentId, so a global message queued before defaults load is routed to the gateway default instead of the intended selected/default agent.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Jun 1, 2026
@steipete
steipete force-pushed the perf/startup-followups branch from 17f3e13 to 5c8396f Compare June 1, 2026 01:05
@steipete steipete self-assigned this Jun 1, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jun 1, 2026
@steipete

steipete commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready maintainer proof for 5c8396f8a3e1.

Local proof run:

  • pnpm exec oxfmt --check ui/src/ui/session-key.ts ui/src/ui/app-chat.ts ui/src/ui/app-chat.test.ts src/routing/session-key.ts src/routing/session-key.test.ts src/tui/tui-session-actions.ts src/gateway/server.chat.gateway-server-chat-b.test.ts passed.
  • pnpm tsgo:test:ui passed.
  • node scripts/run-vitest.mjs ui/src/ui/app-chat.test.ts src/routing/session-key.test.ts src/tui/tui-session-actions.test.ts src/gateway/server.chat.gateway-server-chat-b.test.ts passed: 4 shards, 194 tests.
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main passed clean: no accepted/actionable findings.

Manual review notes:

  • Current head merges cleanly with origin/main; the earlier ui/src/ui/app-gateway.ts conflict finding is stale.
  • The queued global-send regression called out by Codex is covered by current head and the focused regression passes.

CI state at merge attempt:

  • Passing: Real behavior proof, dependency guard, TUI PTY, workflow sanity/actionlint/no-tabs, labeler, auto-response.
  • No failing checks observed.
  • Pending/still queued at the time of this proof: CI preflight/security-fast, CodeQL security shards, CodeQL Critical Quality selection, OpenGrep PR diff scan.

@steipete
steipete merged commit 6b940ed into main Jun 1, 2026
168 of 170 checks passed
@steipete
steipete deleted the perf/startup-followups branch June 1, 2026 01:18
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 1, 2026
* perf: streamline chat startup metadata

* fix: defer global queued agent selection

* style: format gateway startup refresh
SYU8384 pushed a commit to SYU8384/openclaw that referenced this pull request Jun 3, 2026
* perf: streamline chat startup metadata

* fix: defer global queued agent selection

* style: format gateway startup refresh
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* perf: streamline chat startup metadata

* fix: defer global queued agent selection

* style: format gateway startup refresh
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 gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant