Skip to content

fix(worker): provision pieces used as agent tools; keep piece-not-found as engine error - #13798

Merged
abuaboud merged 2 commits into
mainfrom
fix/provision-agent-tool-pieces
Jun 30, 2026
Merged

fix(worker): provision pieces used as agent tools; keep piece-not-found as engine error#13798
abuaboud merged 2 commits into
mainfrom
fix/provision-agent-tool-pieces

Conversation

@amrdb

@amrdb amrdb commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

What

Two related fixes around piece provisioning and how a missing piece surfaces.

1. Provision pieces referenced as agent tools

A run_agent step (@activepieces/piece-agent) references the pieces it can call through its settings.input.agentTools array (the AGENT_TOOLS prop), not through the step's own pieceName. The worker's extractPiecePackages only walked PIECE/TRIGGER step settings, so a piece used solely as an agent tool was never installed into the sandbox — and the engine then failed to load it at run time.

extractPiecePackages now also collects PIECE-type agent tools (AgentPieceTool) from each step's input.agentTools, deduped against the normal step pieces. FLOW / MCP / KNOWLEDGE_BASE tools are skipped — they have no piece package to install.

2. Revert #13773 — keep piece-not-found as an ENGINE error

#13773 reclassified the engine's PieceNotFoundError as a USER-level error so a missing piece failed the step quietly instead of paging. But a piece that passes provisioning yet cannot be loaded from disk is an install-integrity fault, not a user/config condition — masking it hides the real problem. This restores EngineGenericError('PieceNotFoundError', …) at both piece-loader throw sites (→ INTERNAL_ERROR → failed job + page) and removes the USER-level export.

Why

Both came out of investigating failed EXECUTE_FLOW jobs surfacing PieceNotFoundError (e.g. perplexity-ai@0.2.8 as an agent tool, and store@0.6.15). Fix #1 is the concrete provisioning gap; the revert restores the loud signal so any remaining provisioning/skew faults stay visible rather than silent.

Testing

  • packages/server/worker unit tests — 11/11 green (new agent-tool extraction cases included)
  • npx turbo run lint on worker, @activepieces/shared, @activepieces/engine — 0 errors

@activepieces/shared bumped 0.96.0 → 0.96.1 (PieceNotFoundError export removed).

🤖 Generated with Claude Code

@amrdb amrdb added the bug label Jun 18, 2026
@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

Safe to merge — both code changes are correct and well-scoped; the only open item is a missing update to the workers feature doc.

The provisioning and error-classification changes are straightforward and well-tested. The workers.md feature doc is not updated to reflect that agent tool pieces are now included in the sandbox provisioning pass.

.agents/features/workers.md — the Resolver description needs a one-line update to mention agent tool piece resolution.

Important Files Changed

Filename Overview
packages/server/sandbox/src/lib/cache/flow/flow-provisioning.ts Adds agent tool piece extraction to resolvePieces — scans all steps for PIECE-type steps with agentTools arrays, safely parses each as AgentPieceTool via Zod, deduplicates combined refs, then provisions them alongside regular step pieces. Logic is correct.
packages/server/engine/src/lib/helper/piece-loader.ts Replaces two PieceNotFoundError throws with EngineGenericError('PieceNotFoundError', …), restoring ENGINE-level semantics so a piece that is provisioned but missing from disk surfaces as INTERNAL_ERROR rather than silently failing the step.
packages/core/execution/src/lib/engine/execution-errors.ts Removes the PieceNotFoundError class (USER-level error); piece-not-found conditions now exclusively use EngineGenericError, restoring the original ENGINE/INTERNAL_ERROR classification.
packages/server/engine/test/utils.test.ts Removes the PieceNotFoundError test suite that tested the now-reverted USER-level behavior; the remaining sizeof tests are unaffected.

Reviews (2): Last reviewed commit: "fix(worker): provision pieces referenced..." | Re-trigger Greptile

Comment thread packages/server/worker/src/lib/execute/utils/flow-helpers.ts Outdated
@amrdb
amrdb requested a review from abuaboud June 21, 2026 09:19
amrdb and others added 2 commits June 30, 2026 09:41
Reverts the change from #13773 (9017def). A piece that passes
provisioning but cannot be loaded from disk is an install-integrity
fault, not a user/config condition, so it must surface as INTERNAL_ERROR
and page rather than be masked as a quiet FAILED step.

Restores EngineGenericError('PieceNotFoundError', ...) at both
piece-loader throw sites and removes the USER-level PieceNotFoundError
export. shared bumped 0.96.0 -> 0.96.1 (revert of an export added one
version ago).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A run_agent step references pieces through settings.input.agentTools
(the AGENT_TOOLS prop on @activepieces/piece-agent), not through the
step's own pieceName. extractPiecePackages only walked PIECE/TRIGGER
step settings, so a piece used *solely* as an agent tool was never
provisioned and the engine failed to load it at run time.

Extend extractPiecePackages to also collect PIECE-type agent tools
(AgentPieceTool) from each step's input.agentTools, deduped against the
step pieces. FLOW / MCP / KNOWLEDGE_BASE tools are skipped since they
have no piece package to install.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@abuaboud
abuaboud force-pushed the fix/provision-agent-tool-pieces branch from 867b659 to 174f358 Compare June 30, 2026 07:50

@abuaboud abuaboud left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rebased onto main and re-targeted the agent-tool piece extraction into the refactored provisioning path (flow-provisioning.ts resolvePieces), since the old worker flow-helpers path was removed by the sandbox-pool refactor. Kept the #13773 revert per intent. Typechecks clean (sandbox + core/execution).

@abuaboud
abuaboud merged commit 3c387f9 into main Jun 30, 2026
13 checks passed
@abuaboud
abuaboud deleted the fix/provision-agent-tool-pieces branch June 30, 2026 07:51
@abuaboud abuaboud added 🐛 bug Something isn't working and removed bug labels Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants