Skip to content

Stop active TinyFish requests when dataset runs are cancelled#151

Open
dunkeln wants to merge 1 commit into
tinyfish-io:mainfrom
dunkeln:codex/cancel-tinyfish-on-stop
Open

Stop active TinyFish requests when dataset runs are cancelled#151
dunkeln wants to merge 1 commit into
tinyfish-io:mainfrom
dunkeln:codex/cancel-tinyfish-on-stop

Conversation

@dunkeln

@dunkeln dunkeln commented Jul 23, 2026

Copy link
Copy Markdown

What changed

  • Build search and fetch tools per dataset run instead of sharing module-level tool instances.
  • Combine each dataset workflow signal with the existing 30-second TinyFish timeout.
  • Propagate user-initiated cancellation as AbortError while preserving recoverable timeout errors.
  • Wire the scoped tools through populate, investigate, and refresh agents.

Why

The stop routes abort the dataset controller and agent generation, but TinyFish requests previously used independent timeout controllers. An in-flight search or fetch could therefore continue after the user stopped the run, consuming time and potentially provider credits.

Impact

Stopping a building or refreshing dataset now also terminates its active TinyFish HTTP request. Concurrent datasets remain isolated because each tool closure captures its authorized dataset ID.

Verification

  • TypeScript compilation with backend/node_modules/.bin/tsc
  • Runtime cancellation probe confirmed Stop propagates AbortError
  • Runtime timeout probe confirmed provider timeout remains a normal tool error
  • Diff whitespace validation passed

Not changed

This does not alter workflow status transitions, retry behavior, TinyFish response contracts, or model configuration.

Stopping a dataset aborted agent generation but left active TinyFish HTTP calls running until their timeout, wasting time and potentially consuming provider credits.

Scope web tools to their authorized dataset and combine the workflow signal with the existing request timeout. User stops now propagate AbortError while provider timeouts remain recoverable tool errors.

This does not change workflow status handling, retry behavior, or TinyFish response contracts.

Co-authored-by: Codex <codex@openai.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Web tools are now constructed per dataset instead of exported as static instances. Their requests combine dataset workflow cancellation with fetch timeouts and rethrow workflow stop reasons. The investigate, populate, and refresh agents build these tools with their authorized dataset IDs while retaining existing tool bindings. Module documentation now describes explicit signal propagation to workflow steps, agents, and TinyFish requests.

Sequence Diagram(s)

sequenceDiagram
  participant Agent
  participant buildWebTools
  participant WebRequest
  Agent->>buildWebTools: build tools with authorizedDatasetId
  buildWebTools->>WebRequest: issue request with combined abort signal
  Agent->>WebRequest: stop workflow when cancellation is triggered
  WebRequest-->>Agent: rethrow workflow abort reason
Loading

Suggested reviewers: simantak-dabhade

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: cancelling dataset runs now stops active TinyFish requests.
Description check ✅ Passed The description matches the changeset and explains the scoped tools, cancellation behavior, and verification steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@dunkeln
dunkeln marked this pull request as ready for review July 25, 2026 22:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/src/mastra/tools/web-tools.ts`:
- Around line 181-185: Update buildWebTools in
backend/src/mastra/tools/web-tools.ts to accept authContext and pass it to both
buildSearchWebTool and buildFetchPageTool so each closure can perform audit
logging and CAPABILITY_VIOLATION tracking. Update the existing buildWebTools
calls in backend/src/mastra/agents/investigate.ts (line 70),
backend/src/mastra/agents/populate.ts (line 52), and
backend/src/mastra/agents/refresh.ts (line 65) to pass their existing
authContext.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d1bbc1b2-2aa6-4474-a161-34098f4c1714

📥 Commits

Reviewing files that changed from the base of the PR and between eca2170 and f9081d9.

📒 Files selected for processing (5)
  • backend/src/abort-registry.ts
  • backend/src/mastra/agents/investigate.ts
  • backend/src/mastra/agents/populate.ts
  • backend/src/mastra/agents/refresh.ts
  • backend/src/mastra/tools/web-tools.ts

Comment on lines +181 to +185
export function buildWebTools(datasetId: string) {
return {
searchWebTool: buildSearchWebTool(datasetId),
fetchPageTool: buildFetchPageTool(datasetId),
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Capture authContext in the web-tool closures.

buildWebTools() accepts only a dataset ID, so these tools cannot perform the required user/run audit logging or CAPABILITY_VIOLATION tracking.

  • backend/src/mastra/tools/web-tools.ts#L181-L185: accept authContext and pass it into both tool factories so each execution closes over it.
  • backend/src/mastra/agents/investigate.ts#L70-L70: pass the existing authContext to buildWebTools.
  • backend/src/mastra/agents/populate.ts#L52-L52: pass the existing authContext to buildWebTools.
  • backend/src/mastra/agents/refresh.ts#L65-L65: pass the existing authContext to buildWebTools.

As per coding guidelines, “Capture authContext (Clerk userId + workflow run id) in tools for security audit logging and CAPABILITY_VIOLATION PostHog event tracking.”

📍 Affects 4 files
  • backend/src/mastra/tools/web-tools.ts#L181-L185 (this comment)
  • backend/src/mastra/agents/investigate.ts#L70-L70
  • backend/src/mastra/agents/populate.ts#L52-L52
  • backend/src/mastra/agents/refresh.ts#L65-L65
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/mastra/tools/web-tools.ts` around lines 181 - 185, Update
buildWebTools in backend/src/mastra/tools/web-tools.ts to accept authContext and
pass it to both buildSearchWebTool and buildFetchPageTool so each closure can
perform audit logging and CAPABILITY_VIOLATION tracking. Update the existing
buildWebTools calls in backend/src/mastra/agents/investigate.ts (line 70),
backend/src/mastra/agents/populate.ts (line 52), and
backend/src/mastra/agents/refresh.ts (line 65) to pass their existing
authContext.

Source: Coding guidelines

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