Skip to content

fix(spawn): remove last '?? genie' literal — buildResumeParams hierarchy (truly 100%) - #1158

Merged
namastex888 merged 1 commit into
devfrom
fix/resume-team-hierarchy
Apr 16, 2026
Merged

namastex888 merged 1 commit into
devfrom
fix/resume-team-hierarchy

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

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):

// Before
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 chain as handleWorkerSpawn at agents.ts:1606:

-  const team = template?.team ?? agent.team ?? 'genie';
+  const team = template?.team ?? agent.team ?? (await nativeTeams.discoverTeamName());
+  if (!team) {
+    throw new Error(
+      `Cannot resume agent "${agent.id}": no team context (template, agent record, env, or session). Pass --team or set GENIE_TEAM, or run inside a registered tmux session.`,
+    );
+  }

Resolution chain becomes:

  1. template?.team (immediate)
  2. agent.team (stored on registration)
  3. discoverTeamName() (env → tmux session-id matching)
  4. Explicit error if all fail (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.

Verification

After this commit lands: 0 occurrences of ?? 'genie' (or any literal 'genie' team-fallback shape) remain in src/. 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)
  • Manual: kill an agent, then genie resume <name> from inside tmux session → should resume with discovered team
  • Manual: kill an agent, then genie resume <name> from outside tmux with no GENIE_TEAM → should error with recovery hint, not silently fall back to 'genie' team

Sequencing

Fourth and final PR in the spawn-hierarchy cleanup arc. Order:

After this lands, the 'genie' literal team-fallback drift is fully eliminated.

Generated with Claude Code.

…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>
@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f3414458-5f1c-4937-859c-40975cf09fbe

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/resume-team-hierarchy

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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).

Suggested change
const team = template?.team ?? agent.team ?? (await nativeTeams.discoverTeamName());
const team = template?.team ?? agent.team ?? (await nativeTeams.discoverTeamName(agent.repoPath));

@namastex888
namastex888 merged commit 3f9b5b9 into dev Apr 16, 2026
6 checks passed
@automagik-genie
automagik-genie deleted the fix/resume-team-hierarchy branch September 25, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant