Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/release-retained-admission-history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Inactive retained admission history

This supplement remains outside active migrations and runtime imports. It applies
only after the inactive fence reference schema. It snapshots existing decisions
as historical observations, not newly authenticated authorizations. No public or
private hosted database is changed by adding these files.

Immutable decision rows bind operation, channel, owner/epoch, target identity,
expected head/generation and intent. Append-only state observations are recorded
by SQL triggers in the same transaction as current admission mutation. Therefore
failed history persistence rolls back publication event, pointer and consumption.
The channel's current admission can move to a fresh strictly newer epoch only from
an unstopped consumed operation. It cannot reuse a prior operation ID, edit the
old decision, reset stop, or move admitted/consumed state backward. No recovery
exception is implemented. Initial existing states are retained, not reclassified.

The explicit read-only reconcileRetainedPromotion function requires exact stored
consumed decision and stamped publication event agreement. It reports historical
applied revision separately from current head; it cannot authorize a write or
restore an old owner. It does not modify the current promotion function or silently
fall back from failed writes. Normal current-channel admission remains mandatory
for each actual mutation.

This does not authenticate an issuer. Arbitrary SQL/DDL holders can forge new
history or remove guards and remain outside this reference threat model. Missing
policy/semantic/original-artifact evidence cannot be fabricated into the schema.
Authenticated issuance remains held pending server-owned fresh OIDC plus actual
independent release evidence and durable reviewed decision binding described in
release-authenticated-admission-boundary.md. No caller JSON, boolean, fixture or
fresh operation ID can substitute for those proofs. This slice creates no issuer
endpoint, credential, workflow enable, admission mint or automatic transition.

Qualification currently uses actual reference triggers and SQLite transaction
injection, not hosted D1. Before any real migration: test actual D1 semantics,
existing-row integrity, interruption/rollback, size limits and explicit schema
versioning; preserve old state and write-disable on incompatibility. A runtime
rollback must not drop the history/fence or restore unfenced legacy writes.

Consumption additionally requires the exact stamped publication event and current
head/generation inside its transaction; a direct admitted→consumed update without
that proof fails. Historical reconciliation revalidates canonical stored target
bytes/digest/manifest/engine and provenance commit. The state sequence is ordinary
append-only SQL history, not a cryptographic hash chain or proof of issuer identity.
58 changes: 58 additions & 0 deletions tests/publication-core.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,61 @@ for(const scenario of ['legal-rollback','rollback-never-active','publish-formerl
if(scenario==='legal-rollback'){const r=await promoteFenced(db,request,identity,{engineRevision:engine});assert.equal(r.current.revision,a.manifest.revision);assert.equal(r.deliveryVerified,false)}
else await assert.rejects(promoteFenced(db,request,identity,{engineRevision:engine}),/fence-/);
});
async function archivedFixture(t){const f=await fenceFixture(t);f.db.sql.exec(fs.readFileSync('tools/release-coordination/admission-history-reference.sql','utf8'));return f}
test('retained decisions reconcile prior consumed operation after successor publication without writes',async t=>{
const {db,a,b,c}=await archivedFixture(t),op='pub-'+'9'.repeat(32),next='pub-'+'8'.repeat(32);
const {promoteFenced}=await import('../tools/release-coordination/fenced-promotion-reference.mjs');
const {reconcileRetainedPromotion}=await import('../tools/release-coordination/retained-admission.mjs');
const request={...action(1,a,b),operationId:op},identity={operationId:op,owner:'owner-a',epoch:1};
await promoteFenced(db,request,identity,{engineRevision:engine});
db.sql.prepare("UPDATE release_admission SET operation_id=?,epoch=2,target_revision=?,target_digest=?,expected_revision=?,expected_generation=1,state='preparing'").run(next,c.manifest.revision,c.manifest.digest,b.manifest.revision);
db.sql.exec("UPDATE release_admission SET state='admitted'");
await promoteFenced(db,{...action(2,b,c,1),operationId:next},{operationId:next,owner:'owner-a',epoch:2},{engineRevision:engine});
const before=db.sql.prepare('SELECT COUNT(*) AS n FROM release_admission_states').get().n;
const r=await reconcileRetainedPromotion(db,request,identity,engine);
assert.equal(r.applied.revision,b.manifest.revision);assert.equal(r.current.revision,c.manifest.revision);assert.equal(r.productionActionAllowed,false);
assert.equal(db.sql.prepare('SELECT COUNT(*) AS n FROM release_admission_states').get().n,before);
await assert.rejects(reconcileRetainedPromotion(db,request,{...identity,owner:'other'},engine),/mismatch/);
});
test('retained history rolls back with failed atomic publication consumption',async t=>{
const {db,a,b}=await archivedFixture(t);const before=db.sql.prepare('SELECT COUNT(*) AS n FROM release_admission_states').get().n;
db.sql.exec("CREATE TRIGGER injected_history_failure BEFORE INSERT ON release_admission_states WHEN NEW.state='consumed' BEGIN SELECT RAISE(ABORT,'history-failure'); END");
assert.throws(()=>insertFencedEvent(db,a,b),/history-failure/);
assert.equal(db.sql.prepare('SELECT COUNT(*) AS n FROM release_admission_states').get().n,before);
assert.equal(db.sql.prepare('SELECT COUNT(*) AS n FROM content_publication_events').get().n,0);
assert.equal(db.sql.prepare('SELECT revision_id FROM content_publication').get().revision_id,a.manifest.revision);
});
test('retained history and stopped admission cannot be erased or reset',async t=>{
const {db}=await archivedFixture(t);db.sql.exec('UPDATE release_admission SET stopped=1');
assert.throws(()=>db.sql.exec('UPDATE release_admission SET stopped=0'),/immutable-admission/);
assert.throws(()=>db.sql.exec("UPDATE release_admission SET operation_id='pub-88888888888888888888888888888888',epoch=2,state='preparing',stopped=0"),/successor-rejected/);
for(const table of ['release_admission_decisions','release_admission_states']){
assert.throws(()=>db.sql.exec('DELETE FROM '+table),/immutable/);
assert.throws(()=>db.sql.exec('INSERT OR REPLACE INTO '+table+' SELECT * FROM '+table+' LIMIT 1'),/immutable/);
}
assert.throws(()=>db.sql.exec("UPDATE release_admission_decisions SET owner='other'"),/immutable/);
assert.throws(()=>db.sql.exec("UPDATE release_admission_states SET stopped=0"),/immutable/);
});
test('retained lifecycle refuses fabricated consumption without atomic event/head',async t=>{
const {db}=await archivedFixture(t);
assert.throws(()=>db.sql.exec("UPDATE release_admission SET state='consumed'"),/consumption-event-required/);
assert.equal(db.sql.prepare('SELECT state FROM release_admission').get().state,'admitted');
assert.equal(db.sql.prepare('SELECT COUNT(*) AS n FROM release_admission_states').get().n,1);
});
for(const state of ['admitted','consumed'])test('retained reconciliation rejects '+state+' observation without publication event',async t=>{
const {db,a,b}=await archivedFixture(t),op='pub-'+'9'.repeat(32);
if(state==='consumed')db.sql.prepare('INSERT INTO release_admission_states(operation_id,state,stopped) VALUES(?,?,0)').run(op,state);
const {reconcileRetainedPromotion}=await import('../tools/release-coordination/retained-admission.mjs');
await assert.rejects(reconcileRetainedPromotion(db,{...action(1,a,b),operationId:op},{operationId:op,owner:'owner-a',epoch:1},engine),/mismatch/);
});
test('retained reconciliation refuses legacy snapshot with wrong target digest despite exact event',async t=>{
const {db,a,b}=await fenceFixture(t),op='pub-'+'9'.repeat(32);insertFencedEvent(db,a,b);
db.sql.prepare('UPDATE release_admission SET target_digest=?').run('f'.repeat(64));
db.sql.exec(fs.readFileSync('tools/release-coordination/admission-history-reference.sql','utf8'));
const {reconcileRetainedPromotion}=await import('../tools/release-coordination/retained-admission.mjs');
await assert.rejects(reconcileRetainedPromotion(db,{...action(1,a,b),operationId:op},{operationId:op,owner:'owner-a',epoch:1},engine),/target mismatch/);
});
test('new admission after history installation must begin preparing',async t=>{
const {db}=await archivedFixture(t);
assert.throws(()=>db.sql.prepare('INSERT INTO release_admission VALUES(?,?,?,?,?,?,?,?,?,?,?,?)').run('engine:'+'engine-'+'f'.repeat(20),'pub-'+'7'.repeat(32),'owner-b',1,'content-'+'f'.repeat(24),'f'.repeat(64),commit,null,0,'bootstrap','consumed',0),/initial-preparing-required/);
});
51 changes: 51 additions & 0 deletions tools/release-coordination/admission-history-reference.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- INACTIVE supplement to database-fence-reference.sql. No runtime migration.
-- Retains immutable decisions and transactional state history. Not authentication.
CREATE TABLE release_admission_decisions (
operation_id TEXT PRIMARY KEY, channel TEXT NOT NULL, owner TEXT NOT NULL,
epoch INTEGER NOT NULL, target_revision TEXT NOT NULL, target_digest TEXT NOT NULL,
target_commit TEXT NOT NULL, expected_revision TEXT, expected_generation INTEGER NOT NULL,
mode TEXT NOT NULL, UNIQUE(channel,epoch)
);
CREATE TABLE release_admission_states (
sequence INTEGER PRIMARY KEY AUTOINCREMENT,
operation_id TEXT NOT NULL REFERENCES release_admission_decisions(operation_id),
state TEXT NOT NULL CHECK(state IN ('preparing','admitted','consumed')),
stopped INTEGER NOT NULL CHECK(stopped IN (0,1))
);
-- Qualify/back up existing data before a real migration; this only snapshots it.
INSERT INTO release_admission_decisions SELECT operation_id,channel,owner,epoch,target_revision,target_digest,target_commit,expected_revision,expected_generation,mode FROM release_admission;
INSERT INTO release_admission_states(operation_id,state,stopped) SELECT operation_id,state,stopped FROM release_admission;
CREATE TRIGGER admission_decision_no_update BEFORE UPDATE ON release_admission_decisions BEGIN SELECT RAISE(ABORT,'immutable-admission-decision'); END;
CREATE TRIGGER admission_decision_no_delete BEFORE DELETE ON release_admission_decisions BEGIN SELECT RAISE(ABORT,'immutable-admission-decision'); END;
CREATE TRIGGER admission_decision_no_replace BEFORE INSERT ON release_admission_decisions WHEN EXISTS(SELECT 1 FROM release_admission_decisions WHERE operation_id=NEW.operation_id OR rowid=NEW.rowid OR (channel=NEW.channel AND epoch=NEW.epoch)) BEGIN SELECT RAISE(ABORT,'immutable-admission-decision'); END;
CREATE TRIGGER admission_state_no_update BEFORE UPDATE ON release_admission_states BEGIN SELECT RAISE(ABORT,'immutable-admission-state'); END;
CREATE TRIGGER admission_state_no_delete BEFORE DELETE ON release_admission_states BEGIN SELECT RAISE(ABORT,'immutable-admission-state'); END;
CREATE TRIGGER admission_state_no_replace BEFORE INSERT ON release_admission_states WHEN EXISTS(SELECT 1 FROM release_admission_states WHERE sequence=NEW.sequence) BEGIN SELECT RAISE(ABORT,'immutable-admission-state'); END;
CREATE TRIGGER admission_current_no_delete BEFORE DELETE ON release_admission BEGIN SELECT RAISE(ABORT,'admission-current-delete-forbidden'); END;
CREATE TRIGGER admission_current_no_replace BEFORE INSERT ON release_admission WHEN EXISTS(SELECT 1 FROM release_admission WHERE channel=NEW.channel OR operation_id=NEW.operation_id OR rowid=NEW.rowid) BEGIN SELECT RAISE(ABORT,'admission-current-replace-forbidden'); END;
CREATE TRIGGER admission_current_update_guard BEFORE UPDATE ON release_admission BEGIN
SELECT CASE WHEN NEW.state='consumed' AND OLD.state!='consumed' AND NOT EXISTS(
SELECT 1 FROM content_publication_events e JOIN content_publication p ON p.channel=e.channel
WHERE e.operation_id=NEW.operation_id AND e.channel=NEW.channel AND e.to_revision=NEW.target_revision AND e.from_revision=COALESCE(NEW.expected_revision,NEW.target_revision)
AND e.generation=NEW.expected_generation+1 AND e.provenance_commit=NEW.target_commit AND e.intent=CASE WHEN NEW.mode='bootstrap' THEN 'publish' ELSE NEW.mode END
AND e.writer_operation=NEW.operation_id AND e.writer_owner=NEW.owner AND e.writer_epoch=NEW.epoch AND p.revision_id=NEW.target_revision
AND (SELECT MAX(generation) FROM content_publication_events WHERE channel=NEW.channel)=e.generation
) THEN RAISE(ABORT,'consumption-event-required') END;
SELECT CASE WHEN OLD.rowid!=NEW.rowid OR OLD.channel!=NEW.channel THEN RAISE(ABORT,'admission-pointer-identity') END;
SELECT CASE WHEN OLD.operation_id=NEW.operation_id AND (
OLD.owner!=NEW.owner OR OLD.epoch!=NEW.epoch OR OLD.target_revision!=NEW.target_revision OR OLD.target_digest!=NEW.target_digest OR OLD.target_commit!=NEW.target_commit OR OLD.expected_revision IS NOT NEW.expected_revision OR OLD.expected_generation!=NEW.expected_generation OR OLD.mode!=NEW.mode OR
NEW.stopped<OLD.stopped OR (OLD.state='consumed' AND NEW.state!='consumed') OR (OLD.state='admitted' AND NEW.state='preparing') OR (OLD.state='preparing' AND NEW.state='consumed')
) THEN RAISE(ABORT,'immutable-admission-transition') END;
SELECT CASE WHEN OLD.operation_id!=NEW.operation_id AND (
(OLD.state!='consumed' OR OLD.stopped!=0) OR NEW.state!='preparing' OR NEW.stopped!=0 OR NEW.epoch<=OLD.epoch OR EXISTS(SELECT 1 FROM release_admission_decisions WHERE operation_id=NEW.operation_id OR (channel=NEW.channel AND epoch>=NEW.epoch))
) THEN RAISE(ABORT,'admission-successor-rejected') END;
END;
CREATE TRIGGER admission_initial_preparing BEFORE INSERT ON release_admission WHEN NEW.state!='preparing' OR NEW.stopped!=0 BEGIN SELECT RAISE(ABORT,'initial-preparing-required'); END;
CREATE TRIGGER admission_archive_insert AFTER INSERT ON release_admission BEGIN
INSERT INTO release_admission_decisions VALUES(NEW.operation_id,NEW.channel,NEW.owner,NEW.epoch,NEW.target_revision,NEW.target_digest,NEW.target_commit,NEW.expected_revision,NEW.expected_generation,NEW.mode);
INSERT INTO release_admission_states(operation_id,state,stopped) VALUES(NEW.operation_id,NEW.state,NEW.stopped);
END;
CREATE TRIGGER admission_archive_update AFTER UPDATE ON release_admission BEGIN
INSERT INTO release_admission_decisions SELECT NEW.operation_id,NEW.channel,NEW.owner,NEW.epoch,NEW.target_revision,NEW.target_digest,NEW.target_commit,NEW.expected_revision,NEW.expected_generation,NEW.mode WHERE OLD.operation_id!=NEW.operation_id;
INSERT INTO release_admission_states(operation_id,state,stopped) VALUES(NEW.operation_id,NEW.state,NEW.stopped);
END;
26 changes: 26 additions & 0 deletions tools/release-coordination/retained-admission.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Inactive read-only lookup. History records are not authenticated issuer proof.
export async function readRetainedAdmission(db, operationId) {
if (!/^pub-[a-f0-9]{32}$/.test(operationId)) throw Error('Invalid operation');
return db.prepare(`SELECT d.*,s.state,s.stopped FROM release_admission_decisions d
JOIN release_admission_states s ON s.operation_id=d.operation_id
WHERE d.operation_id=? ORDER BY s.sequence DESC LIMIT 1`).bind(operationId).first();
}
import { readPublicationHead, validateBundle } from '../../worker/publication-core.mjs';
// Explicit read-only reconciliation. Does not fall back into a mutating function.
export async function reconcileRetainedPromotion(db, action, identity, engineRevision) {
action=action&&JSON.parse(JSON.stringify(action));identity=identity&&JSON.parse(JSON.stringify(identity));
if(!action || !identity || action.operationId!==identity.operationId || !/^engine-[a-f0-9]{20}$/.test(engineRevision)) throw Error('Invalid reconciliation');
const a=await readRetainedAdmission(db,action.operationId);
const e=await db.prepare('SELECT * FROM content_publication_events WHERE operation_id=?').bind(action.operationId).first();
if(!a || a.state!=='consumed' || a.channel!=='engine:'+engineRevision || a.owner!==identity.owner || a.epoch!==identity.epoch ||
a.target_revision!==action.revision || a.expected_revision!==action.expectedRevision || a.expected_generation!==action.expectedGeneration || a.mode!==action.intent ||
!e || e.channel!==a.channel || e.from_revision!==a.expected_revision || e.to_revision!==a.target_revision || e.provenance_commit!==a.target_commit ||
e.generation!==a.expected_generation+1 || e.intent!==a.mode || e.writer_operation!==a.operation_id || e.writer_owner!==a.owner || e.writer_epoch!==a.epoch) throw Error('Retained admission/event mismatch');
const row=await db.prepare('SELECT * FROM content_revisions WHERE id=?').bind(a.target_revision).first();
if(!row || row.completed!==1 || row.engine!==engineRevision || row.digest!==a.target_digest) throw Error('Retained target mismatch');
const bundle=await validateBundle(JSON.parse(row.bundle_json),engineRevision);
if(bundle.manifest.revision!==a.target_revision || bundle.manifest.digest!==a.target_digest || row.manifest_json!==JSON.stringify(bundle.manifest)) throw Error('Retained target mismatch');
const provenance=await db.prepare('SELECT commit_sha FROM content_publication_provenance WHERE revision_id=?').bind(a.target_revision).first();
if(provenance?.commit_sha!==a.target_commit) throw Error('Retained provenance mismatch');
return {status:'historically-applied',applied:{revision:e.to_revision,generation:e.generation},current:await readPublicationHead(db,engineRevision),productionActionAllowed:false,deliveryVerified:false};
}
Loading