spdl.autoresearch.core.write_engine_state

write_engine_state(workdir: Path, *, queued: list[TaskSpec], running: list[TaskSpec], status: str) None[source]

Persist the orchestrator’s queued, running, and status fields.

Writes <workdir>/engine_state.json (creating <workdir> if needed). Specs are serialized via TaskSpec.to_dict(), so they round-trip through read_engine_state().

The write is atomic from a reader’s perspective: the JSON payload is written to a sibling temp file under <workdir> and then moved into place via os.replace(). If the process is interrupted mid-write, engine_state.json either still holds the previous valid checkpoint or — on the very first checkpoint — is simply absent. It is never observed truncated or partially written, so read_engine_state() cannot fail with json.JSONDecodeError from corrupt content on resume.

Parameters:
  • workdir – Directory in which to persist the JSON file.

  • queued – Specs currently waiting in the priority queue.

  • running – Specs currently scheduled as coroutines.

  • status – One of "running", "stopped", or "interrupted", matching the values Orchestrator.run passes to checkpoint.

Returns:

None.