-
Notifications
You must be signed in to change notification settings - Fork 1.5k
add resumeGenerate to agent #11503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add resumeGenerate to agent #11503
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 89a6b90 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
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 |
WalkthroughAdds a public Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
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 |
🚨 Redirect Validation FailedThe redirect validation found issues in Action Required: Review and fix the redirect configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/src/stream/base/output.ts (1)
824-851: EnsuresuspendPayloadis resolved in tripwire flows to avoidgetFullOutput()errorsThe new
getFullOutput()field:runId: this.runId, suspendPayload: await this.suspendPayload,assumes the
suspendPayloadpromise is always resolved or rejected in all successful agent runs. For:
- Normal completes:
finishcase already resolvessuspendPayloadasundefined.- Suspended completes:
tool-call-suspended/tool-call-approvalresolvesuspendPayloadwith the payload.However, in the
tripwirepath,resolvePromisesdoes not touchsuspendPayload, so it stays pending and is then rejected in the transformerflush’s “reject unresolved promises” loop. With the newawait this.suspendPayload, this will causegetFullOutput()to throw for tripwire runs, even though other fields (text,tripwire, etc.) are valid.To keep the new public surface safe,
suspendPayloadshould be explicitly resolved toundefinedin the tripwire case as well, matching the non‑suspended finish behavior.Proposed fix: resolve
suspendPayloadin the tripwire casecase 'tripwire': // Handle tripwire chunks from processors self.#tripwire = { reason: chunk.payload?.reason || 'Content blocked', retry: chunk.payload?.retry, metadata: chunk.payload?.metadata, processorId: chunk.payload?.processorId, }; self.#finishReason = 'other'; // Mark stream as finished for EventEmitter self.#streamFinished = true; // Resolve all delayed promises before terminating self.resolvePromises({ text: self.#bufferedText.join(''), finishReason: 'other', object: undefined, usage: self.#usageCount, warnings: self.#warnings, providerMetadata: undefined, response: {}, request: {}, reasoning: [], reasoningText: undefined, sources: [], files: [], toolCalls: [], toolResults: [], steps: self.#bufferedSteps, totalUsage: self.#usageCount, content: [], + suspendPayload: undefined, });This keeps
suspendPayloadconsistently defined (orundefined) in all non‑error terminal states while preserving existing semantics for suspended runs.Also applies to: 1118-1142
🧹 Nitpick comments (2)
packages/core/src/agent/__tests__/tool-approval.test.ts (1)
406-471: New generate-based suspend/resume tests look correct and comprehensiveThe added tests for:
- Tool suspend/resume via
generate+resumeGenerate,- Tool suspend/resume via
generatewithautoResumeSuspendedTools,- Workflow suspend/resume via
generate+resumeGenerate,- Workflow suspend/resume via
generatewithautoResumeSuspendedTools,all correctly validate:
finishReason === 'suspended'and emptytoolResultson the initial suspended call,- the shape and content of
output.suspendPayload,- successful resume behavior and final tool/workflow outputs,
resumeOutput.suspendPayloadbeingundefinedafter completion.This gives solid coverage of the new
resumeGenerateAPI and the extendedfullOutputsurface across both tools and workflows. Any duplication in tool/workflow setup is acceptable here for test readability; refactoring to helpers can be deferred.Also applies to: 575-667, 778-877, 992-1093
packages/core/src/agent/agent.ts (1)
2060-2073: Workflow runId selection andresumeGenerateimplementation are consistent; consider deduping withgenerate()
The change to
const runIdToUse = suspendedToolRunId || runId;is consistent with the input schema default of''and ensures:
- New workflow invocations (no suspended run) use the agent run’s
runId.- Resumes with a real
suspendedToolRunIdcontinue to target the original workflow run.The new
resumeGenerate():
- Merges defaults with overrides in the same way as
generate().- Enforces the same v1-model guard (
AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED).- Correctly loads the
agentic-loopsnapshot byrunIdand passesresumeContextinto#executewithmethodType: 'generate'.- Returns
getFullOutput()and propagates finish-time errors exactly asgenerate()does.Functionally this all looks sound. The
generateandresumeGeneratebodies are now largely duplicated; if this evolves further, it may be worth extracting a small shared helper to construct and run the inner execution options to keep behavior in lockstep.Also applies to: 3253-3338
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.changeset/silent-ends-lick.mdpackages/core/src/agent/__tests__/tool-approval.test.tspackages/core/src/agent/agent.tspackages/core/src/stream/base/output.tspackages/core/src/tools/tool-builder/builder.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Run
pnpm typecheckto validate TypeScript types across all packages
Files:
packages/core/src/tools/tool-builder/builder.tspackages/core/src/agent/agent.tspackages/core/src/agent/__tests__/tool-approval.test.tspackages/core/src/stream/base/output.ts
**/*.{ts,tsx,js,jsx,json,md}
📄 CodeRabbit inference engine (CLAUDE.md)
Run
pnpm prettier:formatto format code andpnpm formatto run linting with auto-fix across all packages
Files:
packages/core/src/tools/tool-builder/builder.tspackages/core/src/agent/agent.tspackages/core/src/agent/__tests__/tool-approval.test.tspackages/core/src/stream/base/output.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
packages/**/*.{ts,tsx}: All packages must use TypeScript with strict type checking enabled
Use telemetry decorators for observability across components
Files:
packages/core/src/tools/tool-builder/builder.tspackages/core/src/agent/agent.tspackages/core/src/agent/__tests__/tool-approval.test.tspackages/core/src/stream/base/output.ts
**/*.{test,spec}.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{test,spec}.{ts,tsx}: Use Vitest for testing framework in test files
Co-locate test files with source code using naming patterns like *.test.ts or *.spec.ts
Files:
packages/core/src/agent/__tests__/tool-approval.test.ts
.changeset/*.md
⚙️ CodeRabbit configuration file
.changeset/*.md: Changeset files are really important for keeping track of changes in the project. They'll be used to generate release notes and inform users about updates.Review the changeset file according to these guidelines:
- The target audience are developers
- Write short, direct sentences that anyone can understand. Avoid commit messages, technical jargon, and acronyms. Use action-oriented verbs (Added, Fixed, Improved, Deprecated, Removed)
- Avoid generic phrases like "Update code", "Miscellaneous improvements", or "Bug fixes"
- Highlight outcomes! What does change for the end user? Do not focus on internal implementation details
- Add context like links to issues or PRs when relevant
- If the change is a breaking change or is adding a new feature, ensure that a code example is provided. This code example should show the public API usage (the before and after). Do not show code examples of internal implementation details.
- Keep the formatting easy-to-read and scannable. If necessary, use bullet points or multiple paragraphs (Use bold text as the heading for these sections, do not use markdown headings).
- For larger, more substantial changes, also answer the "Why" behind the changes
- Each changeset file contains a YAML frontmatter at the top. It will be one or more package names followed by a colon and the type of change (patch, minor, major). Do not modify this frontmatter. Check that the description inside the changeset file only applies to the packages listed in the frontmatter. Do not allow descriptions that mention changes to packages not listed in the frontmatter. In these cases, the user must create a separate changeset file for those packages.
Files:
.changeset/silent-ends-lick.md
🧠 Learnings (7)
📓 Common learnings
Learnt from: taofeeq-deru
Repo: mastra-ai/mastra PR: 11486
File: packages/core/src/loop/workflows/agentic-execution/llm-execution-step.ts:643-678
Timestamp: 2025-12-30T15:02:58.132Z
Learning: In `packages/core/src/loop/workflows/agentic-execution/llm-execution-step.ts`, the system guarantees that `metadata.suspendedTools` and `metadata.pendingToolApprovals` never contain resumed tools, so no filtering is needed when using metadata directly.
📚 Learning: 2025-12-30T15:02:58.132Z
Learnt from: taofeeq-deru
Repo: mastra-ai/mastra PR: 11486
File: packages/core/src/loop/workflows/agentic-execution/llm-execution-step.ts:643-678
Timestamp: 2025-12-30T15:02:58.132Z
Learning: In `packages/core/src/loop/workflows/agentic-execution/llm-execution-step.ts`, the system guarantees that `metadata.suspendedTools` and `metadata.pendingToolApprovals` never contain resumed tools, so no filtering is needed when using metadata directly.
Applied to files:
packages/core/src/tools/tool-builder/builder.tspackages/core/src/agent/agent.tspackages/core/src/agent/__tests__/tool-approval.test.ts
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/**/*.test.ts : Include test cases for multiple occurrences of the transformation pattern, aliased imports, type imports, and mixed imports to verify the codemod works consistently
Applied to files:
packages/core/src/agent/__tests__/tool-approval.test.ts
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/__fixtures__/**/*.ts : Create test fixtures by copying examples DIRECTLY from migration guides in `docs/src/content/en/guides/migrations/upgrade-to-v1/` without hallucinating or inventing changes
Applied to files:
packages/core/src/agent/__tests__/tool-approval.test.ts
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/__fixtures__/**/*.ts : In output fixtures, ensure all NEGATIVE test cases remain EXACTLY IDENTICAL to their input fixture counterparts to verify the codemod only transforms intended patterns
Applied to files:
packages/core/src/agent/__tests__/tool-approval.test.ts
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/__fixtures__/**/*.ts : In input fixtures, include both POSITIVE test cases (patterns that should transform) and NEGATIVE test cases (unrelated code with similar names/patterns that should NOT transform)
Applied to files:
packages/core/src/agent/__tests__/tool-approval.test.ts
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/**/*.test.ts : Do NOT use `UPDATE_SNAPSHOT` to force tests to pass; instead fix the codemod implementation when tests fail
Applied to files:
packages/core/src/agent/__tests__/tool-approval.test.ts
🧬 Code graph analysis (2)
packages/core/src/agent/agent.ts (3)
packages/core/src/agent/agent.types.ts (2)
AgentExecutionOptions(34-135)InnerAgentExecutionOptions(137-149)packages/core/src/agent/utils.ts (1)
isSupportedLanguageModel(10-14)packages/core/src/error/index.ts (1)
MastraError(142-142)
packages/core/src/agent/__tests__/tool-approval.test.ts (2)
packages/core/src/tools/tool.ts (1)
createTool(365-388)examples/agent/src/mastra/workflows/other.ts (1)
findUserWorkflow(127-140)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: test
- GitHub Check: test
- GitHub Check: Prebuild
- GitHub Check: test
- GitHub Check: test (hono)
- GitHub Check: test (express)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/core/src/tools/tool-builder/builder.ts (1)
67-73: suspendedToolRunId default aligns with resume semanticsSetting
suspendedToolRunIdtooptional().default('')is consistent with downstream usage (suspendedToolRunId || runId) and avoidsnull/undefinedissues in resume flows. No changes needed here.
## Description <!-- Provide a brief description of the changes in this PR --> - [x] Add `resumeGenerate` method for resuming agent via generate - [x] Add `runId` and `suspendPayload` to fullOuput of agent stream - [x] Fix `suspendedToolRunId: null` sometimes breaking `agent.stream` ## Related Issue(s) <!-- Link to the issue(s) this PR addresses, using hashtag notation: mastra-ai#123 --> mastra-ai#11485 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [x] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [x] Test update ## Checklist - [ ] I have made corresponding changes to the documentation (if applicable) - [x] I have added tests that prove my fix is effective or that my feature works <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Resume suspended agent executions via a new generate-based resume API. * Agent output now exposes runId and suspendPayload for clearer result context. * **Bug Fixes** * suspendedToolRunId now defaults to an empty string to avoid null/undefined issues. * **Tests** * Added tests covering generate-based suspend/resume flows across tools and workflows. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Abhi Aiyer <abhiaiyer91@gmail.com>
Description
resumeGeneratemethod for resuming agent via generaterunIdandsuspendPayloadto fullOuput of agent streamsuspendedToolRunId: nullsometimes breakingagent.streamRelated Issue(s)
#11485
Type of Change
Checklist
Summary by CodeRabbit
New Features
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.