Skip to content

feat: enhance tools with abort signal handling and logging improvements#74

Merged
ssdeanx merged 1 commit intomainfrom
develop
Jan 7, 2026
Merged

feat: enhance tools with abort signal handling and logging improvements#74
ssdeanx merged 1 commit intomainfrom
develop

Conversation

@ssdeanx
Copy link
Owner

@ssdeanx ssdeanx commented Jan 7, 2026

  • Added abort signal logging to the listEvents function in calendar-tool.ts to track if the operation was aborted during input streaming and output generation.
  • Removed unnecessary inheritance from RequestContext in SvgJsonNode, XmlElementInfo, ProcessSVGResult, SymbolContext, and SymbolInfo interfaces in data-processing-tools.ts and find-symbol.tool.ts for cleaner type definitions.
  • Enhanced logging in the readCSVDataTool to include message count during input start and availability.
  • Implemented abort signal handling in the findSymbolTool to log if the operation was aborted during input processing and output generation.
  • Improved the weatherTool to handle abort signals throughout the execution flow, including checks before geocoding and during weather fetching, with appropriate logging for cancellation events.
  • Added specific handling for AbortError in the weatherTool to log cancellation messages and update the progress writer accordingly.

- Added abort signal logging to the `listEvents` function in `calendar-tool.ts` to track if the operation was aborted during input streaming and output generation.
- Removed unnecessary inheritance from `RequestContext` in `SvgJsonNode`, `XmlElementInfo`, `ProcessSVGResult`, `SymbolContext`, and `SymbolInfo` interfaces in `data-processing-tools.ts` and `find-symbol.tool.ts` for cleaner type definitions.
- Enhanced logging in the `readCSVDataTool` to include message count during input start and availability.
- Implemented abort signal handling in the `findSymbolTool` to log if the operation was aborted during input processing and output generation.
- Improved the `weatherTool` to handle abort signals throughout the execution flow, including checks before geocoding and during weather fetching, with appropriate logging for cancellation events.
- Added specific handling for `AbortError` in the `weatherTool` to log cancellation messages and update the progress writer accordingly.
Copilot AI review requested due to automatic review settings January 7, 2026 07:34
@continue
Copy link

continue bot commented Jan 7, 2026

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


Unsubscribe from All Green comments

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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

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.

Sorry @ssdeanx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@github-actions
Copy link

github-actions bot commented Jan 7, 2026

🤖 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 Jan 7, 2026

Caution

Review failed

The pull request is closed.

Summary by CodeRabbit

  • New Features

    • Added real-time input streaming monitoring across tools with new delta event tracking
    • Enhanced browser automation tools with improved capabilities including PDF generation, form filling, and table extraction
    • Added cancellation support with abort signal visibility throughout tool execution lifecycle
  • Improvements

    • Better tool diagnostics and logging for tracking execution state and cancellation events
    • Updated AI agent with revised tool configuration for improved capability access

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

Walkthrough

Changes introduce a new onInputDelta streaming hook for tool lifecycle events and propagate abortSignal cancellation state across tool hooks. Tool implementations are expanded with full configurations (schemas, handlers), some type interfaces are decoupled from RequestContext, and agent tools and workflow conditions are updated.

Changes

Cohort / File(s) Summary
Configuration & Agent Tools
\.github/agents/Beast\.agent\.md, \.github/workflows/gemini-review\.yml
Replaced tool list with revised set including ast-grep-mcp, Mastra tools, UV toolkit, and related utilities; simplified workflow conditional for identity token step.
Tool Hooks & Streaming Documentation
src/mastra/tools/AGENTS\.md
Added onInputDelta hook to tool lifecycle, updated hook execution order, expanded log payloads to include abortSignal state across streaming hooks.
Tool Streaming & Abort Signal Additions
src/mastra/tools/alpha-vantage\.tool\.ts, src/mastra/tools/arxiv\.tool\.ts, src/mastra/tools/calendar-tool\.ts
Added onInputDelta handler (alpha-vantage only); propagated abortSignal?.aborted to logging in onInputStart, onInputAvailable, onOutput hooks.
Comprehensive Cancellation Handling
src/mastra/tools/weather-tool\.ts
Implemented abortSignal propagation and early cancellation checks; added explicit AbortError handling with telemetry; updated internal getWeather signature to accept abortSignal parameter.
Type System Refactoring
src/mastra/tools/data-processing-tools\.ts, src/mastra/tools/find-symbol\.tool\.ts
Decoupled SvgJsonNode, XmlElementInfo, ProcessSVGResult, and SymbolContext from RequestContext extension; expanded type fields (children arrays, metadata objects, symbol info fields).
Major Tool Implementation Refactoring
src/mastra/tools/browser-tool\.ts
Restructured all browser-based tools (browserTool, screenshotTool, pdfGeneratorTool, clickAndExtractTool, fillFormTool, googleSearch, extractTablesTool, monitorPageTool) with explicit public API declarations including id, description, inputSchema, outputSchema, execute, and hook handlers; enhanced browser instance management and added OpenTelemetry instrumentation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐰 Streaming hops with delta flows,
Abort signals help us know,
When to stop and when to pause,
Browser tools now shine because
Types are cleaner, hooks run true—
Whiskers wiggle, thanks to you! 🥕

✨ 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

📜 Recent review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5489f5 and 6183f87.

📒 Files selected for processing (10)
  • .github/agents/Beast.agent.md
  • .github/workflows/gemini-review.yml
  • src/mastra/tools/AGENTS.md
  • src/mastra/tools/alpha-vantage.tool.ts
  • src/mastra/tools/arxiv.tool.ts
  • src/mastra/tools/browser-tool.ts
  • src/mastra/tools/calendar-tool.ts
  • src/mastra/tools/data-processing-tools.ts
  • src/mastra/tools/find-symbol.tool.ts
  • src/mastra/tools/weather-tool.ts

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 enhances the robustness and observability of various tools by integrating comprehensive abort signal handling and improving logging mechanisms. The changes ensure that long-running operations can be gracefully cancelled, and provide more detailed insights into tool execution lifecycle, including input streaming and output generation. Additionally, type definitions for several internal interfaces have been refactored for improved clarity and maintainability.

Highlights

  • Enhanced Abort Signal Handling: Implemented AbortSignal checks and logging in calendar-tool.ts, find-symbol.tool.ts, and weather-tool.ts to gracefully manage cancellations during tool execution, ensuring operations can be stopped cleanly.
  • Improved Logging Across Tools: Added abortSignal status to logging in onInputStart, onInputAvailable, and onOutput hooks across multiple tools, providing better visibility into the cancellation state during various stages of tool execution. The readCSVDataTool also now includes message count in its input hooks.
  • New onInputDelta Lifecycle Hook: Introduced and documented the onInputDelta lifecycle hook, allowing tools to track incremental input streaming. This hook has been integrated into alpha-vantage.tool.ts and weather-tool.ts for more granular input monitoring.
  • Refactored Type Definitions: Removed unnecessary RequestContext inheritance from several interfaces (SvgJsonNode, XmlElementInfo, ProcessSVGResult, SymbolContext, SymbolInfo) for cleaner and more precise type definitions, improving code clarity and maintainability.
  • Agent Tool Updates: The Beast agent configuration has been updated to include new ast-grep-mcp and uv-toolkit tools, and mastra tool references were adjusted to mastrabeta.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/gemini-review.yml
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

github-actions bot commented Jan 7, 2026

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

@ssdeanx ssdeanx merged commit 76a42f4 into main Jan 7, 2026
25 of 30 checks passed
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 enhances several tools by adding support for abort signals, improving logging with abortSignal status, and introducing the onInputDelta lifecycle hook. The changes are generally good, improving observability and cancellation capabilities.

However, there is a critical issue in weather-tool.ts where getWeather is called with an incorrect number of arguments, which will lead to a runtime error. I've also pointed out a few medium-severity issues related to code consistency, robustness, and documentation formatting that should be addressed to improve maintainability. The removal of unnecessary RequestContext inheritance is a good cleanup.

throw new Error('Weather lookup cancelled during geocoding')
}

const result = await getWeather(inputData.location, temperatureUnit, abortSignal)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This call to getWeather will fail at runtime. You are passing abortSignal as the third argument, but the getWeather function is only defined to accept two arguments (location and unit).

You need to update the getWeather function to accept the abortSignal and pass it to the underlying fetch calls. For example:

const getWeather = async (location: string, unit: 'celsius' | 'fahrenheit', abortSignal?: AbortSignal) => {
  // ...
  const geocodingResponse = await fetch(geocodingUrl, { signal: abortSignal });
  // ...
  const response = await fetch(weatherUrl, { signal: abortSignal });
  // ...
}

Comment on lines +244 to +262
| Tool | Hooks Implemented | Purpose |
| -------------------------------- | ------------------------------------------------------------------ | -------------------------------- |
| `weather-tool.ts` | ✅ `onInputStart`, `onInputDelta`, `onInputAvailable`, `onOutput` | Weather data monitoring |
| `github.ts` (listRepositories) | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Repository listing analytics |
| `code-search.tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Search analytics |
| `csv-to-json.tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Data conversion monitoring |
| `web-scraper-tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Scraping analytics |
| `jwt-auth.tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Security monitoring |
| `alpha-vantage.tool.ts` | ✅ `onInputStart`, `onInputDelta`, `onInputAvailable`, `onOutput` | Financial data monitoring |
| `fs.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | File system operation monitoring |
| `json-to-csv.tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Data conversion monitoring |
| `serpapi-search.tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Search query analytics |
| `find-symbol.tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Symbol search analytics |
| `polygon-tools.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Financial market data monitoring |
| `arxiv.tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Academic paper search analytics |
| `browser-tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Browser automation monitoring |
| `serpapi-academic-local.tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Google Scholar search analytics |
| `serpapi-news-trends.tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Google News search analytics |
| `calendar-tool.ts` | ✅ `onInputStart`, `onInputAvailable`, `onOutput` | Calendar events monitoring |
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 formatting of this markdown table is broken, making it difficult to read. Please adjust the column widths to align the content properly.

Suggested change
| Tool | Hooks Implemented | Purpose |
| -------------------------------- | ------------------------------------------------------------------ | -------------------------------- |
| `weather-tool.ts` |`onInputStart`, `onInputDelta`, `onInputAvailable`, `onOutput` | Weather data monitoring |
| `github.ts` (listRepositories) |`onInputStart`, `onInputAvailable`, `onOutput` | Repository listing analytics |
| `code-search.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Search analytics |
| `csv-to-json.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Data conversion monitoring |
| `web-scraper-tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Scraping analytics |
| `jwt-auth.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Security monitoring |
| `alpha-vantage.tool.ts` |`onInputStart`, `onInputDelta`, `onInputAvailable`, `onOutput` | Financial data monitoring |
| `fs.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | File system operation monitoring |
| `json-to-csv.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Data conversion monitoring |
| `serpapi-search.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Search query analytics |
| `find-symbol.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Symbol search analytics |
| `polygon-tools.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Financial market data monitoring |
| `arxiv.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Academic paper search analytics |
| `browser-tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Browser automation monitoring |
| `serpapi-academic-local.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Google Scholar search analytics |
| `serpapi-news-trends.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Google News search analytics |
| `calendar-tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Calendar events monitoring |
| Tool | Hooks Implemented | Purpose |
| -------------------------------- | ------------------------------------------------------------------ | -------------------------------- |
| `weather-tool.ts` |`onInputStart`, `onInputDelta`, `onInputAvailable`, `onOutput` | Weather data monitoring |
| `github.ts` (listRepositories) |`onInputStart`, `onInputAvailable`, `onOutput` | Repository listing analytics |
| `code-search.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Search analytics |
| `csv-to-json.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Data conversion monitoring |
| `web-scraper-tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Scraping analytics |
| `jwt-auth.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Security monitoring |
| `alpha-vantage.tool.ts` |`onInputStart`, `onInputDelta`, `onInputAvailable`, `onOutput` | Financial data monitoring |
| `fs.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | File system operation monitoring |
| `json-to-csv.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Data conversion monitoring |
| `serpapi-search.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Search query analytics |
| `find-symbol.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Symbol search analytics |
| `polygon-tools.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Financial market data monitoring |
| `arxiv.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Academic paper search analytics |
| `browser-tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Browser automation monitoring |
| `serpapi-academic-local.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Google Scholar search analytics |
| `serpapi-news-trends.tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Google News search analytics |
| `calendar-tool.ts` |`onInputStart`, `onInputAvailable`, `onOutput` | Calendar events monitoring |

Comment on lines +414 to +418
log.info('alphaVantageStockTool tool input streaming started', {
toolCallId,
messageCount: messages.length,
abortSignal: abortSignal?.aborted,
hook: 'onInputStart' });
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 formatting of this log object is a bit inconsistent. For better readability, it's good practice to have the closing brace }); on a new line when the object properties are split across multiple lines. This should be applied consistently across the file.

    log.info('alphaVantageStockTool tool input streaming started', {
      toolCallId,
      messageCount: messages.length,
      abortSignal: abortSignal?.aborted,
      hook: 'onInputStart',
    });

Comment on lines +815 to +818
log.info('alphaVantageTool tool input streaming started', { toolCallId,
messageCount: messages.length,
abortSignal: abortSignal?.aborted,
hook: 'onInputStart' });
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the other tools in this file, the formatting of this log object could be improved for consistency and readability. When an object is multi-line, the closing brace }); should be on its own line.

    log.info('alphaVantageTool tool input streaming started', {
      toolCallId,
      messageCount: messages.length,
      abortSignal: abortSignal?.aborted,
      hook: 'onInputStart',
    });

Comment on lines 13 to 24
async function getBrowser(): Promise<Browser> {
if (!browserInstance?.isConnected()) {
if (browserInstance) {
await browserInstance.close().catch(() => { }) // Close the old instance if it's not connected
if (!((browserInstance?.isConnected()) ?? false)) {
if (browserInstance) {
await browserInstance.close().catch(() => {}) // Close the old instance if it's not connected
}
browserInstance = await chromium.launch({
headless: true,
chromiumSandbox: false,
})
}
browserInstance = await chromium.launch({
headless: true,
chromiumSandbox: false,
})
}
return browserInstance
return browserInstance!
}
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 change to !((browserInstance?.isConnected()) ?? false) is a great improvement for null safety. However, the function still ends with a non-null assertion (browserInstance!). While it's unlikely to be null here, it's safer to handle this possibility explicitly. Consider throwing an error if browserInstance is still null after the launch logic, which would indicate a failure in chromium.launch.

async function getBrowser(): Promise<Browser> {
    if (!((browserInstance?.isConnected()) ?? false)) {
        if (browserInstance) {
            await browserInstance.close().catch(() => {}) // Close the old instance if it's not connected
        }
        browserInstance = await chromium.launch({
            headless: true,
            chromiumSandbox: false,
        })
    }
    if (!browserInstance) {
        throw new Error('Failed to launch browser instance.');
    }
    return browserInstance;
}

onInputStart: ({ toolCallId, messages, abortSignal }) => {
log.info('Read CSV tool input streaming started', {
toolCallId,
messages: messages.length,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For logging consistency across tools, please use messageCount as the key for the message length, instead of messages.

Suggested change
messages: messages.length,
messageCount: messages.length,

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