Skip to content

feat: opencodeModel: "inherit" — capture with the session's own model#151

Open
anagnorisis2peripeteia wants to merge 1 commit into
tickernelz:mainfrom
anagnorisis2peripeteia:feat/opencode-model-inherit
Open

feat: opencodeModel: "inherit" — capture with the session's own model#151
anagnorisis2peripeteia wants to merge 1 commit into
tickernelz:mainfrom
anagnorisis2peripeteia:feat/opencode-model-inherit

Conversation

@anagnorisis2peripeteia

Copy link
Copy Markdown

Motivation

Pinned opencodeModel ids rot: when a provider renames a model (or a local endpoint changes its served model id), auto-capture silently fails at session.create on every prompt until someone notices the log spam. That is how I found this — capture had been broken for days on a stale local-model id. Separately, users who switch models during the day may prefer each conversation to be captured by the model that actually produced it.

What this does

"opencodeModel": "inherit" makes auto-capture use the exact provider/model opencode resolved for the captured prompt:

  • a chat.params hook records input.model.providerID / input.model.id onto the prompt's existing user_prompts row (two new nullable columns, added with the same duplicate-column-guarded ALTER TABLE pattern as capture_attempts), keyed by message.id — the same key capture already uses, so the mapping is exact rather than inferred from transcript position;
  • at capture time, "inherit" resolves provider/model from the stored row; the existing isProviderConnected guard runs against the resolved provider;
  • if a prompt has no recorded model (predates the upgrade, or the provider path didn't invoke chat.params), capture throws and the existing retry/cap machinery handles it — it never guesses.

Pinned configuration behaves exactly as before; the hook returns immediately unless "inherit" is configured.

Notes for review

  • opencodeProvider must still be set (the existing opencodeProvider && opencodeModel gate is untouched for diff minimality); with "inherit" its value is only used as a gate. Happy to change the gate if you prefer.
  • On opencode v1.17.11 I observed chat.params firing reliably for models served through the standard providers, but not for every custom npm-provider path — the hard-error fallback covers those prompts. Worth knowing for docs/support.

Testing

  • tsc --noEmit and Prettier clean; migration verified against an existing populated user-prompts.db (old rows read back with null model fields).
  • Live-tested against opencode v1.17.11: sessions on a local llama.cpp-served model recorded provider_id/model_id correctly on their prompt rows, and capture consumed the recorded model (verified via capture-session behavior/logs).
  • Rows without recorded models fail capture with the new explicit error and are retried/capped by the existing machinery.

When opencodeModel is set to "inherit", auto-capture resolves the
provider/model that opencode actually used for the captured prompt
(recorded per message via the chat.params hook and stored on the
user_prompts row), instead of a pinned model id. Pinned ids can go
stale when providers rename models, silently breaking capture; inherit
also means multi-model users capture each conversation with the model
that produced it.
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.

1 participant