Repository navigation
fix(hooks): register OpenCode 2.x sessionStart context without waiting on earlier events - #3932
Merged
Merged
Conversation
…g on earlier events The OpenCode 2.x event loop awaited every handler, so a slow command of an earlier event (a stop hook on session.execution.succeeded, say) held back session.created, and a session's first model requests got no sessionStart context. The loop now never waits: sessionStart starts right away and registers its pending context, while the other event handlers still run one after another on a queue in event order. Also: - Guard the session context hook registration so a 2.x host that cannot register it logs an error instead of breaking every other hook. - Evict kept sessionStart contexts in completion order. - Share the context check and sessionStart extras between the generators. - Document the Bun Shell memory caveat of the 1 MiB cap and the prompt injection risk of hooks that print external data. Closes #3927 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
… after dispose - Log a throw that reaches the event queue instead of swallowing it. - Skip queued event handlers that have not started when the plugin is disposed. - Document that sessionStart runs outside the event order and can overlap other event commands; align the helper JSDoc with the eviction docs. - Test cross-event ordering past a slow and a throwing handler, and wait on a marker file instead of a fixed sleep in the eviction test. Refs #3927 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
| " if (__rulesyncEvents.signal.aborted) return;", | ||
| ...statements.map((line) => ` ${line}`), | ||
| " })", | ||
| ` .catch((error) => console.error(${JSON.stringify(`[rulesync-hooks] ${eventType} event hook failed:`)}, error));`, |
…-session-start-await # Conflicts: # src/generated/docs-content.ts
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
Follow-ups from #3926 (OpenCode-style
sessionStartcontext). Every item of #3927 is addressed:stophook onsession.execution.succeeded) held backsession.created, and the session's first model requests got""from__rulesyncSessionContext. Making onlysessionStartfire-and-forget would not help, because the loop would still be blocked on the earlier handler. The loop now never waits for a command:sessionStartruns asvoid __rulesyncSessionStart(...), which registers the pending context synchronously as soon as the event is read.__rulesyncEventQueue, so they still run one after another in event order, as before. A throw is caught so it does not end the queue.session.deletedstill drops the context inline, so created/deleted ordering is unchanged.sessionStartruns on Bun Shell, which reads the whole stdout before the check. Streaming with a limit there would mean replacing the in-process Bun Shell runner that theeventhooks rely on, so I documented the limit instead.ctx.session.hook("context", ...). The registration is now wrapped intry/catch. A host with noctx.session.hook, or one that rejects thecontexthook point, logs an error instead of making setup throw, so the other hooks (preToolUseguards included) still load. Atypeofcheck would not catch the second case.usesSessionContext(handlers)andsessionContextExtrasFor(canonicalEvent)inopencode-style-generator.ts, used by both generators.Tests
stopcommand is still running whensession.createdarrives, and the session's first context request gets the context right away. Thestophandler after it still runs. This test fails onmain.ctx.session.hook("context")throws still loads the plugin, andpreToolUsestill denies.sessionStartthat starts first but finishes last is kept, and the oldest completed one is evicted. This test fails onmain.await(V1eventhook) andvoid(V2 loop) for each target.pnpm cicheckpasses.Closes #3927
🤖 Generated with Claude Code
https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4