Repository navigation
feat(models): seamless model switch that always keeps the conversation (#20) - #295
Merged
Merged
Conversation
) The /models picker restart-now flow starts a new session on the picked model (provider/model fixed per session => switching = new CreateSession), and until now the transcript was always reset. Add an optional same-provider carryover: the confirm overlay gains a [c] carry-over key that seeds the new session with the current session's conversation, so a model switch can feel like a continuation rather than a cold start. Wire: one additive proto field, CreateSessionRequest.source_session_id (8), server-side so the service owns load/validate/seed and the same-provider gate. Server (internal/adapter/server): - validateCarryover loads the source via the run-entry funnel loadAndReopen, rejects a running/awaiting source (FailedPrecondition), rejects a cross-provider switch (InvalidArgument; provider canonicalised to the default when empty; the MODEL is intentionally not compared — v1 carries the conversation onto a different model within the same provider), and snapshots via session.ForkSnapshot. seedCarryover seeds via SeedHistory before the first Store.Save. Reuses the ADR-0065 fork primitives; zero engine/domain change, port.LLMRequest untouched. - Threaded through the gRPC CreateSession handler and the HTTP POST /v1/sessions handler. mecatui: [c] key gated on liveProviderID() == candidate provider (offered only for a same-provider switch); restartOnModelWithCarryover + carryoverCmd mirror restartOnModel, closing the old session best-effort after the new one is ready; CreateSessionWithCarryover added to the client and the SessionCreator interface (additive sibling). Turn-zero compaction needs no new code: maybeCompact already runs at every turn top against the new model's live-resolved window, with the recent user instructions surviving via snapCutToRecentUserTurn. Cross-provider carryover (strip Message.Reasoning/ProviderPhase) is deferred to v2 — v1 rejects it loudly rather than silently stripping. Tests (offline, mockllm/memfs/teatest): service-level seed/same-provider/ both-default/running+awaiting/missing; gRPC + HTTP handler-wiring (mutation- verified: dropping the field-wiring line turns them red); turn-zero compaction through the real loop (recent user turn survives verbatim, history stays tool-pairing-valid); UI confirm-key unit + teatest e2e (handoff, cross-provider key swallowed, failure recoverable); new models_confirm_carryover golden. Docs: IMPLEMENTATION-NOTES carryover section, PRODUCTION-READINESS flip, ADR 0016 mid-session-switch note, ADR 0065 see-also, docs/tui.md [c] key, user-docs gRPC/HTTP surface. Co-Authored-By: mecatl <[email protected]>
#20) A model switch now keeps the conversation instead of restarting cold. Picking a model in the /models picker switches immediately — no confirm overlay, no fresh-vs-carry choice — and the new session is seeded from the current one. /clear remains the single explicit fresh-start verb. Server (internal/adapter/server): CreateSessionRequest.source_session_id (additive proto field 8) seeds a new session from a source via the existing session.ForkSnapshot + SeedHistory primitives (zero engine-loop change). validateCarryover loads the source through the run-entry funnel loadAndReopen, rejects a running/awaiting source (FailedPrecondition), and seeds before the first Store.Save. Carryover is always allowed across providers: - same provider -> the snapshot replays VERBATIM (Reasoning/ProviderPhase/ ToolCall.ItemID intact, warm prompt-cache prefix); - cross provider -> session.StripProviderState clears the provider-private replay blobs, yielding a provider-neutral history both adapters omit safely; the new session's thinking/reasoning config is derived from the NEW model, not the stripped history. Cross-provider onto OpenAI additionally synthesizes stable, deterministic, non-fc_-prefixed ItemIDs (carryover_item_N) on the carried tool calls: the OpenAI store:false replay de-duplicates function_call items by the provider id, and an id-less carried item collides with auto-assigned fc_N on the second turn (Azure GPT-5.x "Duplicate item" 400). Anthropic ignores ItemID, so non-OpenAI destinations stay bare-stripped. Domain (engine/session): new exported StripProviderState — a pure, non-mutating transform clearing Message.Reasoning, Message.ProviderPhase, and every ToolCall.ItemID while preserving roles/text/tool-call IDs/Args/tool results/ parts. Classified Added (minor) per COMPATIBILITY.md; engine/api/session.txt regenerated. mecatui: the modelsConfirm overlay (enter/c/s/esc) is removed. chooseModel now routes directly — a live session switches via restartOnModelWithCarryover (CreateSessionWithCarryover), no live session falls back to a plain create. A one-shot status note names the switch ("switched to <model> — conversation kept"; cross-provider adds "prior reasoning cache dropped"). /clear is untouched and documented as the fresh-start. Tests (offline: mockllm/memfs/fakeConv/teatest): StripProviderState unit (all three blob fields, parts/tool-result preserved, no input mutation, tool-pairing-valid, backing-array isolation); service-level same-provider- verbatim vs cross-provider-strip vs OpenAI-synthesis (determinism pinned); gRPC + HTTP handler wiring incl. a cross-provider gRPC round-trip (mutation-verified); running/awaiting/missing-source rejection; turn-zero compaction through the real loop; UI seamless-switch unit + teatest e2e (live-session carry, no-session plain create, cross-provider still carries, status-note wording, overlay removal leaves no dangling refs). Docs: IMPLEMENTATION-NOTES + PRODUCTION-READINESS updated, docs/tui.md /models rewritten, user-docs gRPC/HTTP surface, proto comment. ADR 0016 (which documents the removed overlay UX) is superseded by a follow-up ADR. Co-Authored-By: mecatl <[email protected]>
…tion Records the redesign that supersedes ADR 0016's mid-session-switch confirm overlay and same-provider carryover gate, and ADR 0065's same-provider carryover constraint: a model switch always keeps the conversation (verbatim same-provider, StripProviderState cross-provider, OpenAI ItemID synthesis). Adds the 'Superseded by' pointers on the two frozen ADRs (the only edit a frozen ADR takes). Co-Authored-By: mecatl <[email protected]>
JAORMX
pushed a commit
that referenced
this pull request
Jul 25, 2026
(#308) OpenRouter rides the same openai-adapter ItemID-dedup path as OpenAI, so a cross-provider switch onto it hit the same "Duplicate item" collision the OpenAI-specific synthesis was meant to prevent — gate on openrouter too, not just the literal "openai" provider id. A failed carryover create's enter-to-retry re-fires a plain, non-carryover create, but the switch-note armed by the original pick survived the failure and falsely reported "conversation kept" on the retry's success. Clear it in the restartFailedMsg reducer. Co-authored-by: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #20.
A model switch now keeps the conversation instead of restarting cold. Picking a model in the
/modelspicker switches immediately — no confirm overlay, no fresh-vs-carry choice — and the new session is seeded from the current one./clearremains the single explicit fresh-start verb.Server (
internal/adapter/server):CreateSessionRequest.source_session_id(additive proto field 8) seeds a new session from a source via the existingsession.ForkSnapshot+SeedHistoryprimitives (zero engine-loop change).validateCarryoverloads the source through the run-entry funnelloadAndReopen, rejects a running/awaiting source (FailedPrecondition), and seeds before the firstStore.Save. Carryover is always allowed across providers:Reasoning/ProviderPhase/ToolCall.ItemIDintact, warm prompt-cache prefix);session.StripProviderStateclears the provider-private replay blobs, yielding a provider-neutral history both adapters omit safely; the new session's thinking/reasoning config is derived from the new model, not the stripped history.Cross-provider onto OpenAI additionally synthesizes stable, deterministic, non-
fc_-prefixed ItemIDs (carryover_item_N) on the carried tool calls: the OpenAIstore:falsereplay de-duplicatesfunction_callitems by the provider id, and an id-less carried item collides with auto-assignedfc_Non the second turn (Azure GPT-5.x "Duplicate item" 400). Anthropic ignoresItemID, so non-OpenAI destinations stay bare-stripped.Domain (
engine/session): new exportedStripProviderState— a pure, non-mutating transform clearingMessage.Reasoning,Message.ProviderPhase, and everyToolCall.ItemIDwhile preserving roles/text/tool-call IDs/Args/tool results/parts. Classified Added (minor) perengine/COMPATIBILITY.md;engine/api/session.txtregenerated.mecatui: the
modelsConfirmoverlay (enter/c/s/esc) is removed.chooseModelnow routes directly — a live session switches viarestartOnModelWithCarryover(CreateSessionWithCarryover); no live session falls back to a plain create. A one-shot status note names the switch ("switched to <model> — conversation kept"; cross-provider adds "prior reasoning cache dropped")./clearis untouched and documented as the fresh-start.Design
This started as a same-provider-only carryover behind a
[c]key (commitf5a31fa4). Review feedback reframed it: the[c]/fresh-start choice is redundant with/clear, and the right default is that a switch never drops the thread. The feasibility of cross-provider carryover turned on one fact — both adapters treat an empty replay blob as "no blob" and omit it on the wire (OpenAIrequest.go:340/360/368, Anthropicreasoning.go:68), so a stripped history replays safely to any provider. The redesign commits to that.ADR 0016 (which documents the removed overlay UX) is superseded by a follow-up ADR.
Tests (offline: mockllm/memfs/fakeConv/teatest)
StripProviderStateunit — all three blob fields, parts/tool-result preserved, no input mutation, tool-pairing-valid, backing-array isolation.Review
Ran the dev-pipeline: architect plan → implement (strip primitive → server strip → overlay removal → ItemID fix) → review panel (security / architecture / duplication / reuse / spec) + QA test-adequacy → iterate → commit. Security surfaced the OpenAI ItemID de-dup finding (fixed, not deferred); architecture a stale comment (fixed); QA's two must-add coverage gaps (fixed). Panel otherwise clean.
Test plan
task test(root + engine-race, plusGOWORK=offengine-standalone) — greentask lint— 0 issues (both modules)task api:check— engine surface gate green (StripProviderStateAdded/minor)task docs—llms.txtregenerated, strict link gate greentask e2e) — the ItemID synthesis is verified offline (present/stable/collision-free); a live run would confirm Azure's de-dup accepts the synthesized ids. Optional, not part of the gate.Co-Authored-By: mecatl [email protected]