Skip to content

improve(chat): load conversation history on demand - #1040

Merged
shanselman merged 6 commits into
openclaw:mainfrom
calebeden:calebeden-lazy-load-chat-history
Jul 21, 2026
Merged

shanselman merged 6 commits into
openclaw:mainfrom
calebeden:calebeden-lazy-load-chat-history

Conversation

@calebeden

@calebeden calebeden commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Windows tray previously loaded the full transcript for every known session during startup and reconnect. Users with many sessions paid for unnecessary gateway requests, transcript processing, telemetry volume, and startup work even when they opened only one conversation.

Why This Change Was Made

sessions.list metadata remains eager and complete for the session picker, while chat.history is demand-loaded for the current/default or explicitly selected session. Successful loads are cached only for the current connection generation. Disconnect, reconnect, disposal, delayed retries, stale responses, notifications, and queued UI delivery are generation-guarded so old work cannot mutate or report against a newer connection or consume its retry budget.

OpenClawChatRoot remains the initial/selected-session load owner; ChatWindow no longer starts a second eager path. Render-driven requests run only while the snapshot is connected.

User Impact

Users with many sessions should see less startup and reconnect work. Session discovery remains unchanged. Selecting an unopened conversation loads it once; returning to a transcript already loaded in the same connection generation reuses the cached timeline. Failures from a superseded/disposed generation no longer surface stale error UX.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Validation

Validated on merged current origin/main (54927b46) at PR head 6bfa6a8c:

  • $env:OPENCLAW_REPO_ROOT=(Get-Location).Path; .\build.ps1
    • Passed: Shared, CLI, WinNode CLI, SetupEngine, and WinUI builds.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore
    • Passed: 3,161; skipped: 31; failed: 0.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --settings <sequential-runsettings>
    • Passed: 1,875; skipped: 0; failed: 0.
  • Focused history generation/concurrency/notification/telemetry filter
    • Passed: 14; skipped: 0; failed: 0.
    • Core 12-race subset passed 5 consecutive runs on the final implementation (plus 15 earlier repeat runs during iteration).
  • dotnet test .\tests\OpenClaw.Tray.UITests\OpenClaw.Tray.UITests.csproj --no-build -c Debug -r win-x64 --filter "Category!=Accessibility"
    • Passed: 93; skipped: 0; failed: 0.
  • Accessibility lane (Category=Accessibility)
    • Passed: 16; failed: 3 local Axe scans. Failures were existing/offscreen geometry checks on Chat composer buttons, the Connection setup-code tile, and the Sessions overflow button; none is changed by this PR. Current main Build and Test, CodeQL, and push workflows are green at 54927b46.
  • GitHub checks on 6bfa6a8c
    • Passed: repo hygiene, test, setup-connect E2E, revocation-recovery E2E, network-recovery E2E, win-x64 build, win-arm64 build, and CodeQL advanced setup gate. Merge state: clean.

The default parallel Tray run twice exposed the pre-existing shared identity-file race in different connection tests. Each failed test passed in isolation; the complete Tray suite passed with xUnit collection parallelism disabled.

Real Behavior Proof

  • Environment: Windows 11 x64, .NET SDK 10.0.302, live configured gateway, normal user profile.
  • Exact PR head: 6bfa6a8c.
  • Capture boundary: DebugView filtered only to Sending frame: chat.history; no transcript contents, IDs, prompts, or responses were included in proof output.
  • Current-head steps: open the companion Sessions page, choose an uncached session with Open in chat, return to the already loaded default session.
  • Current-head result: uncached explicit selection emitted exactly 1 chat.history request; returning to the generation-cached default emitted 0 additional requests. Both transcripts rendered normally.
  • Startup/default proof: an earlier normal-profile capture on d802c016 emitted exactly 1 startup request. Final follow-ups affect generation, retry, notification, and delivery ordering; current-head proof directly reverified selected-session +1 and cached-return +0 behavior.

Concurrency and Telemetry Coverage

Deterministic behavioral tests verify:

  • one request per session per connection generation;
  • complete metadata with no sessions.list history fan-out;
  • independent completion when selection changes while multiple session requests are in flight;
  • stale success/failure/retry suppression across reconnect;
  • stale-before-notification suppression with canceled, exception-free telemetry;
  • one current-at-delivery synchronous notification when reconnect occurs inside the callback, with no stale retry/new-budget consumption;
  • queued UI notifications are dropped after disposal;
  • retry expected-generation/status validation and _historyInFlight reservation are atomic under _gate;
  • disconnect/dispose cancellation of provider waits and pending/delayed retries;
  • disconnect clears prior in-flight ownership for later explicit loads;
  • generation CTS swap occurs under _gate, while cancellation/disposal occurs outside it;
  • captured late status callbacks no-op after disposal;
  • ownership/observation of late gateway task completion and retry tasks;
  • queued history delivery cannot overwrite a newer disconnected snapshot;
  • finite initial/forced sources and privacy-safe exception-type-only failure telemetry.

Review

Accepted and fixed review findings:

  • queued history delivery could publish an older connected snapshot after disconnect;
  • stale failures could notify after a generation changed before notification;
  • synchronous reconnect during NotificationRequested needed post-callback telemetry/retry revalidation;
  • queued UI notifications needed delivery-time generation/disposal validation;
  • generation CTS cancellation under _gate risked callback deadlock and old CTS instances were not disposed;
  • a captured status callback could reuse a disposed terminal CTS;
  • retry generation validation and new-generation reservation had a check-to-call race.

Final code-review and rubber-duck passes on the completed implementation found no significant actionable issues. The bundled autoreview command was attempted twice earlier but blocked before model execution by the local Codex helper-path restriction; it is reported as blocked, not clean.

GitHub review conversations: no inline/review findings. ClawSweeper has started a fresh review of current head 6bfa6a8c and currently shows only its review started placeholder.

Security Impact

  • New permissions or capabilities? No.
  • Secrets or token handling changed? No.
  • Network calls changed? Existing chat.history calls are reduced; endpoint and payload shape are unchanged.
  • Data access scope changed? Yes, narrowed: unopened transcripts are no longer read by default.
  • Telemetry remains opt-in and exports no content, identifiers, URLs, error messages, model/provider names, or attachment data.

Compatibility and Migration

  • Backward compatible: Yes.
  • Config or environment changes: No.
  • Migration needed: No.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 831649d0-a3be-4df1-9734-8dbff43bd2b3
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 831649d0-a3be-4df1-9734-8dbff43bd2b3
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 831649d0-a3be-4df1-9734-8dbff43bd2b3
@calebeden
calebeden marked this pull request as ready for review July 21, 2026 17:38
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: f08214a3-7553-4cfe-bad3-8d9527d05f08
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: f08214a3-7553-4cfe-bad3-8d9527d05f08
@clawsweeper

clawsweeper Bot commented Jul 21, 2026

Copy link
Copy Markdown

ClawSweeper status: review started.

I am starting a fresh review of this pull request: improve(chat): load conversation history on demand 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.

@shanselman
shanselman merged commit 282e583 into openclaw:main Jul 21, 2026
12 checks passed
@calebeden
calebeden deleted the calebeden-lazy-load-chat-history branch July 21, 2026 22:00
shanselman added a commit to calebeden/openclaw-windows-node that referenced this pull request Jul 21, 2026
Integrate openclaw#1040 demand-loaded history (LoadHistoryCoreAsync split, generation
CTS, connection version guards) with PR openclaw#1036 authoritative reload path.

Resolve provider conflicts preserving both connection-versioned history
flights and authoritative reload pending queue.

Address review findings:
- Replace hardcoded 'New session' with localized Chat_PendingNewSessionTitle
  across all 5 locales (en-us, fr-fr, nl-nl, zh-cn, zh-tw)
- Fix authoritative reload dropping valid live entries without OpenClawSeq
  when gateway clock skews behind local time: entries with no seq are now
  preserved since history coverage cannot be determined
- Add post-timeout session list reconciliation for /new failures so user
  can see potentially-created sessions (protocol has no idempotency key;
  guidance message retained by design)
- Add behavioral composer submission policy tests (reference equality,
  identity preservation, edit-during-send)
- Add behavioral pending selection survival test for stale snapshots

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: d2982ca8-bb56-4728-85bd-29542ce9d554
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants