Skip to content

Commit 2328cd3

Browse files
fix(autoplan): name a shell-built snapshot init as the cause of the missing-evidence denial (#3045)
The guard binds a phase entry only to a literal snapshot-init Bash call. When the model resolved the tool path into a variable, chained or piped the call, init ran and succeeded but the denial said 'Complete the existing snapshot init step', which reads as already done, so the run gave up. When no init binds but a Bash call looks like one, the denial now says the shape cannot be bound and prints the literal re-run (answers reused:true). The binding rule is unchanged, and the skill says to run init on its own. Co-authored-by: CharlesBerg85 <[email protected]>
1 parent e77c532 commit 2328cd3

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎autoplan/SKILL.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ Before scope/review:
685685
```bash
686686
bun "<SNAPSHOT_TOOL>" init "<SOURCE_PLAN>" "<ACTIVE_PLAN>" "<RESTORE_PATH>"
687687
```
688+
Run init as its own Bash call with the literal absolute paths: no variables,
689+
substitutions, chaining, pipes or redirects, which the guard cannot bind.
688690
Use returned paths/`scope`; never hand-wrap. init backs up SOURCE_PLAN exactly,
689691
then initializes ACTIVE_PLAN atomically without losing requirements.
690692
Reviewers get only `## Implementation plan`; analysis stays in `## Review record`,

‎autoplan/SKILL.md.tmpl‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ Before scope/review:
215215
```bash
216216
bun "<SNAPSHOT_TOOL>" init "<SOURCE_PLAN>" "<ACTIVE_PLAN>" "<RESTORE_PATH>"
217217
```
218+
Run init as its own Bash call with the literal absolute paths: no variables,
219+
substitutions, chaining, pipes or redirects, which the guard cannot bind.
218220
Use returned paths/`scope`; never hand-wrap. init backs up SOURCE_PLAN exactly,
219221
then initializes ACTIVE_PLAN atomically without losing requirements.
220222
Reviewers get only `## Implementation plan`; analysis stays in `## Review record`,

‎autoplan/bin/phase-publication-hook.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,17 @@ function initArguments(command: unknown, root: string): string[] | undefined {
224224
return args.slice(1);
225225
}
226226

227+
/** Diagnostic only, never binds: a Bash call that ran snapshot init in a shape the guard cannot bind (#3045). */
228+
const UNBINDABLE_INIT = /(?:gstack-autoplan-snapshot|SNAPSHOT_TOOL|\$\{?[A-Z_]+\}?"?)\S*\s+init\s/;
229+
227230
function invocation(events: Event[], root: string): Invocation {
228231
let bound: Invocation | undefined;
229232
let chosen: Record<string, any> | undefined;
233+
let unbindable = false;
230234
for (const use of events) {
231235
if (use.kind !== 'use' || use.name !== 'Bash') continue;
232236
const args = initArguments(use.input?.command, root);
233-
if (!args) continue;
237+
if (!args) { unbindable ||= typeof use.input?.command === 'string' && UNBINDABLE_INIT.test(use.input.command) && /\.md\b/.test(use.input.command); continue; }
234238
const results = events.filter(x => x.kind === 'result' && x.toolUseId === use.toolUseId && x.order > use.order);
235239
if (results.length !== 1) fail('Autoplan initialization acknowledgment is unavailable or ambiguous.');
236240
const text = textResult(results[0]!);
@@ -244,6 +248,10 @@ function invocation(events: Event[], root: string): Invocation {
244248
bound = { activePlan: result.activePlan, restorePath: result.restorePath,
245249
originalSha256: result.originalSha256, start: results[0]!.order };
246250
}
251+
if ((!chosen || !bound) && unbindable)
252+
fail('Autoplan invocation evidence is unavailable: snapshot init ran through a shell variable, substitution, chaining, ' +
253+
'a pipe or a redirect, which this guard cannot bind. Re-run it as one Bash call with the literal absolute paths: ' +
254+
'`bun "<SNAPSHOT_TOOL>" init "<SOURCE_PLAN>" "<ACTIVE_PLAN>" "<RESTORE_PATH>"` (it answers reused:true), then retry this tool.');
247255
if (!chosen || !bound) fail('Autoplan invocation evidence is unavailable. Complete the existing snapshot init step before phase entry.');
248256
const restore = read(bound.restorePath, true), active = read(bound.activePlan);
249257
const reference = JSON.stringify(bound.restorePath).replace(/--/g, '\\u002d\\u002d');

‎test/autoplan-publication-guard.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,29 @@ describe('Autoplan parent publication guard', () => {
483483
});
484484
}
485485

486+
test('#3045: no init at all keeps the generic missing-evidence denial', () => {
487+
const f = fixture(); f.message(); f.current(); f.events.splice(0, 2); f.reorder();
488+
const reason = (f.evaluate() as any).reason;
489+
expect(reason).toContain('Complete the existing snapshot init step');
490+
expect(reason).not.toContain('cannot bind');
491+
});
492+
for (const [name, command] of [
493+
['a resolved-variable init piped to tail', (f: any) => `ST=$(bun -e 'console.log(require("fs").realpathSync(process.argv[1]))' "${ROOT}/bin/gstack-autoplan-snapshot.ts"); bun "$ST" init "${f.source}" "${f.active}" "${f.restore}" 2>&1 | tail -5`],
494+
['an init through a variable from an earlier call', (f: any) => `bun "$SNAPSHOT_TOOL" init "${f.source}" "${f.active}" "${f.restore}"`],
495+
['a chained literal init', (f: any) => `bun "${ROOT}/bin/gstack-autoplan-snapshot.ts" init "${f.source}" "${f.active}" "${f.restore}" && echo done`],
496+
] as const)
497+
test(`#3045: ${name} is named as the cause with the literal re-run; only the literal re-run binds`, () => {
498+
const f = fixture(); f.message(); f.current();
499+
(f.events[0] as any).input.command = command(f);
500+
const reason = (f.evaluate() as any).reason;
501+
expect(reason).toContain('which this guard cannot bind');
502+
expect(reason).toContain('`bun "<SNAPSHOT_TOOL>" init "<SOURCE_PLAN>" "<ACTIVE_PLAN>" "<RESTORE_PATH>"`');
503+
f.events.splice(2, 0, { ...structuredClone(f.events[0]!), toolUseId: 're-init',
504+
input: { command: `bun "${ROOT}/bin/gstack-autoplan-snapshot.ts" init "${f.source}" "${f.active}" "${f.restore}"` } },
505+
{ ...structuredClone(f.events[1]!), toolUseId: 're-init', content: JSON.stringify({ ...f.init, reused: true }) });
506+
f.reorder(); expect(f.evaluate()).toEqual({ allow: true });
507+
});
508+
486509
test('split successful close ranges through EOF are sufficient', () => {
487510
const f = fixture(); f.events.splice(4, 2); f.read('part1', f.packet.closePacketPath, 1, 10);
488511
f.read('part2', f.packet.closePacketPath, 11); f.message(); f.current(); expect(f.evaluate()).toEqual({ allow: true });

0 commit comments

Comments
 (0)