Skip to content

fix(runner): deliver Pi tool specs via a file instead of an env var (spawn E2BIG) - #6039

Open
mmabrouk wants to merge 1 commit into
release/v0.112.1from
fix-pi-specs-e2big
Open

fix(runner): deliver Pi tool specs via a file instead of an env var (spawn E2BIG)#6039
mmabrouk wants to merge 1 commit into
release/v0.112.1from
fix-pi-specs-e2big

Conversation

@mmabrouk

Copy link
Copy Markdown
Member

Any Pi agent with a large tool set fails every run with Agent run failed: spawn E2BIG, before the model is ever reached. A real session with 44 hydrated Composio tools reproduces it on every turn.

Root cause

buildPiExtensionEnv packed every resolved tool spec into one environment variable (AGENTA_AGENT_TOOLS_PUBLIC_SPECS), which is merged into the daemon env the harness process inherits. Linux rejects execve when any single argv/env string exceeds MAX_ARG_STRLEN (131,072 bytes), so the spawn dies before the harness exists — 44 specs serialize to ~250 KB.

The fix

The specs now ride a file, unconditionally: one code path, no size threshold, because tool JSON Schemas are unbounded and no threshold would be safe.

  • Env carries only the path, under the existing AGENTA_AGENT_TOOLS_PUBLIC_SPECS_FILE name (PUBLIC_SPECS_FILE_ENV) — not a second variable. AGENTA_AGENT_TOOLS_RELAY_DIR is unchanged.
  • The file is a sibling of the relay dir (<relayDir>.tool-specs.json), like the OTLP auth file, because prepareWorkspace clears and recreates the relay dir every turn.
  • Local runs write it in buildRuntimeEnvironment; Daytona runs upload it in prepareDaytonaPiAssets (the sandbox env map is fixed at sandbox creation and the runner's filesystem is not the sandbox's, so the env names a deterministic in-sandbox path and the bytes arrive before the session opens).
  • A delivery failure stops the run with a named message instead of starting an agent whose tools silently vanished (the F-042 failure class).
  • The extension prefers the file and still reads the inline variable for one release, logging which route it used, so a harness started by an older runner keeps working.

This is the pattern the non-Pi stdio MCP shim already uses, for the reason its own comment gives: the env is copied through four exec layers and tool JSON Schemas are unbounded.

Scope

Pi only, and entirely runner-internal — no wire-contract change. Claude Code and Codex were never affected: they get specs over MCP (loopback HTTP) or, on Daytona, through the uploaded specs file.

Testing

  • pnpm test 2185 passed / 127 files, pnpm run typecheck clean. New regression tests cover a 606 KB spec set leaving every env value under 131,072 bytes and round-tripping through the file, the extension read side (file preferred, inline fallback, unreadable/malformed file registers nothing), the Daytona upload path, and both fail-loud paths.
  • Wire-level before/after against a runner served from this source (local sandbox, pi_core, 44 fat tools = 606 KB of specs). With the old inline delivery: {"ok":false,"error":"spawn E2BIG"}. With the fix: the harness spawns and the ACP session opens (sandbox_start, probe_capabilities, create_session all complete); the run then fails only on records-query, because a standalone runner has no Agenta API to rebuild the conversation from.
  • The built bundle dist/extensions/agenta.js — the artifact baked into the runner image — loaded the 606 KB file that run wrote and registered all 44 tools.
  • Not verified: the shared local stack runs the released agenta-runner:v0.112.1 image with no source mount, so it was not rebuilt and the fix was not exercised there; the Daytona upload path is covered by unit tests, not by a live Daytona run.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 14, 2026
@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Blocked Blocked Aug 14, 2026 4:34pm

Request Review

@dosubot dosubot Bot added the bug label Aug 14, 2026
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Pi tool specifications are now delivered through a file, supporting larger configurations without environment-size limitations.
    • Tool specifications are automatically prepared for local and Daytona sandbox sessions.
    • Existing inline configuration remains supported as a fallback.
  • Bug Fixes

    • Improved handling of missing, malformed, or unavailable tool-specification files.
    • Sandbox upload and file-write failures now stop setup safely with clear diagnostics.

Walkthrough

Pi tool specifications now use relay-adjacent JSON files for local and Daytona runs. The Pi extension reads the file first and supports a temporary inline environment fallback. Delivery and parsing failures are logged and fail closed.

Changes

Pi tool specification delivery

Layer / File(s) Summary
Tool-spec delivery contract
services/runner/src/engines/sandbox_agent/pi-assets.ts
Adds deterministic file paths, serialized delivery data, local writes, Daytona uploads, and fail-closed error handling.
Local and Daytona run wiring
services/runner/src/environment/runtime-lifecycle.ts, services/runner/src/engines/sandbox_agent/daytona.ts, services/runner/src/engines/sandbox_agent/environment-setup.ts
Local Pi runs write the specs file. Daytona preparation uploads it before the ACP session. Diagnostics use the shared environment constant.
Extension loading and compatibility
services/runner/src/extensions/agenta.ts
The extension loads valid file-based specifications first, rejects invalid files, logs the source route, and falls back to the legacy inline variable when no file is configured.
Delivery validation and lifecycle documentation
services/runner/tests/unit/extension-tools.test.ts, services/runner/tests/unit/sandbox-agent-pi-assets.test.ts, services/runner/src/lifecycle/reconciliation-router.ts
Tests cover large payloads, precedence, missing or malformed files, deterministic paths, local writes, Daytona uploads, and upload failures. Lifecycle documentation describes the file channel.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to 089a2

The PR replaces oversized environment-variable delivery with file-based tool-spec delivery and includes coverage for local and Daytona paths. No actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Runner
  participant DaytonaSandbox
  participant PiExtension
  Runner->>Runner: Resolve tool specifications
  Runner->>DaytonaSandbox: Upload relay-adjacent JSON file
  Runner->>PiExtension: Set PUBLIC_SPECS_FILE_ENV
  PiExtension->>PiExtension: Read and validate JSON specifications
  PiExtension->>PiExtension: Register advertised tools
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 60.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the spawn E2BIG root cause, file-based fix, compatibility behavior, testing, and known verification limits.
Title check ✅ Passed The title clearly identifies the runner fix and the change from environment-variable delivery to file-based Pi tool-spec delivery.
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 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-pi-specs-e2big

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.

@github-actions

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Preview URL https://gateway-pr-6039.up.railway.app/w
Project agenta-oss-clone-spike
Image tag pr-6039-86795be
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-08-14T16:39:23.165Z

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
services/runner/tests/unit/extension-tools.test.ts (1)

401-428: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Move the fat tool-spec fixture into tests/utils/.

This fixture duplicates fatToolSpecs in services/runner/tests/unit/sandbox-agent-pi-assets.test.ts (lines 449-467): same name pattern, same 40-field schema, same repeat counts. Two copies drift independently, so a later size-limit change touches only one side. Export one generator from tests/utils/ and import it in both test files.

As per coding guidelines, "keep shared helpers and fixtures under tests/utils/".

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 27cc7c0c-afba-4a1f-bf43-050765ca1a3c

📥 Commits

Reviewing files that changed from the base of the PR and between 19b9ab2 and 089a243.

📒 Files selected for processing (8)
  • services/runner/src/engines/sandbox_agent/daytona.ts
  • services/runner/src/engines/sandbox_agent/environment-setup.ts
  • services/runner/src/engines/sandbox_agent/pi-assets.ts
  • services/runner/src/environment/runtime-lifecycle.ts
  • services/runner/src/extensions/agenta.ts
  • services/runner/src/lifecycle/reconciliation-router.ts
  • services/runner/tests/unit/extension-tools.test.ts
  • services/runner/tests/unit/sandbox-agent-pi-assets.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant