Skip to content

feat: update workflows and logging mechanisms across multiple files#49

Merged
ssdeanx merged 1 commit intomainfrom
develop
Dec 13, 2025
Merged

feat: update workflows and logging mechanisms across multiple files#49
ssdeanx merged 1 commit intomainfrom
develop

Conversation

@ssdeanx
Copy link
Owner

@ssdeanx ssdeanx commented Dec 13, 2025

  • Refactored research synthesis workflow to unify progress logging under 'data-tool-progress' type.
  • Removed redundant logging steps and streamlined the workflow for better clarity and performance.
  • Updated stock analysis workflow to use 'data-tool-progress' for all progress updates, enhancing consistency.
  • Modified weather workflow to replace 'data-workflow-progress' with 'data-tool-progress' for fetching and planning activities.
  • Added new instructions for taming Copilot to ensure better adherence to user directives and coding standards.
  • Introduced AI Elements usage guide to provide comprehensive documentation for building AI-native applications.
  • Updated TypeScript configuration to include workflow files for better type checking.

Summary by Sourcery

Standardize tool and workflow progress logging onto data-tool-progress events, enhance streaming behavior for several AI tools and workflows, and expand documentation and typing support for AI/semantic tooling.

New Features:

  • Add streaming support and richer progress feedback to financial chart tools, copywriter agent, code search, symbol search, and multi-string edit tools.
  • Introduce AI Elements usage guide for building AI-native UIs and integrate AI Elements workflows into documentation and configuration.
  • Add new agent-driven weather analysis workflow example and branching order-processing workflow showcasing agent, branching, and streaming patterns.

Bug Fixes:

  • Fix workflow progress status mapping in the workflow provider to correctly interpret done and in-progress states for tool events.

Enhancements:

  • Unify workflow and tool progress events across workflows to use data-tool-progress, simplifying UI handling and status mapping.
  • Improve error handling and fallback behavior when required agents are unavailable, returning structured error payloads and user-facing progress messages.
  • Refine semantic tooling types and AST handling in the symbol finder to avoid runtime type checks and improve robustness.
  • Extend tsconfig includes to cover workflow files for better TypeScript type checking.

Build:

  • Bump @AI-SDK dependency versions to pick up latest runtime and React integration improvements.

Documentation:

  • Restructure workflows and tools AGENTS documentation to focus on standardized progress event patterns and add an AI Elements usage guide for frontend integration.

- Refactored research synthesis workflow to unify progress logging under 'data-tool-progress' type.
- Removed redundant logging steps and streamlined the workflow for better clarity and performance.
- Updated stock analysis workflow to use 'data-tool-progress' for all progress updates, enhancing consistency.
- Modified weather workflow to replace 'data-workflow-progress' with 'data-tool-progress' for fetching and planning activities.
- Added new instructions for taming Copilot to ensure better adherence to user directives and coding standards.
- Introduced AI Elements usage guide to provide comprehensive documentation for building AI-native applications.
- Updated TypeScript configuration to include workflow files for better type checking.
Copilot AI review requested due to automatic review settings December 13, 2025 17:43
@continue
Copy link

continue bot commented Dec 13, 2025

All Green - Keep your PRs mergeable

Learn more

All Green is an AI agent that automatically:

✅ Addresses code review comments

✅ Fixes failing CI checks

✅ Resolves merge conflicts

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 13, 2025

Reviewer's Guide

This PR standardizes workflow/tool progress logging around the data-tool-progress event type, refactors several workflows and tools to use richer progress metadata and streaming, introduces better runtime context typing for selected tools, updates AI SDK dependencies and TS config, and adds documentation for AI Elements usage and events-driven workflows.

Sequence diagram for standardized data-tool-progress events in workflows

sequenceDiagram
    actor User
    participant BrowserApp
    participant WorkflowProvider
    participant AIBackend
    participant WorkflowStep
    participant Writer

    User->>BrowserApp: click run workflow
    BrowserApp->>WorkflowProvider: runWorkflow(input)
    WorkflowProvider->>AIBackend: send workflow request

    AIBackend->>WorkflowStep: execute(inputData, writer)
    activate WorkflowStep

    note over WorkflowStep: start step
    WorkflowStep->>Writer: custom(type: data-tool-progress, data.status: in-progress)
    Writer-->>AIBackend: stream event (data-tool-progress)
    AIBackend-->>WorkflowProvider: assistant message with data-tool-progress
    WorkflowProvider->>WorkflowProvider: map to progressEvent(status: in-progress)

    note over WorkflowStep: intermediate progress
    WorkflowStep->>Writer: custom(type: data-tool-progress, data.status: in-progress)
    Writer-->>AIBackend: stream event
    AIBackend-->>WorkflowProvider: assistant message with data-tool-progress
    WorkflowProvider->>WorkflowProvider: update progressEvents

    alt success
        WorkflowStep->>Writer: custom(type: data-tool-progress, data.status: done)
        Writer-->>AIBackend: final progress event
        AIBackend-->>WorkflowProvider: assistant message with data-tool-progress
        WorkflowProvider->>WorkflowProvider: set step status to done
    else error
        WorkflowStep->>Writer: custom(type: data-workflow-step-error)
        Writer-->>AIBackend: error event
        AIBackend-->>WorkflowProvider: assistant message with data-workflow-step-error
        WorkflowProvider->>WorkflowProvider: add error progressEvent(status: error)
    end

    WorkflowStep-->>AIBackend: return result or throw
    deactivate WorkflowStep

    AIBackend-->>WorkflowProvider: final completion message
    WorkflowProvider-->>BrowserApp: context with progressEvents
    BrowserApp-->>User: render unified progress UI
Loading

Sequence diagram for streaming agent output through writer in tools

sequenceDiagram
    actor User
    participant App
    participant Tool
    participant Agent
    participant Writer

    User->>App: trigger tool (e.g. chartSupervisorTool, copywriterTool)
    App->>Tool: execute(inputData, context)
    Tool->>Writer: custom(type: data-tool-progress, status: in-progress)

    Tool->>Agent: getAgent(id)
    alt agent available
        Tool->>Agent: stream(prompt)
        Agent-->>Tool: streamResult(fullStream, textStream, text)

        alt fullStream available and writer present
            Tool->>Writer: pipe fullStream to writer
        else textStream available
            Tool->>Writer: pipe textStream to writer
        else no streaming support
            Tool->>Agent: generate(prompt)
            Agent-->>Tool: result(text)
        end

        Tool->>Tool: assemble resultText from stream or generate
        Tool-->>App: structured result(parsed from resultText)
        Tool->>Writer: custom(type: data-tool-progress, status: done)
    else agent missing
        Tool->>Writer: custom(type: data-tool-progress, status: done, message: agent not found)
        Tool-->>App: fallback result with error description
    end
Loading

Class diagram for updated tool context types and execution flow

classDiagram
    class ToolExecutionContext {
      +writer
      +mastra
      +requestContext
    }

    class Writer {
      +custom(type, data, id) Promise~void~
    }

    class RequestContext_T_ {
      +get(key) T
    }

    class CopywriterTool {
      +execute(inputData, context) Promise~CopywriterResult~
    }

    class MultiStringEditTool {
      +execute(inputData, context) Promise~MultiStringEditOutput~
    }

    class FindSymbolTool {
      +execute(inputData, context) Promise~FindSymbolOutput~
      -extractSymbolInfo(node, symbolType, searchTerm, caseSensitive) SymbolInfo
      -matchesSearch(name, searchTerm, caseSensitive) boolean
      -isSymbolExported(sourceFile, symbolName) boolean
    }

    class SymbolContext {
      +maxResults number
      +excludePatterns string[]
      +includeNodeModules boolean
      +caseSensitive boolean
      +searchType string
    }

    class MultiStringEditContext {
      +maxFileSize number
      +createBackup boolean
      +dryRun boolean
      +operationType string
    }

    class CopywriterResult {
      +content string
      +contentType string
      +title string
      +summary string
      +keyPoints string[]
      +wordCount number
    }

    class MultiStringEditOutput {
      +filesProcessed number
      +filesChanged number
      +diffSummary string
    }

    class FindSymbolOutput {
      +symbols SymbolInfo[]
      +processedFiles number
      +summary string
    }

    class SymbolInfo {
      +name string
      +kind string
      +filePath string
      +isExported boolean
    }

    CopywriterTool --> ToolExecutionContext : uses
    MultiStringEditTool --> ToolExecutionContext : uses
    FindSymbolTool --> ToolExecutionContext : uses

    ToolExecutionContext --> Writer : uses
    ToolExecutionContext --> RequestContext_T_ : uses

    RequestContext_T_ --> SymbolContext : specializes
    RequestContext_T_ --> MultiStringEditContext : specializes

    FindSymbolTool --> SymbolInfo : returns
    FindSymbolTool --> FindSymbolOutput : returns
    MultiStringEditTool --> MultiStringEditOutput : returns
    CopywriterTool --> CopywriterResult : returns
Loading

File-Level Changes

Change Details Files
Standardize workflow and tool progress logging on data-tool-progress and adjust step lifecycle events.
  • Replace legacy writer.write progress/step events and data-workflow-* types with writer.custom calls using data-tool-progress across multiple workflows (learning extraction, content studio, content review, document processing, governed RAG index, research synthesis, changelog, weather, stock analysis, financial-report).
  • Update step start/complete/error event usage so that only error and selected step-complete events use dedicated data-workflow-step-* types; many success-complete events now emit final data-tool-progress messages instead.
  • Align workflow UI expectations by mapping data-tool-progress status values (in-progress, done, completed, success) to normalized status in the WorkflowProvider progress handling logic.
src/mastra/workflows/learning-extraction-workflow.ts
src/mastra/workflows/content-studio-workflow.ts
src/mastra/workflows/content-review-workflow.ts
src/mastra/workflows/document-processing-workflow.ts
src/mastra/workflows/governed-rag-index.workflow.ts
src/mastra/workflows/research-synthesis-workflow.ts
src/mastra/workflows/changelog.ts
src/mastra/workflows/weather-workflow.ts
src/mastra/workflows/stock-analysis-workflow.ts
src/mastra/workflows/financial-report-workflow.ts
app/workflows/providers/workflow-context.tsx
Enhance tools with progress events, streaming support, and safer runtime context handling.
  • Add data-tool-progress emissions (with status, message, stage, and id) to many tools, including financial chart tools, Finnhub tools, code search, copywriter, and semantic tools (find-symbol, multi-string-edit) for better UX and observability.
  • Introduce streaming-aware execution paths in chart-related tools and copywriter tool: detect agent.stream, pipe fullStream/textStream to the writer when available, and fall back to generate otherwise.
  • Refine runtime context typing: replace Zod-based context schema in copywriter-agent-tool and find-symbol.tool/multi-string-edit.tool with TypeScript interfaces and RequestContext reads, including new required fields (searchType, operationType) and safer type guards (e.g., name !== undefined).
src/mastra/tools/financial-chart-tools.ts
src/mastra/tools/finnhub-tools.ts
src/mastra/tools/copywriter-agent-tool.ts
src/mastra/tools/find-symbol.tool.ts
src/mastra/tools/multi-string-edit.tool.ts
src/mastra/tools/code-search.tool.ts
Add new workflow and tooling documentation, and adjust existing agent/tool docs toward event patterns.
  • Replace the "Execution & debugging" and standardized writer pattern section in AGENTS.md for workflows with detailed examples of agent- and tool-driven workflows (e.g., weather analysis workflow and branching order-processing workflow) using the new progress/event patterns.
  • Remove the generic tool development guide and best practices from src/mastra/tools/AGENTS.md and focus that file on standardized data-tool-progress event requirements.
  • Add a new AI Elements usage guide under .kilocode/rules/ai-elements-usage.md explaining installation, usage, and best practices for AI Elements components within the app.
src/mastra/workflows/AGENTS.md
src/mastra/tools/AGENTS.md
.kilocode/rules/ai-elements-usage.md
Refine specific workflow behaviors and implementations.
  • In the weather workflow, switch from manual text streaming loop over response.textStream to pipe fullStream/textStream directly to the writer when supported and then read response.text for activities.
  • In document-processing workflow steps, update stages to use documentProcessingAgent, revise progress messages (including partial percentages in text), and adjust error handling to emit progress-style errors instead of data-workflow-step-error in some places.
  • In financial-report workflow, remove unused output schemas, add mid-step data-tool-progress messages across fetch/merge/analyze/report steps, and keep Otel span and writer.write progress events for backward compatibility.
src/mastra/workflows/weather-workflow.ts
src/mastra/workflows/document-processing-workflow.ts
src/mastra/workflows/financial-report-workflow.ts
Minor code quality, configuration, and dependency updates.
  • Update AI SDK-related dependencies (@ai-sdk/google-vertex, @ai-sdk/openai, @ai-sdk/react) to newer patch versions and refresh package-lock.json.
  • Extend tsconfig.json include patterns to cover src/mastra/workflows/*.ts so workflow files are type-checked.
  • Adjust AGENTS.md whitespace and add a new agentTextStreamWorkflow example; add a missing newline and minor formatting fixes in editor-agent-tool and multiple workflow files.
package.json
package-lock.json
tsconfig.json
src/mastra/workflows/AGENTS.md
src/mastra/tools/editor-agent-tool.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
Copy link

🤖 Hi @ssdeanx, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@coderabbitai
Copy link

coderabbitai bot commented Dec 13, 2025

Summary by CodeRabbit

Release Notes

  • Documentation

    • Added AI Elements Usage Guide covering component library, installation, and integration patterns.
    • Updated workflow and tools documentation with expanded examples and patterns.
  • New Features

    • Added streaming support for workflow and agent executions.
    • Enhanced progress tracking with structured event reporting across tools and workflows.
  • Improvements

    • Refined error handling with better status reporting when agents are unavailable.
    • Updated progress event structure for improved visibility into in-flight operations.
  • Dependencies

    • Updated @ai-sdk/google-vertex, @ai-sdk/openai, and @ai-sdk/react to latest patch versions.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This PR refactors progress reporting across tools and workflows by replacing workflow-focused events with tool-focused events (data-tool-progress), adds structured progress metadata (status, stage, id), introduces streaming support in agent-based tools with fallback logic, updates dependencies for AI SDK packages, and adds new documentation while removing outdated guidance sections.

Changes

Cohort / File(s) Summary
Documentation & Guides
\.kilocode/rules/ai-elements-usage.md, src/mastra/tools/AGENTS.md, src/mastra/workflows/AGENTS.md
Adds new AI Elements usage guide with prerequisites, installation, and code examples. Removes tool development guidance and best practices from tools AGENTS.md. Updates workflows AGENTS.md with concrete agent/tool workflow examples and branching patterns, removing prior execution/debugging sections.
Dependency Updates
package.json
Bumps AI SDK packages: @ai-sdk/google-vertex ^3.0.90→^3.0.91, @ai-sdk/openai ^2.0.85→^2.0.86, @ai-sdk/react ^2.0.114→^2.0.115.
Workflow Context
app/workflows/providers/workflow-context.tsx
Refines tool event status mapping: "success"→"done", "pending"/"in-progress"→"in-progress", else "error".
Tool Progress & Streaming Enhancements
src/mastra/tools/code-search.tool.ts, copywriter-agent-tool.ts, financial-chart-tools.ts, find-symbol.tool.ts, finnhub-tools.ts
Replaces simple progress messages with enriched data-tool-progress events (status, stage, id). Adds streaming execution paths with fallback to generate calls. Updates progress reporting with structured payloads. Replaces Zod schema-based types with interfaces (SymbolContext). Adds runtime agent availability checks and error handling.
Tool Context & Signature Updates
src/mastra/tools/editor-agent-tool.ts, multi-string-edit.tool.ts
Adds spacing adjustment in editor-agent-tool. Introduces MultiStringEditContext interface, adds RequestContext usage, derives maxFileSize from runtime context, removes explicit Promise return type from execute signature.
Workflow Progress Refactoring
src/mastra/workflows/changelog.ts, content-review-workflow.ts, content-studio-workflow.ts, document-processing-workflow.ts, financial-report-workflow.ts, governed-rag-index.workflow.ts, learning-extraction-workflow.ts, research-synthesis-workflow.ts, stock-analysis-workflow.ts, weather-workflow.ts
Systematically replaces data-workflow-* events with data-tool-progress across all workflow steps. Updates stage identifiers (e.g., "workflow"→"researchAgent"), simplifies status handling (percent-based→semantic states like "in-progress"/"done"), removes redundant step-start/step-complete calls. Adds streaming output to writer in weather-workflow. Removes internal schema declarations in financial-report-workflow.
TypeScript Configuration
tsconfig.json
Adds include pattern for src/mastra/workflows/*.ts files in type checking.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Multiple heterogeneous patterns: Progress event refactoring across 10+ workflow files (repetitive but systematic), streaming additions in 5+ tool files, type/interface changes, schema removals, and context signature updates require separate reasoning per category.
  • Logic density in specific files: financial-chart-tools.ts (streaming/error branches across multiple tools), copywriter-agent-tool.ts (removed schema, streaming paths, context derivation), find-symbol.tool.ts (isKind refactor with runtime checks), financial-report-workflow.ts (schema removals + extensive progress additions).
  • Risk areas:
    • Streaming fallback logic consistency across tools (copywriter-agent, financial-chart, weather workflows)
    • Error handling paths when agents are unavailable vs. throwing behavior
    • RequestContext usage in multi-string-edit vs. runtime availability
    • SymbolContext interface migration from Zod schema (validation behavior change)
    • Workflow step parameter signature changes (e.g., convertPdfToMarkdownStep adding mastra parameter)

Possibly related PRs

Poem

A rabbit hops through workflows bright,
Refactoring progress—what delight!
Streaming flows and stages new,
Tools report with status true,
From workflow-speak to tool-speak clear,
Better tracking far and near! 🐰✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: update workflows and logging mechanisms across multiple files' accurately captures the primary changes, which involve refactoring workflows and standardizing progress logging mechanisms.
Description check ✅ Passed The description is related to the changeset and provides relevant details about the refactoring, including specific workflows modified, logging standardization, new features, and documentation updates.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

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

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ssdeanx, 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 significantly refactors the internal logging and progress reporting infrastructure, moving towards a more unified and consistent 'data-tool-progress' event type across various AI-driven workflows and tools. This change streamlines how progress and status updates are communicated, improving observability and debugging. Furthermore, it introduces streaming capabilities for agent interactions, enabling real-time feedback, and enhances the robustness of several tools by adding agent availability checks. The PR also includes important documentation for AI Elements and minor dependency updates.

Highlights

  • Unified Progress Logging: Standardized workflow and tool progress reporting under a single 'data-tool-progress' event type, replacing disparate 'data-workflow-*' events for consistency across the application.
  • Enhanced Streaming Support: Implemented streaming capabilities for agent responses in several tools and workflows, allowing for real-time feedback during long-running operations and improving user experience.
  • Improved Workflow Robustness: Added checks for agent availability in financial tools and the copywriter agent, providing graceful fallbacks and clearer error messages when agents are not found.
  • New AI Elements Documentation: Introduced a comprehensive guide for using AI Elements, a component library built on shadcn/ui for building AI-native applications, enhancing developer onboarding and usage.
  • TypeScript Configuration Update: Included workflow files in 'tsconfig.json' for improved type checking and better code quality within the workflow definitions.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

🤖 I'm sorry @ssdeanx, but I was unable to process your request. Please see the logs for more details.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • In fetchStockDataStep's error handler you emit a writer.custom event with type: 'data-workflow-p', which looks like a typo and likely should be aligned with the other error events (e.g. data-workflow-step-error or data-tool-progress).
  • In financial-report-workflow.ts several writer?.write({ type: 'progress', ... }) calls now send a status string instead of the original numeric percent, which may break any consumers expecting the previous schema for progress events; consider either keeping the original shape or introducing a separate event type for the new payload.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `fetchStockDataStep`'s error handler you emit a `writer.custom` event with `type: 'data-workflow-p'`, which looks like a typo and likely should be aligned with the other error events (e.g. `data-workflow-step-error` or `data-tool-progress`).
- In `financial-report-workflow.ts` several `writer?.write({ type: 'progress', ... })` calls now send a `status` string instead of the original numeric `percent`, which may break any consumers expecting the previous schema for `progress` events; consider either keeping the original shape or introducing a separate event type for the new payload.

## Individual Comments

### Comment 1
<location> `src/mastra/workflows/stock-analysis-workflow.ts:79-88` </location>
<code_context>
   execute: async (inputData, context): Promise<CodeSearchOutput> => {
     const writer = context?.writer;
-    await writer?.custom({ type: 'data-tool-progress', data: { message: `🔎 Starting code search for pattern '${inputData.pattern}'` } });
+    await writer?.custom({
+      type: 'data-tool-progress',
+      data: {
</code_context>

<issue_to_address>
**issue (bug_risk):** The custom writer event type `'data-workflow-p'` looks like a typo and may break downstream handling.

Other error events use names like `'data-workflow-step-error'` or `'data-tool-progress'`, so `'data-workflow-p'` is likely not recognized by existing handlers. Please update this to the correct existing event type (probably `'data-workflow-step-error'` or another defined error event) so `fetch-stock-data` errors are reported correctly.
</issue_to_address>

### Comment 2
<location> `src/mastra/workflows/document-processing-workflow.ts:408` </location>
<code_context>
+      type: 'data-tool-progress',
       data: {
+        status: "done", // must be "done" for the UI to show the step as completed
+        message: "Text passed through successfully ${inputData.content}`,",
         stepId: 'pass-text-through',
-        success: true,
</code_context>

<issue_to_address>
**issue (bug_risk):** The success message string for `pass-text-through` is malformed and won’t interpolate `inputData.content`.

Because the message is in double quotes, `${inputData.content}` is treated as plain text, and there’s also an extra backtick and comma. To interpolate the value, use a template literal (e.g. ``message: `Text passed through successfully ${inputData.content}` ``); otherwise remove the placeholder and stray punctuation.
</issue_to_address>

### Comment 3
<location> `src/mastra/workflows/research-synthesis-workflow.ts:73-80` </location>
<code_context>
     const writer = context?.writer;
-    await writer?.custom({ type: 'data-tool-progress', data: { message: `🔎 Starting code search for pattern '${inputData.pattern}'` } });
+    await writer?.custom({
+      type: 'data-tool-progress',
+      data: {
+        status: 'in-progress',
+        message: `🔎 Starting code search for pattern '${inputData.pattern}'`,
+        stage: 'coding:codeSearch'
</code_context>

<issue_to_address>
**issue (bug_risk):** Error handling for `research-topic-item` emits an `in-progress` status even when an error occurs.

In the catch block, this event still uses `status: 'in-progress'` while only changing the message to describe an error. That makes it hard for consumers to reliably detect failures based on status alone. Please use a distinct terminal status (e.g. `'error'` or `'done'`) so error states are clearly distinguishable from active work.
</issue_to_address>

### Comment 4
<location> `app/workflows/providers/workflow-context.tsx:419` </location>
<code_context>
                 id: `${message.id}-${part.type}-${partIndex}`,
                 stage: "tool",
-                status: eventData.status === "success" ? "done" : eventData.status === "pending" ? "in-progress" : "error",
+                status: eventData.status === "done" ? "done" : (eventData.status === "pending" || eventData.status === "in-progress") ? "in-progress" : "error",
                 message: eventData.message ?? `${eventData.toolName ?? 'Tool'} ${eventData.status}`,
                 timestamp: new Date(),
</code_context>

<issue_to_address>
**issue (bug_risk):** The new status mapping only treats `'done'` as success; other success-like statuses (e.g. `'success'`, `'completed'`) will be treated as errors.

Since several producers still emit statuses like `'success'`/`'completed'` via `data-tool-progress`, this change will cause many genuinely successful events to appear as errors in the UI. Either standardize all producers to emit `'done'` on success, or expand this mapping to recognize other known success statuses as `'done'` instead of `'error'`.
</issue_to_address>

### Comment 5
<location> `src/mastra/workflows/content-studio-workflow.ts:106-111` </location>
<code_context>
     const writer = context?.writer;
-    await writer?.custom({ type: 'data-tool-progress', data: { message: `🔎 Starting code search for pattern '${inputData.pattern}'` } });
+    await writer?.custom({
+      type: 'data-tool-progress',
+      data: {
+        status: 'in-progress',
</code_context>

<issue_to_address>
**issue (bug_risk):** Using `status: "success"` for completion is inconsistent with the `WorkflowProvider` status mapping and may render as an error.

Completion events in this workflow (research, evaluation, learning, strategy, hook, body, review, refine) currently emit `status: "success"`, but `WorkflowProvider` now only treats `'done'` as completed and maps all other unknown statuses to `'error'`. To avoid these being shown as errors, update them to use `status: "done"` (or otherwise align both sides on a shared status enum).
</issue_to_address>

### Comment 6
<location> `src/mastra/tools/multi-string-edit.tool.ts:235-237` </location>
<code_context>
+  execute: async (inputData, context) => {
+    const { edits, dryRun = false, createBackup = true, projectRoot } = inputData;
     const writer = context?.writer;
+    const requestContext = context?.requestContext as RequestContext<MultiStringEditContext>;
+
+    const maxFileSize = requestContext?.get('maxFileSize') ?? 1_000_000;
+

</code_context>

<issue_to_address>
**question (bug_risk):** Switching `maxFileSize` to come from `requestContext` changes behavior and may ignore user-specified limits in `inputData`.

Previously callers could set a per-invocation limit via `inputData.maxFileSize ?? 1_000_000`. Now the limit is only read from `requestContext`, which may be unset or differently configured, and any `maxFileSize` in the tool input is ignored. If that’s not deliberate, consider preferring `inputData.maxFileSize` when present, and otherwise falling back to `requestContext` or the default.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +79 to 88
await writer?.custom({
type: 'data-tool-progress',
data: {
status: 'in-progress',
message: `Fetching stock data for ${inputData.symbol}...`,
stage: 'workflow',
},
id: 'fetch-stock-data',
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The custom writer event type 'data-workflow-p' looks like a typo and may break downstream handling.

Other error events use names like 'data-workflow-step-error' or 'data-tool-progress', so 'data-workflow-p' is likely not recognized by existing handlers. Please update this to the correct existing event type (probably 'data-workflow-step-error' or another defined error event) so fetch-stock-data errors are reported correctly.

type: 'data-tool-progress',
data: {
status: "done", // must be "done" for the UI to show the step as completed
message: "Text passed through successfully ${inputData.content}`,",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The success message string for pass-text-through is malformed and won’t interpolate inputData.content.

Because the message is in double quotes, ${inputData.content} is treated as plain text, and there’s also an extra backtick and comma. To interpolate the value, use a template literal (e.g. message: `Text passed through successfully ${inputData.content}` ); otherwise remove the placeholder and stray punctuation.

Comment on lines +73 to 80
type: 'data-tool-progress',
data: {
type: 'data-workflow-step-start',
data: {
'initialize-research': {
topicsCount: inputData.topics.length,
concurrency: inputData.concurrency,
},
},
},
id: 'initialize-research',
});

await writer?.custom({
type: 'data-workflow-progress',
data: {
status: "50%",
status: "in-progress",
message: `Researching topic: ${inputData.topics}...`,
stage: "workflow",
stage: "researchAgent",
},
id: 'initialize-research',
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Error handling for research-topic-item emits an in-progress status even when an error occurs.

In the catch block, this event still uses status: 'in-progress' while only changing the message to describe an error. That makes it hard for consumers to reliably detect failures based on status alone. Please use a distinct terminal status (e.g. 'error' or 'done') so error states are clearly distinguishable from active work.

Comment on lines +106 to 111
type: 'data-tool-progress',
data: {
status: "20%",
status: "in-progress",
message: "Starting research phase",
stepId: "research-step",
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Using status: "success" for completion is inconsistent with the WorkflowProvider status mapping and may render as an error.

Completion events in this workflow (research, evaluation, learning, strategy, hook, body, review, refine) currently emit status: "success", but WorkflowProvider now only treats 'done' as completed and maps all other unknown statuses to 'error'. To avoid these being shown as errors, update them to use status: "done" (or otherwise align both sides on a shared status enum).

Comment on lines +235 to +237
const requestContext = context?.requestContext as RequestContext<MultiStringEditContext>;

const maxFileSize = requestContext?.get('maxFileSize') ?? 1_000_000;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (bug_risk): Switching maxFileSize to come from requestContext changes behavior and may ignore user-specified limits in inputData.

Previously callers could set a per-invocation limit via inputData.maxFileSize ?? 1_000_000. Now the limit is only read from requestContext, which may be unset or differently configured, and any maxFileSize in the tool input is ignored. If that’s not deliberate, consider preferring inputData.maxFileSize when present, and otherwise falling back to requestContext or the default.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant and valuable refactoring to standardize logging events across various workflows and tools, unifying them under the data-tool-progress type. This greatly improves consistency and observability. The changes also include adding streaming support to several tools, enhancing error handling, and updating documentation to reflect these new patterns.

However, the refactoring appears to be incomplete or inconsistent in some workflows, where legacy logging events are still present. I've also identified a few critical bugs where error states are being reported with an incorrect status (e.g., done or in-progress instead of error), which could lead to misleading workflow monitoring. Additionally, there are some minor opportunities to improve code clarity and fix typos.

Overall, this is a great step forward, but the identified issues, especially the critical ones related to error reporting, should be addressed to ensure the reliability of the new logging mechanism.

data: {
stepId: 'chunk-document',
error: error instanceof Error ? error.message : 'Unknown error',
status: "done",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

In the error handling block for chunkDocumentStep, the progress event is being sent with status: "done". This is incorrect and will misrepresent the step's outcome as successful when it has actually failed. The status should be "error" to correctly reflect the failure.

Suggested change
status: "done",
status: "error",

topic: inputData.topic,
status: 'error',
error: error instanceof Error ? error.message : 'Unknown error',
status: 'in-progress',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

In the error handling block for researchTopicStep, the progress event is being sent with status: 'in-progress'. This is incorrect and will misrepresent the step's outcome. The status should be "error" to correctly reflect the failure.

Suggested change
status: 'in-progress',
status: 'error',

stepId: 'fetch-stock-data',
error: error instanceof Error ? error.message : 'Unknown error',
await writer?.custom({
type: 'data-workflow-p',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The event type data-workflow-p appears to be a typo. To align with the standardized logging format of this pull request, it should be data-tool-progress. Additionally, since this is an error path, the status in the event data should be 'error'.

Suggested change
type: 'data-workflow-p',
type: 'data-tool-progress',

Comment on lines +120 to 128
await writer?.custom({
type: 'data-tool-progress',
data: {
type: 'workflow',
data: 'extract-learnings',
id: 'extract-learnings',
},
id: 'extract-learnings',
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This workflow still uses a mix of old (data-workflow-step-start, data-workflow-step-error) and new (data-tool-progress) logging events. To align with the PR's goal of standardizing logging, all workflow events should be migrated to the data-tool-progress format. For example, this step-start event should be an in-progress event.

Suggested change
await writer?.custom({
type: 'data-tool-progress',
data: {
type: 'workflow',
data: 'extract-learnings',
id: 'extract-learnings',
},
id: 'extract-learnings',
});
await writer?.custom({
type: 'data-tool-progress',
data: {
status: 'in-progress',
message: 'Starting step: extract-learnings',
stage: 'workflow',
},
id: 'extract-learnings',
});

Comment on lines +265 to 272
await writer?.custom({
type: 'data-workflow-step-error',
data: {
stepId: 'get-company-news',
error: error instanceof Error ? error.message : 'Unknown error',
},
id: 'get-company-news',
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This workflow still uses the legacy data-workflow-step-error event type. To align with the PR's goal of standardizing logging, all workflow events should be migrated to the data-tool-progress format with an appropriate status (e.g., 'error').

Suggested change
await writer?.custom({
type: 'data-workflow-step-error',
data: {
stepId: 'get-company-news',
error: error instanceof Error ? error.message : 'Unknown error',
},
id: 'get-company-news',
});
await writer?.custom({
type: 'data-tool-progress',
data: {
status: 'error',
message: error instanceof Error ? error.message : 'Unknown error',
stage: 'workflow',
},
id: 'get-company-news',
});

id: `${message.id}-${part.type}-${partIndex}`,
stage: "tool",
status: eventData.status === "success" ? "done" : eventData.status === "pending" ? "in-progress" : "error",
status: eventData.status === "done" ? "done" : (eventData.status === "pending" || eventData.status === "in-progress") ? "in-progress" : "error",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The nested ternary operator for determining the status is a bit difficult to read and maintain. Consider refactoring this logic into a helper function or using a switch statement to improve clarity, especially if more statuses are expected in the future.

@@ -215,67 +238,67 @@ function extractSymbolInfo(
): { name: string; kind: string } | null {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In the extractSymbolInfo function, the checks like if (name && name !== undefined && ...) are redundant. The name variable is of type string | undefined. A simple truthiness check if (name) is sufficient to guard against undefined and empty strings. The additional name !== undefined check adds unnecessary verbosity and can be removed to improve code clarity.

priceData.push({ symbol, timestamp: new Date().toISOString() });
}

//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

A stray comment // has been introduced. Please remove it to keep the code clean.

@greptile-apps
Copy link

greptile-apps bot commented Dec 13, 2025

Greptile Overview

Greptile Summary

This PR successfully refactors workflow logging to use a unified data-tool-progress event type, streamlining progress reporting and removing redundant logging steps. The changes improve consistency across workflows and align with the architectural standards defined in the AGENTS.md guides.

Key Changes:

  • Unified progress logging from data-workflow-progress and data-workflow-step-start/complete to single data-tool-progress type
  • Removed redundant step start/complete event emissions across research, stock analysis, and content workflows
  • Improved weather workflow with better stream handling using fullStream/textStream patterns
  • Enhanced TypeScript configuration to include workflow files for better type checking
  • Added comprehensive documentation (AI Elements usage guide and Copilot instructions)
  • Minor dependency updates for AI SDK packages

Issues Found:

  • Syntax error in stock-analysis-workflow.ts: incomplete event type data-workflow-p instead of data-tool-progress
  • Multiple instances in content-studio-workflow.ts using invalid status value "success" instead of the standard "done"

Confidence Score: 3/5

  • This PR improves code quality but contains syntax errors that will cause runtime issues
  • Score reflects the architectural improvements from the logging refactoring, but critical syntax errors prevent safe merging. The incomplete event type data-workflow-p and invalid status values "success" deviate from the documented standards in AGENTS.md and will likely cause issues with event consumers expecting the correct format.
  • Pay close attention to src/mastra/workflows/stock-analysis-workflow.ts (line 136) and src/mastra/workflows/content-studio-workflow.ts (multiple instances of status: "success" throughout the file)

Important Files Changed

File Analysis

Filename Score Overview
src/mastra/workflows/stock-analysis-workflow.ts 3/5 Refactored logging to use data-tool-progress, but contains typo data-workflow-p on line 136
src/mastra/workflows/content-studio-workflow.ts 3/5 Streamlined logging with unified progress type, but uses invalid status value "success" instead of "done"
src/mastra/workflows/research-synthesis-workflow.ts 4/5 Successfully unified progress logging under data-tool-progress, removed redundant step start/complete events
src/mastra/workflows/weather-workflow.ts 4/5 Replaced data-workflow-progress with data-tool-progress, improved stream handling with fullStream/textStream

Sequence Diagram

sequenceDiagram
    participant User
    participant Workflow
    participant Writer
    participant Agent/Tool
    participant Logger

    User->>Workflow: Execute workflow step
    Workflow->>Logger: logStepStart()
    
    Workflow->>Writer: custom({ type: "data-tool-progress" })
    Note over Writer: status: "in-progress"<br/>message: "Starting..."<br/>stage: "step-id"
    Writer-->>User: Stream progress update
    
    Workflow->>Agent/Tool: Execute operation
    Agent/Tool->>Writer: custom({ type: "data-tool-progress" })
    Note over Writer: Tool emits progress<br/>with same format
    Writer-->>User: Stream tool progress
    
    Agent/Tool-->>Workflow: Return result
    
    Workflow->>Writer: custom({ type: "data-tool-progress" })
    Note over Writer: status: "done"<br/>message: "Completed..."<br/>stage: "step-id"
    Writer-->>User: Stream completion
    
    Workflow->>Logger: logStepEnd()
    Workflow-->>User: Return final output
    
    alt Error occurs
        Agent/Tool->>Writer: custom({ type: "data-tool-progress" })
        Note over Writer: status: "error"<br/>message: error details
        Writer-->>User: Stream error
        Workflow->>Logger: logError()
    end
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

24 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

stepId: 'fetch-stock-data',
error: error instanceof Error ? error.message : 'Unknown error',
await writer?.custom({
type: 'data-workflow-p',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: type is incomplete - data-workflow-p should be data-tool-progress to match the refactoring pattern

Suggested change
type: 'data-workflow-p',
type: 'data-tool-progress',
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/mastra/workflows/stock-analysis-workflow.ts
Line: 136:136

Comment:
**syntax:** type is incomplete - `data-workflow-p` should be `data-tool-progress` to match the refactoring pattern

```suggestion
        type: 'data-tool-progress',
```

How can I resolve this? If you propose a fix, please make it concise.

type: 'data-workflow-step-complete',
type: 'data-tool-progress',
data: {
status: "success",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: invalid status value - according to the style guide (src/mastra/tools/AGENTS.md lines 104-105), valid status values are "in-progress", "done", or "error" (not "success")

Suggested change
status: "success",
status: "done",

Context Used: Context from dashboard - src/mastra/tools/AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/mastra/workflows/content-studio-workflow.ts
Line: 143:143

Comment:
**syntax:** invalid status value - according to the style guide (src/mastra/tools/AGENTS.md lines 104-105), valid status values are `"in-progress"`, `"done"`, or `"error"` (not `"success"`)

```suggestion
        status: "done",
```

**Context Used:** Context from `dashboard` - src/mastra/tools/AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=82f7e036-3842-48e0-99d2-74ff94205ff1))

How can I resolve this? If you propose a fix, please make it concise.

type: 'data-tool-progress',
data: {
status: "100%",
status: "success",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: invalid status value - should be "done" not "success"

Suggested change
status: "success",
status: "done",

Context Used: Context from dashboard - src/mastra/tools/AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/mastra/workflows/content-studio-workflow.ts
Line: 199:199

Comment:
**syntax:** invalid status value - should be `"done"` not `"success"`

```suggestion
        status: "done",
```

**Context Used:** Context from `dashboard` - src/mastra/tools/AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=82f7e036-3842-48e0-99d2-74ff94205ff1))

How can I resolve this? If you propose a fix, please make it concise.

type: 'data-tool-progress',
data: {
status: "100%",
status: "success",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: invalid status value - should be "done" not "success"

Suggested change
status: "success",
status: "done",

Context Used: Context from dashboard - src/mastra/tools/AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/mastra/workflows/content-studio-workflow.ts
Line: 253:253

Comment:
**syntax:** invalid status value - should be `"done"` not `"success"`

```suggestion
        status: "done",
```

**Context Used:** Context from `dashboard` - src/mastra/tools/AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=82f7e036-3842-48e0-99d2-74ff94205ff1))

How can I resolve this? If you propose a fix, please make it concise.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 30

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (13)
src/mastra/tools/editor-agent-tool.ts (2)

28-36: Validate/normalize agent output against outputSchema before returning.

Right now parsedResult is untyped and can violate outputSchema (e.g., changes not an array), which can break downstream UI/tooling despite having a schema defined.

Suggested hardening:

-      return {
+      return editorTool.outputSchema.parse({
         editedContent:
           parsedResult.editedContent ??
           parsedResult.copy ??
           result.text,
         contentType: parsedResult.contentType ?? contentType,
         changes: parsedResult.changes ?? [
           'Content edited and improved',
         ],
         suggestions: parsedResult.suggestions ?? [],
-      }
+      })

If editorTool.outputSchema isn’t accessible here, use outputSchema.parse(...) by extracting it or defining a local const outputSchema = ....

Also applies to: 72-99


42-106: Span lifecycle: end spans in a finally to avoid future early-return leaks.

Current flow ends the span on success before the last writer.custom, and on error within catch; that’s OK today, but brittle if more returns/throws are added inside try. Prefer try/catch/finally with span.end() in finally (and keep SpanStatusCode.ERROR in catch).

src/mastra/tools/finnhub-tools.ts (1)

69-112: Consider adding HTTP response status checking and timeouts.

The tools have comprehensive error handling, but there are some gaps that could impact reliability:

  1. HTTP status codes are not checked before attempting to parse the response. If the API returns a 4xx or 5xx status, the code might fail unexpectedly or miss the error condition.

  2. No timeouts on fetch calls, which could cause requests to hang indefinitely if the API is slow or unresponsive.

  3. No retry logic for transient failures, which could improve resilience.

  4. No rate limiting to prevent resource exhaustion from excessive API calls.

Suggested improvements:

  1. Check HTTP status before parsing:
 const response = await fetch(url);
+if (!response.ok) {
+  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
+}
 const data = await response.json();
  1. Add timeout using AbortController:
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10s timeout
try {
  const response = await fetch(url, { signal: controller.signal });
  // ... rest of code
} finally {
  clearTimeout(timeoutId);
}
  1. Consider implementing retry logic with exponential backoff for transient failures (5xx errors, network issues).

  2. Consider implementing rate limiting to comply with API limits and prevent resource exhaustion.

Based on coding guidelines: "Implement try-catch error handling, clear error messages, and retries for API calls in tools" and "set timeouts for performance optimization in tools".

Also applies to: 223-286, 401-461, 570-622, 743-820, 926-956

app/workflows/providers/workflow-context.tsx (2)

259-266: Replace useMemo with useEffect for side effects.

Using useMemo for side effects (updating state) is an anti-pattern in React. useMemo should be pure and only compute derived values. State updates should be performed in useEffect.

Apply this diff:

- // Update workflow status based on chat status
- useMemo(() => {
-   if (status === "streaming") {
-     setWorkflowStatus("running")
-   } else if (status === "ready" && workflowStatus === "running") {
-     setWorkflowStatus("completed")
-   }
- }, [status, workflowStatus])
+ // Update workflow status based on chat status
+ useEffect(() => {
+   if (status === "streaming") {
+     setWorkflowStatus("running")
+   } else if (status === "ready" && workflowStatus === "running") {
+     setWorkflowStatus("completed")
+   }
+ }, [status, workflowStatus])

411-425: Status mapping silently converts multiple non-compliant status values to "error".

The handler at line 419 only recognizes "done", "pending", and "in-progress" as valid status values. Any other value—including "success", "completed", and percentage strings like "20%" or "100%"—is silently mapped to "error".

This affects multiple workflows currently in the codebase:

  • content-studio-workflow.ts: 8 emissions with "success" status
  • learning-extraction-workflow.ts: 5 emissions with "completed" status
  • financial-report-workflow.ts: 3 emissions with "completed", 3 with "50%" status
  • changelog.ts: 5 emissions with percentage statuses ("20%", "50%", "100%")
  • document-processing-workflow.ts: 1 emission with "80%" status

Add validation to log unexpected status values and clarify acceptable values, similar to the data-workflow-progress handler (lines 31-32):

if (eventData && eventData.status !== null && typeof eventData.status === "string") {
+  // Warn on unexpected status values
+  if (!["done", "pending", "in-progress"].includes(eventData.status)) {
+    console.warn(`Unexpected data-tool-progress status: "${eventData.status}"`)
+  }
+
  allProgressEvents.push({
src/mastra/tools/financial-chart-tools.ts (1)

18-22: Consider adding format validation for stock symbols.

The symbols array accepts any string. For financial tools, stock symbols typically follow specific formats (e.g., 1-5 uppercase letters). Adding format validation would prevent malformed inputs and reduce prompt injection risk.

     symbols: z
       .array(z.string())
+      .transform(arr => arr.map(s => s.toUpperCase().trim()))
+      .refine(arr => arr.every(s => /^[A-Z]{1,5}$/.test(s)), {
+        message: 'Symbols must be 1-5 uppercase letters'
+      })
       .min(1)
       .describe('Stock symbols to visualize (e.g., ["AAPL", "GOOGL"])'),
src/mastra/tools/copywriter-agent-tool.ts (2)

132-134: Dead code: condition is always true.

Line 74 guarantees userId is always a non-empty string (either the extracted value or 'anonymous'), so this check will always pass.

-      if (userId !== undefined) {
-        prompt += `\n\nUser: ${userId}`
-      }
+      prompt += `\n\nUser: ${userId}`

177-179: Throwing for valid enum value breaks runtime for users.

'general' is a valid contentType enum option in the input schema (line 24), but selecting it will throw an unhandled error. Either implement the case, remove it from the enum, or return a graceful error response similar to the agent unavailable handling.

       case 'general': {
-          throw new Error('Not implemented yet: "general" case')
+          prompt +=
+            '\n\nCreate versatile general-purpose content suitable for multiple contexts.'
+          break
         }
src/mastra/workflows/changelog.ts (1)

25-26: Unused startTime variable.

startTime is declared but never used in either stepA1 or stepA2. If timing metrics are intended, add them to the progress events or span attributes; otherwise, remove the dead code.

   execute: async ({ mastra, writer }) => {
-    const startTime = Date.now();

Also applies to: 241-242

src/mastra/workflows/content-review-workflow.ts (1)

244-268: Inconsistent stage naming pattern.

The draftContentStep uses generic stage names ("first", "second", "third") while other steps use agent-specific names like "researchAgent". Consider using a consistent naming convention across all steps—either descriptive stages tied to the step's purpose or a uniform pattern.

Also applies to: 302-310

src/mastra/workflows/content-studio-workflow.ts (2)

153-153: Remove extraneous semicolons.

Multiple step definitions end with double semicolons (});;). While syntactically valid, these are likely typos and should be cleaned up.

-});;
+});

Also applies to: 209-209, 263-263, 332-332, 493-493, 563-563


105-113: Missing stage property in progress events.

The progress events in this file use stepId instead of stage, which differs from the pattern used in other workflow files (e.g., content-review-workflow.ts, stock-analysis-workflow.ts). For consistency across the codebase, consider adding the stage property.

     await writer?.custom({
       type: 'data-tool-progress',
       data: {
         status: "in-progress",
         message: "Starting research phase",
+        stage: "research-step",
         stepId: "research-step",
       },
       id: 'research-step',
     });
src/mastra/workflows/research-synthesis-workflow.ts (1)

253-260: Consider adding stage field for consistency.

Several data-tool-progress events in this file include a stage field (e.g., lines 75-78, 110-113, 129-132, 505), while others omit it. For consistent observability and filtering, consider adding stage: 'researchAgent' or stage: 'workflow' to these events as well.

Also applies to: 267-274, 350-357, 419-426, 432-439

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c60421 and 2cce9de.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (23)
  • .kilocode/rules/ai-elements-usage.md (1 hunks)
  • app/workflows/providers/workflow-context.tsx (1 hunks)
  • package.json (2 hunks)
  • src/mastra/tools/AGENTS.md (0 hunks)
  • src/mastra/tools/code-search.tool.ts (3 hunks)
  • src/mastra/tools/copywriter-agent-tool.ts (4 hunks)
  • src/mastra/tools/editor-agent-tool.ts (1 hunks)
  • src/mastra/tools/financial-chart-tools.ts (10 hunks)
  • src/mastra/tools/find-symbol.tool.ts (5 hunks)
  • src/mastra/tools/finnhub-tools.ts (6 hunks)
  • src/mastra/tools/multi-string-edit.tool.ts (2 hunks)
  • src/mastra/workflows/AGENTS.md (2 hunks)
  • src/mastra/workflows/changelog.ts (4 hunks)
  • src/mastra/workflows/content-review-workflow.ts (14 hunks)
  • src/mastra/workflows/content-studio-workflow.ts (16 hunks)
  • src/mastra/workflows/document-processing-workflow.ts (17 hunks)
  • src/mastra/workflows/financial-report-workflow.ts (18 hunks)
  • src/mastra/workflows/governed-rag-index.workflow.ts (5 hunks)
  • src/mastra/workflows/learning-extraction-workflow.ts (22 hunks)
  • src/mastra/workflows/research-synthesis-workflow.ts (14 hunks)
  • src/mastra/workflows/stock-analysis-workflow.ts (19 hunks)
  • src/mastra/workflows/weather-workflow.ts (4 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • src/mastra/tools/AGENTS.md
🧰 Additional context used
📓 Path-based instructions (20)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.github/instructions/next-js.instructions.md)

**/*.{js,jsx,ts,tsx}: Use next/dynamic for dynamic imports to load components only when needed, improving initial load time.
Use next/image component for automatic image optimization, including lazy loading and responsive images.
Use React.memo to prevent unnecessary re-renders of components.
Use the <Link prefetch> tag to prefetch pages that are likely to be visited.
Use getServerSideProps, getStaticProps, or server components for fetching data on the server-side.
Use SWR or React Query for client-side data fetching and caching.
Use CSS Modules, Styled Components, or Tailwind CSS for component-level styling. Prefer Tailwind CSS for rapid development.
Use React Context, Zustand, Jotai, or Recoil for managing global state. Avoid Redux unless necessary.
Use react-hook-form for managing forms and validation.
Only fetch the data that is needed by the component to avoid over-fetching.
Avoid long-running synchronous operations in the main thread to prevent blocking.
Always use setState or hooks to update state instead of mutating state directly.
Include a complete dependency array in useEffect hooks to prevent unexpected behavior.
Avoid writing server-side code in client components to prevent exposing secrets or causing unexpected behavior.
Use try...catch blocks for handling errors in asynchronous operations.
Implement error boundary components using getDerivedStateFromError or componentDidCatch lifecycle methods.
Sanitize user input to prevent Cross-Site Scripting (XSS) attacks. Be especially careful when rendering HTML directly from user input.
Store authentication tokens in HTTP-only cookies or local storage securely.
Implement role-based access control to restrict access to sensitive resources.
Clean up event listeners and timers in useEffect hooks to avoid memory leaks.
Only update state when necessary to reduce the number of re-renders and improve performance.
Use immutable data structures and avoid mutating data directly to prevent unexpected...

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • app/workflows/providers/workflow-context.tsx
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/workflows/content-review-workflow.ts
  • src/mastra/tools/code-search.tool.ts
**/*.{js,ts}

📄 CodeRabbit inference engine (.github/instructions/next-js.instructions.md)

Use parameterized queries or an ORM to prevent SQL injection attacks.

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/workflows/content-review-workflow.ts
  • src/mastra/tools/code-search.tool.ts
src/mastra/tools/**/*.ts

📄 CodeRabbit inference engine (src/mastra/AGENTS.md)

src/mastra/tools/**/*.ts: Use the createTool pattern with Zod schemas when adding new tools under src/mastra/tools
Use explicit Zod schemas for every tool input/output

Implement tools using createTool({ id, inputSchema, outputSchema, execute }) pattern with strict Zod schemas

src/mastra/tools/**/*.ts: Emit progress events with exact format: type: 'data-tool-progress', with id outside data object and status/message/stage inside data
Implement try-catch error handling, clear error messages, and retries for API calls in tools
Sanitize inputs, mask secrets, and rate-limit in tools for security
Implement caching, stream large data, and set timeouts for performance optimization in tools
Add OpenTelemetry (Otel) spans on all tool executions for observability

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/tools/code-search.tool.ts
src/mastra/{tools,workflows}/**/*.ts

📄 CodeRabbit inference engine (src/mastra/AGENTS.md)

Use RuntimeContext to enforce access control in tools and workflows

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/workflows/content-review-workflow.ts
  • src/mastra/tools/code-search.tool.ts
**/*.{ts,tsx,js,jsx,py,java,cs,rb,go,rs,cpp,c,h,hpp,swift,kotlin,php,scala,clj,groovy,lua,sh,bash}

📄 CodeRabbit inference engine (.github/instructions/self-explanatory-code-commenting.instructions.md)

**/*.{ts,tsx,js,jsx,py,java,cs,rb,go,rs,cpp,c,h,hpp,swift,kotlin,php,scala,clj,groovy,lua,sh,bash}: Write code that speaks for itself. Comment only when necessary to explain WHY, not WHAT. Avoid obvious comments that state what the code literally does.
Avoid redundant comments that simply repeat what the code is doing
Keep comments accurate and up-to-date with code changes. Remove or update outdated comments that no longer match the implementation.
Write comments for complex business logic that explain the WHY behind specific calculations or business rules
Document non-obvious algorithms with comments explaining the algorithm choice and its reasoning
Add comments explaining what regex patterns match, especially for complex patterns
Document API constraints, rate limits, gotchas, and external dependencies with explanatory comments
Avoid commenting out dead code. Use version control instead of maintaining commented code blocks.
Do not maintain code change history or modification logs as comments. Rely on git history and commit messages instead.
Avoid decorative divider comments (e.g., lines of equals signs or asterisks) for section separation
Ensure comments are placed appropriately above or adjacent to the code they describe
Write comments using proper grammar, spelling, and professional language
Prefer self-documenting code with clear variable/function names over adding comments to explain unclear code

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • app/workflows/providers/workflow-context.tsx
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/workflows/content-review-workflow.ts
  • src/mastra/tools/code-search.tool.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/instructions/self-explanatory-code-commenting.instructions.md)

**/*.{ts,tsx,js,jsx}: Document public APIs with TSDoc/JSDoc comments including parameter descriptions, return types, examples, and thrown exceptions
Add TSDoc comments to configuration constants and environment variables explaining their source, reasoning, or constraints
Use TSDoc annotation tags (TODO, FIXME, HACK, NOTE, WARNING, PERF, SECURITY, BUG, REFACTOR, DEPRECATED) to mark special comments
Include file headers with @fileoverview, @author, @copyright, and @license tags to document file purpose and ownership
Document function parameters with @param tags, return values with @returns tags, and exceptions with @throws tags in TSDoc comments
Use @see tags in TSDoc comments to reference related functions, methods, or documentation
Include @example tags in public API documentation with code examples showing typical usage

**/*.{ts,tsx,js,jsx}: Use Mastra mcp tools (#mastradocs, #mastraChanges, #mastraexamples, #mastraBlog) for Mastra framework development to stay updated with latest features and best practices
When working with Next.js projects, always utilize the next-devtools-mcp server for all Next.js related queries

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • app/workflows/providers/workflow-context.tsx
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/workflows/content-review-workflow.ts
  • src/mastra/tools/code-search.tool.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/instructions/self-explanatory-code-commenting.instructions.md)

**/*.{ts,tsx}: Document interface and type definitions with TSDoc comments explaining their purpose and usage context
Document interface properties with /** */ comments explaining each field's purpose and constraints
Document generic type parameters with @template tags explaining what each type parameter represents
Use type guards with comments explaining the runtime validation logic being performed
Document advanced/complex TypeScript types with explanatory comments about their purpose and use cases

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • app/workflows/providers/workflow-context.tsx
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/workflows/content-review-workflow.ts
  • src/mastra/tools/code-search.tool.ts
src/mastra/**/*

📄 CodeRabbit inference engine (src/AGENTS.md)

mastra modules can import from utils, but must not import from app or cli (except types)

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/workflows/content-review-workflow.ts
  • src/mastra/tools/code-search.tool.ts
  • src/mastra/workflows/AGENTS.md
**/*.{css,tsx,ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use Tailwind CSS 4 with oklch color variables for styling

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • app/workflows/providers/workflow-context.tsx
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/workflows/content-review-workflow.ts
  • src/mastra/tools/code-search.tool.ts
src/mastra/{tools,agents,workflows}/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Use Zod schemas for strict input/output validation in tools, agents, and workflows

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/workflows/content-review-workflow.ts
  • src/mastra/tools/code-search.tool.ts
src/mastra/tools/**/*.{ts,tsx}

📄 CodeRabbit inference engine (src/mastra/tools/AGENTS.md)

Define inputSchema and outputSchema using Zod for all tools in the tools directory

Files:

  • src/mastra/tools/editor-agent-tool.ts
  • src/mastra/tools/finnhub-tools.ts
  • src/mastra/tools/copywriter-agent-tool.ts
  • src/mastra/tools/financial-chart-tools.ts
  • src/mastra/tools/multi-string-edit.tool.ts
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/tools/code-search.tool.ts
src/mastra/workflows/**/*.ts

📄 CodeRabbit inference engine (src/mastra/AGENTS.md)

Add new workflow definitions under src/mastra/workflows to orchestrate multi-step flows

Use Mastra DSL for multi-step workflow definitions in src/mastra/workflows

src/mastra/workflows/**/*.ts: Use the standardized writer pattern for all workflow step instrumentation with consistent progress tracking including step-start, progress updates (percentage-based), step-complete, and step-error events
Always include step-start at the beginning of each step's execute function using the data-workflow-step-start message type
Use percentage-based status in progress updates (e.g., '20%', '50%', '90%', '100%') instead of 'in-progress'/'done' or other formats
Include step-complete with success status and duration in milliseconds for all successfully completed workflow steps
Include step-error in catch blocks to report workflow step failures with error message details
Add progress update checkpoints at logical stages (e.g., 20%, 50%, 90%) in addition to initial and final progress reports
Define workflows using Mastra DSL patterns (sequential .then(), parallel .parallel(), conditional .branch(), loop .dowhile(), iteration .foreach(), or human-in-the-loop suspend()/resume())
Use tools and agents as building blocks in workflows; prefer composition over duplication
Keep workflow steps idempotent when possible and implement checkpointing for long-running operations
Reuse tools across workflows to reduce duplication
Add logs and robust error handling to workflow steps
Use TracingContext to instrument workflow steps with spans and useful metadata

Files:

  • src/mastra/workflows/governed-rag-index.workflow.ts
  • src/mastra/workflows/content-studio-workflow.ts
  • src/mastra/workflows/stock-analysis-workflow.ts
  • src/mastra/workflows/changelog.ts
  • src/mastra/workflows/weather-workflow.ts
  • src/mastra/workflows/learning-extraction-workflow.ts
  • src/mastra/workflows/research-synthesis-workflow.ts
  • src/mastra/workflows/document-processing-workflow.ts
  • src/mastra/workflows/financial-report-workflow.ts
  • src/mastra/workflows/content-review-workflow.ts
tsconfig*.json

📄 CodeRabbit inference engine (AGENTS.md)

Configure TypeScript with separate tsconfig.json for app (ES2022) and tsconfig.cli.json for CLI builds (CommonJS)

Files:

  • tsconfig.json
src/mastra/tools/**/*.tool.ts

📄 CodeRabbit inference engine (src/mastra/tools/AGENTS.md)

Create tools using createTool() with Zod schemas for inputs and outputs in /src/mastra/tools

Files:

  • src/mastra/tools/multi-string-edit.tool.ts
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/tools/code-search.tool.ts
**/app/**

📄 CodeRabbit inference engine (.github/instructions/next-js.instructions.md)

Use the app/ directory structure for route handlers, server components, and client components (Next.js 13+). Prefer this over the pages/ directory for new projects.

Files:

  • app/workflows/providers/workflow-context.tsx
app/**/*.{tsx,ts}

📄 CodeRabbit inference engine (app/AGENTS.md)

app/**/*.{tsx,ts}: Use Tailwind CSS 4 with oklch color variables for styling in Next.js App Router pages and layouts
Use React 19 latest features in component implementations within the app directory

Files:

  • app/workflows/providers/workflow-context.tsx
app/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Frontend uses Next.js 16 App Router with React 19; use shadcn/ui base components (34 components) from ui/ directory

Files:

  • app/workflows/providers/workflow-context.tsx
app/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Use @ai-sdk/react for streaming and AI interactions in React components

Files:

  • app/workflows/providers/workflow-context.tsx
app/workflows/providers/workflow-context.tsx

📄 CodeRabbit inference engine (app/workflows/AGENTS.md)

app/workflows/providers/workflow-context.tsx: State management in workflow-context.tsx should use useChat hook from @ai-sdk/react with DefaultChatTransport for real-time streaming
Workflow-context.tsx should provide WorkflowContextValue interface with state management for selectedWorkflow, workflowStatus, currentRun, activeStepIndex, and streaming data

Files:

  • app/workflows/providers/workflow-context.tsx
**/*.md

📄 CodeRabbit inference engine (.github/instructions/markdown.instructions.md)

**/*.md: Use appropriate heading levels (H2, H3, etc.) to structure markdown content. Do not use H1 headings, as these will be generated from the title. Use ## for H2 and ### for H3 in a hierarchical manner. Recommend restructuring if content includes H4 or higher levels.
Use bullet points (with -) or numbered lists (with 1.) for lists in markdown. Indent nested lists with two spaces and ensure proper indentation and spacing.
Use fenced code blocks (triple backticks) for code snippets in markdown. Specify the language after the opening backticks for syntax highlighting (e.g., csharp).
Use proper markdown syntax for links: [link text](URL). Ensure that link text is descriptive and URLs are valid and accessible.
Use proper markdown syntax for images: ![alt text](image URL). Include a brief description of the image in the alt text for accessibility.
Use markdown tables (with | delimiters) for tabular data. Ensure proper formatting, alignment, and inclusion of headers.
Limit line length to 80 characters in markdown for readability. Use soft line breaks for long paragraphs.
Use appropriate whitespace in markdown to separate sections and improve readability. Use blank lines between sections and avoid excessive whitespace.
Include YAML front matter at the beginning of markdown files with required metadata fields: post_title, author1, post_slug, microsoft_alias, featured_image, categories (from /categories.txt), tags, ai_note, summary, and post_date.

Files:

  • src/mastra/workflows/AGENTS.md
🧬 Code graph analysis (2)
src/mastra/tools/copywriter-agent-tool.ts (1)
src/mastra/index.ts (1)
  • mastra (95-488)
src/mastra/workflows/learning-extraction-workflow.ts (1)
src/mastra/index.ts (1)
  • mastra (95-488)
⏰ 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). (5)
  • GitHub Check: CodeQL analysis (javascript-typescript)
  • GitHub Check: Agent
  • GitHub Check: Sourcery review
  • GitHub Check: Codacy Security Scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (28)
src/mastra/workflows/AGENTS.md (3)

44-141: Code examples effectively demonstrate data-tool-progress workflow patterns.

The new "Agents and Tools events Workflows" section provides concrete examples that align well with the PR's unified progress logging objective. The agentTextStreamWorkflow demonstrates text streaming with agents using the writer.pipeTo() pattern, and the examples show proper integration of data-tool-progress events with structured metadata (status, stage, id).


143-396: Branching workflow examples properly implement event reporting pattern.

The nested workflow examples (standard and express processing) correctly demonstrate data-tool-progress events with consistent stage naming and status updates. Error handling in the validateOrder step (lines 182–200) properly includes error event reporting with the data-tool-progress type, showing good observability practices.


398-402: Clarify intent of empty sequence diagram section.

The sequence diagram section is now empty. Per the AI summary, this content was removed/replaced intentionally as part of the PR. Please confirm whether this section should be:

  • Retained with new sequence diagram content reflecting the updated event patterns, or
  • Removed entirely if it's no longer needed.
src/mastra/tools/editor-agent-tool.ts (2)

37-41: Enforce RuntimeContext access control in tool execution.

Guidelines call out RuntimeContext for tools/workflows; execute currently runs without any explicit authorization/tenant scoping checks. If enforcement is done elsewhere, add a clear guard here (or document why it’s safe).


1-6: Fix InferUITool import spacing.

Line 1 has inconsistent spacing in the import statement: import type { InferUITool} should be import type { InferUITool } (add space before closing brace).

src/mastra/tools/finnhub-tools.ts (1)

46-50: LGTM! Progress event structure follows guidelines correctly.

The enriched progress events across all six Finnhub tools correctly implement the required format with id outside the data object and status, message, and stage inside the data object. The messages are contextual and descriptive, enhancing traceability of in-flight operations.

Based on coding guidelines: "Emit progress events with exact format: type: 'data-tool-progress', with id outside data object and status/message/stage inside data"

Also applies to: 200-204, 378-382, 547-551, 720-724, 903-907

src/mastra/tools/financial-chart-tools.ts (2)

93-103: Good: Progress events follow the required format.

The progress event structure correctly places id outside the data object and includes status, message, and stage inside data, complying with the coding guidelines.


95-103: Good: OpenTelemetry instrumentation is properly implemented.

Spans are created with appropriate attributes and closed in both success and error paths (except for the early return cases noted separately).

src/mastra/tools/code-search.tool.ts (3)

84-92: Progress event format is correct.

The structured progress event follows the required format with id outside the data object and status/message/stage inside data, aligning with the coding guidelines for tool progress events.


130-138: Intermediate progress update is well-structured.

This provides useful feedback on the number of files to be searched, following the consistent progress event format.


223-231: Completion event provides a clear summary.

The final progress event correctly signals completion with status: 'done' and includes useful metrics about matches found.

.kilocode/rules/ai-elements-usage.md (2)

1-6: Well-structured documentation guide.

The AI Elements usage guide provides comprehensive coverage of installation, usage patterns, component categories, and best practices. The glob patterns appropriately target relevant directories.


195-199: The useChat hook from @ai-sdk/react does return sendMessage as shown in the code. The official API documentation confirms that useChat returns sendMessage(message: CreateUIMessage | string, options?: ChatRequestOptions): void along with messages, id, status, and other properties. The code snippet is correct and requires no changes.

Likely an incorrect or invalid review comment.

src/mastra/tools/multi-string-edit.tool.ts (2)

243-244: Progress events follow the correct format.

The progress events correctly use type: 'data-tool-progress' with id outside the data object and status/message/stage inside data, matching the coding guidelines.


235-237: The RequestContext type assertion and usage pattern are correct and follow established conventions throughout the codebase. Optional chaining (?.get()) provides null-safety, and the fallback value (?? 1_000_000) handles missing configuration appropriately. No guard is necessary here, as this pattern is consistently used across multiple tools without guards (csv-to-json.tool.ts, find-symbol.tool.ts, pnpm-tool.ts, etc.). The RequestContext from @mastra/core/request-context is the appropriate type for configuration access in tools.

package.json (1)

46-49: Patch version updates are valid.

All four AI SDK packages have been verified to exist on npm:

  • @ai-sdk/google-vertex@3.0.91 ✓
  • @ai-sdk/openai@2.0.86 ✓
  • @ai-sdk/openai-compatible@1.0.29 ✓
  • @ai-sdk/react@2.0.115 ✓

These are safe minor patch bumps for the AI SDK packages.

src/mastra/tools/find-symbol.tool.ts (1)

78-87: Progress event format looks correct.

The progress event structure follows the required format with type: 'data-tool-progress', id outside the data object, and status/message/stage inside data. This aligns with the PR objective to standardize progress logging.

src/mastra/tools/copywriter-agent-tool.ts (1)

73-74: LGTM on userId extraction with fallback.

Good defensive handling with trim check and fallback to 'anonymous'.

src/mastra/workflows/changelog.ts (1)

37-46: Progress event format follows the standardized pattern.

The event structure correctly uses type: 'data-tool-progress' with status, message, and stage inside the data object, and id outside. Stage renamed to gitDiffAgent aligns with the PR's agent-specific naming convention.

src/mastra/workflows/weather-workflow.ts (2)

57-65: Progress events in fetch-weather follow correct format.

Events properly use type: 'data-tool-progress' with id outside data and status/message inside. Good consistency with the PR's standardization effort.

Also applies to: 106-114


217-228: This concern is incorrect; response.text and textStream are independent in Mastra's stream API.

The pattern of piping textStream to a writer and then accessing text is used consistently throughout the codebase (content-review-workflow.ts, financial-report-workflow.ts, spec-generation-workflow.ts) without issues. The text property is a separate Promise that doesn't get consumed by pipeTo(). The code is correctly designed to stream progress updates via textStream while simultaneously collecting the full text via text for parsing.

Likely an incorrect or invalid review comment.

src/mastra/workflows/governed-rag-index.workflow.ts (1)

75-82: Missing id field in progress event.

Per coding guidelines, progress events should include id outside the data object. This event and subsequent ones in this file are missing the id field, which is inconsistent with other files in this PR.

       await writer?.custom({
         type: 'data-tool-progress',
         data: {
           status: "in-progress",
           message: `PgVector index ${indexName} created or already exists with 1568 dimensions`,
           stage: "documentIndexingAgent",
-        }
+        },
+        id: "index-documents"
       });

Likely an incorrect or invalid review comment.

src/mastra/workflows/stock-analysis-workflow.ts (2)

78-106: LGTM on progress signaling pattern.

The progress signaling in fetchStockDataStep correctly uses the new data-tool-progress type with consistent 'in-progress' and 'done' status values and a uniform 'workflow' stage.


182-216: Good graceful degradation for missing API key.

The handling when FINNHUB_API_KEY is not set properly emits progress events, logs the situation, and returns a valid empty result rather than throwing. This maintains workflow resilience.

src/mastra/workflows/financial-report-workflow.ts (1)

680-688: Good use of 'completed' status for step finalization.

The merge-data, analyze-data, and generate-report steps consistently use 'completed' status with descriptive messages for their final progress events. This provides clear signaling of step completion.

Also applies to: 852-860, 1024-1032

src/mastra/workflows/learning-extraction-workflow.ts (1)

139-162: LGTM on progress signaling consistency.

The progress events in extractLearningsStep correctly use the data-tool-progress type with consistent status, message, and stage properties. The status transitions ('in-progress''completed') are logical.

Also applies to: 237-245

src/mastra/workflows/content-studio-workflow.ts (2)

126-136: Good defensive parsing with schema validation.

The steps properly handle JSON parsing failures by catching exceptions and falling back to default values that satisfy the output schemas. Using Zod's .parse() for runtime validation adds an extra layer of type safety.

Also applies to: 182-193, 238-247, 302-316, 362-370, 410-416, 462-476, 540-546


567-586: LGTM on workflow definition and loop condition.

The workflow is well-structured using Mastra DSL patterns with a clear dowhile loop that continues refinement until the score reaches 80 or above.

Comment on lines +73 to +74
{messages.map(({ role, parts }, index) => (
<Message from={role} key={index}>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider using stable keys in the example.

Using array index as React key (key={index}) can cause issues with component state when messages are reordered or removed. For a production-ready example, consider using message.id if available:

{messages.map((message) => (
  <Message from={message.role} key={message.id}>

This would align better with the streaming example on line 219 which uses message.id.

🤖 Prompt for AI Agents
In .kilocode/rules/ai-elements-usage.md around lines 73 to 74, the example uses
array index as the React key (key={index}) which can break component identity
when messages change; replace the index with a stable identifier such as
message.id (e.g., key={message.id}) and if message.id may be undefined, fall
back to a stable alternative (like a generated UUID assigned when creating the
message) so keys remain stable across reorders/removals.

Comment on lines +204 to +217
if (writer && typeof agentWithStream.stream === 'function') {
const stream = await agentWithStream.stream(prompt)

if (stream.fullStream) {
await stream.fullStream.pipeTo(writer as unknown as WritableStream)
} else if (stream.textStream) {
await stream.textStream.pipeTo(writer as unknown as WritableStream)
}

contentText = (await stream.text) ?? ''
} else {
const result = await agentWithStream.generate(prompt)
contentText = result.text
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Streaming logic lacks error handling and uses unsafe casts.

The streaming path has several concerns:

  1. No try-catch around pipeTo which can throw if the writer is closed or incompatible
  2. If streaming completes via pipeTo, the writer may be closed, but contentText extraction still occurs
  3. Heavy use of unknown casts bypasses type safety

Consider wrapping the streaming logic in try-catch and verifying the writer interface compatibility.

       let contentText = ''
       if (writer && typeof agentWithStream.stream === 'function') {
-        const stream = await agentWithStream.stream(prompt)
-
-        if (stream.fullStream) {
-          await stream.fullStream.pipeTo(writer as unknown as WritableStream)
-        } else if (stream.textStream) {
-          await stream.textStream.pipeTo(writer as unknown as WritableStream)
+        try {
+          const stream = await agentWithStream.stream(prompt)
+          if (stream.fullStream) {
+            await stream.fullStream.pipeTo(writer as unknown as WritableStream)
+          } else if (stream.textStream) {
+            await stream.textStream.pipeTo(writer as unknown as WritableStream)
+          }
+          contentText = (await stream.text) ?? ''
+        } catch (streamError) {
+          log.warn('Streaming failed, falling back to generate', { error: streamError })
+          const result = await agentWithStream.generate(prompt)
+          contentText = result.text
         }
-
-        contentText = (await stream.text) ?? ''
       } else {

Comment on lines +107 to +114
if (!agent) {
await context?.writer?.custom({ type: 'data-tool-progress', data: { status: 'done', message: '❌ chartSupervisorAgent not found', stage: 'chart-supervisor' }, id: 'chart-supervisor' })
return {
success: false,
sources: [],
error: 'Agent chartSupervisorAgent not found',
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Span is not closed on early return when agent is not found.

When the agent is missing, the function returns early but the OpenTelemetry span started at line 96 is never closed. This will cause span leaks and incomplete traces.

       if (!agent) {
         await context?.writer?.custom({ type: 'data-tool-progress', data: { status: 'done', message: '❌ chartSupervisorAgent not found', stage: 'chart-supervisor' }, id: 'chart-supervisor' })
+        span.setStatus({ code: 2, message: 'Agent not found' })
+        span.end()
         return {
           success: false,
           sources: [],
           error: 'Agent chartSupervisorAgent not found',
         }
       }

The same issue exists in chartDataProcessorTool (lines 441-456) - span needs to be closed there as well.

📝 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.

Suggested change
if (!agent) {
await context?.writer?.custom({ type: 'data-tool-progress', data: { status: 'done', message: '❌ chartSupervisorAgent not found', stage: 'chart-supervisor' }, id: 'chart-supervisor' })
return {
success: false,
sources: [],
error: 'Agent chartSupervisorAgent not found',
}
}
if (!agent) {
await context?.writer?.custom({ type: 'data-tool-progress', data: { status: 'done', message: '❌ chartSupervisorAgent not found', stage: 'chart-supervisor' }, id: 'chart-supervisor' })
span.setStatus({ code: 2, message: 'Agent not found' })
span.end()
return {
success: false,
sources: [],
error: 'Agent chartSupervisorAgent not found',
}
}
🤖 Prompt for AI Agents
In src/mastra/tools/financial-chart-tools.ts around lines 107 to 114 (and
similarly for chartDataProcessorTool around lines 441 to 456), the OpenTelemetry
span started earlier (line ~96) is not ended on the early return when the agent
is not found; update the code to ensure the span is closed before returning by
calling span.end() (and also setting span status or recording the error if
available) right before sending the progress message and returning the error
object; apply the same fix in the chartDataProcessorTool early-return path so
both spans are properly ended on error.

Comment on lines +136 to +152
const agentWithStream = agent as unknown as {
stream?: (_prompt: string) => Promise<{ fullStream?: ReadableStream<unknown>; textStream?: ReadableStream<unknown>; text?: Promise<string | undefined> }>
generate: (_prompt: string) => Promise<{ text: string }>
}

if (writer && typeof agentWithStream.stream === 'function') {
const stream = await agentWithStream.stream(prompt)
if (stream.fullStream) {
await stream.fullStream.pipeTo(writer as unknown as WritableStream)
} else if (stream.textStream) {
await stream.textStream.pipeTo(writer as unknown as WritableStream)
}
resultText = (await stream.text) ?? ''
} else {
const result = await agentWithStream.generate(prompt)
resultText = result.text
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Extract duplicated streaming logic into a helper function.

This streaming pattern with type casting is repeated verbatim across all four tools (lines 136-152, 308-324, 484-500, 661-677). This violates DRY and introduces maintenance burden.

Additionally, the as unknown as {...} cast bypasses type safety entirely. Consider defining a proper interface for streamable agents.

Extract to a shared helper:

// At file top or in a shared module
interface StreamableAgent {
  stream?: (prompt: string) => Promise<{
    fullStream?: ReadableStream<unknown>;
    textStream?: ReadableStream<unknown>;
    text?: Promise<string | undefined>;
  }>;
  generate: (prompt: string) => Promise<{ text: string }>;
}

async function executeAgentWithStreaming(
  agent: unknown,
  prompt: string,
  writer?: { custom: (data: unknown) => Promise<void> } & WritableStream
): Promise<string> {
  const streamableAgent = agent as StreamableAgent;
  
  if (writer && typeof streamableAgent.stream === 'function') {
    const stream = await streamableAgent.stream(prompt);
    if (stream.fullStream) {
      await stream.fullStream.pipeTo(writer as unknown as WritableStream);
    } else if (stream.textStream) {
      await stream.textStream.pipeTo(writer as unknown as WritableStream);
    }
    return (await stream.text) ?? '';
  }
  
  const result = await streamableAgent.generate(prompt);
  return result.text;
}

Then replace each duplicated block with:

const resultText = await executeAgentWithStreaming(agent, prompt, writer);
🤖 Prompt for AI Agents
In src/mastra/tools/financial-chart-tools.ts around lines 136 to 152, the
streaming/generate logic is duplicated verbatim across four locations and uses
an unsafe as unknown as {...} cast; extract that logic to a single helper and
use a proper typed interface. Define a StreamableAgent interface (stream? and
generate) at the top or in a shared module, implement an async helper (e.g.,
executeAgentWithStreaming(agent, prompt, writer)) that performs the stream
checks (fullStream/textStream piping) and falls back to generate, and then
replace the duplicated blocks at lines 136-152, 308-324, 484-500, 661-677 with a
single call to that helper returning resultText. Ensure you remove the unsafe
cast and cast only to the new typed interface inside the helper.

Comment on lines +141 to +152
if (writer && typeof agentWithStream.stream === 'function') {
const stream = await agentWithStream.stream(prompt)
if (stream.fullStream) {
await stream.fullStream.pipeTo(writer as unknown as WritableStream)
} else if (stream.textStream) {
await stream.textStream.pipeTo(writer as unknown as WritableStream)
}
resultText = (await stream.text) ?? ''
} else {
const result = await agentWithStream.generate(prompt)
resultText = result.text
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider adding timeout protection for agent calls.

Per coding guidelines, tools should "set timeouts for performance optimization." The agent stream() and generate() calls have no timeout protection and could hang indefinitely.

Consider wrapping agent calls with Promise.race() or using AbortController:

const AGENT_TIMEOUT_MS = 30000;

const timeoutPromise = new Promise<never>((_, reject) => 
  setTimeout(() => reject(new Error('Agent call timed out')), AGENT_TIMEOUT_MS)
);

const result = await Promise.race([
  agentWithStream.generate(prompt),
  timeoutPromise
]);
🤖 Prompt for AI Agents
In src/mastra/tools/financial-chart-tools.ts around lines 141-152, the
agentWithStream.stream() and .generate() calls lack timeout protection and may
hang indefinitely; add a timeout (e.g., AGENT_TIMEOUT_MS) by racing the agent
promise against a rejecting timeout promise or by using an AbortController if
the agent supports abort signals, ensure the controller is aborted on timeout to
free resources, handle and rethrow or log the timeout error, and make sure any
writer or partial streams are properly closed/cleaned up when a timeout occurs.

Comment on lines 322 to 331
if (!inputData.requireApproval) {
await writer?.write({
type: 'progress',
percent: 100,
message: 'Auto-approval (requireApproval=false)...',
await writer?.custom({
type: 'data-tool-progress',
data: {
status: 'completed',
message: 'Auto-approval (requireApproval=false)...',
stage: 'workflow',
},
id: 'human-approval',
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Status message could be more accurate.

The status is 'completed' with message 'Auto-approval (requireApproval=false)...'. Consider using a more specific status like 'auto-approved' or adjusting the message to not end with ellipsis since this is a terminal state.

       await writer?.custom({
         type: 'data-tool-progress',
         data: {
-          status: 'completed',
-          message: 'Auto-approval (requireApproval=false)...',
+          status: 'completed',
+          message: 'Auto-approved (human approval not required)',
           stage: 'workflow',
         },
         id: 'human-approval',
       });
📝 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.

Suggested change
if (!inputData.requireApproval) {
await writer?.write({
type: 'progress',
percent: 100,
message: 'Auto-approval (requireApproval=false)...',
await writer?.custom({
type: 'data-tool-progress',
data: {
status: 'completed',
message: 'Auto-approval (requireApproval=false)...',
stage: 'workflow',
},
id: 'human-approval',
});
if (!inputData.requireApproval) {
await writer?.custom({
type: 'data-tool-progress',
data: {
status: 'completed',
message: 'Auto-approved (human approval not required)',
stage: 'workflow',
},
id: 'human-approval',
});
🤖 Prompt for AI Agents
In src/mastra/workflows/learning-extraction-workflow.ts around lines 322 to 331,
the progress event for auto-approval uses a generic status 'completed' and a
message that ends with an ellipsis; change the status to a more specific
terminal value such as 'auto-approved' (or 'approved:auto') and update the
message to a definitive sentence without trailing ellipsis (e.g., 'Auto-approved
(requireApproval=false)'). Ensure the id and stage remain the same and update
any downstream consumers if they rely on the old 'completed' status.

Comment on lines 211 to 219
await writer?.custom({
type: 'data-workflow-topic-progress',
type: 'data-tool-progress',
data: {
topic: inputData.topic,
status: 'error',
error: error instanceof Error ? error.message : 'Unknown error',
status: 'in-progress',
message: `Research error for ${inputData.topic}...`,
stage: 'researchAgent',
},
id: 'research-topic-item',
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix incorrect error status.

The error handler uses status: 'in-progress' which incorrectly suggests the operation is still running. Additionally, this deviates from the error handling pattern used in other steps (lines 388-395, 535-543) which use data-workflow-step-error.

Apply this diff to align with the error handling pattern used elsewhere in this file:

       await writer?.custom({
-        type: 'data-tool-progress',
+        type: 'data-workflow-step-error',
         data: {
-          status: 'in-progress',
-          message: `Research error for ${inputData.topic}...`,
-          stage: 'researchAgent',
+          stepId: 'research-topic-item',
+          error: error instanceof Error ? error.message : `Research error for ${inputData.topic}`,
         },
         id: 'research-topic-item',
       });
🤖 Prompt for AI Agents
In src/mastra/workflows/research-synthesis-workflow.ts around lines 211 to 219,
the error handler currently emits a progress event with status 'in-progress' and
type 'data-tool-progress'; change it to follow the file's error pattern by
emitting type 'data-workflow-step-error' and status 'error' (keep the message,
stage 'researchAgent' and id 'research-topic-item' consistent), so the event
aligns with other error handlers in this workflow.

Comment on lines +135 to 142
await writer?.custom({
type: 'data-workflow-p',
data: {
stepId: 'fetch-stock-data',
error: error instanceof Error ? error.message : 'Unknown error',
},
id: 'fetch-stock-data',
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical typo in error event type.

The event type 'data-workflow-p' appears to be a truncated/typo version of 'data-workflow-step-error'. This will cause error events to not be properly recognized by consumers, breaking error handling and observability.

       await writer?.custom({
-        type: 'data-workflow-p',
+        type: 'data-workflow-step-error',
         data: {
           stepId: 'fetch-stock-data',
           error: error instanceof Error ? error.message : 'Unknown error',
         },
         id: 'fetch-stock-data',
       });
🤖 Prompt for AI Agents
In src/mastra/workflows/stock-analysis-workflow.ts around lines 135 to 142, the
event type string 'data-workflow-p' is a typo and should be
'data-workflow-step-error'; update the writer.custom call to use type:
'data-workflow-step-error' (leave the rest of the payload intact), and verify
any other occurrences in this file or related consumers are using the corrected
type so error events are recognized properly.

Comment on lines +220 to +225
if (writer !== undefined && writer !== null) {
if (fullStream !== undefined && typeof (fullStream as unknown as { pipeTo?: unknown }).pipeTo === 'function') {
await (fullStream as unknown as ReadableStream<unknown>).pipeTo(writer as unknown as WritableStream)
} else if (textStream !== undefined && typeof (textStream as unknown as { pipeTo?: unknown }).pipeTo === 'function') {
await (textStream as unknown as ReadableStream<unknown>).pipeTo(writer as unknown as WritableStream)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Excessive type assertions reduce maintainability.

The nested as unknown as casts bypass type safety. If the Mastra agent's stream API is typed, consider importing and using those types. If not, this could be a candidate for creating a shared utility or type definition.

🤖 Prompt for AI Agents
In src/mastra/workflows/weather-workflow.ts around lines 220 to 225, the code
uses nested "as unknown as" casts to force types for fullStream/textStream and
writer which bypasses TypeScript safety; replace these casts by importing or
declaring the correct stream interfaces (e.g., the Mastra agent
ReadableStream/WritableStream types or standard DOM/stream types) and use a
proper type guard (function isReadableWithPipeTo(x): x is ReadableStream<any> {
return x && typeof (x as any).pipeTo === 'function' }) before calling pipeTo,
typing writer as the corresponding WritableStream type; if Mastra does not
export types, add a small shared type definition or utility type and reuse it
rather than double-casting.

".next/dev/types/**/*.ts",
"app/**/*.ts",
"app/**/*.tsx",
"src/mastra/workflows/*.ts",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Redundant include pattern.

The pattern "src/mastra/workflows/*.ts" is already covered by "src/**/*.ts" on line 52. This entry can be removed unless you intend to prioritize or explicitly document workflow files.

-    "src/mastra/workflows/*.ts",
📝 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.

Suggested change
"src/mastra/workflows/*.ts",
🤖 Prompt for AI Agents
In tsconfig.json around line 51 the include entry "src/mastra/workflows/*.ts" is
redundant because "src/**/*.ts" on line 52 already covers it; remove the
specific workflows include (or explicitly document/justify it if you intend
special handling) so the include list is not duplicated and keep only the
broader pattern unless you have a deliberate reason to prioritize workflow
files.

@ssdeanx ssdeanx merged commit 7631f7c into main Dec 13, 2025
321 of 324 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the logging mechanism across multiple workflows and tools to standardize progress tracking under the 'data-tool-progress' event type. The changes aim to improve consistency and clarity in how workflow execution progress is communicated to clients.

Key Changes:

  • Unified all progress logging to use 'data-tool-progress' type instead of mixed types ('data-workflow-progress', 'data-workflow-step-start', etc.)
  • Standardized status values to 'in-progress', 'done', and 'error' (replacing percentage-based values)
  • Removed redundant step-start and step-complete logging events
  • Added comprehensive documentation for AI Elements usage and Copilot instructions
  • Updated TypeScript configuration to include workflow files
  • Minor package version updates for AI SDK dependencies

Reviewed changes

Copilot reviewed 22 out of 25 changed files in this pull request and generated 38 comments.

Show a summary per file
File Description
tsconfig.json Added workflow directory to TypeScript compilation
src/mastra/workflows/*.ts Refactored 8 workflow files to use unified 'data-tool-progress' logging pattern
src/mastra/tools/*.ts Updated 6 tool files to include proper status, message, and stage fields in progress events
src/mastra/workflows/AGENTS.md Expanded with detailed workflow examples and event patterns
.kilocode/rules/ai-elements-usage.md New comprehensive guide for AI Elements library usage
.github/-/taming-copilot.instructions.md New instructions for controlling Copilot behavior
app/workflows/providers/workflow-context.tsx Updated status handling to support both 'success' and 'done' values
package.json & package-lock.json Minor version bumps for AI SDK packages
Comments suppressed due to low confidence (1)

src/mastra/workflows/document-processing-workflow.ts:408

  • This string is not a template literal, but appears to reference the variable inputData.
        message: "Text passed through successfully ${inputData.content}`,",

excludePatterns?: string[];
includeNodeModules?: boolean;
caseSensitive?: boolean;
searchType: 'semantic' | 'text'; // Required field
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SymbolContext interface defines searchType as a required field with specific values ('semantic' | 'text'), but this field is never accessed or used in the tool's execute function. This creates unnecessary requirements for consumers of this interface.

Suggested change
searchType: 'semantic' | 'text'; // Required field

Copilot uses AI. Check for mistakes.
type: 'data-tool-progress',
data: {
status: "100%",
status: "success",
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status field uses 'success' which is inconsistent with the standardized status values. According to the PR pattern, this should be 'done' to indicate completion. This pattern appears multiple times in this file (lines 199, 253, 322, 376, 420, 483, 553).

Suggested change
status: "success",
status: "done",

Copilot uses AI. Check for mistakes.
type: 'data-tool-progress',
data: {
status: "done", // must be "done" for the UI to show the step as completed
message: "Text passed through successfully ${inputData.content}`,",
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message has incomplete interpolation syntax with a trailing backtick and comma: "Text passed through successfully ${inputData.content}`,". This will cause a syntax error. The template literal is not properly closed.

Suggested change
message: "Text passed through successfully ${inputData.content}`,",
message: `Text passed through successfully ${inputData.content}`,

Copilot uses AI. Check for mistakes.
priceData.push({ symbol, timestamp: new Date().toISOString() });
}

//
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete comment with just "// " at this line. This should either be removed or completed with meaningful content.

Suggested change
//

Copilot uses AI. Check for mistakes.
Comment on lines +73 to +74
const userIdVal = context?.requestContext?.get('userId')
const userId = typeof userIdVal === 'string' && userIdVal.trim().length > 0 ? userIdVal : 'anonymous'
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of Zod schema validation for the copywriter context and replacement with a simple string check reduces type safety. The original copywriterToolContextSchema.parse() provided runtime validation, while the new code only checks if the value is a non-empty string. Consider maintaining type safety while simplifying the code.

Copilot uses AI. Check for mistakes.
stage: 'analyze-data',
},
id: 'analyze-data',
})
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid automated semicolon insertion (93% of all statements in the enclosing function have an explicit semicolon).

Suggested change
})
});

Copilot uses AI. Check for mistakes.
stage: 'analyze-data',
},
id: 'analyze-data',
})
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid automated semicolon insertion (93% of all statements in the enclosing function have an explicit semicolon).

Suggested change
})
});

Copilot uses AI. Check for mistakes.
stage: 'generate-report',
},
id: 'generate-report',
})
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid automated semicolon insertion (92% of all statements in the enclosing function have an explicit semicolon).

Suggested change
})
});

Copilot uses AI. Check for mistakes.
stage: 'generate-report',
},
id: 'generate-report',
})
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid automated semicolon insertion (92% of all statements in the enclosing function have an explicit semicolon).

Suggested change
})
});

Copilot uses AI. Check for mistakes.
stage: 'generate-report',
},
id: 'generate-report',
})
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid automated semicolon insertion (92% of all statements in the enclosing function have an explicit semicolon).

Suggested change
})
});

Copilot uses AI. Check for mistakes.
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