Fix some issues with local dev
This commit is contained in:
@@ -48,6 +48,9 @@ export const env = {
|
||||
terminalIdleMs: intEnv('SPOON_AGENT_TERMINAL_IDLE_MS', 1_800_000),
|
||||
// How long a per-user box container survives with no active jobs/terminals.
|
||||
boxIdleMs: intEnv('SPOON_AGENT_BOX_IDLE_MS', 1_800_000),
|
||||
// Dev-only: exit if the parent dev runner dies, so the worker never orphans
|
||||
// and holds port 3921 across restarts. Set by scripts/dev-agent-worker.
|
||||
devWatchdog: process.env.SPOON_AGENT_DEV_WATCHDOG === '1',
|
||||
workdir: process.env.SPOON_AGENT_WORKDIR?.trim() ?? '.local/agent-work',
|
||||
hostWorkdir: process.env.SPOON_AGENT_HOST_WORKDIR?.trim(),
|
||||
network: process.env.SPOON_AGENT_NETWORK?.trim(),
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
import { env } from './env';
|
||||
import { startWorkerServer } from './server';
|
||||
import { startWorker } from './worker';
|
||||
|
||||
// Dev-only watchdog: the dev runner chain (turbo → with-env → dotenv → bash)
|
||||
// doesn't always forward the stop signal to this leaf process, so on restart the
|
||||
// worker can orphan and keep holding port 3921. Exit when our original parent
|
||||
// goes away (we get reparented) or on a stop signal, so restarts stay clean.
|
||||
// Never enabled in prod (gated on SPOON_AGENT_DEV_WATCHDOG).
|
||||
if (env.devWatchdog) {
|
||||
// Bun caches `process.ppid`, so poll whether the original parent still exists
|
||||
// (signal 0 throws once it's gone) rather than comparing ppid.
|
||||
const parentPid = process.ppid;
|
||||
const watcher = setInterval(() => {
|
||||
try {
|
||||
process.kill(parentPid, 0);
|
||||
} catch {
|
||||
console.log('Dev parent exited; shutting down worker.');
|
||||
process.exit(0);
|
||||
}
|
||||
}, 1000);
|
||||
watcher.unref();
|
||||
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP'] as const) {
|
||||
process.on(signal, () => process.exit(0));
|
||||
}
|
||||
}
|
||||
|
||||
startWorkerServer();
|
||||
await startWorker();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://v2-8-20.turborepo.dev/schema.json",
|
||||
"$schema": "https://v2-10-0.turborepo.dev/schema.json",
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"dev": {
|
||||
|
||||
Reference in New Issue
Block a user