Skip to content

fix(agents): tell two people's same-named agents apart - #571

Merged
kgoedecke merged 6 commits into
mainfrom
kgoedecke/fix-mcp-agent-identity
Nov 21, 2026
Merged

kgoedecke merged 6 commits into
mainfrom
kgoedecke/fix-mcp-agent-identity

Conversation

@kgoedecke

@kgoedecke kgoedecke commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The server identified an outside (MCP) agent only by the agent_name it sent, so two agents with the same name on one canvas became one agent:

  • Presence: one entry per canvas, keyed by name (agentPresences / agentTouch).
  • Tasks: sameAgent() matched on agentName, so one agent's set_status closed the other's open task, and endAgentTasks (on presence expiry) ended both, failing claimed cards as "disconnected".
  • Across accounts: two people's "Claude" on a shared canvas merged. An outside agent named "Doop" could also end the resident Doop agent's work.

Fix

An outside agent is now its account + its name, hashed into an opaque agentKey (shared/agentIdentity.ts, mcpAgentKey in server/mcp.ts).

  • agentKey is on Actor, Presence (the presence map is keyed by it and clientId is agent:<key>) and AgentTask (tasks.agent_key, migration 0060_agent_key). Boot already ends open non-card tasks, so legacy keyless rows need no backfill.
  • isAgentsTask is the single matching rule. Set-status and auto tasks, endAgentTasks, edit-burst attribution, the guidelines nudge, the resident status lookup and Live Activity runs all use it, and so do the editor's fly-tos: taskFrameId, locatePresence and GhostFrames (stream actors now keep their key).
  • Resident roles carry no key; their name is their identity, as before.
  • Feedback on an outside agent's task waits OWNER_FIRST_MS (a minute, the presence lifetime) for that agent before any agent may take it. get_feedback and delivered feedback say whose work it is: "your", "another Claude's" or "Ben's".

Why not the MCP session

The first version also put an Mcp-Session-Id (minted on initialize) into the key, to separate one person's two sessions. PostHog's custom_agent_connected (one event per initialize, last 30 days) shows that would split agents apart:

  • codex-mcp-client and the openai-mcp clients start a new session every 1–5s (median), about once per tool call.
  • claude-code re-initializes in bursts (36% of gaps under a minute).
  • Only the claude.ai connectors and Cursor keep one session per connection.

So one person's two same-named agents stay one agent, a documented limit. No session id is issued.

Tests

  • tests/agentIdentity.test.ts: key properties; one agent's status or disconnect leaves the other's tasks open; an outside "Doop" leaves the resident role alone; feedback goes to its own agent first, then to anyone after the minute.
  • tests/agentIdentityHttp.test.ts: real server and SDK client. Two accounts' "Claude" get two presences and two open tasks; one account's two connections are one agent; get_feedback names whose work it is.
  • tests/locate.test.ts: with two Claudes, each face and each task goes to its own agent's frame.

Full local suite passes except serverListen.test.ts, which fails the same way on a clean HEAD on this Mac (IPv6 listen timeouts).

🤖 Generated with Claude Code

The server identified an MCP agent only by the agent_name it sent, so two
agents with one name on a canvas merged: one presence, and one agent's
set_status or disconnect ended the other's tasks, across accounts too.

An outside agent is now its account, its MCP session and its name, hashed
into an opaque agentKey on the actor, its presence and its tasks
(tasks.agent_key, migration 0060). /mcp stays stateless but hands each
initialize a fresh Mcp-Session-Id that clients send back; a client that
does not is known by its account. Resident roles keep their name as
identity. One owner's same-named agents read "Claude", "Claude 2".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect MCP agent work and navigation within shared canvases.

Fix the resident feedback claim before merging so outside agents receive their promised first chance to respond.

Findings

  1. P1 Doop skips the feedback wait ▶
  2. P2 Agents share the wrong icon ▶

Summary

The PR separates outside agents by account and name, then carries their key through presence, tasks, stored task rows, and frame navigation.

  • Same-named agents from different accounts keep separate work.
  • Agent faces and tasks now lead to the right agent’s frame.
  • Agents get first chance at feedback on their own work.
  • Presence faces now choose their agent mark from the displayed name.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["MCP account + agent_name"] --> B["mcpAgentKey"]
  B --> C["Actor.agentKey"]
  C --> D["Separate presence and tasks"]
  D --> E["Frame navigation by key"]
  D --> F["Task feedback carries key"]
  F --> G["Outside agents wait one minute"]
  F --> H["Resident agent skips wait"]
Loading

Reviews (2) · Last reviewed commit: "fix(agents): key outside agents by accou..." · Reviewed by Greptile

Comment thread server/index.ts Resolved
kgoedecke added a commit to prudhvirajkonda8-bot/doop that referenced this pull request Nov 21, 2026
…perks (doop-design#571)

* feat(billing): make upgrading to Pro easy to find, and give Pro real perks

Upgrade to Pro is now one modal reachable from the rail, the account menu,
Settings → Plan, the canvas Help menu and ⌘K, and any `?upgrade` link. It
creates the workspace at checkout (named after payment), sells seats as a
minimum, and lists the plans as short cards with a full comparison folded
underneath. Team is renamed Pro in the UI; the plan id stays `team`.

Pro lifts Free's limits: uploads to 100 MB instead of 5, and font libraries
past two families. Pro also gets priority support. Billing off, nothing is
limited.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(billing): address review: seat changes wait for Stripe, never reuse a canceled workspace

- PUT /billing/seats answers once Stripe has the quantity, and puts the old
  choice back (502) when Stripe refuses.
- The upgrade modal only reuses workspaces that never had a plan; a canceled
  one is reactivated from its own billing page.
- The billing pane edits the seat minimum itself (down to 1), so a minimum
  can be released as people leave.
- The canvas Upgrade action is enabled and shown only where billing is on and
  the account is Free (offersUpgrade, shared with the rail and account menu).
- Settings → Plan with billing off shows the self-hosted allowance, not Free.
- A font upload stores its file only after the in-queue checks pass, so a
  refused family leaves no asset behind.
- The naming prompt is checked on every load that shows the workspace paid,
  not only in the checkout return's sync.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(billing): run a seat change and its rollback on the workspace's seat queue

A failed change restored its old value outside the queue, so it could undo a
later change that was waiting for Stripe. The choice, the Stripe update and
the rollback now run as one step of the per-workspace seat chain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: give the account menu's me mock offersUpgrade

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit fc7f2e56125aa474171bf322f084d032ebf7766d)
kgoedecke and others added 2 commits November 21, 2026 01:30
taskFrameId still looked up a running task's presence and stream by name,
so with two agents called "Claude" a task click could fly to the other
agent's frame. The store also kept only a stream actor's name and colour,
which made locatePresence's identity match miss a streaming outside agent.
Stream actors now keep agentKey, and both lookups match on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PostHog's custom_agent_connected (one per initialize) shows Codex and the
openai-mcp clients starting a session every few seconds and Claude Code in
bursts, so a session-scoped key split one agent into many. The key is now
account + name; one person's same-named agents stay one agent, and the
Mcp-Session-Id minting and the "Claude 2" label go.

Review follow-ups: feedback on an outside agent's task waits a minute for
that agent before any agent may take it; get_feedback and delivered
feedback say whose work it is about; isAgentsTask is the one matching rule;
stream actors pass through whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kgoedecke kgoedecke changed the title fix(agents): tell outside agents sharing a name apart fix(agents): tell two people's same-named agents apart Nov 21, 2026
@kgoedecke

Copy link
Copy Markdown
Collaborator Author

@greptileai

Comment thread server/actions.ts Outdated
* whose work it is about has had its minute, and its own feedback at once.
* Resident roles (no key) are routed by `targetAgent` and never wait. */
function ownerFirst(f: TaskFeedback, agent: Pick<Actor, 'name' | 'agentKey'>, now: number): boolean {
if (!f.agentKey || !agent.agentKey || f.agentKey === agent.agentKey) return true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Doop skips the feedback wait

ownerFirst lets resident agents skip the new one-minute wait because they have no agentKey. When someone replies to an outside Claude's task, addTaskFeedback immediately wakes the resident runner. If a model is available, Doop can claim the reply before Claude's next call, so Claude never receives the requested change. Apply the wait to feedback carrying another agent's key, including when the caller is a resident.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right, fixed in 7a6bd83. The wait now lives in feedbackFor, so it holds for every agent other than the one whose work the feedback is about, residents included. pendingWorkAgents leaves waiting feedback out, so a sweep doesn't run for it early, and addTaskFeedback wakes the residents again once OWNER_FIRST_MS is up. Covered by 'makes the resident agents wait the minute too' in tests/agentIdentity.test.ts.

Comment thread src/components/PeerAvatars.tsx Outdated
const face = (
<PresenceFace name={p.name} color={p.color} kind={p.kind} brand={p.brand} glaze={active} glazeDelay={glazeDelay} />
)
const face = <PresenceFace name={p.name} color={p.color} kind={p.kind} glaze={active} glazeDelay={glazeDelay} />

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Agents share the wrong icon

Removing brand={p.brand} makes same-named agents share the first matching presence's icon. Without an explicit brand, AgentIcon looks it up by name. If two people's agents use the same name but connect through different products, both faces show the first product's mark. Keep passing each presence's brand through PresenceFace so people can tell them apart.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch: that was an accident, not intended. I reverted this file from a stale local main and lost brand. It's restored to the PR's base in 7a6bd83, so the PR no longer touches PeerAvatars.tsx.

kgoedecke and others added 3 commits November 21, 2026 02:17
Feedback on an outside agent's task waited a minute for that agent, but the
resident agents skipped the wait and were woken at once, so Doop could take
a reply meant for Claude. The wait now holds for every other agent
(feedbackFor, pendingWorkAgents), and the residents are woken again when it
ends. Also restores PeerAvatars' brand icons, dropped by a revert taken from
a stale local main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt-identity

# Conflicts:
#	.context/TECHSTACK.md
#	server/db/migrations/meta/0060_snapshot.json
#	server/db/migrations/meta/_journal.json
@kgoedecke
kgoedecke merged commit 38e0c67 into main Nov 21, 2026
9 checks passed
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