Skip to content

fix(tui): keep history and sends on the selected session - #159166

Merged
steipete merged 3 commits into
mainfrom
codex/tui-qualified-global-20260926
Sep 26, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/tui-qualified-global-20260926

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Related: #150153

What Problem This Solves

The TUI discarded an explicit key such as agent:research:global before loading history. It could display an empty or different conversation and send there. Submitting during a session switch also used the provisional key before history resolved.

User Impact

Existing qualified conversations keep their exact history and send target. If the qualified conversation is absent, the legacy selector resolves to the selected agent's Home: agent:<id>:main in per-sender scope, or global in global scope. Bare global, including case and whitespace variants, uses that same Home selection, matching the shipped Gateway send contract.

Saved-session upgrade behavior: a saved bare global selection in per-sender scope now displays the selected agent's existing Home, where the released Gateway already sends messages. This read-presentation correction is accepted; the send destination is preserved. Historical raw-global session IDs and messages remain retained, and an existing exact qualified conversation still wins. Saved-state coverage seeds the shipped scoped SQLite string in the registered startup flow and complements the real Gateway physical-identity tests; it is not an installed 2026.9.4 driver-to-candidate upgrade cell.

Input submitted while selection is unresolved stays in the editor for an explicit Enter after readiness. Session-dependent actions share that readiness decision, including model-picker commits and Escape abort. Failed startup history gives --message an explicit not-sent outcome; the literal message retains its existing one-attempt behavior and is not replayed after recovery. No configuration, protocol, or storage migration is required.

Why This Change Was Made

History prefers the exact qualified row. Only a successful empty result without session identity permits Home fallback; existing empty rows, archived rows, malformed responses, and errors do not. The existing selection/history owner captures the agent and Home target and revalidates after awaited work. Shared explicit-selection receipt comparison rejects stale results without changing Gateway event aliases.

Admission uses the existing historyLoaded fact and captured submit state, including coalesced input. It adds no selection manager, queue, or cache. Ordinary refresh of an already loaded conversation remains usable. Historical raw-global history remains readable; in per-sender scope they are distinct from the shipped writable Home alias.

Evidence

The subsequent CI cleanup makes the disconnect formatter private to its existing admission module; its function body and internal call are unchanged. The same message assertions now use the production formatter. The formerly failing full deadcode scan, 39 focused tests, types, lint, and fresh review pass. This export-only change preserves the applicability of the behavioral proof and screenshots below.

The original selection defect, immediate-submit race, and uppercase alias bypass were reproduced before their fixes. Focused tests passed (420), followed by all 82 selector tests on the final case-normalization change; these counts overlap. All 22 registered TUI identity PTY tests passed. Final production/test types, scoped lint, line-cap checks, and independent review through P2 passed.

The build at 56e02f9 and all four real Gateway/TUI cells passed: qualified-existing and missing-qualified Home fallback in both scopes. The default agent is Main while Research is explicitly selected. Each cell verifies held input, no automatic send, the outgoing physical session ID, rendered reply, and persisted user message on the same conversation. The per-sender historical raw row keeps the same session ID and messages. Direct padded uppercase GLOBAL navigation returns to the same Home without another send. All owned processes and the Testbox lease were settled.

The images below are actual Linux xterm pixels from a synthetic backend: before commit 0a4b6d7, then the behavior-tested 56e02f9 source. Before, input leaves the editor and sends against a provisional selection. After, it remains editable with a readiness notice; the third image shows the resolved Home history with the draft still waiting for Enter. Both TUI processes exited cleanly and all six source hashes were restored. The separate real Gateway proof covers transport and persistence. All data and the loopback model endpoint are synthetic; no authenticated external provider was used.

Before: input sends while session history is unresolved

After: the readiness notice preserves the editable draft

After history resolves: Research Home and the retained draft

@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 in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Sep 26, 2026
@steipete
steipete marked this pull request as ready for review September 26, 2026 20:48
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. 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. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 26, 2026, 7:20 PM ET / 23:20 UTC (Revision 2).

ClawSweeper review

What this changes

This PR changes how the terminal UI selects session history and admits sends during selection, and updates the related documentation and regression tests.

Merge readiness

⛔ Blocked before merge - 5 items remain

The prior send-during-selection finding is addressed. This PR still needs an upgrade repair: a saved bare global selection now reopens Home, changing the conversation and send target for existing users.

Priority: P1
Reviewed head: 56e02f9615a71f96611f0b3892f60926000d0d61
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The real-path report and focused tests are strong, but the saved-session upgrade regression blocks readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body reports exact-source real Gateway/TUI runs in both scopes, observing held drafts, outgoing session IDs, replies, and persisted messages after the fix. The linked screenshots could not be opened in this review because local preparation returned 404 and browser opening returned cache misses; that inspection limit does not negate the reported transport proof. Separately, the saved JSON key changes meaning, and compatible existing-state upgrade behavior remains unproven.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body reports exact-source real Gateway/TUI runs in both scopes, observing held drafts, outgoing session IDs, replies, and persisted messages after the fix. The linked screenshots could not be opened in this review because local preparation returned 404 and browser opening returned cache misses; that inspection limit does not negate the reported transport proof. Separately, the saved JSON key changes meaning, and compatible existing-state upgrade behavior remains unproven.
Evidence reviewed 10 items Previous behavior on current main: Current main preserves a bare global selector instead of resolving it to the agent's Home.
Introduced selector change: The PR resolves bare global to Home in both typed and restored selections.
Persisted selector path: The remembered session key is stored as a JSON string and read without a migration or distinction between saved and newly typed selectors.
Findings 1 actionable finding [P1] Preserve remembered raw-global selections on upgrade
Security None None.

How this fits together

The terminal UI takes a selected agent and session key, loads that conversation from the Gateway, and sends messages and session actions back to it. On startup, it also reads the last selected key from local state.

flowchart LR
  A[Typed or saved session] --> B[TUI selection]
  B --> C[Gateway history]
  C --> D{History ready?}
  D -- Yes --> E[Editor and actions]
  E --> F[Gateway send]
  F --> G[Stored conversation]
  D -- No --> H[Hold draft]
Loading

Decision needed

Question Recommendation
Should a previously saved bare-global TUI selection continue to reopen its historical conversation, or may this upgrade intentionally redirect it to Home? Preserve saved selections: Distinguish restored keys from new input and keep an existing raw-global conversation selected, with upgrade proof.

Why: The branch changes the meaning of persisted user state, and the PR body describes the new behavior without an explicit upgrade disposition for users who saved the old selection.

Before merge

  • Preserve remembered raw-global selections on upgrade (P1) - A saved global key is read from local state and passed through this changed resolver. Previously it restored global; now it opens Home, as the changed PTY test confirms. A user restarting after upgrade can see and send to a different conversation. Preserve the old saved target or add an explicit migration and upgrade proof while keeping the intended behavior for newly typed input.
  • Resolve merge risk (P1) - Existing saved bare-global selections silently open Home on upgrade; a later send can therefore target a different conversation.
  • Resolve merge risk (P1) - The linked before/after TUI images were unavailable to this reviewer, so the repository's screenshot rendering and chat-delivery gate still needs human verification.
  • Complete next step (P2) - Resolve the saved global upgrade finding and record the new test's measured cost; a maintainer should also confirm that the linked before/after images render and satisfy the required chat delivery.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Preserve remembered raw-global selections on upgrade — src/tui/tui.ts:198-203
Agent review details

Security

None.

PR surface

Source +125, Tests +568, Docs +2. Total +695 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 6 211 86 +125
Tests 11 1021 453 +568
Docs 1 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 1236 541 +695

Review metrics

Metric Value Why it matters
Production and test growth production +125 net lines; tests and support +568 net lines The growth is concentrated in session admission and observable selection regressions, including a moved abort suite.
Saved selector meaning 1 persisted key reinterpreted A stored bare global key now resolves to Home during startup.

Merge-risk options

Maintainer options:

  1. Repair saved-key upgrades (recommended)
    Preserve the prior saved raw-global target or migrate it explicitly, then prove an existing-state restart and send.
  2. Accept a changed target
    A maintainer may approve the redirect with a visible upgrade notice and evidence that users can recover the historical conversation.

Technical review

Best possible solution:

Keep Home behavior for newly typed bare global, while preserving or explicitly migrating saved raw-global selections with an existing-state regression and a clear outcome when the old row is absent.

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

Yes, from source: current main retains the bare global selection, while the branch redirects it and changes the saved-state PTY expectation. This read-only review did not execute the TUI.

Is this the best way to solve the issue?

No, not yet. Exact-first history and the readiness guard fit the defect, but saved selectors need an upgrade-safe interpretation before this is the narrowest complete fix.

Full review comments:

  • [P1] Preserve remembered raw-global selections on upgrade — src/tui/tui.ts:198-203
    A saved global key is read from local state and passed through this changed resolver. Previously it restored global; now it opens Home, as the changed PTY test confirms. A user restarting after upgrade can see and send to a different conversation. Preserve the old saved target or add an explicit migration and upgrade proof while keeping the intended behavior for newly typed input.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.92

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • remove proof: 📸 screenshot: Current real behavior proof evidence kind is terminal.

Label justifications:

  • P1: A TUI session choice can affect which conversation receives a user's next message.
  • merge-risk: 🚨 compatibility: The PR changes the meaning of an existing persisted TUI session key on upgrade.
  • merge-risk: 🚨 message-delivery: Restoring that key can direct the next send to Home instead of the previously selected conversation.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body reports exact-source real Gateway/TUI runs in both scopes, observing held drafts, outgoing session IDs, replies, and persisted messages after the fix. The linked screenshots could not be opened in this review because local preparation returned 404 and browser opening returned cache misses; that inspection limit does not negate the reported transport proof. Separately, the saved JSON key changes meaning, and compatible existing-state upgrade behavior remains unproven.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports exact-source real Gateway/TUI runs in both scopes, observing held drafts, outgoing session IDs, replies, and persisted messages after the fix. The linked screenshots could not be opened in this review because local preparation returned 404 and browser opening returned cache misses; that inspection limit does not negate the reported transport proof. Separately, the saved JSON key changes meaning, and compatible existing-state upgrade behavior remains unproven.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: 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.

  • Preserve or explicitly migrate a previously saved raw-global selection and prove its restart and next send.
  • Record measured wall time and CI duration for the new test file, as requested in the prior review.

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-09-26T20:55:13.131Z sha 0a4b6d7 :: blocked before merge. :: [P1] Block sends until qualified-global fallback resolves

Keep exact qualified sessions and resolve absent global aliases through the existing agent Home selector. Preserve blocked editor input and reject session-dependent actions until history establishes the target, including captured coalesced submissions and literal startup-message refusal.
@steipete steipete changed the title fix(tui): preserve qualified global session selection fix(tui): keep history and sends on the selected session Sep 26, 2026
@clawsweeper clawsweeper Bot removed the proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. label Sep 26, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer disposition: accept the corrected read presentation for saved global aliases and reject the claimed send-target regression.

The saved-global finding needs to distinguish the displayed history from the established send destination.

The released 2026.9.4 Gateway already resolves per-sender global plus its selected agent to that agent's main conversation before any store lookup (shipped source, introduced by #112756). This PR does not change that write contract. Our retained failing real-Gateway control confirmed it: a send carrying the historical raw-global session ID was accepted, but its user message and generated reply went to the separately seeded Research Home session; the raw history kept only its prior message.

Keeping a saved raw-global selection in the writable TUI would preserve that history/send mismatch. The intended repair is to interpret the saved alias through the same existing Home resolver as typed input, display the conversation the Gateway already writes, and block sends until its history is established. The saved-pointer PTY regression starts from the saved raw string under its existing agent/scope key, holds startup history, verifies the editable blocked draft, and then permits exactly one explicit send to Home. No saved-state schema, storage migration, or Gateway routing change is introduced. This existing-state startup proof and the separate real Gateway cells are complementary; an installed 2026.9.4 driver-to-candidate upgrade cell was not run.

Historical raw-global data is retained: the final real proof verifies the same raw session ID and unchanged messages through the existing chat.history API, while Home receives the new user message and reply. An existing qualified agent:research:global conversation still wins exactly. Both scopes and a default agent distinct from Research are covered. I therefore reject the claim that this introduces a different send destination; the visible history change is the deliberate repair that makes displayed and writable conversation identity agree.

The screenshot gate is independently verified: all three full native PNGs were inspected as synthetic-only, visibly attached in the originating chat, and checked in the rendered PR with decoded dimensions of 996×614. The reviewer's image-fetch limitation does not leave that delivery gate unverified. The later 58a68de cleanup only removes an unused export keyword; its function body/internal call and displayed behavior are unchanged.

Measured verification runs: 420 focused tests in 48 seconds, 82 final selector tests in 40 seconds, 22 registered identity PTY tests in 75 seconds, and the four real Gateway/TUI cells in 33 seconds. The full remote build, proof, and native capture took about 8 minutes 15 seconds. The export cleanup separately passed the formerly failing full deadcode scan, 39 focused tests, types, lint, and fresh independent review.

@steipete
steipete merged commit ccf4edd into main Sep 26, 2026
216 checks passed
@steipete
steipete deleted the codex/tui-qualified-global-20260926 branch September 26, 2026 23:54
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…9166)

* fix(tui): preserve qualified global session selection

* fix(tui): wait for resolved session history before sending

Keep exact qualified sessions and resolve absent global aliases through the existing agent Home selector. Preserve blocked editor input and reject session-dependent actions until history establishes the target, including captured coalesced submissions and literal startup-message refusal.

* fix(tui): keep disconnect formatter private to admission owner
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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