( runsDir: string, run: RunProgress, )
| 44 | * Failure is best-effort: IO exceptions only log a warn, do not throw (workflow already succeeded; persistence failure only means it cannot be retrieved after restart). |
| 45 | */ |
| 46 | export async function writeRunState( |
| 47 | runsDir: string, |
| 48 | run: RunProgress, |
| 49 | ): Promise<void> { |
| 50 | const dir = join(runsDir, run.runId) |
| 51 | const target = join(dir, STATE_FILE) |
| 52 | const tmp = join(dir, STATE_TMP) |
| 53 | const payload: StateFile = { schemaVersion: SCHEMA_VERSION, run } |
| 54 | try { |
| 55 | await mkdir(dir, { recursive: true }) |
| 56 | await writeFile(tmp, JSON.stringify(payload), 'utf-8') |
| 57 | await rename(tmp, target) |
| 58 | } catch (e) { |
| 59 | logForDebugging( |
| 60 | `[workflow warn] writeRunState failed for ${run.runId}: ${(e as Error).message}`, |
| 61 | ) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Read <runsDir>/<runId>/state.json with fault tolerance: |
no test coverage detected