Skip to content

The design language that makes your AI harness better at design.

JavaScript

Fix: launcher removes its partial engine download when interrupted (#1066) (#1068)

Abdul Wahab9053c84a0001
diff --git a/skill/scripts/impeccable b/skill/scripts/impeccable
index eb60f8667..224028c79 100755
--- a/skill/scripts/impeccable
+++ b/skill/scripts/impeccable
@@ -124,6 +124,12 @@ if [ -n "$version" ] && [ "$os" != unknown ] && [ "$arch" != unknown ]; then
[ "$os" = windows ] && asset="$asset.exe"
url="$base/engine-v$version/$asset"
tmp="$cache_root/bin/$version/.impeccable.part.$$"
+ # An interrupted download (Ctrl-C, a hook timeout) would otherwise leave the
+ # PID-named staging file behind for good. The handlers must exit explicitly.
+ cleanup() { rm -f "$tmp" "$tmp.sha256" 2>/dev/null || :; }
+ trap 'cleanup; exit 129' HUP
+ trap 'cleanup; exit 130' INT
+ trap 'cleanup; exit 143' TERM
if ! mkdir -p "$cache_root/bin/$version" 2>/dev/null; then
echo "impeccable: engine $version is not installed; cannot create cache directory: $cache_root/bin/$version" >&2
setup_help
diff --git a/tests/launcher-download.test.mjs b/tests/launcher-download.test.mjs
index dd023ee9c..68e434ac6 100644
--- a/tests/launcher-download.test.mjs
+++ b/tests/launcher-download.test.mjs
@@ -108,6 +108,9 @@ async function exercise(t, scenario) {
fs.writeFileSync(launcher, source.replace(operation, replacement));
}
const requests = [];
+ const interrupt = scenario.startsWith('interrupt-') ? scenario.slice('interrupt-'.length) : null;
+ let stalled;
+ const stall = new Promise(resolve => { stalled = resolve; });
const server = http.createServer((req, res) => {
requests.push(req.url);
if (scenario === 'transport-failure') {
@@ -121,6 +124,12 @@ async function exercise(t, scenario) {
res.writeHead(scenario === 'no-sidecar' ? 404 : 200);
res.end(scenario === 'empty-sidecar' ? '' : `${scenario === 'mismatch' ? '0'.repeat(64) : HASH} engine\n`);
} else {
+ if (interrupt) {
+ // Send part of the body and never finish, so the launcher is mid-download.
+ res.writeHead(200);
+ res.write(PAYLOAD.subarray(0, 8), stalled);
+ return;
+ }
if (scenario === 'download-failure') res.writeHead(404);
res.end(scenario === 'empty-download' ? '' : PAYLOAD);
}
@@ -139,7 +148,9 @@ async function exercise(t, scenario) {
const run = () => new Promise((resolve, reject) => {
const child = WINDOWS
? spawn(COMSPEC, ['/d', '/s', '/c', `""${launcher}" /d /c echo verified-engine"`], { env, cwd: root, windowsVerbatimArguments: true, timeout: 20000 })
- : spawn('/bin/sh', [launcher], { env, cwd: root, timeout: 20000 });
+ : spawn('/bin/sh', [launcher], { env, cwd: root, timeout: 20000, detached: Boolean(interrupt) });
+ // Signal the whole process group, as Ctrl-C or GNU timeout would.
+ if (interrupt) stall.then(() => process.kill(-child.pid, interrupt));
let stdout = '';
let stderr = '';
child.stdout.on('data', data => { stdout += data; });
@@ -259,3 +270,11 @@ for (const scenario of ['removed', 'emptied', 'empty-download', 'no-sidecar', 'e
}
});
}
+
+for (const [signal, status] of [['SIGINT', 130], ['SIGTERM', 143]]) {
+ test(`launcher removes its partial download when interrupted by ${signal}`, { skip: WINDOWS ? 'POSIX launcher only; the cmd launcher stages in its own directory' : false }, async t => {
+ const result = await exercise(t, `interrupt-${signal}`);
+ assert.equal(result.status, status, JSON.stringify(result));
+ assert.deepEqual(result.files, [], 'no staging file left behind');
+ });
+}