Skip to content

fix(v1): drop watch state on a revert - #40

Merged
Mte90 merged 1 commit into
Mte90:masterfrom
famewolf:local/v1-revert-watch
Oct 5, 2026
Merged

Mte90 merged 1 commit into
Mte90:masterfrom
famewolf:local/v1-revert-watch

Conversation

@famewolf

@famewolf famewolf commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

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.updated with properties.info.revert populated, and the current handler only calls ensureWatch(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/revert and /unrevert; zero event types contain revert, and exactly one event carried the rewind (session.updated with properties.info.revert = { messageID, partID?, snapshot?, diff? }).

Change: src/index.ts — the session.updated case now checks the payload and calls sessions.delete(sid) when properties.info.revert is present (+25/−1). Adds src/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 master head 0c9bc06.

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.
@Mte90
Mte90 merged commit abfb2e2 into Mte90:master Oct 5, 2026
1 check passed
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
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.

2 participants