Skip to content

fix: first quick chat works on a fresh Gateway with no stored sessions - #2432

Open
shanselman wants to merge 8 commits into
mainfrom
shanselman-fix-2316-quick-chat-parent
Open

shanselman wants to merge 8 commits into
mainfrom
shanselman-fix-2316-quick-chat-parent

Conversation

@shanselman

@shanselman shanselman commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 16af7798021043a08e8112291077c06272e767f0

Dimension Assessment Rationale
Change confidence 9/10 ↑ If a parented quick-chat create is still rejected with unknown parent session, it retries once as a root session (no parent, no agent id, no hooks) without posting the error into main; timeout, lost connection and other errors do not retry.
↑ A rejected sessions.list is retried once per connection, so the roster gate cannot stay locked after one failure.
↑ Fresh-Gateway regressions (empty list; pending main timeline placeholder; main row tracked only from a job event) fail without the fix and pass with it.
↑ Stored-parent test proves established installs keep main's /new parent, command hooks and parallel-child request.
↑ Stored is decided only from rows an authoritative Gateway session roster returned (SessionInfo.IsGatewayListed), with a Shared test that job-event rows stay unlisted until a roster includes them and that reconnect clears the flag.
↑ Compose readiness unlocks only for a current-connection roster (every row listed, including empty); a regression shows a job-event republish after reconnect keeps quick chat locked, and fails without the fix.
↑ build.ps1, Shared (6240 passed) and Tray (7240 passed) green locally.
↑ The unknown-parent root retry runs only for a definitive rejection; an uncertain failure with that text does not retry.
↑ An uncertain create (timeout or lost connection) stays cached and refreshes the roster; reopening sends no second create and adopts the single new root (or parent child) session once listed. The test fails without the fix.
↑ The shared create ignores the opening window token, so close and reopen while pending joins one create (fails when the window token is passed).
↓ If an uncertain create never committed, or several new sessions appear, quick chat for that Gateway stays on its error until one new session is listed or the app restarts.
↓ A stored parent beyond the roster's default 100-row limit gets a root session without /new hooks (accepted residual, not a failure).
↑ Live on a fresh 2026.11.13 Gateway: this head's parentless request with agentId omitted succeeds under the Gateway default agent; explicit agentId:null is rejected, and the client omits null (BuildSessionCreateParameters).
↓ The Companion UI itself was not run against the live Gateway.
Diagnosis confidence 9.5/10 ↑ Reproduced live: a fresh OpenClaw 2026.11.13 Gateway (Windows Sandbox, empty state) rejects the old quick-chat request with INVALID_REQUEST unknown parent session: agent:main:main.
↑ Upstream prepareSessionCreateParent returns this error when the parent has no stored entry.
Evidence fit 7/10 ↑ The reported error text matches the live reproduction exactly.
↓ The reporter's first-chat entry point and versions are unknown; another path could also produce the error.

Relates to #2316

What Problem This Solves

On a fresh install, opening the floating claw's quick chat right after setup could fail with unknown parent session: agent:main:main. Quick chat created its conversation as a child of the main session, but a new Gateway advertises that main session before it has stored it, so the Gateway rejects the parent.

User Impact

User impact: the floating claw's quick chat can start its first conversation on a Gateway that has no stored sessions yet.

Why This Change Was Made

Quick chat used to always run the /new child-session command against the compose target. It still does when an authoritative Gateway session roster has returned that session (rows tracked only from job or tool events do not count), so established installs keep the parent link and the Gateway's /new command hooks (for example saving the parent's memory). When the compose target is not yet stored (fresh install), it now creates a root session with no agent id, so the Gateway uses its own default agent, the same parentless creation Workspace uses for a new chat, and refreshes the session list. Typed /new in an existing chat is unchanged.

Evidence

  • Regression CreateQuickChatSession_ZeroSessions_CreatesRootSessionWithoutUnstoredParent (Gateway connected, empty session list): on main behavior it failed with Expected: null, Actual: "agent:main:main" for the parent; with the fix it passes and sends no parent and no agent id.
  • CreateQuickChatSession_UnstoredMainWithPendingTimeline_CreatesRootSession: with no stored sessions but a chat event on agent:main:main (which adds a local placeholder thread), the request has no parent; without the fix it sent the unstored parent.
  • CreateQuickChatSession_MainTrackedOnlyFromJobEvent_CreatesRootSession and Shared TrackedSessionFromJobEvent_IsGatewayListedOnlyAfterSessionRoster: a main row created client-side by a job event is not treated as stored, so quick chat sends no parent; both failed without the fix.
  • Reconnect: OnConnectedAsync clears IsGatewayListed, and a sessions update counts as a roster only when every row is listed. LoadAsync_ReconnectJobEventWithoutRoster_KeepsQuickChatLocked shows a job-event republish after reconnect no longer unlocks quick chat (failed without the fix); the Shared roster test now also covers reconnect.
  • CreateQuickChatSession_UnknownParentRejection_RetriesOnceAsRootSession: a definitive unknown-parent rejection is followed by exactly one parentless retry (no agent id, emitCommandHooks=false) that succeeds, and main gets no error entry; it failed without the fix. CreateQuickChatSession_OtherParentedFailure_DoesNotRetry (timeout, lost connection, other error) sends only the parented request.
  • SessionsListError_RetriesOncePerConnection (Shared): a rejected sessions.list gets one scheduled retry per connection, not a loop, and reconnect re-arms it; it failed without the fix. Before this, the one post-handshake sessions.list was not retried, so only a later Gateway session event could unlock the composer.
  • LoadAsync_JobEventAddsUnlistedRowAfterRoster_KeepsComposeReady: an unlisted job-event row after a roster keeps compose ready.
  • BuildSessionCreateParameters_OmitsMissingAgentId: a null or blank agent id is omitted from sessions.create.
  • CreateQuickChatSession_OtherParentedFailure_DoesNotRetry now also covers an uncertain (timeout or lost connection) result whose error contains unknown parent session: no retry. It failed before the OutcomeUncertain guard and passes with it.
  • QuickChat_UncertainRootCreate_ReopenAdoptsRosterSessionWithoutCreatingAgain: an uncertain root create throws QuickChatCreationUncertainException and refreshes the roster; reopening keeps the attempt (one create request) and, once the roster lists one new root session, adopts it. It failed without the fix (the attempt was dropped and reopening created again).
  • QuickChat_CloseAndReopenWhileParentedCreatePending_JoinsTheSameCreate: closing the first window while the parented create is pending, then reopening, joins that create; after an unknown-parent rejection the reopened window gets the root session. Passing the window token into the shared create (the old host wiring) makes it fail with OperationCanceledException. ChatHost_SharedQuickChatCreateIgnoresTheOpeningWindowToken pins the host wiring and failed on the previous host.
  • The optional sessions.list retry tweak was not needed: errors from older connections are dropped before the handler and sessions.list is sent only on a ready connection, so a scheduled refresh is declined only when disposed or without read scope.
  • Residual: an uncertain create that never committed (or an ambiguous roster) leaves quick chat for that Gateway on its error until one new session is listed or the app restarts, matching how an uncertain draft create is never re-sent.
  • Residual: a stored parent beyond the roster's default 100-row limit gets a root session without /new hooks rather than an error.
  • CreateQuickChatSession_StoredComposeSession_KeepsNewCommandParentAndHooks: with a stored main session the request keeps parent agent:main:main, emitCommandHooks=true and succeedsParent=false, as on main.
  • ./build.ps1: all builds succeeded.
  • dotnet test ./tests/OpenClaw.Shared.Tests: 6240 passed, 28 skipped, 0 failed.
  • dotnet test ./tests/OpenClaw.Tray.Tests (excluding the host-profile SettingsManagerIsolationTests.OpenClawTrayDataDirRedirectsSettingsAwayFromRealAppData): 7240 passed, 0 failed.
  • Live Gateway protocol proof (disposable Windows Sandbox guest, OpenClaw 2026.11.13 from npm, empty OPENCLAW_STATE_DIR, openclaw gateway call): sessions.list returned no sessions; sessions.create {parentSessionKey:"agent:main:main", emitCommandHooks:true, succeedsParent:false} (the old quick-chat request) failed with INVALID_REQUEST unknown parent session: agent:main:main; sessions.create {emitCommandHooks:false} (this head's request, agentId omitted) succeeded and created agent:main:dashboard:… under the default agent; an explicit agentId:null is rejected with at /agentId: must be string, and BuildSessionCreateParameters omits a null agent id. After storing agent:main:main, the old /new request succeeded and created agent:main:dashboard:… with that parent. Request shape unchanged since; re-run on head 7c13bd0 in a new guest; the guest was stopped afterwards.
  • Not verified / blocked: the Companion UI floating claw was not driven against the live Gateway, and the reporter's exact first-chat action is still unconfirmed.

Required proof pools

  • windows-wsl-gateway-e2e: first quick chat against a fresh Gateway with no stored sessions. Partially verified: Gateway protocol reproduced and fix request accepted on a fresh 2026.11.13 Gateway in Windows Sandbox (see Evidence). Not verified / blocked: Companion UI not driven against it.

The floating claw created its dedicated conversation as a child of the
advertised main session. A fresh Gateway advertises agent:main:main before
storing it and rejects the unknown parent. Create a root session for the
compose target's agent instead.

Relates to #2316

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@clawsweeper

clawsweeper Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🦞👀
Pull request received.

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. merge-risk: 🚨 session-state 🚨 Merging this PR could lose, corrupt, stale, or mis-associate session or agent state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Dec 1, 2026
@clawsweeper

clawsweeper Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codex review: needs changes before merge.

What this changes

This PR creates floating-claw quick chats as root sessions instead of children of the advertised main session.

Example: A fresh Gateway advertises agent:main:main and returns an empty session list.

  • Before: Quick chat submits agent:main:main as its parent and receives an unknown-parent error.
  • After: Quick chat requests a root session for agent main without a parent.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) A focused and worthwhile repair with unit-level evidence, blocked by the concrete non-main-agent creation defect.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is exempt from contributor runtime proof; supplied evidence exercises provider request construction through a fake bridge, while the body explicitly discloses that no live Gateway or native quick-chat run was performed.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Opening quick chat after setup can fail because its advertised parent conversation has not been stored yet.
Reason: The maintainer-authored direction reuses an existing root-session contract and addresses a concrete failure; the broader linked report still has an unconfirmed entry point.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this PR addresses a current-main failure, but the new creation request can target the wrong agent when the advertised main session has no stored row.

Reviewed head: 268fef0dbaed4bbe190993414f2b3a5d32c91d6b

Before merge

  • [P2] Resolve the advertised agent before creating the root session (P2) - With MainSessionKey set to agent:ops:main and an empty session list, ChatSnapshotProjector returns ComposeTarget.AgentId=main because no matching row exists. This new call forwards that fallback as an explicit sessions.create agent. A Gateway configured with only ops rejects it as Unknown agent id "main"; if both agents exist, the conversation is created for the wrong agent. Resolve the agent from the advertised canonical target when its row is absent and extend the regression with a non-main agent.

Findings

  • [P2] [P2] Resolve the advertised agent before creating the root session — src/OpenClaw.Tray.WinUI/Windows/DesktopCompanionChatHost.cs:116-117
Agent review details

How this fits together

The floating-claw host obtains a compose target from the shared chat provider, creates a Gateway session through the authenticated bridge, and mounts chat using the returned session key.

flowchart LR
  A[Floating claw] --> B[Quick chat host]
  B --> C[Chat provider]
  C --> D[Gateway bridge]
  D --> E[Session creation RPC]
  E --> F[Returned session key]
  F --> B
Loading

Technical review

Best possible solution:

Create parentless quick chats using the advertised target's actual agent, including when its session row is absent, while preserving per-Gateway reuse and typed /new behavior.

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

Source establishes the empty-store parent failure and the non-main-agent defect in the proposed replacement; the reporter's exact entry point and installed versions remain unknown, and no runtime reproduction was performed.

Is this the best way to solve the issue?

Parentless creation through the existing provider seam is the smallest appropriate repair, provided agent identity comes from the advertised target rather than the session-list fallback.

Full review comments:

  • [P2] [P2] Resolve the advertised agent before creating the root session — src/OpenClaw.Tray.WinUI/Windows/DesktopCompanionChatHost.cs:116-117
    With MainSessionKey set to agent:ops:main and an empty session list, ChatSnapshotProjector returns ComposeTarget.AgentId=main because no matching row exists. This new call forwards that fallback as an explicit sessions.create agent. A Gateway configured with only ops rejects it as Unknown agent id "main"; if both agents exist, the conversation is created for the wrong agent. Resolve the agent from the advertised canonical target when its row is absent and extend the regression with a non-main agent.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6c14fe598718.

Provenance checked

  • Quick-chat child creation and command hooks changes intended behavior with a stated reason (fbc0287: The desktop companion feature created and retained a dedicated conversation through the existing New lifecycle command.)
  • Parentless draft creation keeps the original intent (e9423ae: Workspace new chats gained an agent-aware root-creation seam while deferring Gateway creation until first send; this PR reuses that seam without changing Workspace behavior.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

Acceptance criteria:

  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --filter FullyQualifiedName~CreateQuickChatSession
  • ./build.ps1
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore

What I checked:

Likely related people:

  • Karen: Raw commit fbc0287 adds src/OpenClaw.Tray.WinUI/Windows/DesktopCompanionChatHost.cs:125 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fbc02870795c; files: src/OpenClaw.Tray.WinUI/Windows/DesktopCompanionChatHost.cs)
  • Barbara Kudiess: Raw commit e9423ae adds src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:1146 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e9423aed4ba9; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)
  • Caleb Eden: Raw commit 2fb1da2 adds src/OpenClaw.Tray.WinUI/Chat/ChatLifecycleCommandDispatcher.cs:102 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 2fb1da26c175; files: src/OpenClaw.Tray.WinUI/Chat/ChatLifecycleCommandDispatcher.cs)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Patch size Production +18/-8; tests +22/-0 The change stays within the existing host and provider, with one focused regression and no new state owner.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The new root-session request uses the fallback agent main when the advertised session row is absent, potentially assigning the conversation to a different agent.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • merge-risk: 🚨 session-state: The new root-session request uses the fallback agent main when the advertised session row is absent, potentially assigning the conversation to a different agent.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 readiness starts with the lower of the proof and patch scores. It is capped at 3/6 if the fix is partial, the change offers little benefit, a product decision is still open, or the PR reverses an earlier decision without saying why. ✨ 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.

Reviewed December 1, 2026, 12:09 PM ET / 17:09 UTC.

shanselman and others added 7 commits December 1, 2026 10:58
…on is stored

The floating claw quick chat now creates a root session only when the compose
target is not yet stored on the Gateway (fresh install, #2316). Established
installs keep main's /new request with the parent link and command hooks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…pick default agent

A placeholder thread for an unstored main key could still route quick chat
through /new with an unknown parent. The root path now passes no agent id so
the Gateway's default agent is used.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Job and tool events track session rows client-side for keys the Gateway may
not have stored. Mark rows returned by an authoritative session roster and
use only those when choosing a /new parent for quick chat.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Clear IsGatewayListed on reconnect so cached rows are not trusted, and count a
sessions update as a roster only when every row was listed by the Gateway, so a
job or tool event republish cannot unlock compose readiness. Pin that a missing
agent id is omitted from sessions.create.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…t rejection

A rejected sessions.list is also retried once per connection so the roster gate cannot stay locked.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…rejection

Carry sessions.create OutcomeUncertain through the lifecycle result so an
uncertain failure carrying the unknown-parent text is not retried.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
When a quick-chat create may have committed (timeout or lost connection),
keep the attempt cached instead of dropping it, refresh the roster, and
adopt the single new session once it is listed, so reopening the floating
claw never sends a duplicate create. The shared create no longer takes the
opening window's token, so closing that window cannot cancel a create that
a reopened window has joined.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. merge-risk: 🚨 session-state 🚨 Merging this PR could lose, corrupt, stale, or mis-associate session or agent state. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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