fix turn-end hook chain for opencode checkpoints#541
fix turn-end hook chain for opencode checkpoints#541peyton-alt wants to merge 2 commits intomainfrom
Conversation
PR SummaryMedium Risk Overview OpenCode hook parsing no longer runs Written by Cursor Bugbot for commit 6b064d3. Configure here. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in the OpenCode agent's turn-end hook chain where the transcript file existence check occurred before the file was created, causing "transcript file not found" errors.
Changes:
- Fixed hook chain order: PrepareTranscript now runs before fileExists check in turn-end handler
- Added security validation (validateSessionID) to prevent path traversal attacks in OpenCode session IDs
- Refactored OpenCode's ParseHookEvent to defer export to PrepareTranscript (removed duplicate export call)
- Added comprehensive tests for the preparer pattern and session ID validation
- Added sessionID fallback in TypeScript plugin for session.status events
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/entire/cli/lifecycle.go | Moved PrepareTranscript call before fileExists check to support OpenCode's lazy transcript fetch |
| cmd/entire/cli/lifecycle_test.go | Added test verifying PrepareTranscript is called before fileExists validation |
| cmd/entire/cli/agent/opencode/lifecycle.go | Removed duplicate export from ParseHookEvent, added sessionTranscriptPath helper and validateSessionID security check |
| cmd/entire/cli/agent/opencode/lifecycle_test.go | Unskipped TurnEnd test, added validation tests for path traversal and malformed session IDs, updated PrepareTranscript test expectations |
| cmd/entire/cli/agent/opencode/entire_plugin.ts | Added fallback to currentSessionID when props.sessionID is undefined in session.status events |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
6b064d3 to
a1387ea
Compare
OpenCode checkpoints weren't being created because the turn-end hook chain failed in two places:
ParseHookEventranopencode exportas a subprocess — if it failed (binary not on PATH, DB locked), the hook diedfileExistswas checked beforePrepareTranscripthad a chance to create the fileNo checkpoints meant empty sessions (#490) and wrong badge (#488).
Changes
opencode exportfromParseHookEventtoPrepareTranscriptPrepareTranscriptbeforefileExistscheckcurrentSessionIDin plugin when event omits it