Repository navigation
chore: rolling promotion dev -> main #1020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
159243d
chore(version): bump to 4.260403.3 [skip ci]
github-actions[bot] b56bf59
fix(protocol-router): skip auto-spawn for done/terminated executors (…
db9edc8
fix(tui): prevent nested tmux cascade when running genie inside TUI (…
ef3a818
refactor(protocol-router): extract isExecutorCompleted helper to redu…
ba29886
fix(test): spread real child_process exports in tmux test mock
b564c8e
fix(test): remove tmux.test.ts to prevent child_process mock leak
166bf97
fix(spawn): transition executor state from spawning to running after …
5ac6808
Merge pull request #1019 from automagik-dev/fix-tmux-spawns
namastex888 efff5ca
chore: fix import ordering in agent-registry.ts
9f6afdd
test: add zombie spawn guard integration test
4a0860e
fix(registry): reconcile dead-pane spawning agents + exclude spawning…
16e673b
Merge pull request #1021 from automagik-dev/fix-tmux-spawns
namastex888 ad3531b
fix(brain): checkout main before pulling in brain update
7c36d08
Merge pull request #1022 from automagik-dev/fix/brain-update-checkout…
namastex888 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| /** | ||
| * Regression tests for zombie spawning agents. | ||
| * | ||
| * Bug 1: reconcileStaleSpawns ignored agents with a non-null pane_id, | ||
| * leaving them stuck in 'spawning' forever when the pane died. | ||
| * Bug 2: Concurrency cap counted 'spawning' agents as active, blocking | ||
| * all auto-resume when zombie spawning agents accumulated. | ||
| */ | ||
|
|
||
| import { describe, expect, test } from 'bun:test'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
| import type { Agent } from '../agent-registry.js'; | ||
| import { | ||
| type LogEntry, | ||
| type SchedulerConfig, | ||
| type SchedulerDeps, | ||
| type WorkerInfo, | ||
| attemptAgentResume, | ||
| } from '../scheduler-daemon.js'; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Helpers (mirrored from resume.test.ts) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| const defaultConfig: SchedulerConfig = { | ||
| maxConcurrent: 5, | ||
| pollIntervalMs: 30_000, | ||
| maxJitterMs: 30_000, | ||
| jitterThreshold: 3, | ||
| heartbeatIntervalMs: 60_000, | ||
| orphanCheckIntervalMs: 300_000, | ||
| deadHeartbeatThreshold: 2, | ||
| leaseRecoveryIntervalMs: 60_000, | ||
| }; | ||
|
|
||
| function makeWorker(overrides: Partial<WorkerInfo> = {}): WorkerInfo { | ||
| return { | ||
| id: 'test-agent', | ||
| paneId: '%42', | ||
| state: 'error', | ||
| claudeSessionId: 'session-abc', | ||
| autoResume: true, | ||
| resumeAttempts: 0, | ||
| maxResumeAttempts: 3, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function createMockSql() { | ||
| const sql: any = (_strings: TemplateStringsArray, ..._values: unknown[]) => []; | ||
| sql.begin = async (fn: (tx: typeof sql) => Promise<unknown>) => fn(sql); | ||
| sql.listen = async () => {}; | ||
| sql.end = async () => {}; | ||
| return sql; | ||
| } | ||
|
|
||
| function createMockDeps(overrides: Partial<SchedulerDeps> = {}) { | ||
| const logs: LogEntry[] = []; | ||
| const agentUpdates: { id: string; updates: Partial<Agent> }[] = []; | ||
| let idCounter = 0; | ||
|
|
||
| const deps: SchedulerDeps = { | ||
| getConnection: async () => createMockSql(), | ||
| spawnCommand: async () => ({ pid: 12345 }), | ||
| log: (entry) => logs.push(entry), | ||
| generateId: () => `test-id-${++idCounter}`, | ||
| now: () => new Date('2026-03-20T12:00:00Z'), | ||
| sleep: async () => {}, | ||
| jitter: (maxMs) => Math.floor(maxMs / 2), | ||
| isPaneAlive: async () => false, | ||
| listWorkers: async () => [], | ||
| countTmuxSessions: async () => 0, | ||
| publishEvent: async () => {}, | ||
| resumeAgent: async () => true, | ||
| updateAgent: async (id, u) => { | ||
| agentUpdates.push({ id, updates: u }); | ||
| }, | ||
| ...overrides, | ||
| }; | ||
|
|
||
| return { deps, logs, agentUpdates }; | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Bug 1: reconcileStaleSpawns second pass for dead panes (code review) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('reconcileStaleSpawns dead-pane pass', () => { | ||
| test('source includes dead-pane reconciliation logic', () => { | ||
| const source = readFileSync(join(__dirname, '..', 'agent-registry.ts'), 'utf-8'); | ||
|
|
||
| // Second pass selects agents with non-empty pane_id still in spawning state | ||
| expect(source).toContain("AND pane_id IS NOT NULL AND pane_id != ''"); | ||
|
|
||
| // Calls isPaneAlive to verify pane is actually dead | ||
| expect(source).toContain('isPaneAlive(row.pane_id)'); | ||
|
|
||
| // Uses distinct audit reason for dead-pane reconciliation | ||
| expect(source).toContain('stale_spawn_dead_pane'); | ||
| }); | ||
|
|
||
| test('dead-pane pass gracefully handles tmux errors (code review)', () => { | ||
| const source = readFileSync(join(__dirname, '..', 'agent-registry.ts'), 'utf-8'); | ||
|
|
||
| // The catch block around isPaneAlive ensures TmuxUnreachableError | ||
| // does not incorrectly mark agents as dead | ||
| expect(source).toContain('// TmuxUnreachableError or other'); | ||
| }); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Bug 2: spawning agents should not count toward concurrency cap | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('concurrency cap excludes spawning agents', () => { | ||
| test('spawning agents do not block resume of other agents', async () => { | ||
| // 5 zombie 'spawning' agents that previously blocked all resumes | ||
| const zombieSpawning: WorkerInfo[] = Array.from({ length: 5 }, (_, i) => | ||
| makeWorker({ id: `zombie-${i}`, state: 'spawning' as any }), | ||
| ); | ||
| const { deps, logs } = createMockDeps({ | ||
| listWorkers: async () => zombieSpawning, | ||
| resumeAgent: async () => true, | ||
| }); | ||
|
|
||
| const agent = makeWorker({ id: 'real-agent', state: 'error' }); | ||
| const result = await attemptAgentResume(deps, defaultConfig, agent); | ||
|
|
||
| // Before fix: result was 'skipped' with reason 'concurrency_cap' | ||
| // After fix: spawning is excluded, so activeCount = 0 and resume proceeds | ||
| expect(result).toBe('resumed'); | ||
| expect(logs.some((l) => l.reason === 'concurrency_cap')).toBe(false); | ||
| }); | ||
|
|
||
| test('actually-working agents still enforce the concurrency cap', async () => { | ||
| // 5 genuinely working agents should still block resume | ||
| const working: WorkerInfo[] = Array.from({ length: 5 }, (_, i) => | ||
| makeWorker({ id: `worker-${i}`, state: 'working' }), | ||
| ); | ||
| const { deps, logs } = createMockDeps({ | ||
| listWorkers: async () => working, | ||
| }); | ||
|
|
||
| const agent = makeWorker({ id: 'overflow-agent', state: 'error' }); | ||
| const result = await attemptAgentResume(deps, defaultConfig, agent); | ||
|
|
||
| expect(result).toBe('skipped'); | ||
| const skip = logs.find((l) => l.event === 'agent_resume_skipped'); | ||
| expect(skip?.reason).toBe('concurrency_cap'); | ||
| }); | ||
|
|
||
| test('mix of spawning and working agents only counts working toward cap', async () => { | ||
| const mixed: WorkerInfo[] = [ | ||
| // 3 zombie spawning (should NOT count) | ||
| ...Array.from({ length: 3 }, (_, i) => makeWorker({ id: `zombie-${i}`, state: 'spawning' as any })), | ||
| // 4 actually working (should count) | ||
| ...Array.from({ length: 4 }, (_, i) => makeWorker({ id: `worker-${i}`, state: 'working' })), | ||
| ]; | ||
| const { deps } = createMockDeps({ | ||
| listWorkers: async () => mixed, | ||
| resumeAgent: async () => true, | ||
| }); | ||
|
|
||
| const agent = makeWorker({ id: 'another-agent', state: 'error' }); | ||
| const result = await attemptAgentResume(deps, defaultConfig, agent); | ||
|
|
||
| // activeCount = 4 (only working), which is < maxConcurrent(5), so resume proceeds | ||
| expect(result).toBe('resumed'); | ||
| }); | ||
|
|
||
| test('source code confirms spawning is in the exclusion list', () => { | ||
| const source = readFileSync(join(__dirname, '..', 'scheduler-daemon.ts'), 'utf-8'); | ||
| // The filter that computes activeCount must exclude 'spawning' | ||
| expect(source).toContain("'done', 'error', 'suspended', 'spawning'"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Unnecessary
as anycast.'spawning'is already a validAgentStatevalue (peragent-registry.tsline 25). The type assertion is redundant.♻️ Remove unnecessary cast
Same applies to line 156.
🤖 Prompt for AI Agents