fix(v1): drop watch state on a revert - #40
Merged
Merged
Conversation
A revert in OpenCode v1 has no event of its own. Verified live on 2026-10-01
against v1.18.34 on a clean Arch LXC with this plugin installed as the real
thing: driving a turn, then POSTing /session/:id/revert and /session/:id/unrevert
while logging every event the `event` hook received. Exactly one event carried
the rewind —
session.updated properties.info.revert = { messageID, partID?, snapshot?, diff? }
preceded by `session.diff`. No `session.reverted`, and no `session.revert.*`
family either; those strings in the v1 binary are HTTP route identifiers. So a
plugin that switches on the event name alone never learns the user rewound, which
is how one turn's state carried into the next.
The session.updated handler now reads info.revert and drops the watch when it is
set. Carrying that state across a rewind is the bug: the counters are spent, and
worse, `userCancelled` / `completionSignaled` are deliberately preserved across
busy transitions, so an ESC on a runaway turn followed by a rewind and a re-ask
left the session muted for good. Dropping the watch gives the re-asked turn a
fresh budget. Unreverting restores the messages but not these flags, which is the
conservative direction.
8 tests, every one mutation-verified: guard-never-fires, key-tested-not-value,
state-kept-not-dropped, branch-removed-entirely, counters-not-reported,
counters-hardcoded-zero and drop-any-session-updated each turn the suite red.
famewolf
pushed a commit
to famewolf/opencode-auto-resume
that referenced
this pull request
Oct 5, 2026
famewolf
pushed a commit
to famewolf/opencode-auto-resume
that referenced
this pull request
Oct 5, 2026
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.
Per your request on #39 — the issue carries the full analysis and patch inlined.
What: when a session is reverted in OpenCode v1, drop that session's watch state. v1 has no revert-named event — a rewind arrives as
session.updatedwithproperties.info.revertpopulated, and the current handler only callsensureWatch(sid), so a rewind carries one turn's watch state into the next.Verified: against opencode v1.18.34 with the plugin installed the normal way — 79 events across a turn plus
POST /session/:id/revertand/unrevert; zero event types containrevert, and exactly one event carried the rewind (session.updatedwithproperties.info.revert = { messageID, partID?, snapshot?, diff? }).Change:
src/index.ts— thesession.updatedcase now checks the payload and callssessions.delete(sid)whenproperties.info.revertis present (+25/−1). Addssrc/index.revert-watch.test.ts— 8 mutation-verified tests covering the revert payload path (+304). The v2 module is not affected (it receives reverts through v2's own event family).Single commit on
masterhead0c9bc06.