Skip to content

fix(gateway): keep reconnect chat replays in the canonical thread; empty branch list for fresh sessions - #112756

Merged
steipete merged 3 commits into
mainfrom
claude/branches-list-fresh-session
Jul 23, 2026
Merged

steipete merged 3 commits into
mainfrom
claude/branches-list-fresh-session

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Live stress-testing the shipped web rewind/fork/branch flows (isolated dev gateway, OpenAI-key inference, real browser driving) surfaced two gateway bugs:

  1. Reconnect replays split the thread. The web outbox stores the default agent's thread under the shipped global alias scope. On reconnect, the durable-outbox drain flushes chat.send with sessionKey: "global" + agentId, and session load materialized a parallel literal global session instead of the canonical agent main thread. Queued messages and their model replies landed in a hidden transcript: the user sees their message vanish after reconnect while tokens are spent invisibly. Reproduced 3/3 (isolated gateway, latest main); agent-DB session_entries showed both agent:main:main and global rows, with the queued turns + replies in the orphan session. Online sends were unaffected because the foreground path routes with the page's concrete session key.

  2. Fresh sessions error on branch listing. sessions.branches.list responded INVALID_REQUEST: session not found for a session key that simply has not materialized yet (every new-chat page load), putting spurious failures in gateway logs and forcing clients to special-case a well-defined empty state.

Why This Change Was Made

  • chat.send session load now canonicalizes the global + agentId alias to resolveAgentMainSessionKey(...) (the same resolver history/routes use) whenever the configured session scope is not global, and the admission/pre-admission reloads reuse that same key, so one thread can no longer split. Configured global scope keeps its literal key.
  • sessions.branches.list returns { branches: [] } for a not-yet-materialized session; the mutating siblings (rewind/switch/fork) still treat a missing session as an error.

User Impact

Messages queued offline in the web UI now land in the visible thread with their replies after reconnect, instead of disappearing into a hidden parallel transcript. New-chat loads no longer emit gateway error-log noise for branch listing.

Evidence

  • Regression tests: chat.directive-tags.test.ts ("resolves per-sender global agent aliases to the canonical agent main session" — asserts dispatch lands on agent:main:main and raw global is never loaded) and sessions-rewind.test.ts (empty list for unmaterialized session). Focused runs green: 150/150 and 21/21.
  • Live before/after on the same isolated gateway + state: pre-fix, queued words (fig/grape/honeydew) + replies landed in orphan session fd8f35fa… (key global); post-fix, the same offline→reconnect cycle landed kiwi + reply in the current agent:main:main session (96a034d0…) with the outbox drained and the reply visible in the UI.
  • Root cause traced via sourcemap-resolved stack from a sessionStorage write trap (drain reconcile at ui/src/pages/chat/chat-send.ts:1393) plus agent-DB transcript queries.

@steipete
steipete marked this pull request as ready for review July 22, 2026 20:55
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Jul 22, 2026
@clawsweeper

clawsweeper Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): keep reconnect chat replays in the canonical thread; empty branch list for fresh sessions This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete
steipete merged commit d8325da into main Jul 23, 2026
117 checks passed
@steipete
steipete deleted the claude/branches-list-fresh-session branch July 23, 2026 14:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 24, 2026
…pty branch list for fresh sessions (openclaw#112756)

* fix(gateway): return empty branch list for not-yet-materialized sessions

* fix(gateway): canonicalize global agent alias in chat.send so reconnect replays stay in the visible thread

* test(gateway): assert canonical-key error broadcast for global agent alias sends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant