Software factory / Agent workflows
Keep long jobs going
Your agent job works for an hour: it installs packages, runs tests and edits code. If a container stops or a step fails, you do not want to lose the work of the finished steps, or pay for them again.
9 min read
The forge keeps each step that ended. After an eligible infrastructure failure, it can start a replacement from the unfinished step and the last saved files. An uncertain CLI operation blocks this recovery. When a step fails, you start it again with one click.
Start with a working workflow: see Write your first agent workflow.
What the forge keeps
After each step that ends with success, the forge does two things, in this order:
- It saves the
/workspacefolder of the job,.gitincluded. - It keeps the end of the step and its output.
A job with no container (only agent steps that read) has nothing to save.
When a container stops
For an eligible infrastructure failure, the forge starts a new job for the same cell:
- It starts from the first step that did not end with success.
- The steps before it keep their outputs, and do not run again.
- The new container gets the files that the last finished step saved. When no step finished, it checks out the commit again.
- This happens at most 3 times for a cell. After that, the cell fails.
Caution
An eligible unfinished step runs again from its start. An uncertain CLI operation blocks automatic and manual retries. Its effects can happen twice, for example a comment or a command that deploys. Make each step safe to run twice. open_pr keeps the open pull request of its branch, so it does not open a second one.
When a step fails
These end a job with a failure:
- a command that exits with an error
- a tool that the job cannot have
- a model error
- a budget or the time limit of the job
The forge does not run a failed job again by itself. The jobs that need it are skipped, and the run fails.
- Open the run page, and click the failed cell. Read the reason, and the log of its agent.
- Fix the cause, for example a missing secret or a model key.
- Click Retry from failed step.
An eligible failed cell runs again from its first step that did not succeed. An uncertain CLI operation refuses the retry. The steps before it keep their outputs. The jobs that were skipped because of it run too.
From a terminal:
src factory agent-run rerun <run id> --failed
A change to the workflow file does not change a run that started. The retry runs the steps of the run's own workflow code.
Stop a run
On the run page, click Cancel. Each job that has not ended ends as cancelled.
From a terminal: src factory agent-run cancel <run id>.
A cancelled run cannot be retried. Start a new run.
Done
A job with an eligible infrastructure failure can continue, with its files and the outputs of its finished steps. A failed job goes on from its failed step when you click Retry from failed step.
Next
- Budgets and limits: how long a job can run, and what a retry counts.
Preparation and activation
CLI execution remains disabled. A job does not go on in a new job: it stops at the 2-hour limit of one job. Storage preparation can read compatible history.
Preparation alone does not prove the native executor boundary on Cloudflare. Activation also needs fresh image capability proof, private backup restore proof, compatible receivers after a 300-second drain, and pinned CLI authentication proof.
Protected backup recovery
The prepared CLI path records a completed step before it closes the executor. A heartbeat renews the live close owner. It does not destroy that owner's VM during backup.
The native helper stores the source scope, workspace, physical attempt, purpose, and fingerprint before shutdown. It checks that all payload processes stopped before it stores the completed seal receipt. A lost reply replays that receipt without Git or new payload admission. This evidence survives an object reset while the source VM survives. It does not survive destruction of that VM.
Periodic backups freeze the protected writers, archive every file, and check the frozen proof before publication. Resume requires the same current owner and lease. In a Cloudflare container, a backup ends when it holds the freeze for 25 seconds: the scope thaws before the image helper stops a scope that stays frozen for 45 seconds, and the run goes on without that checkpoint. A resume after the run ended, lost its lease, or lost its scope to a newer attempt stops nothing that the newer attempt owns. The 30-second close deadline bounds operation drain. Backup and shutdown stay within the existing physical job deadline. An unresolved write remains uncertain and cannot advance or retry automatically.
Keep pending charges through an update
The queue keeps the existing string usage IDs for older Workers. New callers send structured receipts through a separate internal method. A receiver must report receipt support before a caller sends one. An unsupported receiver leaves the charge pending for its alarm.
A reservation holds money before a paid call starts. It does not enter the final billing ledger. A completed call settles once under its original ID. An unknown call retains its reservation until trusted evidence can settle it. The model-spend counter keeps its source month. Billing records the final charge when it arrives, as for legacy delivery. A call that never started settles to zero, at the latest when its job ends. A call that fails settles when it fails, so the run can try the call again. A provider error before any output (a rate limit, a full model or a server error) settles to zero. A stream that the provider stopped after some output counts its input and the output that came. A call whose answer was lost, or that was cancelled, stays unknown and keeps its reservation, but the run can still try the call again. Pending receipts and unknown calls stay until settlement. A job that ended wakes again only to send a pending charge, never for an unknown call. Delivery retries run independently. An old unresolved record does not block unrelated fresh work that has account room.
While billing is on, reservations use the plan's AI, credits and allowed overage. The account's admin and owner caps still apply. Site and deployment caps apply while billing is off or the account is exempt. Own-key model calls have no forge model charge. Their containers still need billing room. Each controller and executor contributes its own actual runtime after confirmed stop.
Legacy model charge IDs keep durable acknowledgements after the daily ledger expires. Legacy and structured delivery share duplicate checks. A legacy ID cannot add a charge after a structured zero settlement. Reservation checks add each call's rounded selling price before they admit more work.
Clearing either chat advances a saved server generation. Reusing a client run ID after clear creates a new charge identity. Delivery retries keep the old identity and its pending receipt.
Factory and chat calls reserve money atomically in the existing account queue before upstream work. Outstanding holds reduce admission room, including partial holds. Each call owns its final receipt, including billed provider errors and paid chat summaries. Run and step totals do not charge those calls again.
New factory logs save the sum of individual model call prices in the harness state. Snapshots and object recovery keep that sum. Context tiers, cached reads, and cache writes apply to each call. Legacy logs reconstruct exact prices only from retained individual call records, exact price state, or matching actual call receipts. Cached writes also need their original lifetime.
Some legacy snapshots kept totals but removed individual calls. Some older call records also lost the cache-write lifetime. Their exact prices cannot be recovered from those totals. Source preserves the known totals and account evidence as unresolved, including across object reset. It blocks uncertain model replay. It does not use an average, a zero price, or a new charge for an existing settled receipt. Existing settled billing evidence remains settled. Unrelated fresh work and newer receipt delivery continue independently.
A fresh destination restores the exact required archive before native initialization and payload admission. Its execution identity differs from the original source proof. An existing running payload VM cannot gain a new identity through restore.
A replacement workflow runtime refreshes its checkpoint scope, files, signals, and authorization owner together. Cleanup keeps the saved lost lease identity for runtime and stop receipts. Operation admission stays closed after lease expiry. Paired capacity remains held until both stops and account release are acknowledged.
Saved usage keeps its original model, payer, account, and charge ID when the selected model or key source changes. The original identity stays in harness state through snapshots and log transfer. A new model prices only new calls. If old payer evidence is missing, the old usage stays unresolved. A new key cannot establish who paid for an old call.
The live budget guard includes cached reads, five-minute cache writes, and one-hour cache writes. It checks each call before tools or another paid call can run. Durable totals and receipts keep that same price after error, cancellation, or reset.
Clear fences requests that are still resolving their model, reading their body, or waiting for account admission. A request from an old generation cannot start a model after Clear. A cancelled admission that never reached the model settles at zero. Older pending receipts remain available for delivery.
An atomic reservation refusal keeps the account's billing reason. Monthly cap failures remain distinct from billing limits. A network or receipt transport failure does not become a billing refusal. Live chat refusals retain the standard AG-UI error code and reason.