Files
PaperClipAI/maps/agent-access-map
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
..

Paperclip agent access map

This map accompanies the feature map. It records APIs, agent entry points, permission boundaries and verification for the same capability IDs. The shared contract defines the format and maintenance rules.

The chat scenario catalog uses these same IDs for human requests and expected outcomes. Its scenarios retain the access boundaries here; neither a CEO role nor a planned scenario grants board authority or establishes a working production tool binding.

Use full capability IDs when referring to access contracts outside their file: onboarding/company means the company capability in onboarding.md in both maps. The feature index lists feature and capability IDs; IDs and references explains entry-point references and stable naming.

Browse access contracts

The same-named feature recipes define navigation and capability IDs. Run node scripts/storybook-catalog.mjs for the generated maps/generated/agent-access-map.md index, or browse the published feature guide. Add or update the affected companion; there is no central registration or count.

Existing baseline source references describe the original inspection, not current verification. Record new executed evidence in the PR, issue, or CI artifact with its revision and scope. Do not refresh unrelated headers as bookkeeping.

Using an entry

Read its Policy and Gaps before selecting an agent path. Native fallback, legacy REST/CLI, stdio MCP and a personal assistant connection can have different authority and availability. Use a real admitted production binding; a scenario declaration is not an installed tool. A restricted entry records current enforcement and leaves any unresolved delegation decision visible.

For API catalog disagreements, follow the route/service authorization and record discovery drift. For not-applicable, retain the concrete exception and local path. Split shared business operations from client-only presentation.

Use maintain-verification-skill to reconcile changed source and both maps. Use verify-paperclip and existing API/runner/MCP fixtures to collect the permitted-agent and denial evidence; report blocked/not-run coverage honestly. Run node scripts/check-maps.mjs after editing. The structural check does not certify permissions, API catalog coverage, tool admission or live behavior.

Native REST transport

The call_api parity change reconciles affected baselines against 58e16dbddfc9c8d0cf60867f9d9847f0feda055b and the changes in this PR. Ordinary REST operations use the same route authorization as legacy agent REST. Dedicated tools remain optional for those operations; protocol endpoints still need their existing clients. Board-only routes remain restricted for agent identity.

Native search_api / call_api is enabled by default, but explicit server, company-allowlist and binding settings can narrow admission. It requires a running authorized native run, current task assignment and execution-run binding, company and budget authority, task privacy, and a permitted work mode. Ask and Plan retain mutation restrictions, and runs retain their admitted JWT scope during restart recovery even when task mode changes. A waiting agent does not gain independent native control just because a REST route exists. Connection-management reads support Standard, Ask and Plan; mutations require Standard. Skill-test runs and nonstandard task-bridge keys cannot administer connections. These gates supplement each operation's grants, resolved resource and target scope, and responsible-user authority. See the rollout policy and connection authorization.

Credential-bearing replies, including company exports and their legacy alias, stay inline under a 10 MiB limit and use encrypted mutation receipts. Other saved API snapshots are limited to the issuing actor and responsible user, plus authorized administrators. Artifact uploads enforce the same access checks as downloads; private snapshots are excluded from company exports and public company logos. Explicit deliverables use the existing sharing path. Native event history, checkpoints and completion records omit API bodies while preserving receipt metadata and replay digests. Restored webhook secrets use the same encrypted receipt and inline response policy as newly created webhook secrets. Task image access requires the company boundary and the task permission; skill-test and low-trust agents do not need company-wide browsing authority. Completion replay applies the same idempotent projection to stored and expected payloads; its fields are defined where the run-log event is written.

Sources: API client, catalog, native authority, credential storage classification, snapshot access, and history redaction. The affected entries remain baseline and source-only; this reconciliation does not certify every operation. Targeted real-route proof lives in the API integration suite, including owned routines, skill tests, scoped secrets, proposals and private export replay.