diff --git a/CHANGELOG.md b/CHANGELOG.md index 89aafda..da6dea9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Review fixes — 2026-11-04 + +Close the exhausted host job after a confirmed unmappable retry outcome while +preserving evidence and leaving uncertain writes/timeouts unresolved. Return +`ACTUAL_INPUTS` for unsupported no-output candidate prompt counts instead of +throwing on an empty binding list. The one-job-per-store limit is unchanged. + ## Local candidate — 2026-10-31 Add an opt-in Comic build result 1.1.0 candidate for confirmed no-output diff --git a/docs/offline-orchestration-prototype.md b/docs/offline-orchestration-prototype.md index a4c265f..c07301f 100644 --- a/docs/offline-orchestration-prototype.md +++ b/docs/offline-orchestration-prototype.md @@ -146,8 +146,9 @@ flags. Immutable outcome and result bytes plus terminal linkage must verify. Retry rechecks pinned inputs, prompt, protected outcome and terminal result before allocating IDs and again immediately before dispatch after async mock preflight. IDs are fresh; the prepared event links `retry_of_attempt_id`. -The second attempt always closes the job; there is no third attempt or hidden -retry. Delay is measured conservatively from terminal completion. A caller may +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. The experimental validator lives in `src/comic-manifest/result-candidate.js`; @@ -164,3 +165,23 @@ is a local implementation candidate, not a published contract pin or production consumer adoption. Existing release manifests, v1 validators and fixtures are unchanged. O02/O03 owner review remains pending. Real providers, durable storage, cancellation retries, timeout/integrity mapping and production use are excluded. + +### Confirmed unmappable retry outcomes + +A second attempt with a confirmed, retained provider outcome that cannot map to +Comic Manifest (for example output-validation failure, normalized cancellation, +or a successful response with mismatched output) closes the **host job** after +confirming the `contract-mapping-blocked` event and `job-closed` append. It returns +`status: 'contract-mapping-blocked', job_closed: true`. The prior terminal result +and both provider outcomes remain immutable; no second Comic result or terminal +result link is fabricated. Recovery reports the host job as terminal. + +This closes an exhausted job, not the unresolved contract mapping. Uncertain +outcome/readback/index/close writes and provider timeouts still require +reconciliation and do not claim confirmed closure. The store's existing +one-job lifetime limit remains in force even after confirmed closure. + +The candidate validator's bounded no-output path requires exactly one prompt +binding. Schema-valid productions with zero or multiple prompt bindings receive +`ACTUAL_INPUTS`; validation does not throw or claim support for a broader +transformation path. The stable schema and v1 validation behavior are unchanged. diff --git a/src/comic-manifest/result-candidate.js b/src/comic-manifest/result-candidate.js index 4f965a8..90c6562 100644 --- a/src/comic-manifest/result-candidate.js +++ b/src/comic-manifest/result-candidate.js @@ -27,8 +27,8 @@ export function validateComicBuildResultCandidate(source, productionSource) { || !same(value.inputs, p.inputs)) return failure('PRODUCTION_LINK'); if (['public', 'internal', 'confidential', 'restricted'].indexOf(value.classification) < ['public', 'internal', 'confidential', 'restricted'].indexOf(p.classification)) return failure('CLASSIFICATION'); - if (noOutput && !same(value.execution.transformations[0].input_digests, - [p.inputs.canon.artifact.sha256, p.inputs.prompts[0].identity.sha256])) return failure('ACTUAL_INPUTS'); + if (noOutput && (p.inputs.prompts.length !== 1 || !same(value.execution.transformations[0].input_digests, + [p.inputs.canon.artifact.sha256, p.inputs.prompts[0].identity.sha256]))) return failure('ACTUAL_INPUTS'); const compatible = buildOutputCompatibility(production, { value }); if (compatible) return compatible; const canonical = canonicalJson(value); diff --git a/src/offline-orchestration-prototype/runner.js b/src/offline-orchestration-prototype/runner.js index fcd461c..0a0cc40 100644 --- a/src/offline-orchestration-prototype/runner.js +++ b/src/offline-orchestration-prototype/runner.js @@ -491,6 +491,14 @@ function createRunner({ runtime = defaultRuntime, store = new InMemoryPrototypeS if (!appendConfirmed(store, job.jobId, blocked)) return markUnresolved(job); job.attempts.push(attempt); job.state = 'contract-mapping-blocked'; + // A consumed retry with a confirmed outcome can exhaust the host job + // without inventing a Comic result. Unconfirmed writes still reconcile. + if (attempt.retryOfAttemptId && ['failed', 'cancelled', 'succeeded'].includes(providerResult.status)) { + if (!closeIfTerminal(job, 'retry-contract-mapping-blocked')) return markUnresolved(job); + return freezeDeep({ kind: 'host-outcome', status: 'contract-mapping-blocked', + job_id: job.jobId, attempt_id: attempt.attemptId, execution_id: attempt.executionId, + job_closed: true }); + } return markUnresolved(job, 'contract-mapping-blocked'); }; diff --git a/tests/comic-result-candidate.test.js b/tests/comic-result-candidate.test.js index a400427..197fce3 100644 --- a/tests/comic-result-candidate.test.js +++ b/tests/comic-result-candidate.test.js @@ -24,3 +24,20 @@ for (const kind of ['changed-production', 'fabricated-input', 'changed-tool', 'w if (kind === 'invalid-time') r.execution.finished_at = '2000-01-01T00:00:00Z'; assert.equal(validateComicBuildResultCandidate(JSON.stringify(r), production).valid, false); }); + +for (const promptCount of [0, 2]) test(`no-output candidate diagnoses ${promptCount} prompt bindings without throwing`, () => { + const p = structuredClone(base.production); + p.inputs.prompts = promptCount === 0 ? [] : [p.inputs.prompts[0], { ...p.inputs.prompts[0], binding_id: 'second' }]; + if (promptCount === 0) for (const panel of p.panels) panel.prompt_bindings = []; + const source = JSON.stringify(p); + const validated = validateComicManifest(source); + assert.equal(validated.valid, true); + const r = structuredClone(base.result); + r.inputs = p.inputs; + r.production.identity = validated.identity; + r.execution.transformations[0].input_digests = [p.inputs.canon.artifact.sha256, + ...(promptCount ? [p.inputs.prompts[0].identity.sha256] : [])]; + const report = validateComicBuildResultCandidate(JSON.stringify(r), source); + assert.equal(report.valid, false); + assert.equal(report.diagnostics[0].code, 'ACTUAL_INPUTS'); +}); diff --git a/tests/offline-orchestration-prototype/runner.test.js b/tests/offline-orchestration-prototype/runner.test.js index c6a6be3..e68b497 100644 --- a/tests/offline-orchestration-prototype/runner.test.js +++ b/tests/offline-orchestration-prototype/runner.test.js @@ -981,3 +981,69 @@ test('cancelled retry authorization does not consume a second attempt', async () assert.equal(h.store.readEvents(r.job_id).filter(e => e.type === 'dispatch-started').length, 1); assert.equal((await h.value.retry({ authorizeRetry: true })).result.status, 'complete'); }); + +for (const outcome of ['output-validation', 'cancelled', 'mismatched-success']) test(`confirmed unmappable second ${outcome} closes only the host job and preserves evidence`, async () => { + const clock = createRuntime(); const controller = new AbortController(); let calls = 0; + const h = runner({ runtime: clock.runtime, + mockAdapterFactory: config => { + calls++; + return new MockTextAdapter(outcome === 'mismatched-success' && calls === 2 ? { ...config, content: 'Different synthetic output.' } : config); + }, + onMockCall({ phase }) { if (outcome === 'cancelled' && calls === 2 && phase === 'dispatch-confirmed') setImmediate(() => controller.abort()); } + }); + const first = await h.value.submit(candidateOptions); + const original = h.store.readImmutable(`result:${first.result.result_id}`); + clock.advance(10); + const second = await h.value.retry({ authorizeRetry: true, signal: controller.signal, + mockOutcome: outcome === 'output-validation' ? { kind: outcome } : { kind: 'success', delay_ms: outcome === 'cancelled' ? 5000 : 0 } }); + assert.equal(second.status, 'contract-mapping-blocked'); + assert.equal(second.job_closed, true); + const events = h.store.readEvents(first.job_id); + assert.equal(events.at(-1).type, 'job-closed'); + assert.equal(events.at(-1).reason, 'retry-contract-mapping-blocked'); + const outcomes = events.filter(e => e.type === 'provider-outcome'); + assert.equal(outcomes.length, 2); + const lastOutcome = JSON.parse(h.store.readImmutable(outcomes[1].payload_key)); + assert.equal(lastOutcome.status, outcome === 'cancelled' ? 'cancelled' : outcome === 'mismatched-success' ? 'succeeded' : 'failed'); + if (outcome === 'mismatched-success') assert.equal(lastOutcome.output.content, 'Different synthetic output.'); + assert.deepEqual(h.store.readImmutable(`result:${first.result.result_id}`), original); + assert.equal(events.filter(e => e.type === 'terminal').length, 1); + assert.equal(h.value.inspectRecovery(first.job_id).status, 'terminal'); + await assert.rejects(() => h.value.retry({ authorizeRetry: true }), e => e.code === 'RETRY_NOT_AVAILABLE'); + await assert.rejects(() => h.value.submit({ productionSource }), e => e.code === 'JOB_STORE_LIFETIME_LIMIT'); +}); + +for (const fault of ['outcome-readback', 'mapping-append', 'close-append', 'ambiguous-close']) test(`unmappable retry with ${fault} uncertainty remains unresolved`, async () => { + let armed = false; let unknownEvents = false; let unknownOutcome; + const store = new InMemoryPrototypeStore({ + afterBlobWrite(key) { if (armed && fault === 'outcome-readback' && key.startsWith('provider-outcome:')) unknownOutcome = key; }, + unknownBlob: key => key === unknownOutcome, + beforeAppend(e) { return armed && ((fault === 'mapping-append' && e.type === 'contract-mapping-blocked') || (fault === 'close-append' && e.type === 'job-closed')); }, + afterAppend(e) { if (armed && fault === 'ambiguous-close' && e.type === 'job-closed') { unknownEvents = true; return true; } }, + unknownEvents: () => unknownEvents + }); + const clock = createRuntime(); const h = runner({ store, runtime: clock.runtime }); + const first = await h.value.submit(candidateOptions); clock.advance(10); armed = true; + const second = await h.value.retry({ authorizeRetry: true, mockOutcome: { kind: 'output-validation' } }); + assert.equal(second.status, 'reconciliation-required'); + assert.equal(second.job_closed, undefined); + const inspection = h.value.inspectRecovery(first.job_id); + assert.equal(inspection.read_only, true); + assert.equal(inspection.status, fault === 'ambiguous-close' ? 'reconciliation-required' + : fault === 'close-append' ? 'contract-mapping-blocked' : 'read-only-inspection-required'); + if (!unknownEvents) assert.equal(store.readEvents(first.job_id).some(e => e.type === 'job-closed'), false); + await assert.rejects(() => h.value.retry({ authorizeRetry: true }), e => e.code === 'RETRY_NOT_AVAILABLE'); +}); + +test('a timed-out second attempt preserves uncertainty without closing or fabricating a result', async () => { + const clock = createRuntime(); const h = runner({ runtime: clock.runtime }); + const first = await h.value.submit(candidateOptions); clock.advance(10); + const second = await h.value.retry({ authorizeRetry: true, mockOutcome: { kind: 'timeout' } }); + assert.equal(second.status, 'contract-mapping-blocked'); + assert.equal(second.job_closed, undefined); + const events = h.store.readEvents(first.job_id); + assert.equal(events.some(e => e.type === 'job-closed'), false); + assert.equal(events.filter(e => e.type === 'terminal').length, 1); + assert.equal(events.filter(e => e.type === 'provider-outcome').length, 2); + await assert.rejects(() => h.value.retry({ authorizeRetry: true }), e => e.code === 'RETRY_NOT_AVAILABLE'); +});