Overview
The worker runner is the core execution environment for Longshot tasks running in Modal sandboxes. It orchestrates the execution of the pi-coding-agent with full filesystem and search capabilities, manages git operations, and produces structured handoff results.Main Function
runWorker()
Executes a coding task in an isolated sandbox environment.
- Reads task payload from
/workspace/task.json - Enables distributed tracing if trace context is provided
- Writes worker instructions to
/workspace/AGENTS.md - Registers custom LLM provider and model
- Creates agent session with full Pi capabilities (7 tools)
- Runs agent prompt with task description
- Performs safety-net commit for uncommitted changes
- Runs post-agent build check (
tsc --noEmit) if TypeScript project - Extracts git diff statistics and metrics
- Writes handoff result to
/workspace/result.json
Helper Functions
buildTaskPrompt()
Constructs the prompt that gets sent to the coding agent.
task- Task object with id, description, scope, acceptance criteria, and branch
Tool Configuration
Full Pi Tools
The worker provides all 7 built-in Pi coding agent tools:read- Read filesbash- Execute shell commandsedit- Edit file contentswrite- Write new filesgrep- Ripgrep-powered content searchfind- Glob-based file searchls- Directory listing
Artifact Filtering
The worker automatically excludes build artifacts from git diffs and metrics:Handoff Structure
The worker produces a structured handoff result:Error Handling
Empty LLM Response Detection
The worker detects and handles empty LLM responses:- Task status is marked as
failed - Concerns include “Empty LLM response — possible API failure”
- Safety-net commit is skipped
- Suggestions provided for troubleshooting
Build Validation
For TypeScript projects, the worker runstsc --noEmit after agent execution:
Environment
Working Directory:/workspace/repo
File Locations:
- Task input:
/workspace/task.json - Result output:
/workspace/result.json - Worker instructions:
/workspace/AGENTS.md
Tracing Integration
The worker supports distributed tracing via trace context propagation:sandbox.agentSessionCreate- Before creating agent sessionsandbox.agentPromptStart- Before running promptsandbox.agentPromptEnd- After prompt completion
toolCallCount- Number of tool invocationstokensUsed- Total tokens consumedfilesChanged- Files modified countlinesAdded/linesRemoved- Code change metricsdurationMs- Total execution time