Skip to content

fix: collect the answer from assistant stream events - #19

Merged
PunGrumpy merged 2 commits into
mainfrom
fix/collect-assistant-text
Oct 18, 2026
Merged

PunGrumpy merged 2 commits into
mainfrom
fix/collect-assistant-text

Conversation

@PunGrumpy

@PunGrumpy PunGrumpy commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Description

The stream loop in the runner kept every event with a string text field, but in the SDK's event vocabulary those are thinking and task events; the answer arrives as assistant events with the text nested in message.content[]. On finished runs run.wait().result masked this, but a cancelled run (which is what timeout produces) has no result, so the step published the model's reasoning as summary. The loop now concatenates the text blocks of assistant events and ignores everything else.

Related Issues

None.

Checklist

  • I've reviewed my code
  • I've written tests (skip if not applicable, e.g. .github/–only changes)
  • I've added a changeset when the change affects the published action or release notes (skip for .github/–only community or template updates)
  • I've updated the docs, if necessary (no documented behaviour changes)

Screenshots (if applicable)

N/A

Additional Notes

The test mocks now yield the SDK's real SDKMessage shapes instead of { text } objects, and two new tests cover a cancelled run with mixed thinking, assistant and task events, and the path where result wins over the streamed text. dist/ is rebuilt.

Summary by CodeRabbit

  • Bug Fixes
    • Cancelled or errored runs now report streamed assistant responses as partial output, excluding reasoning and task events.
    • When a run finishes, its final result takes precedence over streamed text.

The stream loop kept the text of thinking events, so a cancelled run published the model's reasoning as its summary. Read the text blocks of assistant events instead.
The mock streams yielded bare text objects that the SDK never emits, which hid the thinking-versus-assistant mix-up. Add assistant and thinking event factories and a cancelled-run case where only assistant text may reach the summary.
@changeset-bot

changeset-bot Bot commented Oct 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 410bb3c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@pungrumpy/cursor-action Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cursor-action Ready Ready Preview Oct 18, 2026 10:47am UTC

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b3016fe-778e-432e-bedf-92d22c1d5e7a
📥 Commits

Reviewing files that changed from the base of the PR and between 6d67266 and 410bb3c.

⛔ Files ignored due to path filters: 1
  • dist/index.mjs is excluded by !**/dist/**
📒 Files selected for processing: 3
  • .changeset/collect-assistant-text.md
  • __tests__/runner.test.ts
  • src/runner.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout: 3
  • GitHub Check: Build & Test
  • GitHub Check: Docs
  • GitHub Check: Baymi security review
🧰 Additional context used
📚 Code guidelines: 1
.cursor/rules/ultracite.mdc — unknown
📓 Path-based instructions: 3
Write assertions inside `it()` or `test()` blocks in test files Avoid done callbacks in async tests - use async/await instead Don't use `.only` or `.skip` in committed code Keep test suites reasonably flat - avoid excessive `describe` nesti...

📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)

Files:

  • __tests__/runner.test.ts
Use explicit types for function parameters and return values when they enhance clarity in TypeScript/JavaScript code Use meaningful variable names instead of magic numbers - extract constants with descriptive names Use arrow functions for c...

📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)

Files:

  • src/runner.ts
  • __tests__/runner.test.ts
Prefer `unknown` over `any` when the type is genuinely unknown Use const assertions (`as const`) for immutable values and literal types Leverage TypeScript's type narrowing instead of type assertions

📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)

Files:

  • src/runner.ts
  • __tests__/runner.test.ts
🔇 Additional comments: 5
src/runner.ts: 2

23-33: LGTM!

106-106: LGTM!

__tests__/runner.test.ts: 2

250-275: LGTM!

277-292: LGTM!

.changeset/collect-assistant-text.md: 1

1-5: LGTM!

📝 Walkthrough

runAgent now collects streamed text from assistant events. Other event types do not add text to stdout. Runner tests cover cancelled-run output and the precedence of a finished run’s final result text.

Changes: Assistant Stream Text

Layer / File(s) Summary
Collect and verify assistant text
src/runner.ts, __tests__/runner.test.ts, .changeset/collect-assistant-text.md
runAgent concatenates text content blocks from assistant events only. Tests verify that cancelled-run output excludes thinking and task events, and that a finished run uses its final result text. The changeset records the patch.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 410bb

The change makes cancelled or errored runs report the model's partial answer instead of its reasoning. No merge-blocking risk is apparent.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: collecting answers from assistant stream events.
Description check Passed The description follows the repository template. It explains the change, identifies related issues as none, documents the checklist status, addresses screenshots, and includes additional implementatio…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description follows the repository template. It explains the change, identifies related issues as none, documents the checklist status, addresses screenshots, and includes additional implementation notes.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

A rabbit reads the stream at dawn,
And gathers words where answers spawn.
It skips the thoughts and task-event trail,
Then checks the final answer without fail.
It thumps a tune and hops away.

Comment @coderabbitai help to get the list of available commands.

@PunGrumpy
PunGrumpy merged commit 18f70f7 into main Oct 18, 2026
12 of 13 checks passed

This branch was successfully deployed

1 active deployment
Preview — 410bb3c3 Deployed Oct 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant