Skip to content

Journal allocation intent before launch and recover interrupted attempts on restart #2

Closed

Description

@gpu004

Summary

An experiment records an attempt only after its remote lifecycle returns. If the runner is killed after a provider allocates a box but before the attempt row is written, there is no durable pending-allocation record for startup to recover.

Rerunning the experiment sees the scheduled key as missing, generates a fresh UUID/name, and allocates a replacement. The first box can remain live but absent from the saved results.

A Python finally block cannot handle SIGKILL, host failure, or loss of the runner process.

Affected code and verification

Confirmed on published commit 9cb4499:

The same behavior was replayed in the local refactor's scenarios.py and lifecycle.py. Those filenames are not yet in the linked published commit.

Failure path

The desired safety rule is UnrecordedBoxBlocksLaunch: Before retrying an interrupted scheduled attempt, recover its earlier allocation or block further launches while its outcome is uncertain.

The shortest path in the bounded model is:

  1. The experiment is ready.
  2. The provider allocates the first box.
  3. SIGKILL stops the runner before cleanup or result recording.
  4. Restart finds no saved attempt for that key.
  5. The same scheduled attempt allocates a replacement with a fresh name, while the first box remains live.
stateDiagram-v2
    [*] --> Allocated
    Allocated --> Killed: SIGKILL before cleanup and recording
    Killed --> MissingAttempt: experiment rerun
    MissingAttempt --> Replacement: new UUID and create request
    Replacement --> Overlap: original allocation still live
Loading

The replay actually killed a child runner process. A separate local fake-provider allocation file survived it. The next runner used a different name, allocated another box while the first was live, and never included the original name in attempts.jsonl.

Why this matters

Possible consequences include untracked charges, quota exhaustion, and overlap that affects later benchmarking. Interrupted attempts can also disappear from the experiment history.

This does not imply that every killed runner leaks a box indefinitely. Standard provider TTLs or idle expiry can limit the duration. They do not make a retry safe while the original allocation may still exist, and the runner currently records no durable evidence linking that allocation to the interrupted work.

Proposed solution

1. Persist allocation intent before the create request

Introduce a small durable allocation journal or one durable state file per allocation. Store the intent before dispatching any remote create operation.

The record needs:

  • A persistent experiment ID.
  • The scheduled attempt key: block, workload, provider, and scenario where applicable.
  • A unique allocation ID and generation that survive runner restarts.
  • The provider lookup identity or idempotency key actually sent with the create request, when supported.
  • Safe provider/account scope references, not credentials.
  • Phase, timestamps, and the returned box ID once known.

For example, a pending intent could contain:

{
  "schema": 1,
  "experiment_id": "example-experiment",
  "attempt_key": {
    "block": 0,
    "workload": "token",
    "provider": "modal",
    "scenario": "standard"
  },
  "allocation_id": "example-allocation",
  "generation": 1,
  "provider_lookup_name": "benchpress-example-allocation",
  "phase": "create_pending",
  "box_id": null
}

Use durable write ordering. Flush and fsync before dispatching create. If using atomic state-file replacement, write and sync the temporary file, replace it, and sync the containing directory where required. A journal that exists only in a buffered stream does not close the crash window.

2. Recover under the experiment lock before scheduling work

Startup must inspect incomplete intents before building the runnable schedule. Recovery must itself be safe to repeat after another interruption.

Useful durable milestones are:

create_pending
allocated
cleanup_confirmed
result_committed

An unresolved create or cleanup remains blocked. The absence of a completed result is not permission to create a new box.

For a known returned ID, check ownership and remove or verify terminal absence of that exact allocation. If a process died after successful cleanup but before recording it, recovery should recognize an already-removed box and converge to the same resolved state.

Do not reuse a recovered live box as a fresh cold benchmark sample. Finish recovery first, retain the interrupted history, and apply an explicit retry policy.

3. Handle the create-response gap explicitly

There is a harder window: the provider accepts create, but the runner dies before persisting the returned ID. Persisting intent alone cannot provide exactly-once remote allocation.

Use a stable remote identity or provider-supported idempotency key that was already in the durable intent. Recovery can then query that exact identity or safely repeat an idempotent request if the provider contract permits it.

A lookup returning no match immediately after a timeout may be inconclusive because creation or indexing can still be in progress. Do not turn a transient empty result into permission for a new allocation.

Provider limitations need explicit treatment:

  • Namespace already sends the trial name with create.
  • Modal standard mode already sends a name. Verify the SDK's lookup and uniqueness semantics before relying on them.
  • E2B already sends the trial name as metadata. Metadata helps discovery; it is not necessarily a create-idempotency guarantee.
  • Tesser's current create path does not send the local trial name as a stable remote lookup key. A returned ID cannot cover the lost-response window.
  • The local refactor's persistent Modal resume path uses no name and cannot rely on ordinary name lookup after an unconfirmed create.

Where safe identity lookup or idempotency is unavailable, keep the intent unresolved and block for manual reconciliation. Do not guess ownership from a list difference or delete another worker's box. Fully automatic recovery is not a prerequisite for a safe first implementation.

4. Preserve results, ownership, and benchmark semantics

  • Keep recovery state separate from ordinary measurement rows, or update the report schema deliberately. Recovery events must not become duplicate benchmark samples.
  • Give completed rows an allocation identity so a crash after row fsync but before journal completion does not append the result again.
  • Handle interruption during the result append itself. The current JSONL writer is not crash-atomic, and read_rows() rejects a partial trailing row. A parse failure must not bypass recovery or allow new allocations. Any tail-repair policy must preserve unresolved allocation intent and avoid discarding a committed result or appending it twice.
  • Decide how an interrupted measurement is represented as a failed or censored attempt. Do not silently remove it from completion accounting or label a reused allocation as a fresh sample.
  • Preserve actual launch/command timing definitions. Put intent persistence outside the measured launch where appropriate, and account explicitly for any other journal overhead.
  • Keep finally for normal exceptions and graceful interruption. Signal handlers and best-effort shutdown cleanup supplement the journal; they do not replace it.
  • Apply verified ownership checks to cleanup. Existing user-owned boxes must never be swept into recovery deletion.
  • If integrating with burst workers, avoid unsynchronized shared journal writes. Per-allocation files or a single coordinating writer are concrete options. Burst recovery is not verified by the current reproducer.

Regression tests and acceptance criteria

Use a local fake provider that persists allocation state outside the runner process. Kill a subprocess at controlled points, restart, and observe provider create/delete calls and durable results.

  • Kill before create dispatch after intent persistence. Recovery must not make an unsafe allocation decision.
  • Kill after remote create succeeds but before its response is durably recorded.
  • Kill after the returned ID is persisted, during readiness, and during workload execution.
  • Kill during cleanup and after remote removal but before its confirmation is journaled.
  • Kill during result append, flush, and fsync. A partial trailing JSONL row must keep scheduling blocked or be repaired safely, without losing allocation intent or duplicating results.
  • Kill after the final result row is synced but before the allocation is marked complete. Do not duplicate the row.
  • Confirm that a restarted runner either resolves the old allocation first or makes zero new create requests.
  • Repeat recovery interruption and confirm that recovery converges without deleting peer allocations.
  • Treat ambiguous lookup, delayed visibility, provider errors, and malformed recovery state as unresolved rather than successful cleanup.
  • Test providers without a safe lookup identity and confirm a useful, fail-closed manual-recovery error.
  • Preserve healthy completed-attempt skipping and the existing experiment-lock behavior.
  • Record the interrupted attempt according to a documented reporting policy.
  • Update and recheck UnrecordedBoxBlocksLaunch in the bounded model.

Safe reproducer

Use the shared standalone script in #1, under "Safe, standalone reproducer". From the repository root:

python /path/to/reproduce_restart.py --repo "$PWD" --fault kill
python /path/to/reproduce_restart.py --repo "$PWD" --fault none

The affected path prints:

CONFIRMED kill: rerun allocated a new box with box-1 still live

The reproducer replaces only the external Sandbox adapter. It executes the real scheduler, file locking, lifecycle, and result persistence. SIGKILL targets only its child runner, not the invoking shell. It uses no cloud credentials or resources and preserves local evidence files.

The script was run against the published commit and the local refactor. The healthy control passed on both. The original TLA+ model explored 19 states and 24 steps; it models one restart and omits provider expiry and real network behavior. The subprocess replay confirms this specific crash path, not every provider recovery contract.

Relationship and delivery order

#1 blocks startup when a failure row already exists. That is a smaller fix and can land first.

This issue covers the missing-row case. Scanning attempts.jsonl cannot recover work that never reached that file. A pending-allocation journal and a conservative recovery policy are required to close that gap.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions