Skip to content

fix(models): close two carryover gaps found in post-merge review of #295 - #308

Merged
JAORMX merged 1 commit into
mainfrom
fix/295-carryover-post-merge-review
Jul 25, 2026
Merged

JAORMX merged 1 commit into
mainfrom
fix/295-carryover-post-merge-review

Conversation

@jhrozek

@jhrozek jhrozek commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Post-merge review of #295 (seamless model-switch carryover) ran a 5-angle
expert panel (architecture, security, protobuf/wire, duplication, design/UX)
over the merged diff. Two independent reviewers converged on the same root
cause from different angles; I verified both concretely and fixed them here.

  • OpenRouter still hits the "Duplicate item" bug the PR meant to fix.
    validateCarryover only synthesized stable ItemIDs
    (carryover_item_N) when the destination provider was the literal
    string "openai". But openrouter is built on the exact same
    openai-Responses-family adapter (newOpenAICompatEntry in
    internal/app/registry.go) that de-duplicates replayed function_call
    items by ItemID (internal/adapter/openai/request.go:359-361). A
    cross-provider carryover landing on an OpenRouter model still stripped
    ItemIDs without re-synthesizing them, so it could hit
    HTTP 400: Duplicate item found with id fc_N on the second post-switch
    turn — the exact failure feat(models): seamless model switch that always keeps the conversation (#20) #295 was written to prevent, just missed for
    one of its two intended destinations. Fix: gate on
    newProv == "openai" || newProv == "openrouter" instead of the literal
    provider id alone.

  • A failed carryover retry lies about keeping the conversation.
    chooseModel arms a one-shot pendingModelSwitchNote ("switched to X —
    conversation kept") before the async create even runs. If that create
    fails, restartFailedMsg left the note armed; the user's enter-to-retry
    re-fires a plain, non-carryover create (by design — see
    onIdleSubmit), and on success applySessionReady still found the
    stale note and reported "conversation kept" even though the retry
    actually dropped the conversation. Fix: clear the note in the
    restartFailedMsg reducer.

Testing

  • task build and go test ./internal/adapter/server/... ./cmd/mecatui/...
    green before and after rebase onto current main.
  • Manual live test against real OpenRouter + OpenCode Go keys (two
    genuinely distinct provider ids/adapters):
    1. Started a conversation on an opencode model, had it run a shell
      command (so the history has a real tool call + result), then said
      something memorable.
    2. Switched via /models to an openrouter model — got
      switched to <model> — conversation kept (prior reasoning cache dropped), no confirm dialog.
    3. Asked the recall question — model still knew the answer (text/tool
      calls survived the provider-state strip).
    4. Kept the conversation going for 2+ more turns post-switch (including
      another tool call) — this is exactly the window where the
      pre-fix Duplicate item found with id fc_N collision would have
      surfaced on OpenRouter. Stayed healthy, confirming the fix live.
    5. /clear still resets the transcript as expected.

Not in scope (raised by the panel, not acted on here)

  • ForkSession RPC and CreateSession.source_session_id are two adjacent
    "clone a conversation" mechanisms with no cross-reference in the
    .proto comments — a documentation nit, not a bug.
  • Three now-near-identical session-handoff preambles in
    cmd/mecatui/ui/models.go (restartOnModel / switchEffort /
    restartOnModelWithCarryover) are a real Rule-of-Three duplication
    candidate, but a refactor-only change felt like scope creep for a
    bugfix PR — flagging for a follow-up.
  • The ADR's "always keep it, it's reversible" framing doesn't fully hold
    for cross-provider switches (stripping is one-way lossy), and the
    always-carry default has a real, under-argued cost for a deliberate
    fresh-topic model switch. Design feedback, not a defect.

🤖 Generated with Claude Code



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]>
@JAORMX
JAORMX merged commit a0cbbd3 into main Jul 25, 2026
14 checks passed
@JAORMX
JAORMX deleted the fix/295-carryover-post-merge-review branch July 25, 2026 19:17
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