Files
makelore/.project-docs/30-worklog/tasks/20260820-session-model-agent-hotfix-6e4c9a2f.md

6.2 KiB

Task: Implement session model parity and partner hot reload

Identity

  • Task ID: 20260820-session-model-agent-hotfix-6e4c9a2f
  • Mode: Feature
  • Branch: codex/20260820-session-model-agent-hotfix-6e4c9a2f-session-model-agent-hotfix
  • Worktree: D:\Datas\OthersProjects\makelore-session-model-agent-hotfix-6e4c9a2f
  • Base commit: 1c6b004436
  • Owner: codex
  • Status: Ready for Integration

Scope

  • Make the AI programming chat model selector and /models / /model commands switch the active OpenCode Session model through OpenCode's native session API.
  • Preserve the Session-selected model across later prompts, project commands, compaction, Session switching, and Session-list hydration without rewriting partner or Provider configuration.
  • Allow a newly created unique-id project Agent to execute in the current fresh runtime generation once the live Agent registry exposes that id.
  • Keep same-id Agent edits, deletion/recreation, attached or unknown runtime generations, and missing live ids fail-closed until a fresh generation rollover.
  • Add focused unit and Electron E2E coverage and synchronize README product behavior.

Intent And Constraints

  • Page model switching must have the same OpenCode Session semantics as the runtime model command and must not trigger runtime restart, reload, dispose, or Provider persistence.
  • Partner model remains the default for a new Session; the active model of an existing Session is owned by OpenCode.
  • Ordinary prompts and project commands must not resend a model override that would undo a Session switch.
  • A live same-id registry entry is not evidence that edited content was reloaded. Hot acceptance is restricted to an id never seen in the current generation; removed ids remain known and cannot be recreated hot.
  • Preserve manager-to-project lock ordering, bounded runtime acceptance, attached/unknown fail-closed behavior, and all existing project Agent prompt/template structures.
  • Work remained isolated in the claimed feature worktree; canonical .project-docs files were not modified.

Outcome

  • Added an OpenCode client adapter for POST /api/session/{sessionID}/model, a Main-owned Host API route, and Renderer Store state/action for per-Session model switching.
  • Replaced the read-only composer model label with a Session selector. The selector and /models / /model share one action; successful switches update only Session state and can be hydrated from OpenCode Session metadata.
  • Removed automatic model overrides from ordinary prompt and project-command submissions. Compaction and attachment capability projection now use the active Session model.
  • Changed project Agent readiness from a whole-manifest execution gate to per-Agent desired/applied tracking. Existing unchanged Agents remain usable when a peer is added, and a new unique id becomes usable only after it appears in the live registry.
  • Preserved sticky pending behavior for same-id edits, missing live Agents, attached/unknown generations, and delete/recreate of an id. A new fresh runtime generation remains the authoritative reset.
  • Updated README and the multi-chat Electron E2E fixture to document and exercise Session switching without prompt model overwrite.

Verification

  • corepack pnpm run typecheck — passed.
  • corepack pnpm run lint:check — passed with 0 errors and 6 pre-existing warnings in unrelated files.
  • Focused unit suite for Agent runtime, routes, client, Store, command registry/hook, and ChatPanel — 405 tests passed.
  • corepack pnpm test — 176 files, 2068 tests passed.
  • corepack pnpm run build:vite — passed; only existing chunk-size/dynamic-import warnings were reported.
  • corepack pnpm run test:e2e -- tests/e2e/opencode-multichat-runtime.spec.ts — 1 Electron E2E passed.
  • git diff --check — passed; only configured LF-to-CRLF notices were emitted.

Follow-ups

  • Integration should reconcile the canonical OpenCode Agent readiness and Session model ownership descriptions listed below.

Promotion Candidates

Per-Agent runtime acceptance

  • Target canonical documents: .project-docs/20-architecture/module-map.md and .project-docs/20-architecture/data-flow.md.
  • Proposal: replace the whole-manifest-only Agent readiness description with per-Agent desired/applied state. A unique id first seen in an owned fresh generation may be accepted after live registry discovery; same-id edits and delete/recreate remain pending until generation rollover.
  • Evidence: electron/opencode/project-agent-runtime.ts, tests/unit/project-agent-runtime.test.ts, and the Agent readiness cases in tests/unit/opencode-routes.test.ts.
  • Future impact: future Agent configuration work must preserve the distinction between identity discovery and same-id content reload, and must not restore a whole-manifest gate that blocks existing Agents when adding a peer.
  • Semantic conflicts: canonical docs currently describe a whole desired/applied fingerprint and state that live id alone cannot prove content. The proposal refines this by using first-seen unique identity as the safe hot-add boundary while retaining the same-id restriction.
  • Human confirmation required: no; this behavior was explicitly requested and is covered by regression tests.

OpenCode Session model ownership

  • Target canonical documents: .project-docs/20-architecture/module-map.md, .project-docs/20-architecture/data-flow.md, and .project-docs/40-domain/business-rules.md.
  • Proposal: document partner model as a new-Session default and OpenCode Session model as the authority for subsequent turns. Page selection and /models / /model call the native Session switch endpoint and ordinary prompts/commands omit model overrides.
  • Evidence: electron/opencode/client.ts, electron/api/routes/opencode.ts, src/stores/opencode.ts, src/pages/Chat/OpencodeChatPanel.tsx, focused unit tests, and tests/e2e/opencode-multichat-runtime.spec.ts.
  • Future impact: Provider configuration and partner maintenance must remain separate from transient per-Session model selection; future prompt paths must not reintroduce implicit model fallback overrides.
  • Semantic conflicts: none known beyond superseding the previous chat-composer read-only model behavior.
  • Human confirmation required: no; the user explicitly approved parity with OpenCode model switching.