an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
fix(breaker): count work in the agent's own directory as progress
divijendrad8b68aa154f1
diff --git a/src/main/breaker.ts b/src/main/breaker.tsindex a2e9718b..a2784018 100644--- a/src/main/breaker.ts+++ b/src/main/breaker.ts@@ -13,7 +13,8 @@* (a) Oscar's usage samples via UsageProvider [Seam 1] — for cost + token velocity;* (b) hook events (repeated identical tool calls, api_error storms) — fed in by* HookServer through recordToolUse/recordError;- * (c) file-mtime no-progress — passed per-agent by the beat as `progressing`.+ * (c) file-mtime no-progress — passed per-agent by the beat as `progressing`+ * (coordination files) and `lastWorkAt` (the agent's own workspace).** Velocity is the DIFF of consecutive cumulative samples (Δoutput/Δt), never a* single sample treated as an increment.@@ -54,6 +55,13 @@ export interface BreakerInput {sample: AgentUsageSample | null;/** Did the agent make coordination progress recently (file-mtime signal)? */progressing: boolean;+ /** When the agent's own WORKING DIRECTORY last changed, or omitted when the+ * caller cannot tell. Coordination and work are different things: an agent+ * can spend twenty minutes editing files, running a build and committing+ * without touching a single hive message, and `progressing` answers only+ * the first question. Optional, so a caller with no workspace notion for an+ * agent omits it and nothing about that agent changes. */+ lastWorkAt?: number;}const LEVELS: BreakerLevel[] = ['healthy', 'steering', 'constrained', 'stopped'];@@ -332,7 +340,17 @@ export class CircuitBreaker {// arms above still backstop). Debounced: fires only after// NO_PROGRESS_BEATS consecutive beats, so a one-beat blip never steers.const toolActive = nowMs - s.lastDistinctToolAt < PROGRESS_TOOL_WINDOW_MS;- if (!input.progressing && !toolActive) {+ // A recently-changed working directory is progress too. The question+ // this arm asks is "is this agent doing anything"; until now it asked+ // "is this agent COORDINATING". The paths behind `progressing` are the+ // inbox, the outbox and memory.md - every one of them messaging or+ // memory, none of them where work lands. An agent that edits, builds+ // and commits touches none of them and reads as wedged. Same window as+ // the tool clock, because it answers the same question over the same+ // span of time.+ const workActive = typeof input.lastWorkAt === 'number' && input.lastWorkAt > 0+ && nowMs - input.lastWorkAt < PROGRESS_TOOL_WINDOW_MS;+ if (!input.progressing && !toolActive && !workActive) {s.noProgressBeats += 1;if (s.noProgressBeats >= NO_PROGRESS_BEATS) {return { tripping: true, reason: 'no-progress: generating tokens without coordinating (stale log/files)' };diff --git a/src/main/index.ts b/src/main/index.tsindex 737d9c8d..66c07336 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -1033,6 +1033,47 @@ function lastCoordinationAt(agentId: string): number {return Math.max(...times);}+/** Newest mtime of the agent's OWN WORKING DIRECTORY — the work+ * `lastCoordinationAt` cannot see. 0 when there is nothing to read.+ *+ * Provider neutral by construction: `cwd` is the agent's registry entry, the+ * same field every supported CLI is spawned into, and none of the paths below+ * is specific to any one of them. An agent whose `cwd` is not a git checkout+ * simply falls back to the directory's own mtime; an agent with no `cwd` at+ * all returns 0 and behaves exactly as it does today.+ *+ * Cheap by construction: a handful of `stat` calls on fixed paths, never a+ * directory walk. This runs for every agent on every beat, and a working+ * directory can hold hundreds of thousands of files. Git is what makes it+ * affordable — each of these is rewritten by ordinary work:+ *+ * cwd a file or directory added or removed at the top level+ * .git/index any `git add`, `git status`, `git checkout`+ * .git/logs/HEAD the reflog: commit, checkout, reset, merge, rebase+ * .git/FETCH_HEAD fetch and pull+ * .git/packed-refs and `.git/refs/remotes`: a push updating a tracking ref+ *+ * Its honest limit: editing a file deep in the tree while running no git+ * command moves none of these. That case is already covered by the breaker's+ * own distinct-tool clock, so the two signals are complementary rather than+ * redundant — this one exists for the window where tool events do not reach+ * the breaker but the work is unmistakably real.+ */+function lastWorkAt(agentId: string): number {+ const cwd = hive.registry().agents[agentId]?.cwd;+ if (!cwd) return 0;+ const times: number[] = [0];+ const pushMtime = (p: string): void => { try { times.push(statSync(p).mtimeMs); } catch { /* missing */ } };+ pushMtime(cwd);+ const git = join(cwd, '.git');+ pushMtime(join(git, 'index'));+ pushMtime(join(git, 'logs', 'HEAD'));+ pushMtime(join(git, 'FETCH_HEAD'));+ pushMtime(join(git, 'refs', 'remotes'));+ pushMtime(join(git, 'packed-refs'));+ return Math.max(...times);+}+/** PTY id owning a given agent id, or undefined. */function ptyForAgent(agentId: string): string | undefined {for (const [ptyId, a] of ptyToAgent) if (a === agentId) return ptyId;@@ -1173,7 +1214,10 @@ function runBreakerBeat(progressWindowMs: number): void {inputs.push({agentId: id,sample,- progressing: now - lastCoordinationAt(id) < progressWindowMs || now - lastSpanAt < progressWindowMs+ progressing: now - lastCoordinationAt(id) < progressWindowMs || now - lastSpanAt < progressWindowMs,+ // Work, as distinct from coordination. The breaker decides what to do+ // with it; the beat only reports it.+ lastWorkAt: lastWorkAt(id)});}for (const d of breaker.tick(inputs, now)) {diff --git a/test/breaker.test.cjs b/test/breaker.test.cjsindex ca08ce3a..a1af2191 100644--- a/test/breaker.test.cjs+++ b/test/breaker.test.cjs@@ -54,8 +54,8 @@ const T0 = 1_000_000_000_000; // fixed epoch base so tests are deterministicconst BEAT = 30_000;/** Run one beat for a single agent; returns its decision. */-function beat(b, id, s, progressing, now) {- return b.tick([{ agentId: id, sample: s, progressing }], now)[0];+function beat(b, id, s, progressing, now, lastWorkAt) {+ return b.tick([{ agentId: id, sample: s, progressing, lastWorkAt }], now)[0];}// ── regression: pre-existing trips still fire ────────────────────────────────@@ -178,6 +178,46 @@ test('recent distinct tool calls exempt the no-progress trip', () => {assert.equal(d.state.level, 'healthy', `reason: ${d.state.reason}`);});+// -- fix 4: the agent's own working directory counts as progress ------------+//+// `progressing` is computed from coordination files only - inbox, outbox and+// memory.md. An agent editing, building and committing touches none of them,+// so a working agent read as wedged. These three pin the whole behaviour: it+// counts, staleness still trips, and a caller that reports nothing is+// unaffected.++test('a recently changed working directory counts as progress', () => {+ const b = makeBreaker();+ // No coordination, no tool events - only the workspace moving. This is the+ // shape that misfired: real work, invisible to every signal the arm had.+ beat(b, 'a', sample('a', T0, 0), false, T0, T0 - 1000);+ beat(b, 'a', sample('a', T0 + BEAT, 5000), false, T0 + BEAT, T0 + BEAT - 1000);+ const d = beat(b, 'a', sample('a', T0 + 2 * BEAT, 9000), false, T0 + 2 * BEAT, T0 + 2 * BEAT - 1000);+ assert.equal(d.state.level, 'healthy', `reason: ${d.state.reason}`);+});++test('a STALE working directory still trips the no-progress arm', () => {+ const b = makeBreaker();+ const stale = T0 - 10 * 60_000; // older than PROGRESS_TOOL_WINDOW_MS+ beat(b, 'a', sample('a', T0, 0), false, T0, stale);+ beat(b, 'a', sample('a', T0 + BEAT, 5000), false, T0 + BEAT, stale);+ const d = beat(b, 'a', sample('a', T0 + 2 * BEAT, 9000), false, T0 + 2 * BEAT, stale);+ assert.equal(d.state.level, 'steering', `reason: ${d.state.reason}`);+ assert.match(d.state.reason, /no-progress/);+});++test('an ABSENT lastWorkAt behaves exactly as before', () => {+ const b = makeBreaker();+ // A caller with no workspace notion for this agent omits the field entirely.+ // Nothing about that agent may change, or the fix would alter behaviour for+ // every provider that reports nothing.+ beat(b, 'a', sample('a', T0, 0), false, T0);+ beat(b, 'a', sample('a', T0 + BEAT, 5000), false, T0 + BEAT);+ const d = beat(b, 'a', sample('a', T0 + 2 * BEAT, 9000), false, T0 + 2 * BEAT);+ assert.equal(d.state.level, 'steering', `reason: ${d.state.reason}`);+ assert.match(d.state.reason, /no-progress/);+});+test('REPEATED identical tool calls do not count as progress', () => {const b = makeBreaker();b.recordToolUse('a', 'Bash', { cmd: 'same' }, T0 - 10 * 60_000); // distinct stamp long ago