Skip to content

Commit 26c51f0

Browse files
bradygasterCopilot
andauthored
fix(gh-aw): submit bootstrap chunks without agent transcription (#2115)
* fix(gh-aw): submit bootstrap chunks without agent transcription Closes #2112 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * fix(ci): seed immutable actions in native workflow consumer Closes #2112 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 59bedd0 commit 26c51f0

8 files changed

Lines changed: 291 additions & 71 deletions

File tree

‎.github/workflows/squad-ci.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@ jobs:
791791
test "$(find .github/workflows -maxdepth 1 -name 'squad*.md' | wc -l | tr -d ' ')" = 8
792792
test "$(find .github/workflows/shared -type f ! -name 'squad-bootstrap-trigger-probe.json' | wc -l | tr -d ' ')" = 17
793793
test "$(find .github/skills/gh-aw-enlistment -type f | wc -l | tr -d ' ')" = 1
794+
node --input-type=module -e '
795+
import { compileWithPinnedActions } from "./.github/workflows/shared/squad-install-verifier.mjs";
796+
compileWithPinnedActions(process.cwd());
797+
'
794798
gh aw compile --strict --approve --no-check-update
795799
for workflow in squad squad-implement-worker squad-review squad-deps-worker squad-retro squad-improvement-worker squad-bootstrap squad-command-router; do
796800
gh aw compile "$workflow" --strict --no-check-update

‎docs/src/content/docs/guide/gh-aw.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ validated payload:
150150
- a draft Cast PR on `squad/bootstrap-cast`; and
151151
- `[Research Proposals] Agent-discovered repo opportunities`.
152152

153+
Bootstrap submits the shared payload through one authenticated command. Runtime
154+
code assembles and validates its bounded chunks, then passes JSON directly to
155+
the existing typed safe-output tool; the agent never copies chunks into tool
156+
arguments. Missing, duplicate, reordered, malformed, oversized, or mismatched
157+
payloads fail closed before submission, and the write job independently
158+
revalidates the payload. A submission error is terminal, not permission to retry.
159+
153160
Review and merge the Cast PR, then rerun `/squad triage` on the linked issue to
154161
classify its existing bootstrap proposals. If a proposal needs deeper or newer
155162
evidence, use one of the issue's focused `/squad research ...` commands first;

‎test/gh-aw-bootstrap-workflow.test.ts‎

Lines changed: 130 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { afterAll, describe, expect, it } from 'vitest';
22
import {
33
cpSync,
4+
chmodSync,
5+
existsSync,
46
mkdirSync,
57
mkdtempSync,
68
readFileSync,
@@ -12,6 +14,7 @@ import { createHash } from 'node:crypto';
1214
import { dirname, join, resolve } from 'node:path';
1315
import { tmpdir } from 'node:os';
1416
import { fileURLToPath } from 'node:url';
17+
import { parse } from 'yaml';
1518
import {
1619
BOOTSTRAP_BRANCH,
1720
BOOTSTRAP_ISSUE_MARKER,
@@ -375,6 +378,48 @@ function validateFixture(
375378
);
376379
}
377380

381+
function submissionFixture() {
382+
const fixture = createFixture();
383+
const targetBytes = 40_843;
384+
const remaining = targetBytes - Buffer.byteLength(JSON.stringify(fixture.payload));
385+
const rationale = ' Repository evidence informs this proposed specialist; human review is required before activation.';
386+
fixture.payload.pr_body += rationale.repeat(Math.ceil(remaining / rationale.length)).slice(0, remaining);
387+
const text = JSON.stringify(fixture.payload);
388+
expect(Buffer.byteLength(text)).toBe(targetBytes);
389+
writeFileSync(fixture.payloadPath, text);
390+
const envelope = createBootstrapPayloadEnvelope(text) as Record<string, string>;
391+
expect(envelope.payload_chunk_count).toBe('7');
392+
const envelopePath = join(fixture.root, 'envelope.json');
393+
writeFileSync(envelopePath, JSON.stringify(envelope));
394+
const capture = join(fixture.root, 'calls.jsonl');
395+
const proxy = join(fixture.root, 'bin/safeoutputs');
396+
write(fixture.root, 'bin/safeoutputs', `#!${process.execPath}
397+
const fs = require('node:fs');
398+
const args = process.argv.slice(2);
399+
if (JSON.stringify(args) !== JSON.stringify(['materialize_bootstrap', '.'])) process.exit(2);
400+
const input = JSON.parse(fs.readFileSync(0, 'utf8'));
401+
if (Object.values(input).some(value => typeof value !== 'string' || Buffer.byteLength(value) > 10240)) process.exit(3);
402+
fs.appendFileSync(process.env.CAPTURE, JSON.stringify(input) + '\\n');
403+
if (process.env.PROXY_FAIL === '1') { console.error('proxy rejected request'); process.exit(4); }
404+
console.log('tool accepted');
405+
`);
406+
chmodSync(proxy, 0o700);
407+
const env = {
408+
...process.env,
409+
PATH: `${join(fixture.root, 'bin')}:${process.env.PATH}`,
410+
CAPTURE: capture,
411+
GITHUB_WORKSPACE: fixture.root,
412+
GITHUB_REPOSITORY: 'octo/example',
413+
DEFAULT_BRANCH: 'main',
414+
};
415+
const submit = (overrides = {}) => spawnSync(process.execPath, [
416+
VALIDATOR, '--submit-envelope', envelopePath,
417+
'--root', fixture.root, '--payload', fixture.payloadPath,
418+
'--repository', 'octo/example', '--default-branch', 'main', '--link-mode', 'placeholder',
419+
], { env: { ...env, ...overrides }, encoding: 'utf8' });
420+
return { ...fixture, text, envelope, envelopePath, capture, proxy, env, submit };
421+
}
422+
378423
function compileWorkflow(source = WORKFLOW): string {
379424
const root = mkdtempSync(join(tmpdir(), 'gh-aw-bootstrap-compile-'));
380425
workspaces.push(root);
@@ -601,12 +646,8 @@ describe('automatic Squad bootstrap workflow', () => {
601646
});
602647

603648
it('fails closed for every chunk transport corruption class', () => {
604-
const payloadText = JSON.stringify({
605-
shared: 'Cast and research stay in one validated payload.',
606-
content: 'x'.repeat(PAYLOAD_CHUNK_BYTES * 2),
607-
});
608-
const valid = createBootstrapPayloadEnvelope(payloadText) as Record<string, string>;
609-
expect(Number(valid.payload_chunk_count)).toBeGreaterThanOrEqual(3);
649+
const fixture = submissionFixture();
650+
const valid = fixture.envelope;
610651

611652
const mutations: Array<[string, (envelope: Record<string, string>) => void, RegExp]> = [
612653
['missing', (envelope) => delete envelope.payload_chunk_00, /payload_chunk_00 is missing/],
@@ -653,6 +694,8 @@ describe('automatic Squad bootstrap workflow', () => {
653694
/decoded length does not match|length mismatch/,
654695
],
655696
['hash mismatch', (envelope) => { envelope.payload_sha256 = '0'.repeat(64); }, /SHA-256 mismatch/],
697+
['noncanonical count', (envelope) => { envelope.payload_chunk_count = '07'; }, /canonical decimal/],
698+
['invalid slot', (envelope) => { envelope.payload_chunk_16 = '16:QQ=='; }, /not a valid fixed chunk slot/],
656699
[
657700
'trailing data',
658701
(envelope) => {
@@ -680,7 +723,74 @@ describe('automatic Squad bootstrap workflow', () => {
680723
() => reconstructBootstrapPayload(envelope),
681724
`${name} corruption must fail closed`,
682725
).toThrow(error);
726+
writeFileSync(fixture.envelopePath, JSON.stringify(envelope));
727+
const result = fixture.submit();
728+
expect(result.status, name).not.toBe(0);
729+
expect(result.stderr, name).toMatch(error);
730+
expect(existsSync(fixture.capture), `${name} must not invoke safeoutputs`).toBe(false);
731+
}
732+
});
733+
734+
it('submits seven chunks through the authenticated runner without printing or transcribing them', () => {
735+
const fixture = submissionFixture();
736+
cpSync(resolve(ROOT, 'workflows/shared'), join(fixture.root, '.github/workflows/shared'), { recursive: true });
737+
write(fixture.root, '.github/workflows/squad-bootstrap-payload.json', fixture.text);
738+
const config = parse(WORKFLOW.split('---')[1]);
739+
const prepare = config['pre-agent-steps'].find(
740+
(step: { name: string }) => step.name === 'Prepare authenticated bootstrap validator',
741+
);
742+
const setup = spawnSync('bash', ['-c', prepare.run], { env: fixture.env, encoding: 'utf8' });
743+
expect(setup.status, setup.stderr).toBe(0);
744+
const result = spawnSync(
745+
join(fixture.root, '.github/workflows/run-squad-bootstrap-validator'),
746+
[],
747+
{ env: fixture.env, encoding: 'utf8' },
748+
);
749+
expect(result.status, result.stderr).toBe(0);
750+
expect(result.stdout).toBe('Squad bootstrap validation passed; materialize_bootstrap submitted.\n');
751+
const calls = readFileSync(fixture.capture, 'utf8').trim().split('\n');
752+
expect(calls).toHaveLength(1);
753+
expect(JSON.parse(calls[0])).toEqual(fixture.envelope);
754+
expect(reconstructBootstrapPayload(JSON.parse(calls[0]))).toBe(fixture.text);
755+
expect(result.stdout.length).toBeLessThan(100);
756+
expect(result.stderr).toBe('');
757+
});
758+
759+
it('rejects schema, repository, Cast, and stale payload mutations before submitting', () => {
760+
for (const mutate of [
761+
(payload: ReturnType<typeof createFixture>['payload']) => { payload.schema_version = '2'; },
762+
(payload: ReturnType<typeof createFixture>['payload']) => { payload.repository = 'other/repo'; },
763+
(payload: ReturnType<typeof createFixture>['payload']) => { payload.default_branch = 'other'; },
764+
(payload: ReturnType<typeof createFixture>['payload']) => { payload.files[0].content += '\nchanged'; },
765+
]) {
766+
const fixture = submissionFixture();
767+
mutate(fixture.payload);
768+
const text = JSON.stringify(fixture.payload);
769+
writeFileSync(fixture.payloadPath, text);
770+
writeFileSync(fixture.envelopePath, JSON.stringify(createBootstrapPayloadEnvelope(text)));
771+
const result = fixture.submit();
772+
expect(result.status).not.toBe(0);
773+
expect(result.stderr).toContain('Squad bootstrap validation failed');
774+
expect(existsSync(fixture.capture)).toBe(false);
683775
}
776+
const fixture = submissionFixture();
777+
writeFileSync(fixture.payloadPath, `${fixture.text}\n`);
778+
expect(fixture.submit().stderr).toContain('does not match the generated payload bytes');
779+
expect(existsSync(fixture.capture)).toBe(false);
780+
});
781+
782+
it('fails explicitly without retries when the mounted tool fails or is unavailable', () => {
783+
const fixture = submissionFixture();
784+
const failed = fixture.submit({ PROXY_FAIL: '1' });
785+
expect(failed.status).not.toBe(0);
786+
expect(failed.stderr).toContain('proxy rejected request');
787+
expect(failed.stderr).toContain('Do not retry');
788+
expect(readFileSync(fixture.capture, 'utf8').trim().split('\n')).toHaveLength(1);
789+
rmSync(fixture.proxy);
790+
const unavailable = fixture.submit({ PATH: join(fixture.root, 'bin') });
791+
expect(unavailable.status).not.toBe(0);
792+
expect(unavailable.stderr).toContain('ENOENT');
793+
expect(unavailable.stdout).toBe('');
684794
});
685795

686796
it('enforces encoder total-size and fixed chunk-count bounds', () => {
@@ -738,6 +848,10 @@ describe('automatic Squad bootstrap workflow', () => {
738848
expect(lock).toContain('"payload_sha256"');
739849
expect(lock).not.toMatch(/"materialize-bootstrap":\{"inputs":\{"payload":/);
740850
expect(lock).toContain('reconstructBootstrapPayload(items[0])');
851+
expect(lock).toContain('mcp-cli');
852+
expect(lock).toContain('--submit-envelope');
853+
expect(parse(lock).jobs.agent.env.DEFAULT_BRANCH).toBe('${{ github.event.repository.default_branch }}');
854+
expect(parse(WORKFLOW.split('---')[1]).tools['cli-proxy']).toBe(true);
741855
expect(lock).toContain('SQUAD_BOOTSTRAP_INSTALL_SHA: ${{ github.sha }}');
742856
expect(lock).toContain('SQUAD_BOOTSTRAP_REPOSITORY: ${{ github.repository }}');
743857
expect(lock).toContain('SQUAD_BOOTSTRAP_RUN_ID: ${{ github.run_id }}');
@@ -762,6 +876,16 @@ describe('automatic Squad bootstrap workflow', () => {
762876
);
763877
}, 180000);
764878

879+
it('detects a compiled mutation that removes the file-backed safe-output CLI', () => {
880+
const assertMounted = (lock: string) => {
881+
const agent = parse(lock).jobs.agent;
882+
expect(agent.steps.some((step: { id?: string }) => step.id === 'mount-mcp-clis')).toBe(true);
883+
expect(lock).toContain('GH_AW_MCP_CLI_SERVERS=\'["safeoutputs"]\'');
884+
};
885+
assertMounted(compileWorkflow());
886+
expect(() => assertMounted(compileWorkflow(WORKFLOW.replace(' cli-proxy: true\n', '')))).toThrow();
887+
}, 180000);
888+
765889
it('declares deterministic output bounds and paginated recovery checks', () => {
766890
expect(WORKFLOW).toContain('max: 1');
767891
expect(WORKFLOW).toContain("state: 'all'");

‎test/gh-aw-quality.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3992,6 +3992,57 @@ describe('gh-aw: canonical package integrity contract', () => {
39923992
120_000,
39933993
);
39943994

3995+
it('seeds native-consumer CI pins without usable authentication and rejects tampering', () => {
3996+
const workflow = parseDocument(readText(join(process.cwd(), '.github/workflows/squad-ci.yml'))).toJS();
3997+
const step = workflow.jobs['gh-aw-compile'].steps.find(
3998+
(candidate: { name?: string }) => candidate.name === 'Verify a clean native package consumer',
3999+
);
4000+
const seed = step.run.match(/node --input-type=module -e '([\s\S]*?)'/)?.[1];
4001+
expect(seed, 'native consumer must execute the version-bound pin helper').toBeDefined();
4002+
expect(step.run.indexOf('compileWithPinnedActions(process.cwd())'))
4003+
.toBeLessThan(step.run.indexOf('gh aw compile --strict --approve'));
4004+
expect(step.run).toContain('--verify-install');
4005+
expect(step.run).toContain('--strict-compile');
4006+
4007+
const root = makeConsumer(revisionA, true, 'package');
4008+
execFileSync('git', ['init', '--quiet'], { cwd: root });
4009+
execFileSync('git', ['remote', 'add', 'origin', 'https://github.com/example/squad-consumer.git'], { cwd: root });
4010+
// A deliberately invalid test credential prevents fallback to local keychain authentication.
4011+
const env = { ...process.env, GH_TOKEN: 'invalid-test-token', GITHUB_TOKEN: '' };
4012+
const compile = () => execFileSync('gh', ['aw', 'compile', '--strict', '--no-check-update'], {
4013+
cwd: root, env, stdio: 'pipe', timeout: 120_000,
4014+
});
4015+
const lockPath = join(root, '.github/workflows/squad.lock.yml');
4016+
compile();
4017+
const unpinned = readText(lockPath);
4018+
expect(createHash('sha256').update(normalizeCompiledLock(unpinned, revisionA)).digest('hex'))
4019+
.toBe('bf54175720e6e9ab3fe5d5e3054c28f3a69595c95cdf50e56f9b30988158270f');
4020+
expect(verifyInstall(root).failures.join('\n')).toContain('Installed digest mismatch');
4021+
4022+
const seedPins = () => spawnSync(process.execPath, ['--input-type=module', '-e', seed!], {
4023+
cwd: root, env, encoding: 'utf8', timeout: 120_000,
4024+
});
4025+
const seeded = seedPins();
4026+
expect(seeded.status, seeded.stderr).toBe(0);
4027+
compile();
4028+
expect(verifyInstall(root, { expectedRevision: revisionA, strictCompile: true }).failures).toEqual([]);
4029+
const contract = JSON.parse(readText(join(root, CONTRACT_DESTINATION)));
4030+
for (const entry of contract.workflows) {
4031+
const lock = readText(join(root, entry.lock));
4032+
expect(() => validateCompilerActionPins(lock)).not.toThrow();
4033+
expect(createHash('sha256').update(normalizeCompiledLock(lock, revisionA)).digest('hex'))
4034+
.toBe(entry.package_lock_sha256);
4035+
}
4036+
4037+
const pinPath = join(root, '.github/aw/actions-lock.json');
4038+
const pins = JSON.parse(readText(pinPath));
4039+
pins.entries[`github/gh-aw-actions/setup@${MIN_GH_AW_VERSION}`].sha = '0'.repeat(40);
4040+
writeFileSync(pinPath, JSON.stringify(pins));
4041+
const tampered = seedPins();
4042+
expect(tampered.status).not.toBe(0);
4043+
expect(tampered.stderr).toContain('missing or noncanonical pin');
4044+
}, 120_000);
4045+
39954046
function updateOwnedDigest(root: string, destination: string): void {
39964047
const path = join(root, '.github/aw/packages/bradygaster-squad-workflows-test.json');
39974048
const record = JSON.parse(readFileSync(path, 'utf8'));

‎workflows/package/squad-bootstrap.md‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ network:
3030
allowed:
3131
- defaults
3232
tools:
33+
cli-proxy: true
3334
edit: null
3435
bash: true
3536
github:
@@ -153,17 +154,18 @@ pre-agent-steps:
153154
# BEGIN GENERATED RESOURCE DIGESTS
154155
check_hash "$install_verifier" "514e210ebeae3b355ff73ed81bfd17f37207c9a3576ca44eaf8af7bfa21fc173"
155156
check_hash "$cast_validator" "0988e04aeef316f4d7a0107c902bbbcf6538b8899b9fffba5f62150717967685"
156-
check_hash "$bootstrap_validator" "d449b9204f7fad133ff7133c1a30c9381c87e3c0c9d481352819ca93ea1a1dad"
157+
check_hash "$bootstrap_validator" "4fc1bcc79b887bb4f2f78e7eef8693d5c1eaf817d8715ce3c92169934aa225b7"
157158
# END GENERATED RESOURCE DIGESTS
158159
node "$bootstrap_validator" \
160+
--encode-payload "${GITHUB_WORKSPACE:?}/.github/workflows/squad-bootstrap-payload.json" \
161+
> "${GITHUB_WORKSPACE:?}/.github/workflows/squad-bootstrap-envelope.json"
162+
node "$bootstrap_validator" \
163+
--submit-envelope "${GITHUB_WORKSPACE:?}/.github/workflows/squad-bootstrap-envelope.json" \
159164
--root "$PWD" \
160165
--payload "${GITHUB_WORKSPACE:?}/.github/workflows/squad-bootstrap-payload.json" \
161166
--repository "${GITHUB_REPOSITORY:?}" \
162-
--default-branch "${SQUAD_BOOTSTRAP_DEFAULT_BRANCH:?}" \
167+
--default-branch "${DEFAULT_BRANCH:?}" \
163168
--link-mode placeholder
164-
node "$bootstrap_validator" \
165-
--encode-payload "${GITHUB_WORKSPACE:?}/.github/workflows/squad-bootstrap-payload.json" \
166-
> "${GITHUB_WORKSPACE:?}/.github/workflows/squad-bootstrap-envelope.json"
167169
SQUAD_BOOTSTRAP_VALIDATOR
168170
chmod 500 "$runner"
169171
safe-outputs:
@@ -737,33 +739,25 @@ exemplar's long audit format.
737739

738740
## Validation and output
739741

740-
Run exactly:
742+
After generating the payload, run this command exactly once:
741743

742744
```bash
743745
"${GITHUB_WORKSPACE:?}/.github/workflows/run-squad-bootstrap-validator"
744746
```
745747

746-
Only exit status zero with stdout exactly
747-
`Squad bootstrap validation passed.` authorizes reading
748-
`.github/workflows/squad-bootstrap-envelope.json`. That file is the only
749-
transport source for one `materialize_bootstrap` call.
750-
751-
The envelope contains:
752-
753-
- `payload_encoding`: exactly `base64`
754-
- `payload_byte_length`: canonical decimal UTF-8 byte length, maximum 96,000
755-
- `payload_sha256`: lowercase SHA-256 of the complete payload bytes
756-
- `payload_chunk_count`: canonical decimal from 1 through 16
757-
- `payload_chunk_00` through `payload_chunk_15`: only the populated fixed slots
758-
759-
Each populated chunk is `NN:` followed by canonical Base64 for at most 6,000
760-
payload bytes, so every string is at most 8,003 bytes and stays conservatively
761-
below gh-aw's 10,240-byte per-string input limit. Pass every property from the
762-
envelope byte-for-byte to the typed safe-output call. Do not reserialize the
763-
payload, recompute metadata, rename slots, add unused slots, or split semantic
764-
generation into separate Cast and research outputs. The writer reconstructs the
765-
one shared payload and verifies order, count, bounds, UTF-8, total byte length,
766-
and SHA-256 before parsing any JSON.
767-
768-
Any validation or envelope error is terminal: emit no materialization output,
769-
report the exact validator stderr, and stop.
748+
The authenticated command deterministically encodes the payload, reconstructs
749+
and checks all chunk ordinals, count, bounds, UTF-8, byte length and SHA-256,
750+
validates the payload schema and Cast tree, then invokes the existing typed
751+
`materialize_bootstrap` safe-output tool through its mounted CLI with JSON on
752+
stdin. Its tool invocation is bounded to 60 seconds. GitHub writes still occur
753+
only in the safe-output job, which independently revalidates the payload.
754+
755+
Exit status zero with stdout exactly
756+
`Squad bootstrap validation passed; materialize_bootstrap submitted.`
757+
means the one output has already been submitted. Stop immediately.
758+
Never read, print, extract, or transcribe `squad-bootstrap-envelope.json` or its
759+
chunks. Never invoke `materialize_bootstrap` separately, retry the command, or
760+
split Cast and research into separate outputs.
761+
762+
Any validation, envelope, or submission error is terminal: report the exact
763+
stderr and stop without another materialization attempt.

0 commit comments

Comments
 (0)