Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes

garrytanb8611b2e60f5
diff --git a/src/commands/doctor/checks/local-audits.ts b/src/commands/doctor/checks/local-audits.ts
index e867fe3f0e..24c7b12eaf 100644
--- a/src/commands/doctor/checks/local-audits.ts
+++ b/src/commands/doctor/checks/local-audits.ts
@@ -29,6 +29,7 @@ import type { Check } from '../../doctor.ts';
import { withSkippedSegmented } from '../check-fix.ts';
import type { DoctorContext, DoctorEntry } from '../context.ts';
import { scanDeadline } from '../budget.ts';
+import { currentStatementDeadline } from '../../../core/statement-deadline.ts';
async function runStubGuard(ctx: DoctorContext): Promise<Check[]> {
const { engine, orphanRatioSourceId } = ctx;
@@ -382,18 +383,23 @@ export const extractionBacklogsEntry: DoctorEntry = {
/**
* #8979: a local probe's stdout, or null when it fails or outlives its bound (5 s, clipped to the entry deadline less
* the report reserve; `entryDeadlineAt` is read when the entry starts). It runs asynchronously and is killed with
- * SIGKILL at its bound, so a probe that hangs never blocks the event loop or outlives the entry's deadline.
+ * SIGKILL at its bound, so a probe that hangs never blocks the event loop or outlives the entry's deadline. A probe
+ * the entry deadline cut short marks the entry's scope expired, so its checks report unknown instead of absent.
*/
async function localProbe(entryDeadlineAt: number | undefined, file: string, args: string[]): Promise<string | null> {
- const timeout = scanDeadline({ entryDeadlineAt }, 5_000) - Date.now();
- if (timeout <= 0) return null;
+ const scope = currentStatementDeadline();
+ const ownEnd = Date.now() + 5_000;
+ const end = scanDeadline({ entryDeadlineAt }, 5_000);
+ const cutShort = () => { if (scope && end < ownEnd) scope.expired = true; return null; };
+ const timeout = end - Date.now();
+ if (timeout <= 0) return cutShort();
const { execFile } = await import('../../../core/spawn.ts');
return new Promise((resolve) => {
const child = execFile(file, args, { encoding: 'utf8', shell: process.platform === 'win32' }, (error, stdout) => {
clearTimeout(timer);
resolve(error ? null : stdout);
});
- const timer = setTimeout(() => { child.kill('SIGKILL'); resolve(null); }, timeout);
+ const timer = setTimeout(() => { child.kill('SIGKILL'); resolve(cutShort()); }, timeout);
child.stdin?.end();
});
}
diff --git a/test/doctor-entry-deadline-6803.test.ts b/test/doctor-entry-deadline-6803.test.ts
index 7cddc54ca3..efea52b65d 100644
--- a/test/doctor-entry-deadline-6803.test.ts
+++ b/test/doctor-entry-deadline-6803.test.ts
@@ -37,6 +37,7 @@ import type { DoctorContext, DoctorEntry } from '../src/commands/doctor/context.
import { StatementDeadlineError, deadlineBoundEngine, withStatementDeadline } from '../src/core/statement-deadline.ts';
import { testBackends } from './helpers/test-backends.ts';
import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
+import { withEnv } from './helpers/with-env.ts';
const ENTRY_BUDGET = 'doctor.entry_budget_ms';
const noProgress = new Proxy({}, { get: () => () => undefined }) as DoctorContext['progress'];
@@ -109,21 +110,34 @@ test('#8979: a local probe that hangs is killed at its entry deadline instead of
// Ignores SIGTERM, so only a hard kill ends it before its 6 s sleep.
writeFileSync(join(bin, tool), `#!/bin/sh\necho $$ >> '${pids}'\ntrap '' TERM\nexec sleep 6\n`, { mode: 0o755 });
}
- const path = process.env.PATH;
- process.env.PATH = `${bin}:${path}`;
try {
- const args = ['--json', '--budget-ms', '1000'];
- const started = Date.now();
- const checks = await runDoctorRegistry(ctxFor(null, args), [homeDirInWorktreeEntry]);
- expect(Date.now() - started).toBeLessThan(1_000 + 400);
- expect(byName(checks, 'home_dir_in_worktree')).toBeDefined();
+ await withEnv({ PATH: `${bin}:${process.env.PATH}` }, async () => {
+ const args = ['--json', '--budget-ms', '1000'];
+ const started = Date.now();
+ const checks = await runDoctorRegistry(ctxFor(null, args), [homeDirInWorktreeEntry]);
+ expect(Date.now() - started).toBeLessThan(1_000 + 400);
+ // Cut short by the deadline, the probes' checks are unknown, never absent.
+ expect(byName(checks, 'npm_squat')?.details).toMatchObject({ health: 'unknown', reason: 'budget' });
+ });
await new Promise((r) => setTimeout(r, 1_500));
const launched = readFileSync(pids, 'utf8').split('\n').filter(Boolean).map(Number);
expect(launched.length).toBeGreaterThan(0);
const alive = launched.filter((pid) => { try { process.kill(pid, 0); return true; } catch { return false; } });
expect(alive).toEqual([]);
} finally {
- process.env.PATH = path;
+ rmSync(bin, { recursive: true, force: true });
+ }
+}, 30_000);
+
+test('#8979: a local probe that answers in time feeds its check', async () => {
+ const bin = mkdtempSync(join(tmpdir(), 'gbrain-8979-bin-'));
+ writeFileSync(join(bin, 'crontab'), "#!/bin/sh\necho '0 * * * * gbrain sync --all'\n", { mode: 0o755 });
+ try {
+ await withEnv({ PATH: `${bin}:${process.env.PATH}`, GBRAIN_HOME: undefined }, async () => {
+ const checks = await runDoctorRegistry(ctxFor(null, ['--json']), [homeDirInWorktreeEntry]);
+ expect(byName(checks, 'cron_gbrain_home')).toMatchObject({ status: 'ok' });
+ });
+ } finally {
rmSync(bin, { recursive: true, force: true });
}
}, 30_000);