Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(grants): preserve inherited admission [V4,H16]
Corey Olson477b4255762d
diff --git a/src/gate.js b/src/gate.jsindex 57408a05..c4d71cf7 100644--- a/src/gate.js+++ b/src/gate.js@@ -488,8 +488,12 @@ async function withOneGateSlot(root, action, { landing = false, itemCheck = fals};const inherited = inheritedGateSlot({ root, browser, namedFiles: shortEligible, timing });if (inherited && (!runnerOnly || inherited.runnerExecution)) {- timed(Object.assign(inherited, { inherited: true })).tracker.mark('actionAt');- try { return await action(inherited); }+ timed(Object.assign(inherited, { inherited: true }));+ try {+ await onWait?.({ admitted: true });+ inherited.tracker.mark('actionAt');+ return await action(inherited);+ }finally {try { settleReceipt(inherited); } finally { inherited.release(); }record(inherited);diff --git a/src/machine.js b/src/machine.jsindex d68e3f3a..9a90a012 100644--- a/src/machine.js+++ b/src/machine.js@@ -176,7 +176,8 @@ export const MOVES = [guards: ['joined', 'itemExists', IN_STATE, 'outsideSubmission'], sets: ['item_built_by', 'item_commit', 'item_frozen_digest'], command: 'pullboard intake <PR> --criterion \"...\" --check \"...\"' },{verb: 'claim', from: ['open', 'claimed'], to: 'claimed', by: ['agent', 'coordinator'], refuse: 'NOT_CLAIMABLE',- alsoRefuses: [{ code: 'BAD_DEPENDENCIES', rule: 'persisted prerequisites contain only positive local item ids or exact repo#id references', next: 'restore the item dependencies from their ordered history, then retry' }],+ alsoRefuses: [{ code: 'BAD_DEPENDENCIES', rule: 'persisted prerequisites contain only positive local item ids or exact repo#id references', next: 'restore the item dependencies from their ordered history, then retry' },+ { code: 'ITEM_LEASE_LOST', rule: 'a submit admission renews the same still-live build claim', next: 'claim the item before starting a new submit' }],guards: ['joined', 'itemExists', IN_STATE, 'checkProvesSomething', 'barReady', 'itemNotHeld', 'inLane', 'routeAllows', 'dependenciesVerified', 'notHeldByAnother', 'builderFirstRefusal', 'correctionRefrozen', 'laneOpen', 'lineCapacity', 'oneLiveClaim', 'rowsInForce'],sets: ['item_owner', 'item_lease_until', 'item_frozen_digest'], command: 'pullboard claim <id>',},diff --git a/src/moves/claim.js b/src/moves/claim.jsindex bb23160a..98341c8c 100644--- a/src/moves/claim.js+++ b/src/moves/claim.js@@ -48,6 +48,7 @@ export default Object.freeze({ operation: "claim", order: 13, engine: 1,"BLOCKED": "take another item with pullboard next, or shout the lane it waits on: pullboard shout <lane> \"<text>\"","CRITERION_PROVES_NOTHING": "set a check that fails before the work: pullboard edit <id> --check \"<command>\", or ask the person to accept this one: pullboard check accept <id>","HELD": "take another item: pullboard next",+ "ITEM_LEASE_LOST": "read pullboard show <id>; if the item is free, claim it again for a build or reserve it with pullboard next --verify <id> for a review, then retry","ITEM_HELD": "take another item with pullboard next while the coordinator holds this one","LANE_HELD": "wait for the lane: pullboard next --wait 9 (minutes)","NOT_CLAIMABLE": "take open work: pullboard next",diff --git a/src/submit-admission.js b/src/submit-admission.jsindex 21c7ff86..854311d1 100644--- a/src/submit-admission.js+++ b/src/submit-admission.js@@ -14,6 +14,8 @@ export function submitAdmission(board, itemId, actor, value) {if (item?.item_status !== 'claimed' || item.item_owner !== actor || !(item.item_lease_until > board.clock.now().toISOString())) {throw new Refused('ITEM_LEASE_LOST', 'the submit admission needs the same live claim; claim the item before starting a new submit');}+ const used = board.db.prepare("SELECT 1 FROM event WHERE event_kind IN ('claim','renew') AND json_valid(event_detail) AND json_extract(event_detail,'$.submitAdmission.id')=? LIMIT 1").get(value.id);+ if (used) throw new Refused('USAGE', 'a submit admission id is used once; start a new native admission instead of reusing an old proof');return { id: value.id, commit: value.commit, tree: value.tree };}@@ -33,5 +35,5 @@ export function completesAdmittedSubmit(board, move, item, actor) {.filter(receipt => receipt?.submitAdmission === admission.id);return receipts.length > 0 && receipts.every(receipt => receipt.kind === 'submit' && receipt.item === item.item_id&& receipt.seat === actor && receipt.commit === admission.commit && receipt.tree === admission.tree- && receipt.frozenDigest === item.item_frozen_digest && receipt.sourceClean === true && receipt.exitCode === 0);+ && receipt.frozenDigest === item.item_frozen_digest && receipt.sourceClean === true && Number.isSafeInteger(receipt.exitCode));}diff --git a/test/resources-lease-fixture.js b/test/resources-lease-fixture.jsindex 0b878f9a..92c81428 100644--- a/test/resources-lease-fixture.js+++ b/test/resources-lease-fixture.js@@ -211,6 +211,64 @@ function refuseFreshExpiredSubmit(box, id) {} finally { store.closeBoard(replica); }}+/** Replay the real completed native receipt; changed source or a new claim cannot borrow it. */+function admittedCompletionReplicas(box, id, snapshot) {+ const receipt = store.proofReceipts(box.board, id).findLast(run => run.submitAdmission);+ assert.ok(receipt, 'the real mandatory submit proof carries its admission witness');+ const proof = prepareEngineMove(box.board, 'recordProofRun', [{ agentId: receipt.seat, itemId: id, receiptId: receipt.id }]);+ for (const scenario of ['same admission', 'different commit', 'different tree', 'reclaim', 'historical engine']) {+ let instant = box.clock.now().getTime();+ const clock = { now: () => new Date(instant) };+ const peer = store.openBoard(join(box.dir, `completion-${scenario.replaceAll(' ', '-')}.sqlite`), clock);+ try {+ importBoard(peer, snapshot);+ assert.equal(applyEngineMove(peer, proof, { sequence: appliedSequence(peer) + 1, at: clock.now().toISOString() }).error, undefined);+ const item = store.itemById(peer, id);+ if (scenario === 'reclaim') {+ const options = { agentId: item.item_owner, lane: item.item_lane, leaseMs: 60_000, head: receipt.commit };+ store.claim(peer, id, options);+ assert.throws(() => store.claim(peer, id, { ...options, submitAdmission: {+ id: receipt.submitAdmission, commit: receipt.commit, tree: receipt.tree } }), error => error.code === 'USAGE',+ 'a new claim cannot reuse an earlier admission id');+ store.claim(peer, id, options);+ instant = Date.parse(store.itemById(peer, id).item_lease_until) + 1;+ }+ const move = prepareEngineMove(peer, 'submit', [id, { agentId: receipt.seat,+ commit: scenario === 'different commit' ? '1'.repeat(receipt.commit.length) : receipt.commit,+ tree: scenario === 'different tree' ? '2'.repeat(receipt.tree.length) : receipt.tree,+ submissionProof: { version: 1, files: [], full: false, deferred: true, reason: 'private replay of actual native proof' } }]);+ if (scenario === 'historical engine') move.engine = proof.engine - 1;+ const result = applyEngineMove(peer, move, { sequence: appliedSequence(peer) + 1, at: clock.now().toISOString() });+ assert.equal(result.error?.code, scenario === 'same admission' ? undefined : 'AGENT_GRANT_EXPIRED', scenario);+ } finally { store.closeBoard(peer); }+ }+}++/** Inherit a genuine private lease and prove awaited admission runs before the nested action. */+function inheritedAdmissionProof(box) {+ const program = `+import assert from 'node:assert/strict';+import { takeResource, gateSlotEnvironment } from ${JSON.stringify(pathToFileURL(resolve(import.meta.dirname, '../src/resources.js')).href)};+import { withGateSlot } from ${JSON.stringify(pathToFileURL(resolve(import.meta.dirname, '../src/gate.js')).href)};+const root = process.cwd();+const lease = await takeResource({ name: 'gate', capacity: 2, scope: 'machine', root, agent: 'inherited-admission-control' });+Object.assign(process.env, gateSlotEnvironment(lease));+try {+ let renewed = false;+ await withGateSlot(root, inherited => {+ assert.equal(inherited.inherited, true);+ assert.equal(renewed, true, 'renewal finishes before inherited work starts');+ }, { onWait: async state => { assert.equal(state.admitted, true); await Promise.resolve(); renewed = true; } });+ const lost = new Error('private item lease lost');+ await assert.rejects(withGateSlot(root, () => assert.fail('lost admission must not run'), {+ onWait: async () => { throw lost; },+ }), error => error === lost);+} finally { lease.release(); }+`;+ const result = runFixtureChild(process.execPath, ['--input-type=module', '-e', program], { cwd: box.repo, env: box.env, encoding: 'utf8' });+ assert.equal(result.status, 0, `${result.stdout}\n${result.failure ?? result.stderr}`);+}+/*** Run the queued-lease scenario against the resource suite's private pool helpers.*@@ -300,9 +358,11 @@ export async function queuedLeaseProof(t, deps) {assert.equal(end(buildId, 'check'), runningBuildEnd, 'admission ends build item renewals');assert.ok(runningBuildEnd < box.clock.now().toISOString(), 'the running build resumes ordinary lease expiry');refuseFreshExpiredSubmit(box, buildId);+ const admittedBuild = exportBoard(box.board);writeFileSync(buildGate.release, 'release');assert.equal((await build.finished).code, 0, `${build.stdoutText}\n${build.stderrText}`);assert.equal(item(buildId).item_status, 'submitted', 'the actual queued submit completes its ordinary board move');+ admittedCompletionReplicas(box, buildId, admittedBuild);await waitUntil(() => existsSync(checkGate.events), 'the independent owned check starts');const runningCheckEnd = end(checkId, 'check');box.advance(Date.parse(runningCheckEnd) - box.clock.now().getTime() + 1);@@ -363,6 +423,7 @@ export async function queuedLeaseProof(t, deps) {assert.deepEqual(pool.holders, [], 'failed renewal never leaves a held resource');} finally { result.lease?.release(); }});+ await t.test('an inherited native slot awaits item admission and refuses a lost lease', () => inheritedAdmissionProof(box));} finally {for (const gate of box.gates) writeFileSync(gate.release, 'release');if (holder && !holder.exitResult) await release(holder);