Long-Horizon Coding
Keep a coding task alive across polls and retries with isolated workspaces and a disk state machine.
Long-Horizon Coding
Use this when a coding job is longer than one chat turn: it must survive polls, stalls, and retries without stuffing the full history into one prompt.
Do not turn this on for a short SDK AgentExecutor.run. That path does not need longrun or project_state.
Orchestrator
agenticx/longrun/ polls task sources, gives each task an isolated workspace, heals stalls, and applies continuation / failure backoff. Token use is counted incrementally (TaskTokenAccountant), not guessed from a single completion.
Shipped sources include a manual queue, cron, and project-feature source. Treat a source as real only if it is wired in longrun/sources/.
Disk state machine
project_state keeps a versioned feature state on disk (init → implement → verify → commit). File locks and atomic writes make the loop auditable after a crash.
Isolated workspace
TaskWorkspace pins the task to its own directory and rejects path escapes (TaskWorkspaceSecurityError). Hooks can fail closed (TaskWorkspaceHookError).
Worked example: keep a feature on disk
Scene. “Add login, with tests” will take many polls. You do not want the next retry to smash the previous workspace.
- Start the job through a wired longrun source (manual queue / cron / project feature in
longrun/sources/). - The orchestrator assigns an isolated
TaskWorkspace. Path escapes raiseTaskWorkspaceSecurityError. - Watch
project_statemove init → implement → verify → commit. A stall detector retries with backoff instead of stuffing the whole history into one prompt. - Token use is incremental (
TaskTokenAccountant).
What you should see. A progress card that names the phase, not a static hourglass. After a crash, the same feature directory and state file are still there to audit.
project_state moving init → implement → verify → commit.Related
- Agent Runtime — single-turn
run_turnvs this multi-poll loop - Studio Server — HTTP routes under
longrun/studio_routes.py - Deployment — where long jobs should not share a laptop lid-sleep session