iteration_state
Manage retry tracking for individual modules in forge runs. Track attempt counts, scores, and stagnation flags to decide between retrying or escalating failed modules.
Instructions
Read, update, or reset the per-module retry state for a forge run. Tracks attempt count, score history, last status, last root cause from the debugger, and a stagnation flag. In v0.4.0+ state is scoped per run via runId so attempt counts don't accumulate across unrelated forge runs that happen to share a moduleId (pre-v0.4.0 a brand-new m1 in a fresh plan could see attempt: 21 because 20 prior runs had also used "m1" — stagnation detection would then escalate a module that had just started).
Behaviour:
READ (get), MUTATION (update, reset).
State files live at
.forge/iterations/<runId>/<moduleId>.jsonwhen runId is provided, or.forge/iterations/<moduleId>.jsonfor legacy callers.runIdis guarded against path traversal via the_RUN_ID_PATTERNregex (/^[\w.-]{1,128}$/) — invalid values return a structured error, never a traversal attempt.No authentication, no network, no rate limits.
geton an unknown module returns a clean empty-state object{ attempts: [], scores: [], stagnant: false }rather than throwing.
Use when:
The orchestrator wants to know how many times module m3 has been retried so far and whether the stagnation flag has flipped — drives the decision between RETRY and ESCALATE.
A debugger agent wants to inspect the last root cause before proposing a new approach.
Resetting: a plan has finished and the next run should start fresh even if moduleIds are reused. Or a human has manually cleared a stuck module and wants the counter zeroed.
Do NOT use for:
Cross-module reasoning or run-wide progress — that is
session_state.Recording the result of a single validation attempt — that is done automatically by
validateon every call.Inspecting validation results without side effects —
getis safe, butupdatebumps counters and flags.
Returns (get): The full state object
{ attempts: [...], scores: [...], stagnant: bool, lastStatus,
lastRootCause }.
Returns (update): { updated: true, attempt: N, stagnant: bool }.
Returns (reset): A confirmation string.
Example: iteration_state({ moduleId: "m3", action: "get", runId: "2026-04-15-1" }) → { "attempts": [ { "timestamp": "...", "status": "failed", "score": 0.4, "issues": [...] }, { "timestamp": "...", "status": "failed", "score": 0.6, "issues": [...] } ], "scores": [0.4, 0.6], "stagnant": false }
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| moduleId | Yes | Module ID (e.g. m1) | |
| runId | No | Optional run ID (plan slug). Scopes state to the current forge run. Without it, falls back to legacy global-state behavior. | |
| action | Yes | get = read state, update = add attempt, reset = clear state | |
| update | No | Data for update action |