From a94cce4f553ff244cef1646747ace48c8af19f7e Mon Sep 17 00:00:00 2001 From: Andrew Peris Date: Mon, 9 Nov 2026 17:28:38 +0000 Subject: [PATCH 1/2] Prove simultaneous process resume claim --- docs/o08-durable-resume-decision-packet.md | 59 ++++++++++++----- docs/offline-orchestration-prototype.md | 45 ++++++++----- .../resume-subprocess-worker.mjs | 16 +++++ .../resume-subprocess.test.js | 66 ++++++++++++++++++- 4 files changed, 151 insertions(+), 35 deletions(-) diff --git a/docs/o08-durable-resume-decision-packet.md b/docs/o08-durable-resume-decision-packet.md index 7a95142..f620555 100644 --- a/docs/o08-durable-resume-decision-packet.md +++ b/docs/o08-durable-resume-decision-packet.md @@ -7,13 +7,16 @@ creative material. ## Current evidence and gap -Platform `main` at `e0d31cf9505858aea81f94615dc18eb546197c60` has a bounded -same-process retry and an experimental local file store with atomic claims and -durable writes. The first attempt is retry-eligible only when its verified -provider outcome is the exact rate-limit-before-acceptance case. Explicit retry +At the start of this slice, Platform `main` at `31fd4d0` had bounded +same-process retry and an experimental opt-in local-file resume path with +atomic claims and durable writes. The default prototype remains in-memory. +The first attempt is retry-eligible only when its verified provider outcome is +the exact rate-limit-before-acceptance case. Explicit retry then rechecks current authority and immutable evidence, honors the original deadline and two-attempt limit, and creates one new attempt with a new execution -ID and idempotency key. Recovery after a new runner/process is read-only. +ID and idempotency key. The opt-in synthetic no-context path can resume only +the narrowly eligible first attempt after restart; inspection remains +read-only, and other recovery states are not replayed. The ordinary prototype defaults to in-memory state and monotonic retry timing. The opt-in local-file store supplies the durable primitives used by the @@ -26,10 +29,10 @@ Platform mock currently derives a distinct key for each attempt. No existing contract here states that an arbitrary adapter/provider will honor that key or retain a deduplication record. -Therefore the current safe retry proof does not generalize to replaying an +The original same-process retry proof did not generalize to replaying an uncertain dispatch. A dispatch marker without a verified provider outcome must -remain unresolved. A restart-resume implementation also needs a way to verify -that both the original job deadline and `retry_not_before` remain valid without +remain unresolved. The later bounded resume implementation described below +adds an injected stable time authority to verify both original bounds without resetting the budget or shortening the retry delay. ## Recommended first bounded resume contract @@ -150,10 +153,10 @@ and metadata. No signing key or separate integrity service is introduced. The initial storage slice supplies local persistent store and claim primitives plus restart/corruption tests, but does not reconstruct jobs or dispatch resumed -attempts. The bounded follow-up below adds only read-only candidate -rehydration/classification; it does not consume a claim or dispatch. A later -slice must integrate writable resume and effect authorization. O09 remains open -and is not satisfied by these primitives. +attempts. The bounded follow-up below adds read-only candidate +rehydration/classification; it does not consume a claim or dispatch. The +subsequent writable-resume slice below adds only the approved synthetic +no-context path. O09 remains open and is not satisfied by these primitives. ## Bounded read-only candidate rehydration slice — 2026-11-08 @@ -246,10 +249,12 @@ separate and unaccepted. `resume-subprocess.test.js` seeds only the pinned Comic Manifest fixture in a private temporary local store, then exercises the runner from fresh Node child processes. It verifies: a new process completes attempt two with the original -attempt linkage; two concurrent processes contend while one is paused in -preflight and only one dispatches; process exit immediately after claim leaves -a held claim with no takeover; exit after the durable dispatch marker leaves no -mock effect and no replay; and exit after one mock effect plus a durable but +attempt linkage; two processes are released together at a barrier immediately +before the real atomic claim and yield one claim/second dispatch; a separate +staggered contention case pauses a claim winner in preflight; process exit +immediately after claim leaves a held claim with no takeover; exit after the +durable dispatch marker leaves no mock effect and no replay; and exit after one +mock effect plus a durable but unlinked provider-outcome blob is quarantined without a second mock effect. The test-only worker records every adapter `execute()` entry in a shared temporary per-execution effect log, including normal restarts and both crash @@ -345,6 +350,28 @@ This validates the proposal's scenario logic only. It is not wired to the orchestration runner and does not establish runtime conformance, implement a durable store/time authority, prove storage authenticity, or satisfy O08. +## O08 acceptance evidence map — 2026-11-09 + +This map distinguishes executable prototype evidence from the separate +reference-only proposal model. The proposal harness is not wired into the +runner. + +| Acceptance area | Runner/store evidence | Reference-only or remaining limit | +| --- | --- | --- | +| Candidate boundaries and corrupt state | `resume-candidate.test.js` covers candidate classification; `local-file-store.test.js` covers persistence and corruption. | The proposal harness models additional time/async combinations; those cases do not prove runner behavior. | +| Current authority, protected evidence and retry lineage | `resume-candidate.test.js` and runner retry/resume tests cover denial, evidence validation, attempt linkage and no dispatch on failed gates. | Context-enabled resume and arbitrary providers are excluded. | +| One-shot claims and process contention | Resume/candidate runner tests and `local-file-store.test.js` cover claim behavior. `resume-subprocess.test.js` releases two processes together immediately before `claimResume`, asserting one claim, one second attempt, two total dispatch markers and one mock effect. | A separate test covers staggered preflight contention. Filesystem/OS trust assumptions apply. | +| Restart and crash points | `resume-subprocess.test.js` verifies restart linkage, permanent claim/no takeover, no replay after marker, and quarantine after an unlinked outcome blob; the shared effect log counts actual mock calls. | Process-crash tests do not simulate power loss or prove behavior on other filesystems. | +| Original bounds and attempt ceiling | Candidate boundary and runner resume tests cover the original deadline, inclusive retry bound and two-attempt cap; subprocess events assert second-attempt linkage. | Provider idempotency and generic exactly-once behavior are not established. | +| Async fresh-time/authority matrix | Runner resume tests cover implemented boundaries; `resume-proposal-harness.test.js` enumerates the broader claim/evidence/preflight/marker scenario matrix. | Harness-only cases are reference logic, not runner conformance. | +| Storage bootstrap and integrity | `local-file-store.test.js` covers initialization ordering, immutable writes and corruption handling. | Digests cannot authenticate a record against an actor who can modify both record and digest. | +| Full O08 acceptance | Independent acceptance verdict is pending. | This finite synthetic evidence does not close O08; broader criteria remain open. | + +The simultaneous-process barrier demonstrates one successful claim and at most +one mock effect for this pinned local synthetic fixture. It does not generalize +to other filesystems, production deployment, live providers, or arbitrary +durable-resume implementations. + ## Scope estimate and exclusions The owner-approved local store slice was estimated at 1–2 focused days. The diff --git a/docs/offline-orchestration-prototype.md b/docs/offline-orchestration-prototype.md index 07f5fb6..f477450 100644 --- a/docs/offline-orchestration-prototype.md +++ b/docs/offline-orchestration-prototype.md @@ -8,9 +8,11 @@ Provider Execution and Comic Manifest implementations. Its default path uses one exact public synthetic Comic Manifest fixture, the existing Prompt SDK, and one `MockTextAdapter` instance. An explicitly installed, opt-in path also reads the exact public Context Builder fixture through six bounded synthetic readers -under separate current execution and package-use authority. It does not contact -a provider, use credentials, write to a filesystem, or persist state across -processes. The store is in-memory only. +under separate current execution and package-use authority. Neither path +contacts a provider or uses credentials. The default path uses an in-memory +store; a separate experimental opt-in no-context resume path uses the local +file store described in the O08 packet and persists synthetic state across +processes. Neither path is a production execution service. This implementation was informed by [RFC 0010 at Codex commit `3f5549f29faf1ca3e0912e6b8407dbe19310a7e2`](https://github.com/DefinitelySecureStudio/codex/blob/3f5549f29faf1ca3e0912e6b8407dbe19310a7e2/rfcs/0010-build-attempt-lifecycle.md) @@ -32,11 +34,13 @@ the Comic Manifest schema. - At most two attempts per job and at most one provider call per attempt. - A fixed 300,000 ms monotonic job budget. It is not reset between attempts. - One synthetic mock adapter only. No real providers, network, production - storage, filesystem, scheduler, daemon, credential handling, or automatic - restart continuation. -- Read-only recovery inspection. State uncertainty, integrity mismatch, an - unknown clock epoch, or an expired nonterminal deadline cannot authorize a - write or another provider call. + storage, scheduler, daemon, or credential handling. Only the explicit + experimental no-context resume uses the local filesystem; it is bounded to + the pinned eligible first-attempt rate-limit case. +- `inspectRecovery()` is read-only. The separate opt-in `resume()` path may + continue only that narrow candidate after current checks and a durable + one-shot claim. Uncertainty, integrity mismatch, an unknown clock epoch, or + an expired nonterminal deadline cannot authorize another provider call. - Each prototype instance requires an explicitly installed synthetic execution authority verifier. It rechecks finite preexisting decisions for the exact synthetic production identity, purpose, and action before input use, again @@ -270,19 +274,22 @@ preflight. IDs are fresh; the prepared event links `retry_of_attempt_id`. A confirmed second result or retained unmappable outcome closes the host job; uncertain outcomes or writes remain unresolved. There is no third attempt or hidden retry. Delay is measured conservatively from terminal completion. A caller may -use `closeJob()` instead. A restart can only inspect; it cannot resume retry. +use `closeJob()` instead. With the default in-memory store, a process restart +cannot continue this job. The separate opt-in local-file-store `resume()` path +supports only the narrow no-context candidate documented in the O08 packet. The only retry admission proof in this prototype is the exact normalized mock rate-limit outcome that states the request was rate-limited before acceptance. Each attempt makes at most one provider call and uses a distinct `idempotency_key` derived from its fresh execution ID. The mock does not deduplicate across keys, and the prototype -does not claim cross-attempt or restart deduplication, durable resume, or -exactly-once effects. A retry is an explicit, same-process continuation after -the no-acceptance proof, under the original job deadline and two-attempt cap; -recovery after restart remains read-only. Tests cover denied retry (no second -call), authorized retry (one new call/key on the successful fixture path), -immutable prior result, the second-attempt limit, and read-only recovery. +does not claim cross-attempt or provider-level deduplication, or exactly-once +effects. A retry is an explicit continuation after the no-acceptance proof, +under the original job deadline and two-attempt cap. The experimental +no-context resume path and its limits are documented in the O08 packet. Tests +cover denied retry (no second call), authorized retry (one new call/key on the +successful fixture path), immutable prior result, the second-attempt limit, +and read-only `inspectRecovery()`. The experimental validator lives in `src/comic-manifest/result-candidate.js`; the stable `validateComicManifest` entry point continues to reject 1.1.0. @@ -340,6 +347,8 @@ resource cleanup, and preservation of verified results and immutable evidence; uncertain in-flight outcomes remain unresolved and are never converted into success or absence. New Comic Manifest results for cancellation, timeout, or uncertain external effects require a separate contract decision. This evidence -does not establish O05 or O07 completion or broader production readiness. O08 -and O09 are outside this work; their prerequisites and acceptance criteria are -not assessed here. +does not establish O05 or O07 completion or broader production readiness. O05 +and O07 acceptance remain separate. O08 evidence and remaining acceptance +gates are tracked in the +[durable-resume decision packet](o08-durable-resume-decision-packet.md). O08 +remains open pending independent acceptance; O09 remains separately gated. diff --git a/tests/offline-orchestration-prototype/resume-subprocess-worker.mjs b/tests/offline-orchestration-prototype/resume-subprocess-worker.mjs index 9633659..e358e5a 100644 --- a/tests/offline-orchestration-prototype/resume-subprocess-worker.mjs +++ b/tests/offline-orchestration-prototype/resume-subprocess-worker.mjs @@ -44,6 +44,22 @@ if (mode === 'crash-after-claim') { }; } +if (mode === 'barrier-before-claim') { + const claimResume = store.claimResume.bind(store); + store.claimResume = value => { + const ready = `${process.env.DSS_O08_CLAIM_READY_DIR}/${process.pid}.ready`; + const release = process.env.DSS_O08_CLAIM_RELEASE_MARKER; + writeFileSync(ready, 'ready\n', { flag: 'wx', mode: 0o600 }); + const deadline = Date.now() + 10_000; + const poll = new Int32Array(new SharedArrayBuffer(4)); + while (!existsSync(release)) { + if (Date.now() >= deadline) process.exit(76); + Atomics.wait(poll, 0, 0, 5); + } + return claimResume(value); + }; +} + if (mode === 'crash-after-dispatch-marker') { const append = store.append.bind(store); store.append = event => { diff --git a/tests/offline-orchestration-prototype/resume-subprocess.test.js b/tests/offline-orchestration-prototype/resume-subprocess.test.js index dce58f7..c2380b2 100644 --- a/tests/offline-orchestration-prototype/resume-subprocess.test.js +++ b/tests/offline-orchestration-prototype/resume-subprocess.test.js @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import { spawn } from 'node:child_process'; -import { existsSync, mkdtempSync, readFileSync, rmSync, watch, writeFileSync } from 'node:fs'; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, watch, writeFileSync } from 'node:fs'; import { randomUUID } from 'node:crypto'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; @@ -184,6 +184,70 @@ test('two Node processes contend for one durable claim and only the winner dispa assert.equal(seeded.store.readEvents(seeded.jobId).filter(event => event.type === 'dispatch-started').length, 2); }); +test('two Node processes released together immediately before atomic claim produce one claim and at most one second dispatch', async t => { + const seeded = await seedCandidate(t); + const originalEvents = seeded.store.readEvents(seeded.jobId); + const originalDeadline = originalEvents.find(event => event.type === 'admitted').resume_time.deadline_at_ms; + const originalRetryBound = seeded.window.retry_not_before_at_ms; + const barrier = join(seeded.root, 'claim-barrier'); + const readyDirectory = join(barrier, 'ready'); + mkdirSync(readyDirectory, { recursive: true, mode: 0o700 }); + const release = join(barrier, 'release'); + const effectLog = join(seeded.root, 'synthetic-effects.log'); + const extraEnv = { + DSS_O08_CLAIM_READY_DIR: readyDirectory, + DSS_O08_CLAIM_RELEASE_MARKER: release, + DSS_O08_EFFECT_LOG: effectLog + }; + const first = startWorker(seeded, 'barrier-before-claim', extraEnv); + const second = startWorker(seeded, 'barrier-before-claim', extraEnv); + const readyMarkers = [ + join(readyDirectory, `${first.child.pid}.ready`), + join(readyDirectory, `${second.child.pid}.ready`) + ]; + try { + await waitForFile(readyMarkers[0], readyDirectory, first.child); + await waitForFile(readyMarkers[1], readyDirectory, second.child); + assert.deepEqual(readdirSync(join(seeded.root, 'resume-claims')), []); + + // Both processes are synchronously paused in the claim wrapper. One shared + // release lets them enter the real exclusive claim operation together. + writeFileSync(release, 'release\n', { flag: 'wx', mode: 0o600 }); + const [firstExit, secondExit] = await Promise.all([first.closed, second.closed]); + assert.equal(firstExit.code, 0, firstExit.stderr); + assert.equal(secondExit.code, 0, secondExit.stderr); + const results = [firstExit, secondExit].map(exit => + JSON.parse(exit.stdout.trim().split('\n').at(-1)).result + ); + assert.equal(results.filter(result => result.kind === 'terminal').length, 1); + assert.equal(results.filter(result => result.status === 'resume-claim-held').length, 1); + + const events = seeded.store.readEvents(seeded.jobId); + const prepared = events.filter(event => event.type === 'prepared'); + assert.equal(prepared.length, 2); + assert.equal(prepared[1].retry_of_attempt_id, prepared[0].attempt_id); + assert.equal(events.filter(event => event.type === 'dispatch-started').length, 2); + assert.equal(readdirSync(join(seeded.root, 'resume-claims')).length, 1); + assert.equal(effectCount(effectLog), 1); + assert.equal(seeded.window.retry_not_before_at_ms, originalRetryBound); + assert.equal(events.find(event => event.type === 'admitted').resume_time.deadline_at_ms, originalDeadline); + assert.equal(events.filter(event => event.type === 'prepared').length, 2); + + const restarted = await runWorker(seeded, 'normal', { DSS_O08_EFFECT_LOG: effectLog }); + assert.equal(restarted.code, 0, restarted.stderr); + assert.notEqual(restarted.result.kind, 'terminal'); + assert.equal(effectCount(effectLog), 1); + const afterRestart = seeded.store.readEvents(seeded.jobId); + assert.equal(afterRestart.filter(event => event.type === 'dispatch-started').length, 2); + assert.equal(afterRestart.find(event => event.type === 'admitted').resume_time.deadline_at_ms, originalDeadline); + assert.equal(afterRestart.find(event => event.type === 'resume-window').retry_not_before_at_ms, originalRetryBound); + } finally { + if (!existsSync(release)) writeFileSync(release, 'release\n', { flag: 'wx', mode: 0o600 }); + first.child.kill('SIGKILL'); + second.child.kill('SIGKILL'); + } +}); + test('process death after claim leaves a permanent claim and no takeover', async t => { const seeded = await seedCandidate(t); const crashed = await runWorker(seeded, 'crash-after-claim'); From 6f5caa3ad417bfde522504a810849393819e4de2 Mon Sep 17 00:00:00 2001 From: Andrew Peris Date: Mon, 9 Nov 2026 17:36:26 +0000 Subject: [PATCH 2/2] Cover incomplete concurrent resume claims --- docs/o08-durable-resume-decision-packet.md | 19 +++++++++------ .../resume-subprocess-worker.mjs | 6 +++++ .../resume-subprocess.test.js | 24 ++++++++++++++++++- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/docs/o08-durable-resume-decision-packet.md b/docs/o08-durable-resume-decision-packet.md index f620555..3c93ac5 100644 --- a/docs/o08-durable-resume-decision-packet.md +++ b/docs/o08-durable-resume-decision-packet.md @@ -250,12 +250,17 @@ separate and unaccepted. private temporary local store, then exercises the runner from fresh Node child processes. It verifies: a new process completes attempt two with the original attempt linkage; two processes are released together at a barrier immediately -before the real atomic claim and yield one claim/second dispatch; a separate -staggered contention case pauses a claim winner in preflight; process exit +before the real atomic claim and yield one claim/second dispatch. The contender +may observe either the complete held record or a partial record and fail closed +as `reconciliation-required`. A separate staggered contention case pauses a +claim winner in preflight; process exit immediately after claim leaves a held claim with no takeover; exit after the durable dispatch marker leaves no mock effect and no replay; and exit after one -mock effect plus a durable but -unlinked provider-outcome blob is quarantined without a second mock effect. +mock effect plus a durable but unlinked provider-outcome blob is quarantined +without a second mock effect. A deterministic worker fixture creates an empty +claim record before resume; the runner returns `reconciliation-required`, +performs no second dispatch, and a later process does not take over the partial +record. The test-only worker records every adapter `execute()` entry in a shared temporary per-execution effect log, including normal restarts and both crash points; all call counts are checked against the durable event history. @@ -289,7 +294,7 @@ and zero unauthorized effects. | `retry_not_before >= original_deadline` | No eligible time interval exists; do not resume | 0 | Both original bounds retained | | Time authority epoch is unknown/different, unavailable, or rolled back | Unverifiable; do not resume | 0 | No use of persisted monotonic observation to infer elapsed reboot time | | Authority is denied, expired, revoked, missing, or unverifiable | Deny resume | 0 | No protected evidence read after denial; no dispatch | -| Two runners race to resume the same eligible job | One confirmed claim at most; loser denied/conflict | At most 1 total | Atomic transaction; no automatic takeover; no duplicate dispatch | +| Two runners race to resume the same eligible job | One confirmed claim at most; loser reports held or reconciliation-required if the claim record is not yet complete | At most 1 total | Exclusive claim creation; malformed/partial claims fail closed; no automatic takeover or duplicate dispatch | | Attempt limit already consumed | Exhausted; do not resume | 0 | Existing attempts preserved | | Required event/blob is missing, malformed, corrupt, mismatched, or ambiguous | Quarantine/reconciliation required | 0 | No success-implying write and no provider call | | Persisted bytes and plain hashes are both edited to a self-consistent forgery | Outcome follows selected threat model; hashes alone cannot authenticate it | 0 | Test demonstrates limitation; require a protected chain/root or trusted-storage assumption | @@ -360,8 +365,8 @@ runner. | --- | --- | --- | | Candidate boundaries and corrupt state | `resume-candidate.test.js` covers candidate classification; `local-file-store.test.js` covers persistence and corruption. | The proposal harness models additional time/async combinations; those cases do not prove runner behavior. | | Current authority, protected evidence and retry lineage | `resume-candidate.test.js` and runner retry/resume tests cover denial, evidence validation, attempt linkage and no dispatch on failed gates. | Context-enabled resume and arbitrary providers are excluded. | -| One-shot claims and process contention | Resume/candidate runner tests and `local-file-store.test.js` cover claim behavior. `resume-subprocess.test.js` releases two processes together immediately before `claimResume`, asserting one claim, one second attempt, two total dispatch markers and one mock effect. | A separate test covers staggered preflight contention. Filesystem/OS trust assumptions apply. | -| Restart and crash points | `resume-subprocess.test.js` verifies restart linkage, permanent claim/no takeover, no replay after marker, and quarantine after an unlinked outcome blob; the shared effect log counts actual mock calls. | Process-crash tests do not simulate power loss or prove behavior on other filesystems. | +| One-shot claims and process contention | Resume/candidate runner tests and `local-file-store.test.js` cover claim behavior. `resume-subprocess.test.js` releases two processes together immediately before `claimResume`, asserting one claim, one second attempt, two total dispatch markers and one mock effect. | In the file-creation/write window, a contender may see an incomplete record and return `reconciliation-required`; deterministic coverage confirms fail-closed behavior and no takeover. A separate test covers staggered preflight contention. Filesystem/OS trust assumptions apply. | +| Restart and crash points | `resume-subprocess.test.js` verifies restart linkage, permanent and partial claim/no takeover, no replay after marker, and quarantine after an unlinked outcome blob; the shared effect log counts actual mock calls. | Process-crash tests do not simulate power loss or prove behavior on other filesystems. | | Original bounds and attempt ceiling | Candidate boundary and runner resume tests cover the original deadline, inclusive retry bound and two-attempt cap; subprocess events assert second-attempt linkage. | Provider idempotency and generic exactly-once behavior are not established. | | Async fresh-time/authority matrix | Runner resume tests cover implemented boundaries; `resume-proposal-harness.test.js` enumerates the broader claim/evidence/preflight/marker scenario matrix. | Harness-only cases are reference logic, not runner conformance. | | Storage bootstrap and integrity | `local-file-store.test.js` covers initialization ordering, immutable writes and corruption handling. | Digests cannot authenticate a record against an actor who can modify both record and digest. | diff --git a/tests/offline-orchestration-prototype/resume-subprocess-worker.mjs b/tests/offline-orchestration-prototype/resume-subprocess-worker.mjs index e358e5a..4646cfc 100644 --- a/tests/offline-orchestration-prototype/resume-subprocess-worker.mjs +++ b/tests/offline-orchestration-prototype/resume-subprocess-worker.mjs @@ -1,5 +1,6 @@ import { randomUUID } from 'node:crypto'; import { appendFileSync, existsSync, watch, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; import { createSyntheticExecutionAuthorityVerifier, SYNTHETIC_EXECUTION_PURPOSE } from '../../src/offline-orchestration-prototype/execution-authority.js'; import { createOfflineOrchestrationPrototypeForTest, LocalFilePrototypeStore } from '../../src/offline-orchestration-prototype/testing.js'; import { MockTextAdapter } from '../../src/prompt-sdk/index.js'; @@ -44,6 +45,11 @@ if (mode === 'crash-after-claim') { }; } +if (mode === 'partial-claim-before-resume') { + const partialClaim = join(root, 'resume-claims', `${Buffer.from(jobId).toString('base64url')}.json`); + writeFileSync(partialClaim, Buffer.alloc(0), { flag: 'wx', mode: 0o600 }); +} + if (mode === 'barrier-before-claim') { const claimResume = store.claimResume.bind(store); store.claimResume = value => { diff --git a/tests/offline-orchestration-prototype/resume-subprocess.test.js b/tests/offline-orchestration-prototype/resume-subprocess.test.js index c2380b2..82f27b8 100644 --- a/tests/offline-orchestration-prototype/resume-subprocess.test.js +++ b/tests/offline-orchestration-prototype/resume-subprocess.test.js @@ -220,7 +220,9 @@ test('two Node processes released together immediately before atomic claim produ JSON.parse(exit.stdout.trim().split('\n').at(-1)).result ); assert.equal(results.filter(result => result.kind === 'terminal').length, 1); - assert.equal(results.filter(result => result.status === 'resume-claim-held').length, 1); + const contender = results.find(result => result.kind !== 'terminal'); + assert.ok(contender); + assert.ok(['resume-claim-held', 'reconciliation-required'].includes(contender.status)); const events = seeded.store.readEvents(seeded.jobId); const prepared = events.filter(event => event.type === 'prepared'); @@ -248,6 +250,26 @@ test('two Node processes released together immediately before atomic claim produ } }); +test('a partially published claim fails closed and is not taken over after restart', async t => { + const seeded = await seedCandidate(t); + const effectLog = join(seeded.root, 'synthetic-effects.log'); + const interrupted = await runWorker(seeded, 'partial-claim-before-resume', { + DSS_O08_EFFECT_LOG: effectLog + }); + assert.equal(interrupted.code, 0, interrupted.stderr); + assert.equal(interrupted.result.status, 'reconciliation-required'); + const claimPath = join(seeded.root, 'resume-claims', `${Buffer.from(seeded.jobId).toString('base64url')}.json`); + assert.equal(readFileSync(claimPath).byteLength, 0); + assert.equal(effectCount(effectLog), 0); + assert.equal(seeded.store.readEvents(seeded.jobId).filter(event => event.type === 'dispatch-started').length, 1); + + const restarted = await runWorker(seeded, 'normal', { DSS_O08_EFFECT_LOG: effectLog }); + assert.equal(restarted.code, 0, restarted.stderr); + assert.equal(restarted.result.status, 'reconciliation-required'); + assert.equal(effectCount(effectLog), 0); + assert.equal(seeded.store.readEvents(seeded.jobId).filter(event => event.type === 'dispatch-started').length, 1); +}); + test('process death after claim leaves a permanent claim and no takeover', async t => { const seeded = await seedCandidate(t); const crashed = await runWorker(seeded, 'crash-after-claim');