fix(opencode): handle session.idle event for turn-end detection#771
Open
fix(opencode): handle session.idle event for turn-end detection#771
Conversation
OpenCode stopped reliably emitting `session.status` events with `status.type === "idle"` after a recent update (~v1.3.x). Instead, it now emits `session.idle` events. The plugin only listened for `session.status`, causing turn-end hooks to never fire. Without turn-end, `PrepareTranscript` never runs, the transcript file is never created, and condensation silently fails on every commit with: "transcript not found at .entire/tmp/<sessionID>.json: file does not exist" This results in empty checkpoint directories on the metadata branch — the `Entire-Checkpoint` trailer is added to commits but no session data is written to `entire/checkpoints/v1`. Handle both `session.idle` and `session.status` (with idle type) as a fall-through case for cross-version compatibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: bd73a3b73f81
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the embedded OpenCode plugin template so Entire can reliably detect turn completion across OpenCode versions by handling the newer session.idle event in addition to session.status idle events.
Changes:
- Add
session.idleas an additional switch case to trigger theturn-endhook. - Branch per event type to extract
sessionIDfrom the correct event shape while keeping the sync hook execution behavior.
Comment on lines
+118
to
+122
| case "session.idle": | ||
| case "session.status": { | ||
| // session.status fires in both TUI and non-interactive (run) mode. | ||
| // session.idle is deprecated and not reliably emitted in run mode. | ||
| const props = (event as any).properties | ||
| if (props?.status?.type !== "idle") break | ||
| const sessionID = props?.sessionID ?? currentSessionID | ||
| // session.status fires with status.type "idle" when the agent finishes. | ||
| // session.idle is a separate event that some OpenCode versions emit instead. | ||
| // Handle both for compatibility across OpenCode versions. |
There was a problem hiding this comment.
Consider adding a regression assertion in the existing Go hook installation tests (cmd/entire/cli/agent/opencode/hooks_test.go) that the generated plugin content contains handling for both "session.status" and the newly-added "session.idle" event. Without a test, this compatibility fix could be accidentally removed or drift during future template edits without being caught by CI.
OpenCode ≥1.3.x changed session.status to only carry "busy"/"retry" and introduced a separate session.idle event for turn completion. Confirmed via diagnostic plugin logging. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 5a1b1939a74a
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.
Summary
session.statusnow only carries"busy"/"retry"(never"idle"), and a separatesession.idleevent fires when the agent finishes a turnsession.statuswithstatus.type === "idle", soturn-endhooks stopped firing entirely after upgrading from 1.2.x to 1.3.xsession.idleas a fall-through case alongsidesession.statusfor cross-version compatibilityRoot cause
Confirmed via diagnostic plugin logging. After the OpenCode 1.2.x → 1.3.x upgrade, the plugin's event handler receives:
The plugin checked
props?.status?.type !== "idle"which always evaluated totrue(since type is"busy"), so the handler broke out of everysession.statusevent. Thesession.idleevent that actually signals turn completion was unhandled.Impact chain
turn-endhook never fires →PrepareTranscriptnever runsopencode export <sessionID>never called → transcript file (.entire/tmp/<sessionID>.json) never created"transcript not found at .entire/tmp/<sessionID>.json: file does not exist"Entire-Checkpointtrailer is still added to commits, but no session data is written toentire/checkpoints/v1Fix
Handle both event types as a fall-through case.
session.idlehasproperties.sessionIDdirectly, whilesession.statusrequires checkingproperties.status.typefor"idle"(for ≤1.2.x backwards compatibility).Test plan
session.idleis emitted by OpenCode 1.3.2session.statusonly carries"busy"in 1.3.2turn-endappears in.entire/logs/entire.log.entire/tmp/<sessionID>.jsonsession condensedlog entry with non-zerotranscript_linesentire/checkpoints/v1branch🤖 Generated with Claude Code