Skip to content

AI-3763: match a tool approval to its person by kind - #2436

Merged
martinmitrevski merged 3 commits into
mainfrom
martinmitrevski/ai-3763-a-tool-approval-is-matched-to-the
Nov 25, 2026
Merged

martinmitrevski merged 3 commits into
mainfrom
martinmitrevski/ai-3763-a-tool-approval-is-matched-to-the

Conversation

@martinmitrevski

@martinmitrevski martinmitrevski commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes AI-3763, a follow-up from #2384 (AI-3725).

Why

A connector call held for approval kept only the user id of the person it asked, and an answer was accepted from the customer's backend or from anyone with that id (by.UserID == asked, session/connector_approval.go). POST /v1/agents/conversations/{cid}/tool_approvals requires a verified caller who is a member of the channel. But a channel knows its members by id alone, so a token with role: guest and a signed-in user's id passed both checks and allowed that user's call. Reproduced on main: the guest's answer was a 204 and the call ran.

A session's owner is already matched by id and kind (session.Owner.Reaches). #2384 matches a conversation's owner the same way, and this applies that rule to the person an approval asks.

How it works

call held for approval  (holdForApproval -> askedAs)
  asked = conversation.AwaitApproval(...)          a user id
  ├─ the session's own user  -> Owner{id, spec.CallerKind}
  │    (also when they wrote the message the reply answers)
  └─ any other writer        -> Owner{id, KindServer}
       (a chat channel: the router reads the writer's id alone, so the
        writer is held like a user a backend opened a session for)

answer  (AnswerConnectorApproval)  ->  by.Reaches(asked)
  ├─ customer's backend                         -> yes
  ├─ same id, same kind                         -> yes
  ├─ same id, verified, asked held as server    -> yes
  └─ anything else                              -> ErrApprovalAskedOfAnother (403)

Before and after, for a call held for the session's own user alice:

Session opened by Answer from Before After
alice, signed in alice, signed in allowed allowed
alice, signed in guest token with id alice allowed refused (403)
guest alice guest alice allowed allowed
guest alice alice, signed in allowed refused
backend, for alice alice, signed in or guest allowed allowed
any the customer's backend allowed allowed

Only the REST answer changes: a socket's seat already has to reach the session (sessions.Get → Owner.Reaches), and the person a session asks is its own user. A message's writer in a channel an agent config answers in: any verified caller of their id, as before, unless the writer is the session's own user (a session opened through the API answering in the channel), who is asked as the kind of caller that opened it. The router reads only message.user.id and name from the hook (messageEvent in api/messagehooks.go), so nothing it reads proves a writer's kind. Stream's sample message.new also carries message.user.role; holding a writer by that is a follow-up (review R1.2). An anonymous caller naming them is refused, but POST .../tool_approvals already refused it as unverified.

Changes

Change Result Test
heldCall.asked is an Owner, set by askedAs the call remembers the kind of the person asked TestACallerOfAnotherKindGoingByTheUsersIdMayNotAnswer, TestAGuestAnswersTheCallOfTheirSessionAndAUserOfTheirIdDoesNot
AnswerConnectorApproval checks by.Reaches(asked) the rule a session's owner is reached by TestAGuestGoingByTheUsersIdCannotAnswerThroughTheirConversation (REST, end to end)
A writer is held as KindServer any verified caller of the writer's id still answers TestAVerifiedCallerOfTheWritersIdAnswersTheCallTheirMessageAsked
Connectors skill says who may answer

Validation

  • The four new ConnectorApprovalSuite tests and TestAGuestGoingByTheUsersIdCannotAnswerThroughTheirConversation fail on main (0e5197a7a): the guest's REST answer was a 204, not a 403.
  • Mutations, each failing a test: holding everyone asked as KindServer (kills the guest/user tests), holding a writer as the session's kind (kills the writer test).
  • Passing with -tags integration: internal/session TestConnectorApprovalSuite, internal/api TestSessionConnectorsSuite, TestAppHooksSuite (chat channel approvals, approvals answered on another node), TestChannelTypeTurnSuite, TestChatLoginsSuite, TestForwardedSessionSuite, TestSessionEventsSuite. go test ./internal/session without the tag.
  • Merged with main (d89d15dc7). connector_approvals_test.go conflicted with main's three team tests; both sides are kept. On the merge, the integration suites above pass again, and go vet -tags integration ./internal/api ./internal/session is clean.
  • No API, spec or SDK change.

🤖 Generated with Claude Code

…and kind

A call held for approval kept only the user id of the person it asked, so
any verified caller of that id answered it. A conversation's channel knows
its members by id alone, so a guest token naming a signed-in user's id got
through POST /conversations/{cid}/tool_approvals and allowed their call.

The held call now keeps whom it asked as a session owner: the session's
own user as the kind of caller that opened it, and the writer of a message
in a channel an agent config answers in as a backend names a user, since
the hook names the writer by id alone. The answer is checked with
Owner.Reaches, the rule a session's owner is reached by.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the docs label Nov 25, 2026
@martinmitrevski
martinmitrevski marked this pull request as ready for review November 25, 2026 08:30

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

VERDICT: GO

Reviewed d12b39b1c merged onto main (641ee3038, then again onto 3d837a3fc). CI on the head: all checks pass, integration (router) included.

Merge conflict: GitHub shows this PR as CONFLICTING. acceleration/internal/api/connector_approvals_test.go conflicts with main: this PR adds TestAGuestGoingByTheUsersIdCannotAnswerThroughTheirConversation, and main added the three team tests (TestAUserInTheConfigsTeam..., TestAUserWhoLeftTheConfigsTeam..., TestAnAnswerWhileTheUsersTeamsCannotBeRead...) at the same place, plus imports. Keep both sides. With both kept, TestSessionConnectorsSuite passes.

Checked and sound:

  • The fix holds. With connector_approval.go reverted to the base, the new REST test fails: the guest gets a 204 where the test expects a 403.
  • I tried 7 mutations and the tests caught all 7: the person asked always held as server, always held as the session's kind, the writer held as authenticated, CustomerID dropped, the old id-only rule, Reaches reversed, and the REST call site dropping the caller's kind.
  • Only two paths answer an approval: the socket tool_approval (sessionws.go:546) and POST .../tool_approvals (conversations.go:122). On the socket the rule decides the same as before for every seat that reaches the session, so the body's "only the REST answer changes" holds. An answer forwarded to another node is re-authenticated there, because node.Forward replays the request headers.
  • Approvals pending across the deploy are not affected. A held call lives only in the memory of the node that holds it (approvals.held), and the stored step's target_user_id is never read for authorization. A call held on an old node is answered by the old rule until it ends, and a new node never reads a record from before the kind was kept.
  • Touched suites pass on the merged tree: TestConnectorApprovalSuite, TestSessionConnectorsSuite, TestAppHooksSuite, TestChannelTypeTurnSuite, TestChatLoginsSuite, TestForwardedSessionSuite, TestSessionEventsSuite. gofmt and go vet -tags integration are clean.

There are no Blockers or Should fixes. R1.1 (Nit) and R1.2 (Question) are inline; each one is a follow-up.

Comment thread .claude/skills/connectors/SKILL.md Resolved

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving on the reviewer's GO (#2436 (review)). It conflicts with main in connector_approvals_test.go; keeping both sides works.

martinmitrevski and others added 2 commits November 25, 2026 15:49
…63-a-tool-approval-is-matched-to-the

# Conflicts:
#	acceleration/internal/api/connector_approvals_test.go
…y kind

askedAs holds a writer who is the session's own user as the kind of caller
that opened it, so a guest token of their id does not answer for them. The
askedAs comment and the connectors skill said any verified token of the
writer's id answers; they now name that exception.

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

@thesyncim thesyncim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed at d12b39b merged with main b86e02f, and with #2384 (merged since), #2404, #2371, #2431 and #2432. No defect found: the approval, app hooks, channel type and forwarded session suites pass, and nine mutants of the rule are all killed. I'll approve once it is rebased.

  • Conflict with main, in connector_approvals_test.go alone: the imports, and the tests added after TestTheUserMayAnswerThroughTheirConversation. Keeping both blocks works.
  • Nit: the ticket asks that a claimed guest keeps working. From reading it does (the claim moves the row to the account's kind), but no test shows it. Could one be added, or the line be answered in the description?
  • Nit: the operation's description in api/conversations.go (answerConversationToolApproval) still says target_user_id is who may answer. A caller of another kind with that id now gets the 403. Worth a sentence there and a spec regeneration, since a client author reads that and not the skill.
  • Question: a texted session is opened as an authenticated user whatever kind the linked user is (channels/service.go). If an app links a guest-role user to a number, that guest no longer answers the call through the conversation. Is that intended? It does match how they reach the session.

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-approving on the reviewer's GO (#2436 (review)). The new head merges main, and its test-file conflict keeps both sides. Its docs commit fixes the R1.1 Nit in comments and the skill only.

@martinmitrevski
martinmitrevski merged commit 76175b3 into main Nov 25, 2026
13 checks passed
@martinmitrevski
martinmitrevski deleted the martinmitrevski/ai-3763-a-tool-approval-is-matched-to-the branch November 25, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants