Skip to content

fix(chat): keep a chat's loaded history when New Chat or a resume leaves it - #15934

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/reopen-chat-history-truncation
Oct 2, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/reopen-chat-history-truncation

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A chat you leave through New Chat or a history resume comes back with all the history you had loaded.

Open a long chat and scroll back through its history. Click New Chat, then close the new chat. The dashboard lands back on the first chat, but the transcript jumps and only the newest page of 100 messages is left. The "Load earlier messages" bar is back and the history has to be paged in again. When the chat grew while it was open, the landing first repaints an older snapshot that is missing the recent turns. A later turn's refresh can bring the rest back, which makes it look like the history loads in late.

Why it matters

New Chat and reopening a chat from history are everyday ways to leave a chat. Each one silently throws away the scroll-back the reader built up. On a long session that means paging hundreds of messages in again, and the reader loses their place.

Not a goal

  • No change to how much history a switch or refresh fetches, or to the paging cursor rules.
  • No change to the background pane warm or grid pane hydrate.

What changed (motivation → approach → change)

Leaving a chat through New Chat or a history resume no longer throws away the history you had loaded in it. Coming back shows the same transcript you left.

The per-chat cache slotMessages[key] is what a switch paints the moment you return to a chat. Only switchSlot.pending wrote it when the active chat changed. New Chat clears the selection with setActiveSlot(null) and then createSlot activates the new chat. A resume activates its chat in resumeFromHistory.fulfilled. None of those three wrote the cache, so the chat being left kept whatever the cache held from its last switch. Closing the new chat runs deleteSlot, which returns through switchSlot(X). That paints the stale entry, and the bounded switch read, sized to the stale entry, keeps it.

parkActiveTranscript in website/src/store/chat/slotCache.ts is now the one writer of the outgoing chat's cache entry. switchSlot.pending, setActiveSlot, createSlot.fulfilled and resumeFromHistory.fulfilled all call it before the selection moves. It writes the has-more marker from the open view, and it keeps the existing marker for a view whose own switch has not landed. That is the rule switchSlot.pending already used, so the switch path behaves as before.

Backwards compatibility

Compatible: the change only adds cache writes on the paths that leave a chat. No request, response, setting or stored value changes.

Tests

website/src/store/chatSlice.leaveViaOpen.test.ts drives the real reducers with a mocked slot-detail endpoint that slices like the server. Each case pages in all 600 messages of a chat first.

  • Closing a New Chat lands back on all 600 messages, both when the switch starts and after it settles. On main it lands on 100.
  • A chat that grew by 300 rows while open is repainted with all 900 rows, not the older 600-row snapshot.
  • Returning from a resumed history chat keeps all 600 messages.

All three fail on main and pass with this change.

Manual verification

Real browser, headless Chromium at 1400x900, against isolated gateways built from main 996b4506912d and from this branch. Chat X was a real slot whose slot-detail reads were answered with a synthetic 600-message history. The steps were to open X, press "Load earlier messages" until the transcript starts at "X message 0", click New chat session, then close the new chat from its sidebar row.

main this branch
After the close newest 100 messages, bar shown starts at "X message 0", no bar
Reads for X after the close limit=100 limit=500, then one unbounded read

Screenshots / video

Landing after closing the New Chat, main:

main: after closing the New Chat

Landing after closing the New Chat, this branch:

fix: after closing the New Chat

Related Issues

Fixes #15933

Pattern harvest

Rule candidate: review-prompt
Pattern: a reducer that moves activeSlot without caching the outgoing chat's transcript. Every writer of the active selection has to go through the same park step that switchSlot.pending uses.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@Pearcekieser
Pearcekieser requested a review from a team October 1, 2026 16:45
@Pearcekieser
Pearcekieser requested a review from a team as a code owner October 1, 2026 16:45
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Intent: A chat left through New Chat or a history resume comes back with the transcript the reader had loaded, by caching it on every path that moves the active chat.
Not a goal: changing how much history a switch, refresh, warm or pane hydrate fetches, or the paging cursor rules.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — ✅ PASS

UX-level review of 950afd0d064530ef699535f3157c01bfeb29ee39 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Verify in the real app that scroll position, not only the loaded message set, is restored when landing back on the old chat.

[UX-REVIEWED] 950afd0

Description read

[DESCRIPTION-READ] 3c05031b2c019954dd1b30e2c0a6f61e5bfbe95ceefa4a6dcde50bf09d004b1e

That sha256 names everything this verdict read: the PR description, plus the 5 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed 950afd0d064530ef699535f3157c01bfeb29ee39 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 950afd0

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of 950afd0d064530ef699535f3157c01bfeb29ee39 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify no activeSlot writer beyond the two documented exceptions (deleteSlot eviction, rejected-restore) still skips parkActiveTranscript.

Suggestions

  • The park invariant is held by a doc comment on four call sites while enterActiveSlot is the real single mutator of activeSlot; a small test that drives each remaining selection-moving reducer and asserts the outgoing cache entry would pin the convention the description's own "pattern harvest" flags as a future-regression risk.

[DESIGN-REVIEWED] 950afd0

Description read

[DESCRIPTION-READ] 533e6b1b1c157fde88f71e9f4ca1cb70e601302d7a995b3991450f04d98592d7

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of 950afd0d064530ef699535f3157c01bfeb29ee39 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Verify the relocated switchSlot.pending write: it now runs before the cursor/requestId re-key instead of after; nothing between reads the cache, but confirm.

What this change ships

Inventory (5 items) — 5 justified

Intent: FIX — a chat left via New Chat or a history resume returns with the history the reader had loaded (issue #15933; three tests fail on base).

  1. Closing a New Chat lands back on the full loaded transcript, not the newest 100 — justified
  2. Returning from a history-resumed chat keeps the loaded transcript — justified
  3. A chat that grew while open repaints current rows, not an older snapshot — justified
  4. The sidebar-switch cache write moved into one shared helper all leave-paths call — justified
  5. Any selection clear/change (setActiveSlot) now caches the outgoing transcript — justified

Counts run: writers of activeSlot = 5 (enterActiveSlot call sites ×4 + switchSlot.rejected restore at slotSwitch.ts:680); the four leave-paths all park, and the rejected-restore leaves a GONE target with nothing loaded, so no unfixed sibling. parkActiveTranscript consumers = 4 (not counting definition/tests). Cause-level fix: single writer replaces per-site duplication.

[FIRST-PRINCIPLES-REVIEWED] 950afd0

Description read

[DESCRIPTION-READ] e050efabc0b7519213d8d866e2767cf0d033dec819e88fe35058e309e84abb5c

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

Reviewed 950afd0d064530ef699535f3157c01bfeb29ee39 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 950afd0

@Pearcekieser
Pearcekieser force-pushed the fix/reopen-chat-history-truncation branch from 30d9949 to a438863 Compare October 1, 2026 18:16
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed a438863. CI shard Frontend Tests (2) caught a real regression on 30d9949: chatSlice.warmSlotCacheBound.test.ts pins that switching away caches the outgoing chat with its own slotHasMore, and my first revision dropped the marker when the paging cursor was not keyed to that chat. The marker now comes from the open view exactly as switchSlot.pending wrote it before; the 3 failing cases and 3,018 other store, chat-page and pane tests pass locally. The macOS backend shard red on the old head (test_autonudge_refactor_contract.py, file lock OSError) is in a Python test this PR does not touch.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in website/src/store/chat/slotSwitch.ts (#13236, window walk) since this head went green-in-progress (8ab2a0e -> 5ca51b0); same commit, no code change. On the new base the leave-via-open regression test still fails without the fix and passes with it, and 1,395 store tests pass. CI re-running.

@Pearcekieser
Pearcekieser force-pushed the fix/reopen-chat-history-truncation branch from a438863 to 81f5fe8 Compare October 1, 2026 21:30
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 1, 2026
Leaving the active chat through New Chat (setActiveSlot(null) then
createSlot) or a history resume never wrote its on-screen transcript to
slotMessages; only switchSlot.pending did. Returning to it (closing the
new chat lands back through switchSlot) painted whatever the cache held
from the last switch: the first page of an earlier visit, missing the
history paged in or streamed since. The bounded switch read then kept
that short view whenever its window covered the stale cache.

parkActiveTranscript is now the one writer of that cache entry, called
by switchSlot.pending, setActiveSlot, createSlot.fulfilled and
resumeFromHistory.fulfilled.
@Pearcekieser
Pearcekieser force-pushed the fix/reopen-chat-history-truncation branch from 81f5fe8 to 950afd0 Compare October 2, 2026 00:45
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: optional provisional argument on parkActiveTranscript

  • Item 6, one consumer generalized: fixed

fixed in 950afd0: the provisional parameter is deleted and parkActiveTranscript derives the in-flight state itself.
switchSlot.pending calls it before re-keying slotSwitchRequestId / slotSwitchTarget, so the derived value equals the one it used to pass.
1,395 store tests pass, including the three leave-via-open cases and chatSlice.warmSlotCacheBound.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto main 55d6539 and pushed 950afd0. Same fix, plus the First Principles subtraction (the unused provisional argument is gone). The two red jobs on the previous head, Build Windows Installer (x64) and Backend Tests (Windows) (1) in test_subagent_continuable.py, do not exercise this frontend-only change, and a fork cannot rerun single jobs, so this push re-runs them.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 2, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

self-added: no

  • Suggestion: pin the park invariant with a test per selection-moving reducer: rebutted

the four writers that move the active chat away are already each driven by a test that asserts the outgoing cache entry.
chatSlice.leaveViaOpen.test.ts covers New Chat (setActiveSlot(null) then createSlot), deleteSlot landing back through switchSlot, and resumeFromHistory, asserting the full 600-row transcript is painted on return.
chatSlice.warmSlotCacheBound.test.ts covers switchSlot.pending, asserting the cached entry and its has_more marker on switch-away.
enterActiveSlot stays free of the park step on purpose: switchSlot.pending must park before it re-keys the switch fields, and the switch.rejected restore must not park the 404'd target.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: PR Readiness green on this head, merges cleanly into current main, no outstanding blocking review.

@bolichen97
bolichen97 merged commit 5aee845 into kirodotdev:main Oct 2, 2026
100 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 2, 2026
@Pearcekieser
Pearcekieser deleted the fix/reopen-chat-history-truncation branch October 2, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat history is cut off after New Chat or a history resume, then close

2 participants