The runtime starts in polyphony-cli and then hands control to a small set of long-lived
components.
When you want to create the initial files deliberately instead of relying on first-run side effects, use:
polyphony initAt startup the CLI:
- initializes tracing, routing local logs into the TUI when active and falling back to local stderr logs if OTLP exporter setup fails
- creates
~/.config/polyphony/config.tomlif it is missing - creates
WORKFLOW.mdwhen it is missing, via a startup modal in TUI mode or automatically in--no-tuimode - seeds
.polyphony/config.tomlin git repos when the checked-in workflow is still generic and local repo wiring is unset, including GitHub and GitLab remote detection where possiblepolyphony initcan also seed tracker/repository/project slug/default branch values directly with--pack,--tracker,--repository,--project-slug, and--default-branch
- loads the merged runtime config from built-in defaults,
~/.config/polyphony/config.toml,WORKFLOW.md, and.polyphony/config.toml - builds the selected tracker and agent registry runtime
- creates the git-backed workspace provisioner
- optionally connects the SQLite state store
- starts
RuntimeService - starts the workflow file watcher
- launches the TUI unless
--no-tuiis set, and falls back to headless mode if the TUI fails
If no agent profiles are configured yet, the orchestrator still polls the tracker and publishes visible issues into the snapshot, but it skips dispatch until an agent is added.
The file watcher is only a nudge. The orchestrator still re-reads WORKFLOW.md defensively on poll
ticks, merges it with the same user config and repo-local config files, and rebuilds hot-reloadable
components so missed filesystem events do not leave the runtime on stale config.
polyphony-orchestrator owns the main loop. On each tick it:
- validates the currently loaded workflow
- defensively re-loads
WORKFLOW.mdand rebuilds hot-reloadable runtime components when it changed - refreshes running issue state
- polls tracker candidates
- respects throttles and concurrency limits
- provisions a workspace for eligible issues
- renders the workflow prompt
- dispatches the selected agent
When an issue is dispatched:
polyphony-workspacecreates or reuses the workspacepolyphony-workspacerunsafter_createorbefore_runhooks when configuredpolyphony-workflowchooses the agent profile and renders the promptpolyphony-agentsselects the provider runtime and starts the agent- Codex app-server sessions can stay alive across multiple
turn/startcalls on the same thread - after each successful live turn, the orchestrator re-checks tracker state before deciding whether to continue
- continuation turns can render a workflow-configured
agent.continuation_prompt, with turn context such asturn_numberandmax_turns - agent events stream back into the orchestrator with live session metadata such as
session_id,thread_id,turn_id, and the app-server PID when available - the orchestrator updates snapshots, saved context, retry state, and budgets from those streamed events
- optional handoff automation can commit the branch, open a PR, run a review pass, and notify humans
- once an outcome has been published,
polyphony-workspacecan run an optionalafter_outcomehook, for examplecargo clean
When WORKFLOW.md changes successfully, future dispatch, retry handling, model discovery, budget
polling, and feedback/automation surfaces use the rebuilt runtime components. In-flight agent
sessions are not restarted automatically.
When pipeline.enabled = true, dispatch_issue() branches into the pipeline path instead
of the single-agent path. The flow becomes:
- The orchestrator creates a run record (
Run) for the issue - If a
planner_agentis configured:- The planner agent is dispatched to the workspace
- On completion, the orchestrator reads
.polyphony/plan.json - Tasks are created from the plan and saved to the state store
- If no planner is configured (static stages):
- Tasks are created directly from the
pipeline.stagesconfig
- Tasks are created directly from the
- Tasks execute sequentially by ordinal:
- The orchestrator selects the agent for each task (task hint → stage config → default)
- Each task's prompt includes the plan, completed task summaries, and task description
- On success, the next task is dispatched
- On failure, the task retries with backoff or re-plans if
replan_on_failureis set
- After all tasks complete:
- The run status is updated to Review or Delivered
- The standard
run_success_handoff()runs (commit, PR, review, feedback)
Runs and tasks are persisted via the state store and restored on startup. The TUI Runs and Tasks views display pipeline progress from the runtime snapshot.
After an attempt finishes, the orchestrator:
- records run metadata when persistence is enabled
- preserves distinct attempt outcomes such as
TimedOutandStalledinstead of flattening them into generic failures - updates workflow status on the tracker when supported
- schedules retries for non-terminal failures
- cleans up workspaces for terminal issues during reconciliation or startup cleanup
polyphony-tui remains a consumer of snapshots rather than a source of orchestration logic.