Skip to content

fix(team-lead): seed GENIE_AGENT_NAME from leader, not cwd basename#1434

Merged
namastex888 merged 1 commit into
devfrom
fix/team-lead-genie-agent-name-only
Apr 28, 2026
Merged

fix(team-lead): seed GENIE_AGENT_NAME from leader, not cwd basename#1434
namastex888 merged 1 commit into
devfrom
fix/team-lead-genie-agent-name-only

Conversation

@namastex888
Copy link
Copy Markdown
Contributor

Summary

Closes the `genie send` echo loop surfaced during dog-food. Every `genie send 'msg' --to ` from the felipe team-lead echoed the message back to the operator's own conversation as `<teammate-message teammate_id="workspace" ...>`.

Root cause: `buildTeamLeadCommand` seeded `GENIE_AGENT_NAME` from `basename(process.cwd())` while `--agent-name` came from the leader name. When cwd basename ≠ leader (e.g. cwd=`/home/genie/workspace` → `workspace`, leader=`felipe`), genie CLI labeled `from=workspace`, the existing `from === to` self-loop guards (msg.ts:555, protocol-router.ts:500) saw `'workspace' !== 'felipe'`, the message landed in `~/.claude/teams/felipe/inboxes/felipe.json`, and the operator's own CC instance polled it back as a teammate-message.

Changes

File Change
`src/lib/team-lead-command.ts` `GENIE_AGENT_NAME` now seeds from `sanitizedLeader` (matches `--agent-name`). Removes `basename` import. Doc comment explains why parity matters.
`src/lib/team-lead-command.test.ts` +3 regression tests under `buildTeamLeadCommand identity parity`: default leader, override-leader, and the env-vs-cwd-basename mismatch case. 19/19 pass (was 16/16).
`knip.json` Adds `src/lib/design-tokens.ts` to ignore — it's WIP source-of-truth for the Severance palette (its own header documents intent), consumers being wired in separate refactors.

Reproduction

Direct trace from the felipe team-lead while diagnosing:

  • Parent claude PID env: `GENIE_AGENT_NAME=workspace, GENIE_TEAM=felipe`
  • Same parent CLI flags: `--agent-name felipe --agent-id felipe@felipe`
  • Sent: `genie send 'X' --to felipe`
  • `~/.claude/teams/felipe/inboxes/felipe.json` contained `from=workspace, summary=X` at the exact send timestamp
  • Next conversation turn for the operator: `<teammate-message teammate_id="workspace" ...>X`

After the fix, env-side and flag-side identities agree, the existing `from === to` guards fire correctly, and the echo disappears.

Validation

  • `bun test src/lib/team-lead-command.test.ts` — 19/19 pass (3 new identity-parity assertions)
  • `bun run typecheck` clean
  • `bun run lint` clean
  • `bunx knip` clean (after design-tokens.ts ignore)

Defense-in-depth follow-up (not in this PR)

Trace report suggested a second guard in `bridgeToNativeInbox` that reads parent CC's `--agent-name` from `/proc//cmdline` and bails if recipient matches, even when `from` disagrees. Worth tracking but not strictly needed once env/flag identities align — leaving for a follow-up so this PR stays cirurgical.

Note on PR #1433

Earlier branch (`fix/team-lead-genie-agent-name-mismatch`) accumulated unrelated commits from a stale base + a hook fix that landed independently as #939e8a8b. Closed and re-cut clean from `origin/dev` here.

🤖 Generated with Claude Code

See preceding attempt commit message for full context. Re-commit after
biome auto-format fixed knip.json.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b4cde71e-50ec-4e6c-8ee8-a41d4f15cb92

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/team-lead-genie-agent-name-only

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.

@namastex888 namastex888 merged commit d6b7a33 into dev Apr 28, 2026
8 of 10 checks passed
Copy link
Copy Markdown
Contributor

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

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 buildTeamLeadCommand to ensure that the GENIE_AGENT_NAME environment variable matches the --agent-name flag, preventing self-loop messaging issues caused by identity mismatches. It removes the dependency on the current working directory's basename for the agent name and adds regression tests to verify this behavior. Additionally, src/lib/design-tokens.ts is added to the knip ignore list. I have no feedback to provide.

namastex888 added a commit that referenced this pull request Apr 28, 2026
…urface (#1436)

Followup to #1434. The original commit replaced the function's
header comment with a 9-line forensic explanation of the echo bug;
that wide rewrite created merge conflicts on every parallel branch
that only kept the original 1-line comment (feat/channel-envelope-
inbox, wish/invincible-genie, fix/1296-1298-team-lead-role-vs-
identity were all blocked).

Shrunk the new comment to 5 lines and dropped the inline 6-line
basename-history comment — they were narrative, not load-bearing.
Issue ref (#1434) is enough breadcrumb for anyone who wants the
detail; PR description carries the full root cause analysis.

Behavior unchanged. 19/19 tests still pass.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
namastex888 added a commit that referenced this pull request Apr 28, 2026
…1434)

See preceding attempt commit message for full context. Re-commit after
biome auto-format fixed knip.json.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
namastex888 added a commit that referenced this pull request Apr 28, 2026
…urface (#1436)

Followup to #1434. The original commit replaced the function's
header comment with a 9-line forensic explanation of the echo bug;
that wide rewrite created merge conflicts on every parallel branch
that only kept the original 1-line comment (feat/channel-envelope-
inbox, wish/invincible-genie, fix/1296-1298-team-lead-role-vs-
identity were all blocked).

Shrunk the new comment to 5 lines and dropped the inline 6-line
basename-history comment — they were narrative, not load-bearing.
Issue ref (#1434) is enough breadcrumb for anyone who wants the
detail; PR description carries the full root cause analysis.

Behavior unchanged. 19/19 tests still pass.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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