Repository navigation
feat(opencode-plugin): send lifecycle signals to the proxy - #1317
Conversation
The plugin now posts {session, event, kind} to /signal on compact,
session delete and permission or question prompts, from OpenCode's own
events (v1 event hook, v2 ctx.event.subscribe). It signals only for a
session that already sent a routed request. One second timeout, fire
and forget. CONTEXT_GURU_CLIENT_SIGNALS=off turns it off.
Closes #1313
Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 9fdf96ff4db5 |
blocking |
Verdict: blocking
Findings
- docs/data-dependence.md:248 — the generated page was edited by hand; the row file was not, so the datadep test fails
- What fails:
internal/datadepTestGeneratedPageIsUpToDatebuilds the page from the row files underdocs/data-dependence/and compares it with the checked-in page, string for string. This PR adds the sentence "The OpenCode plugin sends them too since #1313 ..." only to the generated page. The row filedocs/data-dependence/features/next-request-metadata.mdhas no such sentence (0 mentions of "OpenCode"). The build output and the checked-in page differ, so the test fails on this head. The nextgo run ./cmd/gen-datadepalso reverts the sentence. - Proof:
grep -c "OpenCode" docs/data-dependence/features/next-request-metadata.mdreturns 0; the sentence is present indocs/data-dependence.mdline 248 only.internal/datadep/datadep_test.go(TestGeneratedPageIsUpToDate) comparesBuild(repoRoot)with the file, byte for byte. CLAUDE.md says: edit the feature's row file, then rungo run ./cmd/gen-datadep; "Never edit that page by hand". - Fix: move the sentence into
docs/data-dependence/features/next-request-metadata.md(item 3 of the reason text), then rungo run ./cmd/gen-datadepfrom the repo root and commit the regenerated page.
- What fails:
Non-blocking
opencode-plugin/index.js:1304— thesessionsset increateSignalergrows for the life of the OpenCode process. Onlysession.deletedremoves an id. A session that ends without that event keeps its id forever. Each id is a short string, so this is small; note it only.opencode-plugin/index.js:1423— the v2 subscription asks forquestion.askedandsession.compacted, which do not exist as v2 events (checked in the 2.4.1 client types). The filter matches nothing and nothing rejects the names. Harmless, but a reader may look for them.
What I checked
- The full diff (5 files) and the code around each change in
opencode-plugin/index.js. - Wire shape and semantics against the proxy:
proxy/clientsignal.goaccepts{session, event, kind}, JSON only, closed event and kind sets; all five mappings (SessionStart/compact,SessionEnd/other,Notification/permission_prompt,Notification/elicitation_dialog) are in the closed sets. RoutePOST /signalatproxy/proxy.go:614. The local plugin proxy needs no credential:tenancyFor(proxy/tenancy.go:823) returns the static tenant whenOptions.Tenantsis nil. - Key consistency: requests key the session by
x-context-guru-sessionthroughsession.Scoped; the signal path usesscopedClientID, the same scoping. OpenCode ids (ses_...) passsafeExplicit, so a signal retires the entry the requests created. - OpenCode v1.18.29 plugin SDK (read from
sst/opencode): theeventhook exists (event?: (input: { event: Event })), andsession.compacted,session.deleted,permission.asked,question.askedare events withproperties.sessionID. OpenCode 2.4.1 client types:session.compaction.ended,session.deleted,permission.askedexist withdata.sessionID;question.askeddoes not exist — the code comment and the README table say the same. - Fail-open: the signal fetch is fire and forget with a 1 s abort, sync throws are caught, a missing port, an unrouted session, an unknown event and the off switch all send nothing. The v2 subscription is optional (
ctx.event?.subscribe?.). - Routing scope: v1
chat.headersreturns early for a provider not inroutedIds; v2 hooks are per routed provider and check the routed set.noteSessionruns only on that path, as the comment claims. - The generated-page rule:
internal/datadepbuildsdocs/data-dependence.mdonly from the row files;TestGeneratedPageIsUpToDatecompares exactly. - The new tests in
signals.test.mjsand the helper change: read in full. Port range 9700 does not collide with the other test files. No tests were run (not approved). - The PR body states the behavior change at the top, with the off switch, as CLAUDE.md requires.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 9fdf96ff4db5 |
blocking |
Verdict: blocking
Findings
- docs/data-dependence.md:248 — the generated page was edited by hand; the row file was not, so the datadep test fails.
- What fails:
go test ./internal/datadepfails onTestGeneratedPageIsUpToDate. The new sentence ("The OpenCode plugin sends them too since #1313, from OpenCode's own events...") exists only indocs/data-dependence.md. The row sourcedocs/data-dependence/features/next-request-metadata.mddoes not contain it, soBuild()produces a page without it and the checked-in page no longer matches. CI (go test ./...in ci.yaml) goes red. Also, the nextgo run ./cmd/gen-datadepby any other PR silently deletes the sentence. - Proof:
grep "OpenCode" docs/data-dependence/features/next-request-metadata.mdreturns nothing.internal/datadep/datadep_test.go:12(TestGeneratedPageIsUpToDate) compares the page byte-for-byte withBuild(repoRoot), which reads only the row files. CLAUDE.md says: edit the row file, run the generator, never edit the page by hand. - Fix: add the same sentence to the "(3) the client signals" part of
docs/data-dependence/features/next-request-metadata.md, then rungo run ./cmd/gen-datadepand commit the regenerated page.
- What fails:
Non-blocking
opencode-plugin/index.js:1304— thesessionsset increateSignalergrows for the life of the process. Only aSessionEndevent removes an entry. A long-running OpenCode with many sessions keeps one small string per session. Harmless today; note it if the set gains more state later.opencode-plugin/index.js:1291—question.askedandsession.compactedare inSIGNAL_EVENT_TYPES, which v2 subscribes to, but v2 has no such events. I checked the v2 subscribe (sst/opencode v2.4.1,packages/client/src/shared-events.ts): it builds a plain filter set and never validates names, so this is safe. A one-line comment saying "names the other generation lacks are ignored by subscribe" would save the next reader the same check.- OpenCode v1 also has
permission.v2.asked. It is not mapped, so a permission prompt on that flow sends no signal. The proxy recordsNotificationevents only, so the loss is one dashboard row, not a keep-alive action.
What I checked
- The full diff (5 files) and the code around each change in
opencode-plugin/index.js(v1ContextGuruPlugin, v2setupV2,createSignaler), plus the tests and the stub proxy intest/helpers.mjs. - The proxy side:
proxy/clientsignal.go(POST /signal, closed sets of events and kinds, tenant-scoped session ids),proxy/proxy.go(route registration,authenticate→tenancyFor), and the session resolution fromx-context-guru-session(proxy/proxy.go:796,session/session.go). The plugin's proxy runs tenant-less (static tenancy), so the signal post needs no credential, same as the Claude Code hook (context-guru-plugin/scripts/signal.sh). The session id the plugin sends is the same one it puts inx-context-guru-session, so the keep-alive key matches. - The event names and payload shapes against the upstream SDKs: v1.18.29
packages/sdk/js/src/v2/gen/types.gen.ts(all five mapped events exist, each withproperties.sessionID; the plugin hookevent?: (input: { event: Event })exists inpackages/plugin/src/index.ts) and v2.4.1packages/client/src/promise/generated/types.ts(session.compaction.ended,session.deleted,permission.askedexist withdata.sessionID;question.askeddoes not, as the comment says). - The v2 subscribe path (
packages/plugin/src/promise/event.ts,packages/client/src/shared-events.ts): no type validation, so extra names are ignored, and thetry/catcharound the subscription matches the "signals are optional" design. - Fail-open: every signal path is fire-and-forget with a 1 s
AbortSignal.timeout, a.catch, and a synctry/catch; a lost signal only means the no-signal keep-alive behavior. Theeventhook and the v2 loop cannot throw into the host. - Routing gate: both generations note a session only inside the request hook that already checks
routedIds, so an unrouted session never signals (also asserted by the tests). - The datadep generator (
cmd/gen-datadep,internal/datadep) and which CI workflow runs the drift test (ci.yaml,go test ./...); the plugin's own workflow (.github/workflows/opencode-plugin.yaml,node --test). - Test conventions: port ranges per file (
freePortskips busy ports, so the shared 9700 base with picker.test.mjs is safe), condition-based waits (waitForRecordpolls a file with a deadline, no fixed sleeps), and proxy cleanup viainstall.jsonpid. - Live tests were not run; Go is not invoked. Upstream SDK files were read from github.com to verify the OpenCode event contracts the plugin depends on.
… session set - Put the OpenCode sentence in the row file next-request-metadata.md. The generated page is unchanged by gen-datadep. - Bound the remembered sessions to 256, oldest out. - Map the v1 SDK event permission.v2.asked to permission_prompt. - Comment why the v2 subscribe filter may hold v1 names. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Round 1 reply. Fixed in e58408c. Both reviews had the same blocking finding. Blocking (both reviewers): the data-dependence page was edited by hand
Non-blocking:
Non-blocking: v2 filter holds names v2 lacks (both reviewers)
Non-blocking:
Tests: |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | e58408c5fc97 |
approve |
Verdict: approve
Findings
None. My round-1 finding is fixed, and the fix is correct.
Round-1 findings
- docs/data-dependence.md:248 — the generated page was edited by hand; the row file was not. Fixed.
- The sentence now lives in
docs/data-dependence/features/next-request-metadata.md, item (3), anddocs/data-dependence.mdis untouched by the fix commit. - Proof: I parsed the row file (front matter plus reason) and compared every cell of the page's line 248 against it. Name, kind, off, metadata-only, everything and reason all match, string for string. So
Build()now reproduces the checked-in page andTestGeneratedPageIsUpToDatepasses. This matches the author's round-1 reply, which also reportsgo run ./cmd/gen-datadepandgo test ./internal/datadep/... ./components/all/...passing.
- The sentence now lives in
Non-blocking (new in this round)
opencode-plugin/README.md:141— the table row now listspermission.asked,permission.v2.askedwith version "v1, v2".permission.v2.askedis a v1 SDK type only. The code comment (opencode-plugin/index.js:1284) says this correctly. The README cell is a small imprecision, nothing more.
What I checked
- Last review: round 1, 9fdf96f, 2026-11-24T08:31:57Z.
- New commits read: 1 —
e58408c5fix(opencode-plugin): move the data row to its source file, bound the session set. - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review:
- Commit
e58408c5(4 files): read the whole diff and the code around each change. - Author's round-1 reply (comment, 2026-11-24T08:36:16Z): each claim checked below.
- Commit
- The datadep fix: row file versus page cell compared field by field (all match, see above). The page itself did not change in the fix commit, so the branch's only page change is the round-1 line, which the row file now reproduces.
- The bounded session set (
opencode-plugin/index.js:1312): delete-then-add moves an id to newest; the eviction removes the oldest insertion when the size passes 256; the set cannot be empty on the eviction path. The new test covers eviction, re-seeing an evicted id, and the safe fallback (a dropped id sends no signal). permission.v2.asked: verified in the v1.18.29 SDK (packages/sdk/js/src/v2/gen/types.gen.ts) — the event exists withproperties.sessionID, so the new mapping reads a real field. The author's limit (no publisher found in the v1 source, so it may never fire) is honest and the mapping is harmless: the proxy recordsNotificationevents only.- The new
SIGNAL_EVENT_TYPEScomment matches what I verified in round 1: the v2 subscribe (packages/client/src/shared-events.tsat 2.4.1) builds a filter set and never validates names. - The updated mapping test and the new bound test in
signals.test.mjs: read in full; the expected values match the code's behavior (44 ids evicted after 300 notes,ses_45evicted after the re-add ofses_44plus 40 more). - Nothing else changed on the branch:
git log 9fdf96ff..HEADshows onlye58408c5; no inline comments exist on the PR. - Live tests were not run; Go is not invoked. The upstream SDK file was read from github.com to verify the
permission.v2.askedcontract.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | e58408c5fc97 |
approve |
Verdict: approve
Findings
None.
Non-blocking
opencode-plugin/README.md:141— the row "permission.asked,permission.v2.asked| v1, v2" is imprecise for the second name.permission.v2.askedexists in the v1.18.29 SDK only; the v2.4.1 client has no such event (checked: its permission events aresession.permissions,permission.asked,permission.replied). The code comment says "(v1 SDK type)", which is right. One-word doc fix if wanted.
What I checked
- Last review: round 1,
9fdf96ff4db53b25ef05a135f652b10d99e1a279, 2026-11-24T08:30:38Z. - New commits read: 1 (
e58408c5fix(opencode-plugin): move the data row to its source file, bound the session set). Full diff read; each changed file read around the change. - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files in my folder).
- New items since my last review, and what I did about each:
- Reviewer 1's round-1 review (08:31:57Z): same blocking finding as mine, plus
permission.v2.askedunmapped. Checked each against the fix commit. - The author's round-1 reply (08:36:16Z): verified every claim it makes, as below.
- Commit
e58408c5: reviewed as a first review.
- Reviewer 1's round-1 review (08:31:57Z): same blocking finding as mine, plus
Earlier findings, and their state:
- Mine, blocking — the data-dependence page was edited by hand. Fixed. The sentence now lives in
docs/data-dependence/features/next-request-metadata.md. I could not run the generator (live runs not approved), so I replicated its transform exactly (front matter keys, body joined on whitespace, pipes escaped, cells in the Features column order) and compared with the checked-in page: the row renders byte-for-byte the page's "Next-request metadata" line, and the commit does not touchdocs/data-dependence.md. SoTestGeneratedPageIsUpToDatepasses and the next generator run changes nothing. The author's reply states the same result from a real run. - Mine, non-blocking — the
sessionsset grows without bound. Fixed.noteSessionnow deletes and re-adds the id (a session seen again counts as newest) and evicts the oldest id above 256. ASetkeeps insertion order, sovalues().next().valueis the least recently noted id. A dropped id only loses the signal, the no-signal fallback. The new test covers eviction, the re-note refresh and the silent drop; its arithmetic is right (ses_44 kept, ses_45 evicted). - Mine, non-blocking — the v2 filter holds names v2 lacks. Fixed. A comment at
SIGNAL_EVENT_TYPESsays subscribe ignores names the host does not have. - Reviewer 1, non-blocking —
permission.v2.askedwas not mapped. Fixed. It now maps toNotification,permission_prompt, with a test. I checked the v1.18.29 SDK:EventPermissionV2Askedis in theEventunion and its payload hasproperties.sessionID, so the mapping is type-correct. The author's caveat — no publisher of that event found in the v1.18.29 server source — is stated in the reply and does not change the verdict: an unmapped or never-fired event only loses a recorded (never acted-on) signal.
New code in this commit, checked on its own:
- The
permission.v2.askedentry lands inSIGNAL_EVENTSonly;handlereads it through the same closed map, so no new path exists. - The README and the code comment agree with the SDK facts, except the one imprecision under Non-blocking above.
- The new test uses the stub recorder, no new ports, no time-based waits beyond the existing
waitForRecordpoll.
|
Behavior change: approved by a human developer. @amiddavid approved the behavior change on 2026-11-24, in the session that owns this PR.
|
Cite #1317, #1318 and #1322 per client. Record Cortex facts from its plugin: host session id, no thread tracker, no signal route. Note that the bifrost adapter needs the transport to pass headers. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Cite #1317, #1318 and #1322 per client. Record Cortex facts from its plugin: host session id, no thread tracker, no signal route. Note that the bifrost adapter needs the transport to pass headers. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Cite #1317, #1318 and #1322 per client. Record Cortex facts from its plugin: host session id, no thread tracker, no signal route. Note that the bifrost adapter needs the transport to pass headers. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
docs: add rules for client-specific code and a client coverage table Add "Client-specific code" to CLAUDE.md, a client-rule check to the offload-review prompt, a third refactor-scan pattern, and a wider step 5 in RELEASING.md. Add docs/client-coverage.md and a test that fails when a registered agent has no row. Closes #1321 docs: fill the client coverage table from the open PRs and Cortex Cite #1317, #1318 and #1322 per client. Record Cortex facts from its plugin: host session id, no thread tracker, no signal route. Note that the bifrost adapter needs the transport to pass headers. docs: mark Cortex wait cause n/a and note the thread gap owner docs: leave the Cortex follow-up issue to the Cortex integration owner docs: update the client coverage table for merged and open PRs docs: address round 1 notes on the client coverage test and rules Anchor the table scan on the By client heading, map each pending row to its issue, name one Identify, say why Pi has no plain-string sign, and note that dashboard-only labels have no rules. test: fix the heading fixtures of the client coverage parser test Find the heading at the start of the page. Prefix the no-table case with a title so the next-heading guard runs. Drop a dead empty-rows check. docs: add the client coverage page to the nav docs: state client rules without issue numbers Write each rule as a general rule with an example. State the coverage table as facts on main. Map pending rows to a reason, not an issue. No behavior change: rules, skill prompts and docs, plus one Go test. The owner checked the text-only commits by hand (2026-11-24). Approvals still count (approval-still-valid). Local tests waived (owner rule). Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Behavior change. Needs a human yes before merge.
CONTEXT_GURU_CLIENT_SIGNALS=off(the proxy then answers 404, and the plugin sends nothing when it sees the variable).Summary
The OpenCode plugin now posts
{session, event, kind}to/signal. This is the same shape the Pi plugin uses. Closes #1313.What changed
opencode-plugin/index.js: a smallcreateSignaler. It posts tohttp://127.0.0.1:<port>/signal, JSON, 1 s timeout, fire and forget.eventhook. The v2setupsubscribes withctx.event.subscribe. A host with noctx.eventonly loses the signals.x-context-guru-session. The plugin signals only for a session that already sent a request through the proxy.session.compactedSessionStart,compactsession.compaction.endedSessionStart,compactsession.deletedSessionEnd,otherpermission.askedNotification,permission_promptquestion.askedNotification,elicitation_dialogdocs/data-dependence.mdrow updated.Data dependence
Metadata only. The body holds a session id, an event name and a kind from a closed set. No change at any storage level (off, metadata only, everything). The row in
docs/data-dependence.mdnow names the OpenCode plugin as a sender.How it was tested
macOS, Node v22.23.4.
node --check opencode-plugin/index.js opencode-plugin/tui.js: pass.node --test opencode-plugin/test/*.test.mjs: 119 pass, 0 fail. 6 tests are new (signals.test.mjs)./signal.Open questions
session.deletedisother. OpenCode has no quit or exit event for plugins, so a quit without a delete sends nothing.session.compacted(v1) fires after the compaction. The proxy's 2 s race margin covers a late event.question.askedhas no v2 event in 2.4.1. TheNotificationsignal is recorded only, never acted on.Technical notes
OpenCode sources (read only,
sst/opencode):v1.18.29:packages/plugin/src/index.ts:224(event?: (input: { event: Event })).packages/opencode/src/plugin/index.ts:255-259(hook delivery,properties = event.data). Event types inpackages/sdk/js/src/v2/gen/types.gen.ts:EventSessionCompacted(~6986),EventSessionDeleted(~6209),EventPermissionAsked(~6862),EventQuestionAsked(~6951).@opencode/plugin/ client 2.4.1 (dev branch, commit81045bf4):packages/plugin/src/promise/event.ts(ctx.event.subscribe({types}), async iterable). Event types inpackages/client/src/promise/generated/types.ts:SessionCompactionEnded(~1670),SessionDeleted(~1321),PermissionAsked(~1889). Use of the same API:packages/core/src/plugin/warming.ts:185-205.proxy/clientsignal.go(closed event and kind sets, JSON only, tenant-scoped id).opencode-plugin/test/helpers.mjsnow answersPOST /signaland records it whenCG_TEST_RECORDis set.