t1306: OpenCode upstream — stream hooks proof-of-concept PR complete#2318
t1306: OpenCode upstream — stream hooks proof-of-concept PR complete#2318marcusquinn merged 1 commit intomainfrom
Conversation
Mark t1305 and t1306 as complete — upstream PR anomalyco/opencode#14741 is open with all 9/9 CI checks passing and MERGEABLE status. Add task brief documenting the implementation, acceptance criteria, and completion evidence.
Summary of ChangesHello @marcusquinn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request finalizes the internal tracking and documentation for the upstream proof-of-concept implementation of real-time stream hooks in OpenCode. The completed work enables plugins to interact with streaming events, offering capabilities like early abortion and intelligent retries, which are foundational for advanced features such as Time-To-Stream Rules (TTSR) and real-time policy enforcement. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
WalkthroughUpdates to TODO.md introduce new upstream OpenCode integration tasks (t1305–t1314), including proof-of-concept stream hooks (t1306), observability instrumentation, verification tooling, and cross-repo coordination. New task brief document (t1306-brief.md) specifies implementation details, acceptance criteria, and completion evidence for the stream hooks proof-of-concept. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Wed Feb 25 22:46:50 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
🤖 Augment PR SummarySummary: Documents completion of the upstream OpenCode “stream hooks” proof-of-concept work needed to unblock real-time TTSR enforcement. Changes:
Technical Notes: This PR is documentation-only in this repo; the functional implementation lives upstream (anomalyco/opencode#14740/#14741). 🤖 Was this summary useful? React with 👍 or 👎 |
|
There was a problem hiding this comment.
Code Review
My review focuses on ensuring the documentation is consistent and accurate. I've pointed out a factual inconsistency in the TODO.md summary and suggested an addition for clarity in the detailed brief, aligning with guidelines for clear and complete operational details.
| - [ ] t1306 OpenCode upstream: proof-of-concept PR for stream hooks — fork anomalyco/opencode, implement `stream.delta` and `stream.aborted` hooks in streaming loop. Add plugin trigger calls at `text-delta`, `reasoning-delta`, and `tool-input-delta` cases. Implement abort mechanism via AbortController exposure. Add tests. Reference the issue from t1305. NOTE: v1.2.7 migrated from Bun.file() to Filesystem module across entire codebase — fork from latest main, not our stale clone. ~4h #feature #auto-dispatch #harness #opencode #upstream model:opus ref:GH#2130 [proposed:auto-dispatch model:opus] status:deployed | ||
| - Notes: CANCELLED: cancelled by supervisor | ||
| - [x] t1305 OpenCode upstream: open issue proposing stream.delta + stream.aborted plugin hooks — research existing OpenCode issues for overlap. Draft issue citing oh-my-pi benchmark data (hashline improved 15 models, 5-68% success rate gains, 20-61% token reduction). Propose two new hooks: `stream.delta` (observe individual streaming tokens, return `{abort?: boolean}`) and `stream.aborted` (handle abort with `{retry?: boolean, injectMessage?: string}`). Reference the streaming loop where hooks would be inserted. Include code sketch showing the modest change needed. ~2h #feature #auto-dispatch #harness #opencode #upstream model:opus ref:GH#2129 pr:#2152 completed:2026-02-22 upstream-issue:anomalyco/opencode#14740 | ||
| - [x] t1306 OpenCode upstream: proof-of-concept PR for stream hooks — fork anomalyco/opencode, implement `stream.delta` and `stream.aborted` hooks in streaming loop. Add plugin trigger calls at `text-delta`, `reasoning-delta`, and `tool-input-delta` cases. Implement abort mechanism via AbortController exposure. Add tests. Reference the issue from t1305. ~4h #feature #auto-dispatch #harness #opencode #upstream model:opus ref:GH#2130 completed:2026-02-25 upstream-pr:anomalyco/opencode#14741 |
There was a problem hiding this comment.
The task description for t1306 mentions implementing the abort mechanism using AbortController exposure. However, the newly added task brief (todo/tasks/t1306-brief.md) states that a StreamAbortedError custom error class was used instead. To maintain consistency and accurately reflect the work done, it would be best to update the task description in this file.
| - [x] t1306 OpenCode upstream: proof-of-concept PR for stream hooks — fork anomalyco/opencode, implement `stream.delta` and `stream.aborted` hooks in streaming loop. Add plugin trigger calls at `text-delta`, `reasoning-delta`, and `tool-input-delta` cases. Implement abort mechanism via AbortController exposure. Add tests. Reference the issue from t1305. ~4h #feature #auto-dispatch #harness #opencode #upstream model:opus ref:GH#2130 completed:2026-02-25 upstream-pr:anomalyco/opencode#14741 | |
| - [x] t1306 OpenCode upstream: proof-of-concept PR for stream hooks — fork anomalyco/opencode, implement `stream.delta` and `stream.aborted` hooks in streaming loop. Add plugin trigger calls at `text-delta`, `reasoning-delta`, and `tool-input-delta` cases. Implement abort mechanism via a custom StreamAbortedError. Add tests. Reference the issue from t1305. ~4h #feature #auto-dispatch #harness #opencode #upstream model:opus ref:GH#2130 completed:2026-02-25 upstream-pr:anomalyco/opencode#14741 |
| 6. Add tests in `packages/opencode/test/session/stream-hooks.test.ts` | ||
|
|
||
| Key files: | ||
| - `packages/opencode/src/session/processor.ts` — streaming loop (two locations: reasoning and text delta handlers) |
There was a problem hiding this comment.
The brief mentions that stream.delta hooks are triggered for text-delta, reasoning-delta, and tool-input-delta. However, this line only lists "reasoning and text delta handlers" as key locations. For clarity and consistency, it would be good to include tool-input-delta here as well.
| - `packages/opencode/src/session/processor.ts` — streaming loop (two locations: reasoning and text delta handlers) | |
| - `packages/opencode/src/session/processor.ts` — streaming loop (handlers for text-delta, reasoning-delta, and tool-input-delta) |
References
- Ensuring all relevant operational details, such as delta handlers, are explicitly listed for clarity and consistency, especially when presented in a bulleted format.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
todo/tasks/t1306-brief.md (4)
87-87: Document a staleness-prevention step for future upstream contributions.Two PRs were closed due to a stale base before the v2 rebase succeeded. The brief notes the incident but doesn't record a guard against repeating it. A one-liner here would help future task authors:
- **v2 branch**: First attempt (`feature/stream-hooks`, PR `#14701/`#14727) was closed due to stale base. Rebased onto latest dev as `feature/stream-hooks-v2` (PR `#14741`). +- **Staleness guard**: For future upstream PRs, run `git fetch upstream && git rebase upstream/dev` and force-push before opening — or set a calendar reminder to rebase after >3 days without merge.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@todo/tasks/t1306-brief.md` at line 87, Add a one-line guard to the brief advising to update the PR base before long-lived rebases: mention the branch names `feature/stream-hooks` and `feature/stream-hooks-v2` (and optionally PR `#14701/`#14727/#14741) and instruct future authors to rebase onto the latest `dev` and verify CI and mergeability immediately before leaving the PR open to prevent stale-base closures.
43-81: All acceptance criteria are manual-only — add automated verification scripts.Every criterion here delegates to a human eyeballing a PR diff or running
gh pr checksonce. For a DevOps harness claiming zero technical debt and A-grade tooling, this creates a silent regression risk: if the upstream PR is amended, force-pushed, or superseded, none of these checks will fire.At a minimum, add a companion
verify.sh(or inline it under each criterion) that does the real work:- verify: - method: manual - prompt: "gh pr checks 14741 --repo anomalyco/opencode — all 9 checks SUCCESS" + verify: + method: script + script: | + gh pr checks 14741 --repo anomalyco/opencode \ + | awk '{print $2}' \ + | grep -v "^pass$" \ + && echo "FAIL: some checks did not pass" && exit 1 \ + || echo "OK: all checks pass"The same pattern applies to the diff-inspection criteria —
gh pr diff 14741 --repo anomalyco/opencode | grepis automatable.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@todo/tasks/t1306-brief.md` around lines 43 - 81, Replace the manual-only verification steps in todo/tasks/t1306-brief.md with automated checks by adding a verify.sh script and wiring each YAML criterion to call it (or inlining the commands) — script should run `gh pr diff 14741 --repo anomalyco/opencode | grep` for the Plugin.trigger and Hooks type diffs, `gh pr checks 14741 --repo anomalyco/opencode` for CI status, and run the test suite (e.g., npm/yarn test or the repository’s test command) to assert passing tests and StreamAbortedError coverage; update the YAML verify blocks to invoke the script/commands and fail nonzero on mismatches so CI can catch regressions.
89-89:STREAM_ABORT_MAX_RETRIES = 3is not plugin-configurable — note as a design limitation.If
stream.abortedis meant to be a general-purpose plugin hook, hardwiring the retry budget to 3 means every plugin shares that ceiling regardless of its use case. Cost-control plugins may want a budget of 1; resilience plugins may need more. Since this is upstream-bound code, changing it later is a breaking change.Either justify
3as a deliberate safe default in the brief (and link a follow-up to exposemaxRetriesin the hook output type), or document this explicitly as a known limitation so downstream TTSR consumers aren't surprised.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@todo/tasks/t1306-brief.md` at line 89, The brief currently presents STREAM_ABORT_MAX_RETRIES = 3 as a hardcoded constant but does not call out that this retry budget is not plugin-configurable; update the task brief to either (a) justify 3 as a deliberate safe default and add a follow-up note to expose a maxRetries field in the stream.aborted hook output type, or (b) explicitly document this as a known design limitation so downstream consumers are warned that plugins cannot change retry budget (reference STREAM_ABORT_MAX_RETRIES and stream.aborted in the text). Ensure the brief includes the chosen path and a linked follow-up issue for exposing maxRetries if you pick (a).
90-90: Track the(value as any)type assertions as follow-up debt.The brief documents the
anycast as a deliberate workaround, but there's no linked issue or follow-up task to resolve it when the upstream SDK ships proper types fortool-input-delta. Without a tracked item, this silently staysanyindefinitely — which is exactly the kind of debt this harness claims to avoid.Consider adding a
Blocks:orFollow-up:entry referencing a new task (e.g.,t1315: upstream SDK types PR for tool-input-delta fields) so the cast gets revisited when upstream types land.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@todo/tasks/t1306-brief.md` at line 90, Add a tracked follow-up task and reference it in the brief so the temporary any casts used for tool-input-delta fields are not forgotten: create a task like "t1315: upstream SDK types PR for tool-input-delta fields" and add a "Blocks:" or "Follow-up:" line in the brief that mentions that task and the specific workaround locations (the `(value as any).id` and `(value as any).delta` casts) so reviewers can find and remove the casts once upstream exposes proper types.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@todo/tasks/t1306-brief.md`:
- Around line 115-120: Rename the "## Completion Evidence" header to "##
Delivery Evidence" in todo/tasks/t1306-brief.md, update the paragraph that lists
the upstream PR anomalyco/opencode#14741 to explicitly state that the PR is OPEN
and that delivery is pending upstream merge (e.g., "Upstream PR is open;
delivery is pending maintainer merge — re-engage if PR is closed or requests
rework"), and add a follow-up task entry (suggested id: t1315) that tracks the
upstream merge of anomalyco/opencode#14741 so the task can be closed only after
the PR is merged.
---
Nitpick comments:
In `@todo/tasks/t1306-brief.md`:
- Line 87: Add a one-line guard to the brief advising to update the PR base
before long-lived rebases: mention the branch names `feature/stream-hooks` and
`feature/stream-hooks-v2` (and optionally PR `#14701/`#14727/#14741) and instruct
future authors to rebase onto the latest `dev` and verify CI and mergeability
immediately before leaving the PR open to prevent stale-base closures.
- Around line 43-81: Replace the manual-only verification steps in
todo/tasks/t1306-brief.md with automated checks by adding a verify.sh script and
wiring each YAML criterion to call it (or inlining the commands) — script should
run `gh pr diff 14741 --repo anomalyco/opencode | grep` for the Plugin.trigger
and Hooks type diffs, `gh pr checks 14741 --repo anomalyco/opencode` for CI
status, and run the test suite (e.g., npm/yarn test or the repository’s test
command) to assert passing tests and StreamAbortedError coverage; update the
YAML verify blocks to invoke the script/commands and fail nonzero on mismatches
so CI can catch regressions.
- Line 89: The brief currently presents STREAM_ABORT_MAX_RETRIES = 3 as a
hardcoded constant but does not call out that this retry budget is not
plugin-configurable; update the task brief to either (a) justify 3 as a
deliberate safe default and add a follow-up note to expose a maxRetries field in
the stream.aborted hook output type, or (b) explicitly document this as a known
design limitation so downstream consumers are warned that plugins cannot change
retry budget (reference STREAM_ABORT_MAX_RETRIES and stream.aborted in the
text). Ensure the brief includes the chosen path and a linked follow-up issue
for exposing maxRetries if you pick (a).
- Line 90: Add a tracked follow-up task and reference it in the brief so the
temporary any casts used for tool-input-delta fields are not forgotten: create a
task like "t1315: upstream SDK types PR for tool-input-delta fields" and add a
"Blocks:" or "Follow-up:" line in the brief that mentions that task and the
specific workaround locations (the `(value as any).id` and `(value as
any).delta` casts) so reviewers can find and remove the casts once upstream
exposes proper types.
| ## Completion Evidence | ||
|
|
||
| - **Upstream PR:** [anomalyco/opencode#14741](https://github.com/anomalyco/opencode/pull/14741) — OPEN, MERGEABLE, 9/9 CI checks pass | ||
| - **Upstream issue:** [anomalyco/opencode#14740](https://github.com/anomalyco/opencode/issues/14740) — OPEN | ||
| - **Changes:** 267 additions, 2 deletions across 3 files | ||
| - **Tests:** 11 new tests in `stream-hooks.test.ts` + all 120 existing session tests pass |
There was a problem hiding this comment.
Completion evidence references an OPEN PR — clarify the task completion boundary.
The brief marks all checkboxes [x] and the task is listed as done, but the upstream PR is still OPEN and awaiting maintainer review. "Delivery complete" ≠ "merged and shipped." If the upstream maintainer requests significant rework or closes the PR, this task needs to be re-engaged.
Recommend rephrasing the section header from ## Completion Evidence to ## Delivery Evidence and adding an explicit note:
+> ⚠️ Merge is pending upstream maintainer review. Task status reflects delivery of the PoC PR, not upstream adoption.
- **Upstream PR:** [anomalyco/opencode#14741](https://github.com/anomalyco/opencode/pull/14741) — OPEN, MERGEABLE, 9/9 CI checks passAlso consider adding a follow-up task (e.g., t1315: track upstream merge of anomalyco/opencode#14741) to close the loop.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ## Completion Evidence | |
| - **Upstream PR:** [anomalyco/opencode#14741](https://github.com/anomalyco/opencode/pull/14741) — OPEN, MERGEABLE, 9/9 CI checks pass | |
| - **Upstream issue:** [anomalyco/opencode#14740](https://github.com/anomalyco/opencode/issues/14740) — OPEN | |
| - **Changes:** 267 additions, 2 deletions across 3 files | |
| - **Tests:** 11 new tests in `stream-hooks.test.ts` + all 120 existing session tests pass | |
| ## Completion Evidence | |
| > ⚠️ Merge is pending upstream maintainer review. Task status reflects delivery of the PoC PR, not upstream adoption. | |
| - **Upstream PR:** [anomalyco/opencode#14741](https://github.com/anomalyco/opencode/pull/14741) — OPEN, MERGEABLE, 9/9 CI checks pass | |
| - **Upstream issue:** [anomalyco/opencode#14740](https://github.com/anomalyco/opencode/issues/14740) — OPEN | |
| - **Changes:** 267 additions, 2 deletions across 3 files | |
| - **Tests:** 11 new tests in `stream-hooks.test.ts` + all 120 existing session tests pass |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@todo/tasks/t1306-brief.md` around lines 115 - 120, Rename the "## Completion
Evidence" header to "## Delivery Evidence" in todo/tasks/t1306-brief.md, update
the paragraph that lists the upstream PR anomalyco/opencode#14741 to explicitly
state that the PR is OPEN and that delivery is pending upstream merge (e.g.,
"Upstream PR is open; delivery is pending maintainer merge — re-engage if PR is
closed or requests rework"), and add a follow-up task entry (suggested id:
t1315) that tracks the upstream merge of anomalyco/opencode#14741 so the task
can be closed only after the PR is merged.
Mark t1305 and t1306 as complete — upstream PR anomalyco/opencode#14741 is open with all 9/9 CI checks passing and MERGEABLE status. Add task brief documenting the implementation, acceptance criteria, and completion evidence.



Summary
todo/tasks/t1306-brief.md) documenting the implementationWhat was done
The upstream proof-of-concept PR for
stream.deltaandstream.abortedplugin hooks has been submitted and is passing all CI:processor.ts(stream hooks + abort handling),plugin/index.ts(type definitions), andstream-hooks.test.ts(11 tests)Implementation details (in upstream repo)
stream.deltahook fires ontext-delta,reasoning-delta, andtool-input-delta— plugins can setabort: trueto cancelstream.abortedhook fires after abort — plugins can setretry: truewith optionalinjectMessagefor corrective contextStreamAbortedErrorclass for clean abort signaling with max 3 retry attemptsWhy
This unblocks full TTSR (Time-To-Stream Rules) — real-time stream policy enforcement in the aidevops OpenCode plugin. Currently blocked on upstream maintainer review.
Closes #2130
Summary by CodeRabbit
Documentation
Chores
Note: This release contains no user-facing changes. Updates are limited to internal project planning and documentation.