SuperPi.CodeMode.Journal (super_pi v0.1.0)

Copy Markdown View Source

Deterministic Codemode Replay Journal (Decision 07, Step 8).

When a Codemode script executes nested execute_tool(call_index, tool_name, args) calls inside a durable task (task_id), each completed nested call is persisted in a task-scoped document (scope_kind: "task", scope_id: task_id, kind: "pi.codemode.journal").

If the BEAM node or worker crashes mid-script and TaskEngine.reconcile_on_open!/1 restarts the Codemode task, execute_journaled_tool/5 replays the exact recorded 3-channel result for already completed call_index steps without re-executing external side effects, and only runs live tool execution for unrecorded steps.

Summary

Functions

Executes a nested tool call at deterministic step call_index within task_id.

Runs a sequence of Codemode step specifications [{tool_name, args}, ...] under task_id with automatic crash recovery replay. If simulate_crash_at_index is set, raises after that step so tests can verify deterministic replay on subsequent runs.

Functions

execute_journaled_tool(task_id, call_index, tool_name, args, executor_fun)

Executes a nested tool call at deterministic step call_index within task_id.

  • If (call_index, tool_name, args) is already recorded in pi.codemode.journal for task_id, returns {:replayed, cached_result} without invoking executor_fun.
  • Otherwise invokes executor_fun.(tool_name, args), persists the result in pi.codemode.journal, and returns {:executed, fresh_result}.

run_script(task_id, steps_spec, executor_fun, opts \\ [])

Runs a sequence of Codemode step specifications [{tool_name, args}, ...] under task_id with automatic crash recovery replay. If simulate_crash_at_index is set, raises after that step so tests can verify deterministic replay on subsequent runs.