Skip to content

feat: scope terminal panels to chat sessions - #10120

Closed
Skymore wants to merge 2 commits into
kirodotdev:mainfrom
Skymore:codex/session-terminal-ownership
Closed

Skymore wants to merge 2 commits into
kirodotdev:mainfrom
Skymore:codex/session-terminal-ownership

Conversation

@Skymore

@Skymore Skymore commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

The docked terminal shares one tab list and active shell across every chat. Switching to another chat exposes the previous chat's terminals, and a terminal popout is not bound to the chat that opened it.

Why it matters

Terminal commands and close actions can target a different conversation's shell. Independent windows must agree on ownership and the existing eight-terminal creation cap without dropping updates or restoring deleted terminals.

What changed (motivation → approach → change)

Terminal tabs, ordering, selection, visibility and errors now belong to their originating chat. Geometry remains shared. Legacy ownerless tabs migrate once to the first selected chat, retaining their PTY IDs.

IndexedDB transactions own terminal state and cap checks across windows. React publishes committed revisions; localStorage carries layout preferences, the one-time migration input and refresh notifications. A mutex around localStorage was insufficient in native-browser testing because another renderer could read stale cached bytes.

Terminal popouts retain their origin in their URL and window identity. Explicit Return selects the origin chat and closes the popup only after reopening succeeds. Native close preserves the main window's selected chat. Socket release precedes close acknowledgment, and the main host refreshes canonical state before reconnecting terminals.

Confirmed permanent history deletion retires the matching terminal generation and releases its capacity. A canonical preparation prevents another window from creating terminals in that generation during deletion; failed HTTP requests preserve the conversation and terminals. Archive/resume remains unchanged. Cleanup failures expose a bounded Retry area, while an interrupted operation offers an explicit terminal-only close without guessing whether history deletion succeeded. Fresh validated reuse of a session key gets a new generation, so old callbacks and cleanup receipts cannot delete its terminals.

Tests

A complete frontend run on 5da502d66 finished with 32,150 passed tests, five failed i18n checks, one expected failure, two skips, and three unhandled errors in the chat deep-link fixture. The i18n failures were corrected in the five added messages and quote registration; all 683 i18n tests now pass. The deep-link fixture now uses valid normal-chat slots and the same store as its Provider, with a controlled pending response. All 51 chat jump/deep-link tests pass without unhandled errors. This is not a claim that the final full suite has been rerun green.

After rebasing onto 075e77ca5, 205 affected upstream/terminal tests and 33 follow-up retirement/popup tests passed. TypeScript, the production build and i18n lint passed. The separate Electron suite passed 1,849 tests with one Windows-only skip.

Shared backend verification ran against unchanged Python sources: 97,375 passed, 213 failed and 380 errors. Representative baseline reproductions identified host atomic-rename limitations, dependency/ABI issues and installed-edition contamination; 60 failure/error rows remain unclassified. The backend suite is not claimed green. CI requires maintainer approval before the fork workflows can run.

Manual verification

Native Chromium verification of the canonical adapter completed 200 concurrent mutations across four windows on both secure and insecure origins. Each run retained exactly eight unique terminal IDs and revision 200 after reload. The independent production build also passed mocked browser checks in light and dark themes: A/B tab isolation, active-tab restoration, popup origin pinning, explicit Return to A, and native close while B stays selected. All APIs and WebSockets were mocked; no real PTYs were created.

Screenshots / video

Main window keeps session B while A is popped out

The separate window retains A's terminals

Explicit Return restores A and its active terminal

Light theme verification

Session B retains its own terminal

Native popup close keeps B selected

Permanent deletion and interrupted cleanup

Production-browser checks cover confirmed deletion, a cleanup failure after server confirmation, and a reload before a deletion response. Cleanup retry does not repeat the history DELETE. Interrupted recovery requires an explicit terminal-only close, preserves the history row, and releases the eight-terminal capacity. APIs and WebSockets are mocked.

Cleanup can be retried after history deletion

history-cleanup-retry.webm

An interrupted operation offers a terminal-only recovery

history-interrupted-recovery.webm

Related Issues

Related terminal lifecycle work: #7649 and #8863. This PR changes client-side panel state and is independently based on main.

Pattern harvest

Rule candidate: review-prompt
Pattern: Cross-window state mutations must read their authoritative transaction snapshot; acquiring a lock does not make another renderer's localStorage cache current.

Checklist

  • At most two commits, with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 11, 2026
@Skymore
Skymore force-pushed the codex/session-terminal-ownership branch 3 times, most recently from f6b2bc6 to 882ae2f Compare September 11, 2026 16:20
@dwu96

dwu96 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@Skymore
Skymore marked this pull request as ready for review September 11, 2026 23:14
@Skymore
Skymore requested review from a team and iamwhatever September 11, 2026 23:14
@github-actions

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — 🔴 BLOCK (blocking)

Which legitimate operations does 882ae2f8ff00d492066fd5f801113424ff73ef83 newly refuse? Model proposes, scripts/deny_diff.py decides — updated in place on each push. A script-confirmed regression blocks PR readiness.

no leg reported, and this was not the nothing-to-adjudicate short circuit

No [SCOPE-REVIEWED] marker for this head was produced, so the model's text is withheld: it cannot be shown to describe this revision. See the job logs.

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

A hand-rolled distributed-coordination protocol (epochs, fencing tokens, tombstones, revisioned publish) now lives in the view layer, coordinating truth the gateway already owns.

Watch

  • Terminal↔chat ownership, the 8-PTY cap, and deletion fencing are enforced only by a client-side IndexedDB protocol (terminalStateLock.ts, the lease/epoch machinery in useBottomTerminal.ts), while the ground truth — live PTYs and history rows (api.deleteSession) — is server-side. Every future terminal feature must thread leases/epochs correctly, and a protocol bug silently strands or deletes another window's shells with only frontend tests pinning it.
    Clears when: a maintainer confirms client-canonical authority is the intended long-term home, or a follow-up issue tracks moving generation/retirement authority behind the gateway.
  • Every terminal interaction — including setActiveTab and tab reorder — now awaits a cross-window IDB readwrite transaction (5s timeout); on IDB failure inSession routes to stateFailures and the panel becomes unusable, where the old localStorage path degraded to in-memory state. A wedged or unavailable IndexedDB turns a tab click into an error notice.
    Clears when: non-membership mutations (selection, order, open/close) fall back to in-window state on lock failure, or the error path is shown recovering in a degraded-storage check.

Suggestions

  • Keep activeId/open per-window (localStorage, last-writer-wins) and reserve the IDB transaction for membership, cap, and lifecycle — same ownership guarantees, smaller hot path and failure surface.

[DESIGN-REVIEWED] a030094

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — 🔴 BLOCK

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

UX-Verdict: BLOCK

cannot evaluate: missing stills of the new "Something went wrong" terminal-state error, the capacity notice, and three of the five cleanup-failure notice variants.

Evidence gaps

  • terminal-state-error notice (something_went_wrong + dismiss + ask-agent, BottomTerminalPanel.tsx) — in no image in the attachment list; attach a still of a failed tab commit.
  • terminal-capacity-error inline notice (maximum_terminals fired cross-window) — no still; attach one showing it beside a session's tab strip.
  • history_delete_failed, terminal_revive_check_failed, terminal_cleanup_failed notice variants with their Retry buttons — only history_cleanup_failed (attachment-06) and history_deletion_unconfirmed (attachment-07) are shown; attach stills of the other three.

Watch

  • Notices print the raw internal key: attachment-06 shows "Chat dashboard_chat-1-123 was deleted…", but users know chats by title ("Session B"); after deletion the key maps to nothing on screen, every failure, so the user can't tell which chat failed. Interpolate the history row's title.
  • "Something went wrong" (terminal-state-error) after a failed tab close/add says neither what failed nor that the tab is still live; replace with a terminal-specific message naming the retryable action.
  • atCap = totalTabs >= MAX_TERminals counts all chats while the strip shows one chat's tabs: a user with two visible tabs hits a disabled + reading "Maximum 8 terminals" and can't find the other six. Say "across all chats".

Suggestions

  • history_deletion_unconfirmed: "unconfirmed in this window" is system vocabulary — reword to "Couldn't confirm chat "{{session}}" was deleted. Its terminals are still running — close them now."

[UX-REVIEWED] a030094

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

Premise-level review of a0300948f81a95669900797102affa5b554fba7d 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: CONCERNS

Per-chat terminal scoping is a regroup with no named failing user — base pinned the panel app-wide by design, and per-chat terminal tabs already exist.

Not justified as shipped

  • 1 — unjustified move. No linked issue or report of anyone mis-targeting a shell; the deleted comment pinned the opposite decision ("A single docked terminal panel shared by the ENTIRE app"), and each chat already has terminal tabs (usePanelTabs.ts:895, kind: 'terminal'). docs: propose terminal session ownership protocol #7649/fix: fence terminal mutations after websocket takeover #8863 are "related work", not this defect.
  • 2 — undeclared. With IndexedDB unavailable, terminal creation now fails closed with an error; base degraded to in-memory and kept working. The description never mentions this changed default.
  • 8 — symptom-level. The unconfirmed-deletion recovery surface exists only because the backend DELETE's ok: false "cannot distinguish an absent file from an index, lock, or filesystem failure" — the nameable cause, left unfixed.
  • 9 — duplicate of src/kiro_crew/dashboard/handlers/terminal.py. A manual Retry for a rejected PTY DELETE duplicates reap_orphaned_terminals (terminal.py:2440, 15-min reap) — the existing close_failed notice already promises "It will be cleaned up automatically."

What this change ships

Inventory (10 items) — 6 justified

Intent: make each chat's docked terminal panel, popout and deletion lifecycle belong to that chat — an ADDITION (a redesign of terminal ownership).

  1. Docked terminal tabs, active tab and open state now swap with the selected chat — unjustified move (no named person failing; base pinned app-wide as deliberate)
  2. Terminal state moves to a canonical IndexedDB store; without it the panel fails closed — undeclared
  3. The 8-terminal cap is enforced atomically across windows, with a scoped max-terminals notice — justified
  4. Legacy ownerless tabs migrate once to the first selected chat, keeping PTYs — justified
  5. A popout is pinned to its origin chat; main-window switches never retarget it — justified
  6. Popout Return selects the origin chat and closes only after reopen succeeds; native close leaves selection alone — justified
  7. Permanently deleting a chat's history now closes its terminals and frees cap capacity — justified
  8. Interrupted deletion persists an "unconfirmed" notice with an explicit Close-terminals action — symptom-level (backend ok:false ambiguity is the cause, acknowledged out of scope)
  9. Failed PTY HTTP cleanup gets a manual Retry notice — duplicate of the gateway orphan reaper
  10. Retired terminals revive only after a fresh server existence check, with its own retryable notice — justified

More than 10 exist (global test fixture rework, three new one-consumer popoutController options, mc-bottom-terminal-layout pref-key rename, UpdateModal/deep-link test rewrites); these 10 are the most user-noticeable.

Watch

  • The whole redesign's premise — "Terminal commands and close actions can target a different conversation's shell" — is asserted, not evidenced; existing users lose the cross-chat persistent terminal they had. Clears when: a linked issue or user report of the cross-chat confusion exists.
  • Fail-closed on unavailable IndexedDB trades a working feature for a cap guarantee the gateway already backstops server-side (terminal.py:1384, 429 at max_sessions=12). Clears when: the description declares the behavior and names the environments where IndexedDB may be absent as unsupported.
  • Item 8 sits at symptom level. Clears when: an issue is linked for the backend DELETE distinguishing absent-from-failed, which would make retry safe and delete the unconfirmed-recovery concept.

Subtractions

  • Drop the failed-PTY-DELETE retry phase (phase: 'terminals' re-filtering in historyTerminalCleanup.ts plus terminal_cleanup_failed in 14 locales) — the reaper self-heals rejected DELETEs (1 existing mechanism: reap_orphaned_terminals, terminal.py:2440); keep Retry only for the failed IndexedDB retirement commit.
  • Defer the interrupted-deletion recovery (history_deletion_unconfirmed, closePreparedTerminals, prepared-lease reload survival): cancel the fence on reload instead — the zero option leaves one lingering terminal bucket closable by hand, which is exactly what base ships for every deleted chat today.

[FIRST-PRINCIPLES-REVIEWED] a030094

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings (all downgraded on adjudication)

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

Opus 4.8 adjudication downgraded every blocking finding to advisory. Adjudication downgraded all 1 blocking finding(s) to advisory: the remedy each one requires is disproportionate to the harm it prevents. Read them as advice, not as merge conditions.

Review details

BLOCKING -- website/src/App.tsx:1346 -- Terminal ownership change leaves the feature map incorrect (origin: validation)
const terminalSessionScope = useAppSelector(s => s.chat.activeSlot)
Chat selection -> docked terminal becomes session-scoped -> feature map still documents an app-wide docked PTY.
Anchor: feature-map-correctness
Fix: Update the existing Terminal panel feature-map row to describe session-scoped docked terminals and popout ownership.
FINDING -- website/src/App.tsx:1425 -- a 404 from "dispatch(switchSlot(...))" arrives after openBottomTerminal closes the popup, restoring the previous chat and stranding the origin terminal -> Fix: await dispatch(switchSlot(...)).unwrap() and only reopen/close after fulfillment.
[BLOCK-MERGE-DOWNGRADED] a030094
[GPT-REVIEWED] a030094

Adjudication (Opus 4.8) — is blocking on each finding proportionate?

Verified from code opened this run:

  • The change: docked terminal became session-scoped (website/src/App.tsx diff: sessionScope={terminalSessionScope} on BottomTerminalPanel/TerminalDetachedBar, patch lines 288–292). This is a behavior change to an existing feature.
  • The stale row: docs/feature-map/README.md:88 Terminal panel row still reads "an app-wide docked PTY"; that file is not in the diff. Confirmed stale.
  • Scope of the anchored rule: AUTOSDE.yaml:19-37 (feature-map-correctness) triggers only on pages/handlers added-or-deleted and <Route> added-or-removed. The diff adds/deletes no file under website/src/pages/ or dashboard/handlers/, and the <Route> block (patch 277-281) is unchanged context. docs/feature-map/README.md:14-18 states behavior-only changes do not require a map update, and README.md:20-24 confirms check_feature_map.py fires only on structural add/remove — none present here. So the rule's triggering conditions are not met; the claimed blocking anchor does not genuinely fire.
  • Harm/recovery: The map is explicitly "a navigation index, not a contract" (README.md:8); the row's ownership columns (page, handler, route) remain correct — only a descriptive parenthetical is stale, self-correcting on any future read of the code. No runtime, data, or security consequence.

LOW — stale descriptive phrase in an explicit navigation index whose ownership columns stay correct; conditions confirmed at App.tsx patch:288-292 and README.md:88; the map's own maintenance contract (README.md:14-18) excludes behavior-only changes, so blocking a merge to force this edit is disproportionate.

[ADJUDICATION] a0300948f81a95669900797102affa5b554fba7d total=1 uphold=0 downgrade=1
DOWNGRADE F1 website/src/App.tsx:1346 reason=disproportionate-remedy
[GPT-ADJUDICATED] a0300948f81a95669900797102affa5b554fba7d

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

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

Review details

No merge-blocking issues; one advisory finding.

FINDING — website/src/components/BottomTerminalPanel.tsx:~130 — in the last-popout-tab branch, del.mutate(id) now fires after await removeTab(id, sessionScope) has emptied the store, so the tabs.length===0 effect in TerminalPopoutFrame runs closeSelfToMain() → window.close() and tears down the JS context before the DELETE response can arrive; on a failing DELETE /api/terminal/sessions/{id} (500 / network error) the mutation's onError → setTerminalCloseFailed(true, variables.scope) never runs, so no cross-window close-failed flag is written and neither window shows the "shell couldn't be closed" notice — the exact silent PTY leak the retained comment says must not happen (base code awaited del.mutateAsync(id) to settle before removeTab, recording the rejection while the window still existed) → Fix: for lastPopoutTab, record the close-failed flag before the removal commit tears the window down — e.g. await del.mutateAsync(id).catch(() => {}) (or otherwise write the cross-window flag) before removeTab empties the tabs and triggers closeSelfToMain().

[OPUS-REVIEWED] a030094

@Skymore
Skymore force-pushed the codex/session-terminal-ownership branch from 882ae2f to 3cee868 Compare September 12, 2026 00:52
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 12, 2026
@Skymore
Skymore force-pushed the codex/session-terminal-ownership branch from 3cee868 to d5e765f Compare September 12, 2026 01:15
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 12, 2026
@Skymore
Skymore force-pushed the codex/session-terminal-ownership branch from ef02933 to 5510686 Compare September 12, 2026 02:18
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 12, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 13, 2026
Rui Tao added 2 commits September 13, 2026 21:43
Keep terminal tabs, selection, visibility and errors with their chat.
Commit shared state atomically before publishing it across windows.

Retire terminals after confirmed history deletion, preserve archived
sessions, and fence stale operations while allowing valid key reuse.
Expose bounded cleanup and interrupted-operation recovery without
repeating an already confirmed history deletion.
@Skymore
Skymore force-pushed the codex/session-terminal-ownership branch from 6007c60 to a030094 Compare September 13, 2026 22:08
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 13, 2026
@Skymore Skymore closed this Sep 13, 2026
@Skymore Skymore reopened this Sep 13, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 14, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 15, 2026
@Behordeun

Copy link
Copy Markdown
Contributor

Confirming the allowMissing && res.status === 404 guard in useDeleteTerminalSession is the right call, from an independent diagnosis of the same symptom.

A user hit the "Couldn't stop this terminal's shell on the server. It will be cleaned up automatically." banner and I traced it to the same place this PR fixes. The DELETE /api/terminal/sessions/{id} handler does registry.pop(session_id, None) and returns 404 when the session is already gone. The server-side orphan reaper (reap_orphaned_terminals) pops from that same registry on its own schedule, so a disconnected/dead session it reaps first — or a prior close, or the popout's in-flight keepalive DELETE racing this one — leaves the handler nothing to pop and it answers 404. That 404 is the desired end state (no shell left running), not a failure worth alarming the user about, and the handler's own docstring says the kill is best-effort and reaper-backstopped. Treating it as success is correct; a 5xx / network rejection is the case that should still surface.

For anyone else who lands here: the isolated core of this change is a one-liner — if (!res.ok && res.status !== 404) throw ... in the delete mutation. This PR does the fuller job (per-scope setTerminalCloseFailed, TerminalSessionScope, subscription-based retirement), which is more than the banner bug needs but is a superset of it, so no objection to the wider shape.

The PR currently shows CONFLICTING / DIRTY against main — a rebase would unblock it.

@dwu96 dwu96 added needs-pr-triage PR scanner: awaiting automated triage needs-author-decision PR blocked on author input and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 21, 2026
@dwu96

dwu96 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: dwu96#8c08bee0]: This PR has been inactive for 7+ days. I reviewed the blockers but they require your input:

  • The UX Review lane BLOCKs on missing stills of five specific states, and that evidence cannot be produced from this pipeline. The lane needs images of the terminal-state-error notice (something_went_wrong + dismiss + ask-agent in BottomTerminalPanel.tsx), the terminal-capacity-error inline notice fired cross-window beside a session's tab strip, and three of the five cleanup-failure notice variants (history_delete_failed, terminal_revive_check_failed, terminal_cleanup_failed with their Retry buttons — only history_cleanup_failed and history_deletion_unconfirmed are attached today). Each still requires driving the app into a distinct failure state and attaching the capture to the PR description as a GitHub user-attachment, which is a browser upload only you or a maintainer can perform on a fork PR.
  • Three copy and scoping decisions are product calls on your feature, not mechanical fixes. (1) Notices print the raw internal key — Chat dashboard_chat-1-123 was deleted… — where users know chats by title; interpolating the history row's title changes what the message promises. (2) Something went wrong after a failed tab close/add says neither what failed nor that the tab is still live; the replacement text needs to name the retryable action. (3) atCap = totalTabs >= MAX_TERMINALS counts tabs across all chats while the strip shows one chat's tabs, so a user with two visible tabs can read "Maximum 8 terminals" and be unable to find the other six — whether to reword to "across all chats" or to rescope the cap itself is a design decision.

The branch is also CONFLICTING against current main. The macOS jobs on the last run were cancelled rather than failed, so there is no platform failure to chase. Design Review and First Principles are neutral, not blocking.

When you've addressed these, the pipeline will re-assess on its next cycle.

@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.

Request changes: terminal storage can block history deletion for good, and Retry cannot clear it

The First Principles and Design reviews already cover the per-chat dock and fail-closed terminal creation, and the maintainer note accepted both. I'm not reopening those. That note set one condition: the IndexedDB prerequisite for history deletion "must remain visibly recoverable". At a030094 the failure is visible but not recoverable. It also applies when the terminal is turned off.

1. Retry repeats the step that failed.
website/src/lib/historyTerminalCleanup.ts:85-98 sets the fence before the HTTP call:

lease = await prepareTerminalRetirement(key)
...
const result = await api.deleteSession(key)

If the fence rejects, the catch records { phase: 'delete', lease: undefined } and rethrows, so the DELETE is never sent. For that phase, the notice's Retry (HistoryTerminalCleanupNotice.tsx:27) is dispatch(deleteHistorySession(failure.key)). On re-entry, deleteConfirmedHistory (:74-81) has no lease to cancel, so it calls prepareTerminalRetirement again.

Scenario: indexedDB is undefined (website/src/utils/terminalStateLock.ts:60, code unavailable), or indexedDB.open keeps erroring (code storage). Every delete from the sidebar (ChatSidebar.tsx:8674, :8723) and every Retry then fails the same way. The notice stays and no chat history can be deleted. A transient failure, such as the 5 s timeout, can clear on a later Retry. A persistent one cannot.

2. No terminal gate.
website/src/store/chatSlice.ts:3382 now always awaits deleteHistoryWithTerminals(key), where the base called api.deleteSession(key) directly. A user with dashboard.terminal.enabled: false never gets a terminal, yet deleting history still depends on IndexedDB.

Who is affected: only environments where IndexedDB is missing or keeps failing. In those environments history deletion stops working, including for users who disabled the terminal.

Smallest fix:

  • In deleteConfirmedHistory, skip the fence when isTerminalEnabled() (website/src/utils/terminalRegistry.ts:17) returns false.
  • On a TerminalStateLockError with code unavailable (and probably storage), call api.deleteSession without a lease. Terminal creation already fails closed in that state. The worst case is a leftover terminal bucket the user closes by hand, which is what the base already does for every deleted chat.
  • Keep timeout fail-closed, because Retry already handles it.
  • Add a test with indexedDB undefined that proves the delete goes through.

From a full open-PR audit against origin/main c66f95b (2026-09-25); findings were checked by independent reviewers reading the code. Reply here if this is wrong.

Copy link
Copy Markdown
Contributor

Open-PR triage (origin/main a97659d): rebase needed, plus one overlap to coordinate

Verdict: OVERLAPPING with #10724, PARTIALLY_COVERED by #11791. Recommendation: rebase and continue development. Do not close.

Rebase. The head a0300948f8 is 2,847 commits behind main. git merge-tree against main conflicts in 8 files:

Already on main. #11791 (1f3e48f3bc) makes useDeleteTerminalSession treat a 404 as success, unconditionally. This PR's deleteTerminalSessionRequest(sessionId, allowMissing) limits that to the retry path. When you rebase, keep main's behaviour for ordinary closes, or explain why you are narrowing it. Everything else here (per-chat scope, the IDB canonical store, popout origin pinning, history-deletion retirement) is not on main.

Overlap to coordinate: #10724 (close menus on terminal tabs). It adds Close others, Close to the right and Close all to BottomTerminalPanel.tsx's TabChip. Each of those loops over closeTab. This PR makes closeTab async: it awaits removeTab(id, sessionScope) through an IDB transaction, and only then sends the DELETE. Whichever PR lands second has to:

  • scope the batch closes to the current chat's tabs;
  • serialize the IDB commits, or batch them into one transaction;
  • keep the "Maximum 8" notice's cross-chat count understandable.

The two are complementary, not duplicates.

Design note, not blocking. The merged RFC #7649 (1b2dbf9882, docs/request-for-change/rfc-terminal-session-ownership.md) proposes a server-authoritative owner per PTY. This PR keeps ownership, the cap and retirement in a client-side IndexedDB protocol. Maintainers should confirm the two directions agree.

The request-changes review from 2026-09-25 still applies to this head: with IDB unavailable, history deletion is blocked permanently and Retry cannot clear it (historyTerminalCleanup.ts:85-96, chatSlice.ts:3382). I am not posting it again.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you @Skymore for this careful work on per-chat terminals, including the cross-window locking and popout pinning. We are closing it because the branch is now thousands of commits behind main, with conflicts in files that were reworked or deleted (PanelToggles, the chatSlice split), and the 2026-09-25 review is still open: if IndexedDB is unavailable, no chat history can be deleted and Retry cannot recover, even with terminals turned off. The close-on-404 part already landed in #11791. If you would like to continue, a fresh PR against current main that keeps history deletion independent of terminal storage would be very welcome.

The branch is left untouched, so you can reopen this PR at any time, or open a fresh one on current main, if you want to pick it back up.

@iamwhatever iamwhatever closed this Nov 1, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 1, 2026
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) merge conflict Branch has merge conflicts with its base — author must resolve before merge needs-author-decision PR blocked on author input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants