Repository navigation
opencode: hand over a session that has gone quiet - #230
Have-Purple wants to merge 1 commit into
Conversation
|
@microsoft-github-policy-service agree |
Aaron Li (aaron-jx-li)
left a comment
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.
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. plugin/README.md and docs/PLUGIN.md no longer say a TUI session waits for the next start.
0c56082 to
941a210
Compare
|
Split as offered: this PR is now the quiet hand-over only (one commit, Both review items that apply here are in:
The model PR carries the other three fixes: the usage read is back after Evidence for each: offline suite green (1167 passed / 36 skipped here, 1171 / 36 on #243), the |
On 2.x
opencode runand the TUI are the same background service, somode()— which readsprocess.argvfor"run"— cannot tell a headless run from an interactive one. A headless runtherefore 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 ownrecovery rule;
TE_OPENCODE_QUIET_MSoverrides the window (floor 10 s). Wheremode() == "run"can still be detected, the immediate hand-over is unchanged, and any prompt or tool call resets
the timer.
This is the first half of what was #230: the session-model change split out to #243 so it can be
discussed on its own, as review asked.
Tests
end_reason == "idle"after the window, while the process is still up.Docs
plugin/README.mdanddocs/PLUGIN.mdno longer say a TUI session is only folded at the nextsession's start; they say the plugin hands it over itself after the quiet window.
Verification
opencode 2.3.0, Python 3.15, Windows. Offline suite: 1167 passed, 36 skipped, 0 failed. The
plugin's non-service tests (console windows, quiet hand-over) pass. The two
opencode servicetests fail on this machine on
mainas well (baseline re-run at583fff7), so they are notevidence about this change; CI runs them on the pinned 2.2.5.