Repository navigation
fix: auto-resume Claude session on genie spawn #994
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -973,6 +973,21 @@ function prependEnvVars(command: string, env?: Record<string, string>): string { | |||||
| return `env ${envArgs} ${command}`; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Find a dead worker with a resumable Claude session for the given role/team. | ||||||
| * Must run BEFORE rejectDuplicateRole which would unregister the dead worker | ||||||
| * and lose the claudeSessionId needed for resume. | ||||||
| */ | ||||||
| async function findDeadResumable(team: string, role: string): Promise<registry.Agent | null> { | ||||||
| const existing = await registry.list(); | ||||||
| const candidate = existing.find( | ||||||
| (w) => w.role === role && w.team === team && w.claudeSessionId && w.provider === 'claude', | ||||||
| ); | ||||||
| if (!candidate) return null; | ||||||
| const alive = await isPaneAlive(candidate.paneId); | ||||||
| return alive ? null : candidate; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Reject spawn if a live worker with the same role already exists in the team. | ||||||
| * Dead/suspended workers (pane gone) are auto-cleaned from registry — only live panes block. | ||||||
|
|
@@ -1192,6 +1207,16 @@ export async function handleWorkerSpawn(name: string, options: SpawnOptions): Pr | |||||
| console.error('Error: --team is required (or set GENIE_TEAM, or run inside a genie session)'); | ||||||
| return process.exit(1) as never; | ||||||
| } | ||||||
| // Auto-resume: if a dead worker exists with a Claude session, resume instead of fresh spawn. | ||||||
| const deadResumable = await findDeadResumable(team, effectiveRole); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The auto-resume logic should respect the
Suggested change
|
||||||
| if (deadResumable) { | ||||||
|
Comment on lines
+1211
to
+1212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Auto-resume runs before provider resolution and does not consider Useful? React with 👍 / 👎. |
||||||
| console.log( | ||||||
| `Resuming existing session for "${effectiveRole}" (session: ${deadResumable.claudeSessionId?.slice(0, 8)}...)`, | ||||||
| ); | ||||||
| await resumeAgent(deadResumable); | ||||||
| return deadResumable.id; | ||||||
|
Comment on lines
+1216
to
+1217
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This branch always calls Useful? React with 👍 / 👎. |
||||||
| } | ||||||
|
|
||||||
| await rejectDuplicateRole(team, effectiveRole); | ||||||
|
|
||||||
| // 2b. Override CWD with team worktree path if available. | ||||||
|
|
||||||
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.
If multiple dead workers exist for the same role and team,
find()will return the first one encountered in the registry list, which may not be the most recent session. Additionally, we should avoid resuming workers that reached adonestate. Sorting bystartedAtdescending ensures the most recent context is resumed.