Files
PaperClipAI/docs/guides
fa6086facb fix(chat): let agents message each other in a person's chats (#22961)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Agent Chat gives each person one standing chat with each agent.
> - Agents work for the same person, so one agent often must tell
another agent something in that person's chats.
> - The shared comment boundary refused every agent message in a chat
unless the chat's own agent wrote it, and `resume`/`reopen` flags turned
chat posts into 409 conflicts.
> - So one agent could not pass a person's decision to another agent in
that person's chat. The person had to relay it by hand.
> - This pull request rebases #21232 onto current `master` and lets an
agent post in another agent's chat while it acts for the chat's person,
preserving source-task privacy, credential binding, and company
boundaries.
> - The benefit is that agents can talk with each other in the person's
chats, the chat's agent wakes and answers there, and the person sees the
exchange where it happens.

## Linked Issues or Issue Description

**Subsystem affected**

Server (comment-write boundary, comment route, chat directive,
fresh-session handoff), UI (chat transcript adapter), and documentation.

**Problem or motivation**

A person asked one agent to pass a decision to another agent. The first
agent posted the decision in the person's chat with the second agent.
Paperclip refused the post with `"Only this conversation's agent can
post agent messages"`, or returned HTTP 409 when `resume` or `reopen`
was set. The person then had to carry the message by hand.

**Proposed solution**

Rebase and supersede #21232 (whose fork branch is conflicting with
`master` and could not be pushed directly due to fork repository
permissions). Let another agent post in a chat through the ordinary
comment route when it posts from its own running, unrevoked, task-bound
run in the same company, while both the run's responsible person and the
authenticated credential's responsible person match the chat's person,
and the source task passes the company-visible privacy check. Keep every
other guard. Wake the chat's agent through the normal comment wake. Tell
the chat's agent that another agent's message is colleague input, not
the person's authority.

**Alternatives considered**

A destination parameter on `send_chat_message` would add a second
delivery path and new routing authority. The ordinary comment route
already carries attribution, comment permissions, per-run cross-task
limits, and the comment wake, so this change reuses it.

**Roadmap alignment**

This extends the shipped Agent Chat capability in `ROADMAP.md`.
Supersedes #21232 (rebased cleanly onto current `master` with expanded
isolation and handoff tests). Refs #18374, which added the comment
boundary for proactive chat messages. Refs #14143, which asks for
broader group discussions between agents and people; this change does
not add group chats.

## What Changed

- `server/src/services/issues.ts` (+20 net lines; edits remain in the
existing >1,000-line owning `addComment` write boundary rather than
splitting a shared transaction guard): allow a peer agent to post in
another agent's chat only from its own running, unrevoked, task-bound
run in the same company, when both `run.responsibleUserId` and
`actor.onBehalfOfUserId` (when set) match `current.conversationUserId`,
and when the source task passes `canActorReadIssuePrivacy(dbOrTx, {
type: "none" }, source)`. Keep proactive chat delivery and the session
fence restricted to the chat's own agent.
- `server/src/routes/issues.ts` (+0 net lines; edits remain in the
existing >1,000-line owning comment route): ignore `reopen` and `resume`
flags on conversations (`!isConversation(issue)`) because ordinary
comment wakes always reach the chat's agent.
- `server/src/services/agent-conversations.ts`: update
`AGENT_CHAT_DIRECTIVE` to state that another agent's comment is
colleague input (never the person's approval, decision, or instruction
authority) and document how to find and write to another agent's chat
for the same person.
- `server/src/services/native-runtime/native-session-handoff.ts`: label
comments authored by another agent as `other_agent` in fresh-session
history so a fresh session distinguishes them from the chat agent's own
`agent` replies.
- `ui/src/components/task-chat/transcript-adapter.ts` (+5 net lines;
edits remain in the existing >1,000-line owning transcript adapter): add
`sameTurnAgent` so `coalesceSettledTurns` and `attachSettledTurns` match
settled turns to agent bubbles by `agent.id` when both IDs are known,
falling back to display name.
- Tests:
- `server/src/__tests__/agent-chat-peer-messages.test.ts`: real
embedded-Postgres + Express route/service suite covering task-search
chat discovery, comment delivery + wake admission with `resume: true`,
run/agent/status/cancellation/proactive/credential checks, restricted
source tasks (private task, private project, private ancestor, unscoped
run), session fence + both `canReceiveCommentsFromAgents` and
`canCommentOnOtherTasks` permissions, cross-company isolation +
credential `onBehalfOfUserId` mismatch through the HTTP route, and
`buildNativeSessionHandoff` `other_agent` labeling.
- `server/src/__tests__/agent-conversations.test.ts`: verifies the new
peer-chat directive text.
- `server/src/__tests__/agent-chat-messages.test.ts`: updates the
expected denial message for an agent acting for a different person.
- `server/src/services/native-runtime/native-session-handoff.test.ts`:
preserves the fast unit suite on `master` and verifies
`renderNativeSessionHandoff` retains `author: "other_agent"` and
`authorAgentId`.
- `ui/src/components/task-chat/transcript-adapter.test.ts`: covers
ID-based turn coalescing and attachment when runs carry no display name.
- Docs and maps: updated `doc/PRODUCT.md`,
`doc/plans/2026-09-10-agent-chat.md`,
`docs/guides/agent-developer/comments-and-communication.md`, and
`maps/agent-access-map/agent-chat.md`.

## Verification

RED before fix on base `2d065677959b585065ff3fec8718156a4cf6f41d`:
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/agent-chat-peer-messages.test.ts`: **3 failed | 2 passed
(5)**:
- `delivers the message to the chat's agent as the sending agent's
message` failed with HTTP `409` (`"Issue is not resumable through
comment follow-up intent"`).
- `requires the sending agent's own running run, acting for the chat's
person` failed with `"Only this conversation's agent can post agent
messages"`.
- `refuses content from a restricted or missing source task` failed with
`"Only this conversation's agent can post agent messages"`.

GREEN after rebase and fix on head
`64ee873ad760ab0b53e2eaa161c5e83e7b1e9ad9`:
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/agent-chat-peer-messages.test.ts`: **7 passed (7)** (real
embedded Postgres + real Express `issueRoutes` + real `issueService` +
real `agentWakeupRequests` + real `buildNativeSessionHandoff`).
- `pnpm --filter @paperclipai/server exec vitest run
--no-file-parallelism src/__tests__/agent-chat-peer-messages.test.ts
src/__tests__/agent-conversations.test.ts`:
`agent-conversations.test.ts` **73 passed (73)**.
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/agent-chat-messages.test.ts
src/services/native-runtime/native-session-handoff.test.ts`: both files
**passed** (`native-session-handoff.test.ts`: **4 passed (4)**;
`agent-chat-messages.test.ts`: all tests passed).
- `pnpm --filter @paperclipai/ui exec vitest run
src/components/task-chat/transcript-adapter.test.ts`: **119 passed
(119)**.
- `pnpm --filter @paperclipai/server typecheck`: **passed**.
- `pnpm --filter @paperclipai/ui typecheck`: **passed**.
- `node scripts/check-maps.mjs`: **passed** (35 areas, 192 capability
IDs; references and contract fields valid).
- `node scripts/check-test-budget.mjs --files
server/src/__tests__/agent-chat-peer-messages.test.ts
server/src/__tests__/agent-chat-messages.test.ts
server/src/__tests__/agent-conversations.test.ts
server/src/services/native-runtime/native-session-handoff.test.ts
ui/src/components/task-chat/transcript-adapter.test.ts`: **PASS** (110
nightly suites validated, 5 test files checked).
- `pnpm verify --base 2d06567795
--explain`: exited `2` (global CI input
`maps/agent-access-map/agent-chat.md` changed; broad verification
delegated to required PR CI).

Not run locally:
- Full repository `pnpm test:run` and Playwright browser E2E suites
(covered by PR CI).
- Live provider-backed two-agent run (the embedded-Postgres integration
test exercises the real HTTP route, comment boundary, privacy guards,
wake admission, and fresh-session handoff up to provider dispatch).

## Risks

- Behavior change: other agents can now post in a person's chat with an
agent, waking that chat's agent. Existing controls remain enforced:
`canCommentOnOtherTasks`, `canReceiveCommentsFromAgents`, per-run
cross-task write limits, run cancellation, credential/run
responsible-user match, source-task privacy, and company boundaries.
- Prompt injection: another agent's text reaches a chat turn. Owner-only
paths still require the person's own message/outbox, fresh-session
history labels peer comments `other_agent`, and the chat directive
states peer comments never carry the person's approval or instruction
authority.
- Delivery & loops: peer chat messages use ordinary best-effort comment
wakes (not the durable human outbox). Budgets, cross-task write limits,
and directive guidance bound back-and-forth chatter.
- No schema, migration, or API contract change.

## Model Used

- Rebase, conflict resolution, additional boundary/handoff tests, and
verification: Google Gemini via Google Antigravity with tool use, shell
execution, and extended reasoning.
- Original implementation and design from #21232: Claude Opus 5.5
(`claude-opus-5-5`, Anthropic, via Claude Code).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: marshall <13757243+lucktastic@users.noreply.github.com>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-25 15:33:14 -06:00
..