Repository navigation
fix(spawn): remove last '?? genie' literal — buildResumeParams hierarchy (truly 100%) - #1158
Conversation
…archy Final cleanup of the literal 'genie' team-fallback anti-pattern. Trace investigation after PRs #1154/#1156/#1157 merged found one remaining site missed by prior audits because it was on the RESUME path, not the spawn path: src/term-commands/agents.ts:1901 (buildResumeParams) was: const team = template?.team ?? agent.team ?? 'genie'; When both template?.team and agent.team are undefined (registry corruption, pre-team-tracking record, or template missing team), the literal 'genie' silently captured the resumed agent into the wrong team — same drift the spawn-path fixes targeted, just on a different code path. Fix: use the same hierarchical resolution as handleWorkerSpawn (agents.ts:1606). Falls through to nativeTeams.discoverTeamName() which checks GENIE_TEAM env then tmux session-id matching. Throws explicit error if no team context can be resolved (matches the pattern at agents.ts:1607-1609). Behavior change: resume operations that previously fell back silently to 'genie' team now either resolve hierarchically OR fail loudly with a recovery hint. No more silent team-misattribution on resume. After this, 0 occurrences of `?? 'genie'` remain in src/ — full 100% removal of the literal team-fallback drift. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the buildResumeParams function in src/term-commands/agents.ts to dynamically resolve the team name using nativeTeams.discoverTeamName() instead of a hardcoded default. It also adds an error check to ensure a team context is available. A review comment suggests passing agent.repoPath to the discovery function to improve robustness when the command is executed from outside the agent's repository.
| const agentName = agent.role ?? agent.id; | ||
| const provider = (template?.provider ?? agent.provider ?? 'claude') as ProviderName; | ||
| const team = template?.team ?? agent.team ?? 'genie'; | ||
| const team = template?.team ?? agent.team ?? (await nativeTeams.discoverTeamName()); |
There was a problem hiding this comment.
When discovering the team name as a fallback during resume, it is more robust to pass agent.repoPath to discoverTeamName(). This allows the discovery logic to correctly identify the team context from the agent's project directory, even if the current working directory of the CLI process is different (e.g., when running genie resume from outside the repository).
| const team = template?.team ?? agent.team ?? (await nativeTeams.discoverTeamName()); | |
| const team = template?.team ?? agent.team ?? (await nativeTeams.discoverTeamName(agent.repoPath)); |
Summary
Final cleanup of the
?? 'genie'team-fallback anti-pattern. Trace investigation after PRs #1154 / #1156 / #1157 merged found one remaining site the prior audits missed because it lived on the RESUME path, not the spawn path.The remaining site
src/term-commands/agents.ts:1901(buildResumeParams):When BOTH
template?.teamandagent.teamare undefined (registry corruption, pre-team-tracking record, or template missing team), the literal'genie'silently captured the resumed agent into the wrong team — same drift the spawn-path fixes targeted, just on a different code path.Fix
Use the same hierarchical resolution chain as
handleWorkerSpawnatagents.ts:1606:Resolution chain becomes:
template?.team(immediate)agent.team(stored on registration)discoverTeamName()(env → tmux session-id matching)agents.ts:1607-1609)Behavior change
Resume operations that previously fell back silently to
'genie'team now either resolve hierarchically OR fail loudly with a recovery hint. No more silent team-misattribution on resume.Verification
After this commit lands: 0 occurrences of
?? 'genie'(or any literal'genie'team-fallback shape) remain insrc/. Full 100% removal.The remaining
'genie'literals in the codebase are NOT anti-patterns:process.argv[1] ?? 'genie'— CLI binary name (correct)process.env.GENIE_TMUX_SOCKET || 'genie'— tmux socket name (correct)Test plan
bun run check— full gate: 2461 tests, 0 fail, lint clean (modulo pre-existing complexity warning at line 1073)genie resume <name>from inside tmux session → should resume with discovered teamgenie resume <name>from outside tmux with no GENIE_TEAM → should error with recovery hint, not silently fall back to 'genie' teamSequencing
Fourth and final PR in the spawn-hierarchy cleanup arc. Order:
genie agent spawnlong form)genie spawntop-level alias) + dispatch.ts (4 sub-spawns) + SpawnOptions.team optional + ci.yml 8vcpuAfter this lands, the
'genie'literal team-fallback drift is fully eliminated.Generated with Claude Code.