Repository navigation
opencode: hand over a quiet session, and follow the session's model in side calls - #230
Open
Have-Purple wants to merge 2 commits into
Open
Have-Purple wants to merge 2 commits into
Have-Purple wants to merge 2 commits into
Conversation
On 2.x 'opencode run' and the TUI are the same background service, so mode() cannot tell them apart: a headless run only folded at the next session start. A session quiet for TE's own recovery rule (fold.STALE_S, 600 s; TE_OPENCODE_QUIET_MS overrides it) is now handed over on a timer. Where mode()=='run' can still be detected, the immediate hand-over is unchanged, and any prompt or tool call resets the timer.
With neither opencode_paid_model nor paid_model set, a side call ran 'opencode run' with no --model and took the CLI's configured default. That default can be a free model the session has already moved past; the free tier's 429 then looked like the plugin was broken while the session ran fine on a paid provider. The 2.x plugin now reports the model from session.step.started (provider/model#variant) with each hook; the session state keeps it, and the loop guard's judge and the micro-skills proposer use it where no paid_model is set. An explicit paid_model still wins, and the other hosts keep their own defaults (Claude's haiku): the fallback is opencode-only.
|
Have-Purple please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Author
|
@microsoft-github-policy-service agree |
Aaron Li (aaron-jx-li)
requested changes
Nov 16, 2026
Aaron Li (aaron-jx-li)
left a comment
Collaborator
There was a problem hiding this comment.
Related to #229, this PR also needs a few changes before it can be merged:
tokeneconomizer/plugin/fold.py:505now readssession_usagebeforectx.host.settle(transcript)(fold.py:520). Copilot'ssettlewaits forsession.shutdown, the only event that carries usage, which Copilot writes just after the SessionEnd hook returns (hosts.py:1176). With the read moved ahead of it, a Copilot fold that starts before that line is written records no tokens: whensession.shutdownlands one second into the fold, main records 4 requests and 1500 input tokens, this branchrequests: 0, input_tokens: None. Please keep the usage read aftersettle.- The fallback to the log's model (
fold.py:506) passes a bare model id, because the opencode reader keeps onlymodelID(trace/opencode.py:156,186): the side call becomesopencode run --model gpt-5.6-sol. opencode reads--modelasprovider/model, so that is a resolution error, not the session's model. On 1.x theserverentry never sendsmodel, so every paid proposer call would take this path and fail where it runs on the default model today.test_a_fold_takes_the_model_from_the_session_log(tests/test_live_hooks.py:1761) asserts the bare id. Please drop the log fallback, or buildproviderID/modelIDfrom the log. - Please split the two changes, as you offered. The quiet hand-over only changes the plugin. Following the session's model changes what side calls cost: they would run on the session's own model and variant (
#highincluded,plugin/opencode/tokeneconomizer.ts:546), wheredocs/PLUGIN.md:98describes the optimizer as the cheapest capable model. That needs its own discussion, andplugin/README.md:412("on your default opencode model") has to change with it. - Please rebase onto main: since this was opened, #185 added a
role=argument tosidecall.runner_forand the local judge's runner, and #160 changed_fold_microskills, so this conflicts infold.py,judge.pyandsidecall.py. The session's model has to go throughrunner_foralongsiderole=rather than replace it. - For the quiet hand-over, please update
plugin/README.md:403-410anddocs/PLUGIN.md:832, which still say a TUI session is only handed over at the next session's start.
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.
Two small fixes for 2.x. They touch different code paths and can be split if you'd rather take one.
1. A quiet session is handed over
mode()readsprocess.argvfor"run", but 2.x runs plugins in the background service:opencode runand the TUI are both the sameserve --serviceprocess, so the plugin cannot tell a headless run from an interactive one. A headless run therefore only folded at the next session start, through the recovery path.A session quiet for
fold.STALE_S(600 s) is now handed over on a timer, matching TE's own recovery rule.TE_OPENCODE_QUIET_MSoverrides the window (floor 10 s). Wheremode() == "run"can still be detected, the immediate hand-over is unchanged.2. Side calls follow the session's model
With neither
opencode_paid_modelnorpaid_modelset, the plugin ranopencode runwith no--model, so TE used the CLI's configured default. That default can be a free model the session has already moved past — the resulting 429s looked like TE being broken while the session was running fine on a paid provider.The plugin now reports the model from
session.step.startedasprovider/model#variantwith each hook. The session state keeps it; the loop guard's judge and the micro-skills proposer use it when nopaid_modelis set. An explicitpaid_modelstill wins, and other hosts keep their own defaults (Claude'shaiku) — the fallback is opencode-only.Design notes
fold.STALE_S; the model fallback changes cost semantics. Both can be gated behind config, or this PR can be split, if that fits the project better.100755), so the 1.x/shpath is untouched.Tests
end_reason == "idle"after the window, while the process is still up;session.step.startedwith its hooks (end-to-end under opencode's runtime);paid_modelwins, Claude stayshaiku;Verification
opencode 2.3.0, Python 3.15, Windows. The full offline suite is green locally. I could not reproduce CI's opencode 2.2.5 matrix here, so that run is the one thing I'd watch on the PR.