Skip to content

feat: update conversation access rules to allow agents to read projec… - #646

Merged
pikann merged 3 commits into
masterfrom
fix/fix-error-cannot-read-conversation
Oct 27, 2026
Merged

pikann merged 3 commits into
masterfrom
fix/fix-error-cannot-read-conversation

Conversation

@pikann

@pikann pikann commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #634. The MCP read_conversation tool returned conversation not found (404) when an agent tried to read another agent's conversation, e.g. a Planner reading the conversation of a Remote Agent it delegated a task to, even when the caller held conversations.read.

Cause

GetConversationForAgent rejected any target conversation whose agent_id differed from the caller's, before the conversations.read and project/audience checks ran. Cross-agent reads could never succeed.

Changes

  • services/api/internal/service/agent/agent_service.go: the same-agent requirement now applies only to the "current conversation" shortcut. Cross-conversation reads (including another agent's) go through the existing checks:
    • the caller holds conversations.read (global, or in the target's project);
    • the caller's current conversation is verified to belong to the caller;
    • the target is visible in that context (same project and project-shared, or owner-private to the same chat-session member; global conversations must share the same actor).
  • services/api/internal/domain/agent/service.go: updated the interface doc comment to match.
  • services/api/internal/service/agent/agent_service_test.go: replaced the "different agent always rejected" test with:
    • a same-project cross-agent read with permission succeeds;
    • a cross-agent read through a spoofed current-conversation ID, or with no current conversation, is still rejected.

Notes

  • Owner-private conversations of another agent stay unreachable unless they belong to the same chat-session member as the caller's current conversation.
  • Not verified end to end with a real Planner and Remote Agent; covered by unit tests only.

Test plan

  • go test ./internal/service/agent/ ./internal/transport/http/...
  • go build ./...

@pullfrog pullfrog 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.

ℹ️ No critical issues — the authorization logic looks correct. A test-coverage gap and some stale docs, both non-blocking.

Reviewed changes

  • GetConversationForAgent no longer rejects a cross-agent target up front; the same-agent requirement now applies only to the target.ID == currentConversationID shortcut. Every other conversation is gated by authorizeConversationsReadForConversation plus authorizeAgentConversationRead (visibility against the human driving the caller-asserted current conversation).
  • domain/agent/service.go interface doc comment updated to describe the relaxed rule.
  • Tests: the "different agent always rejected" case is replaced by a same-project cross-agent allowed case and spoofed/no-current rejected cases.

I traced the branches (GetConversationForAgent L1636-1691, authorizeAgentConversationRead L1742, authorizeConversationAccess L1779, authorizeConversationsReadForConversation L1701): the shortcut still fails closed on a spoofed or uuid.Nil current, global targets still require the same actor, project targets still require the same project plus project_shared/matching session member. Cross-agent reads are now bounded exactly by what the human driving the current conversation could already reach directly, which matches the method's stated model. go test ./internal/service/agent/ ./internal/transport/http/handler/... passes.

ℹ️ Stale descriptions of the authorization rule in apps/mcp

Three comments/tool copy still describe the pre-PR rule that the endpoint authorizes by the target conversation's own agent_id matching the caller. These now contradict the behavior this PR introduces.

Technical details
# Stale cross-agent authorization descriptions

## Affected sites
- apps/mcp/src/api/conversation-client.ts:28-29 — "it authorizes by the server's own verified the calling agent against the conversation's own agent_id" (also an awkward pre-existing phrase).
- apps/mcp/src/__tests__/api/conversation-client.test.ts:121-124 — "this path authorizes by the conversation's own agent_id matching the caller ..., not by project or human membership".
- apps/mcp/src/tools/conversation-tools.ts:33 — tool description: "Works for any conversation you (this agent) participated in", now understated since another agent's project_shared conversation is reachable.

## Required outcome
- Comments/copy should describe the current rule in `agentdom.Service.GetConversationForAgent`: the caller must hold conversations.read, and the target must be visible to the human driving the caller's current conversation. The `PacaConfig.conversationId` comment (apps/mcp/src/types/index.ts:33-37) already reads correctly and is a good reference.

## Open questions for the human
- Whether the tool description should be broadened to mention reading another agent's delegated run, since that is the feature this PR enables.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

ℹ️ No critical issues — the previously flagged coverage gap is now closed; one minor copy inaccuracy inline.

Reviewed changes

  • Updated the apps/mcp comments (conversation-client.ts and its test) to describe the current authorization rule — the caller's conversations.read grant plus visibility of the target from the caller's current conversation — instead of the old target-agent_id match.
  • Broadened the read_conversation tool description to cover reading another agent's delegated run.
  • Added two cross-agent tests against a wired authorizer: a project conversations.read grant succeeds, and no grant is rejected with ErrConversationNotFound.

Verified the four TestGetConversationForAgent_DifferentAgent_* cases pass.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pikann
pikann merged commit fc88f4e into master Oct 27, 2026
7 checks passed
@pikann
pikann deleted the fix/fix-error-cannot-read-conversation branch October 27, 2026 08:39
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.

[Bug] MCP read_conversation returns 404 for valid current and cross-agent conversation IDs

1 participant