Skip to content

fix: keep the Auto route across plugin reloads - #8

Merged
kristoflemmens merged 1 commit into
mainfrom
fix/keep-auto-route-across-reloads
Nov 9, 2026
Merged

kristoflemmens merged 1 commit into
mainfrom
fix/keep-auto-route-across-reloads

Conversation

@kristoflemmens

Copy link
Copy Markdown
Contributor

Summary

opencode reloads plugins on every config change and recycles idle instances. Each reload dropped the pinned route, so the next turn routed again on the last prompt alone and could switch the model mid-conversation (seen in the plugin log: gpt-6-luna → gpt-6.1-sol after a config change, back to gpt-6-luna on an 8-character prompt the next morning), losing the prompt cache.

 conversations.get(session, auto)
   live state in memory?          → use it
+  route in routes.json?
+    token valid and servable?    → restore it (log "restored …")
+    otherwise                    → route again
 after a routing round
+  save route + token + expiry    → routes.json (0600, atomic, expired entries pruned)
 on compaction
-  mark live routes only
+  mark live and restored-but-unused routes, and save
 src/
-├── v1.ts   # own ConvState + getConv
-├── v2.ts   # own ConvState + getConv
+├── core.ts # Conversations: shared state + routes.json
+├── v1.ts   # uses Conversations
+└── v2.ts   # uses Conversations

Evidence

  • Before: the new reload tests against the old source: 66 pass, 4 fail
    setup(dir) → turn("auto")            # routes to gpt-6-luna
    setup(dir) → turn("auto", "continue")
    expect(calls).toHaveLength(1)        # ✗ 2: routed again
    expect(model).toBe("gpt-6-luna")     # ✗ gpt-6.1-sol
    
    After: bun run typecheck && bun run build && bun test → 75 pass, 0 fail

The other new tests guard behaviour that must not change: an expiring token, a model the anchor can no longer send, and a compaction before or after the reload all still route again.

Merge Danger

Door: two-way

Revert and the plugin ignores routes.json again. The file holds only Auto session tokens (24 h, routing only, not the GitHub credential), owner-only.

Blast Radius: routing

A bad restore would pin a conversation to a stale model until its token expires. Restores are checked for expiry and servability; a failed write is logged and never breaks a turn.

🤖 Generated with Claude Code

opencode reloads plugins on every config change and recycles idle
instances. That dropped every pinned route, so the next turn routed
again on whatever was typed last and could switch the model
mid-conversation, losing its prompt cache.

Routes are now kept per session and auto, with their session token, in
routes.json next to the plugin log (mode 0600, written atomically) until
the token expires. A restored route the auto can no longer send is
routed again, and a compaction marks restored routes for re-routing too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kristoflemmens
kristoflemmens merged commit 89b1ac3 into main Nov 9, 2026
2 checks passed
@kristoflemmens
kristoflemmens deleted the fix/keep-auto-route-across-reloads branch November 9, 2026 12:33
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