Skip to content

Commit d7fe29b

Browse files
Fix CI: the budget timer never throws after its database is closed; Docker builds without git (#76)
* Fix CI: the budget timer never throws after its database is closed The debounced check after a budget change ran outside its try/catch: in a test that closed its database (or while shutting down) it threw "database not opened" and failed whatever test was running then (on Linux CI: the three `godmode binary` runner tests). It is caught now, and the timer no longer keeps the process alive. * Fix the Docker build: the build stamp works without git Bun.spawnSync throws when git isn't installed (the image's build stage), so the stamp's own fallback to "unknown" was never reached and the binary build failed.
1 parent ff7d7b3 commit d7fe29b

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎packages/core/scripts/build.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ class BuildError extends Error {}
6262
/** "<commit>[+changes] <date>" of the checkout that is built; "unknown" outside a git checkout. */
6363
function buildStamp(): string {
6464
const git = (...args: string[]) => {
65-
const res = Bun.spawnSync(["git", ...args], { cwd: repoDir, stdout: "pipe", stderr: "ignore" });
66-
return res.exitCode === 0 ? res.stdout.toString().trim() : null;
65+
// Without git installed (the Docker build stage) spawning throws instead of failing.
66+
try {
67+
const res = Bun.spawnSync(["git", ...args], { cwd: repoDir, stdout: "pipe", stderr: "ignore" });
68+
return res.exitCode === 0 ? res.stdout.toString().trim() : null;
69+
} catch {
70+
return null;
71+
}
6772
};
6873
const commit = git("rev-parse", "--short", "HEAD");
6974
if (!commit) return "unknown";

‎packages/core/src/services/budgets.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,18 @@ function budgetsMayHaveChanged(): void {
229229
if (releaseTimer) return;
230230
releaseTimer = setTimeout(() => {
231231
releaseTimer = null;
232-
const now = amountsNow();
233-
if (now === lastAmounts) return;
234-
lastAmounts = now;
235-
if (!get("SELECT 1 FROM paused_runs WHERE reason = 'budget'")) return;
232+
// A timer outlives what started it (shutting down, a test that closed its database): it never throws.
236233
try {
234+
const now = amountsNow();
235+
if (now === lastAmounts) return;
236+
lastAmounts = now;
237+
if (!get("SELECT 1 FROM paused_runs WHERE reason = 'budget'")) return;
237238
releaseHeld("auto");
238239
} catch (err) {
239240
log.warn("could not continue held runs", err);
240241
}
241242
}, 250);
243+
releaseTimer.unref?.();
242244
}
243245

244246
export function startBudgets(): void {

0 commit comments

Comments
 (0)