Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(connected-apps): pass stored Composio user ID during execution (#10174)

Multica Evec54de2bd2b33
diff --git a/server/internal/connectedapps/gateway.go b/server/internal/connectedapps/gateway.go
index 31ef1ee7ae..f0ab489f6a 100644
--- a/server/internal/connectedapps/gateway.go
+++ b/server/internal/connectedapps/gateway.go
@@ -498,15 +498,17 @@ func (s *Service) toolRun(ctx context.Context, rn *run, toolSlug string, args ma
s.recordCall(ctx, call)
return textResult(fmt.Sprintf("rate limited: this %s account already ran %d calls in the last minute. Wait a minute before the next call, and batch work where the app allows it.", slug, s.perMinute), true)
}
- resp, err := s.composio.ExecuteTool(ctx, acct.connectedAccountID, *tool, args)
+ resp, err := s.composio.ExecuteTool(ctx, acct.connectedAccountID, acct.composioUserID, *tool, args)
s.touch(ctx, rn.workspaceID, acct)
if err != nil {
call.outcome, call.err = "error", truncate(err.Error(), 500)
+ logExecutionFailure(ctx, call, "request_failed")
s.recordCall(ctx, call)
return textResult("the app call failed: "+truncate(err.Error(), 500), true)
}
if !resp.Successful {
call.outcome, call.err = "error", truncate(resp.Error, 500)
+ logExecutionFailure(ctx, call, "tool_unsuccessful")
s.recordCall(ctx, call)
return textResult("the app returned an error: "+truncate(resp.Error, 2000), true)
}
diff --git a/server/internal/connectedapps/requests.go b/server/internal/connectedapps/requests.go
index e82bbfc3aa..40c37304f7 100644
--- a/server/internal/connectedapps/requests.go
+++ b/server/internal/connectedapps/requests.go
@@ -270,12 +270,14 @@ func (s *Service) executeApproved(ctx context.Context, req db.AppActionRequest)
if Decide(req.ToolkitSlug, app.Level, class, rule) == PolicyBlock {
return fail("a rule now blocks this call")
}
- resp, err := s.composio.ExecuteTool(ctx, acct.connectedAccountID, *tool, args)
+ resp, err := s.composio.ExecuteTool(ctx, acct.connectedAccountID, acct.composioUserID, *tool, args)
s.touch(ctx, req.WorkspaceID, acct)
if err != nil {
+ logExecutionFailure(ctx, call, "request_failed")
return fail(truncate(err.Error(), 500))
}
if !resp.Successful {
+ logExecutionFailure(ctx, call, "tool_unsuccessful")
return fail(truncate(resp.Error, 500))
}
result, err := json.Marshal(resp.Data)
diff --git a/server/internal/connectedapps/service.go b/server/internal/connectedapps/service.go
index 995d6805b1..1de7691a8e 100644
--- a/server/internal/connectedapps/service.go
+++ b/server/internal/connectedapps/service.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "log/slog"
"strings"
"time"
@@ -337,6 +338,7 @@ func (s *Service) activePersonalAccounts(ctx context.Context, userID pgtype.UUID
type account struct {
scope string
connectedAccountID string
+ composioUserID string
connectionID pgtype.UUID
// owner is the member whose personal account it is; invalid for team.
owner pgtype.UUID
@@ -354,7 +356,7 @@ func (s *Service) resolveAccount(ctx context.Context, workspaceID, triggeredBy p
if !ok {
return account{}, ErrAccountMissing
}
- return account{scope: ScopeTeam, connectedAccountID: row.ConnectedAccountID, connectionID: row.ID}, nil
+ return account{scope: ScopeTeam, connectedAccountID: row.ConnectedAccountID, composioUserID: row.ComposioUserID, connectionID: row.ID}, nil
}
if !triggeredBy.Valid {
return account{}, ErrAccountMissing
@@ -367,7 +369,7 @@ func (s *Service) resolveAccount(ctx context.Context, workspaceID, triggeredBy p
if !ok {
return account{}, ErrAccountMissing
}
- return account{scope: ScopePersonal, connectedAccountID: row.ConnectedAccountID, connectionID: row.ID, owner: triggeredBy}, nil
+ return account{scope: ScopePersonal, connectedAccountID: row.ConnectedAccountID, composioUserID: row.ComposioUserID, connectionID: row.ID, owner: triggeredBy}, nil
}
// accountRule returns the account owner's rule for one class, or "".
@@ -404,6 +406,17 @@ type toolCall struct {
err string
}
+// Upstream errors can contain tool arguments or private app data. Log only
+// fixed failure classes and the local identifiers needed to find the call.
+func logExecutionFailure(ctx context.Context, c toolCall, errorClass string) {
+ slog.WarnContext(ctx, "connectedapps: tool execution failed",
+ "workspace_id", util.UUIDToString(c.workspaceID),
+ "task_id", util.UUIDToString(c.taskID),
+ "request_id", util.UUIDToString(c.requestID),
+ "toolkit", c.toolkit, "tool", c.tool,
+ "account_scope", c.acct.scope, "error_class", errorClass)
+}
+
func (s *Service) recordCall(ctx context.Context, c toolCall) {
scope := c.acct.scope
if scope == "" {
diff --git a/server/internal/handler/connected_apps_test.go b/server/internal/handler/connected_apps_test.go
index 5622878de1..f01d8ecf89 100644
--- a/server/internal/handler/connected_apps_test.go
+++ b/server/internal/handler/connected_apps_test.go
@@ -4,9 +4,12 @@ import (
"bytes"
"context"
"encoding/json"
+ "errors"
"fmt"
+ "log/slog"
"net/http"
"net/http/httptest"
+ "reflect"
"strings"
"sync"
"testing"
@@ -15,6 +18,7 @@ import (
"github.com/multica-ai/multica/server/internal/connectedapps"
composio "github.com/multica-ai/multica/server/internal/integrations/composio"
"github.com/multica-ai/multica/server/internal/middleware"
+ "github.com/multica-ai/multica/server/internal/testutil"
"github.com/multica-ai/multica/server/internal/util"
sdk "github.com/multica-ai/multica/server/pkg/composio"
db "github.com/multica-ai/multica/server/pkg/db/generated"
@@ -23,8 +27,10 @@ import (
// appsFakeSDK serves a small Gmail toolkit and records executions.
type appsFakeSDK struct {
composioFakeSDK
- mu sync.Mutex
- executed []sdk.ExecuteToolRequest
+ mu sync.Mutex
+ executed []sdk.ExecuteToolRequest
+ executeErr error
+ toolError string
}
var appsFakeGmailTools = []sdk.Tool{
@@ -57,6 +63,15 @@ func (f *appsFakeSDK) ExecuteTool(_ context.Context, slug string, req sdk.Execut
f.mu.Lock()
defer f.mu.Unlock()
f.executed = append(f.executed, req)
+ if req.UserID == "" || req.ConnectedAccountID == "" {
+ return nil, errors.New("User ID is required with connected account")
+ }
+ if f.executeErr != nil {
+ return nil, f.executeErr
+ }
+ if f.toolError != "" {
+ return &sdk.ExecuteToolResponse{Error: f.toolError}, nil
+ }
return &sdk.ExecuteToolResponse{Successful: true, Data: map[string]any{"tool": slug}}, nil
}
@@ -594,3 +609,229 @@ func TestConnectedApps_CustomCatalogAndIssueCalls(t *testing.T) {
t.Fatalf("unlisted app in custom catalog: %d, want 403", w.Code)
}
}
+
+// executionAccount gives each scope a stored identity distinct from the run's
+// originator, so deriving the identity instead of reading it fails the test.
+func (f *appsFixture) executionAccount(t *testing.T, scope string) (table, id, userID, accountID string) {
+ t.Helper()
+ userID = fmt.Sprintf("stored_%s_%d", scope, testSeq.Add(1))
+ accountID = fmt.Sprintf("ca_%s_%d", scope, testSeq.Add(1))
+ if scope == "team" {
+ table = "workspace_composio_connection"
+ id = dbfx.Insert(t, table, testutil.Cols{
+ "workspace_id": testWorkspaceID, "toolkit_slug": "gmail", "auth_config_id": "ac_gmail",
+ "connected_account_id": accountID, "composio_user_id": userID, "connected_by": testUserID,
+ })
+ } else {
+ table = "user_composio_connection"
+ dbfx.QueryRow(t, `UPDATE user_composio_connection SET composio_user_id = $1, connected_account_id = $2
+ WHERE user_id = $3 AND toolkit_slug = 'gmail' AND status = 'active' RETURNING id`, userID, accountID, testUserID).Scan(&id)
+ dbfx.Cleanup(t, `DELETE FROM user_composio_connection WHERE id = $1`, id)
+ }
+ return
+}
+
+func (f *appsFixture) approve(t *testing.T, requestID string, args map[string]any) AppRequestResponse {
+ t.Helper()
+ var body any
+ if args != nil {
+ body = map[string]any{"arguments": args}
+ }
+ req := appsReqAs(t, testUserID, http.MethodPost, "/api/app-requests/"+requestID+"/approve", body)
+ var out AppRequestResponse
+ testutil.Call(t, f.h.ApproveAppRequest, withURLParam(req, "id", requestID)).Want(http.StatusOK).JSON(&out)
+ return out
+}
+
+func TestConnectedApps_ExecutionIdentity(t *testing.T) {
+ for _, scope := range []string{"personal", "team"} {
+ for _, approved := range []bool{false, true} {
+ t.Run(fmt.Sprintf("%s/approved=%t", scope, approved), func(t *testing.T) {
+ f := newAppsFixture(t)
+ table, id, userID, accountID := f.executionAccount(t, scope)
+ if w := f.putAgentApps(t, testUserID, []map[string]string{{"toolkit_slug": "gmail", "account_scope": scope, "level": "confirm_writes"}}); w.Code != http.StatusOK {
+ t.Fatalf("attach app: %d %s", w.Code, w.Body.String())
+ }
+ tool := "GMAIL_FETCH_EMAILS"
+ if approved {
+ tool = "GMAIL_SEND_EMAIL"
+ }
+ args := map[string]any{"user_id": "me", "connected_account_id": "caller_account", "body": "private draft"}
+ _, text, isErr := f.gateway(t, f.token(t), "apps_run_tool", map[string]any{"tool": tool, "arguments": args})
+ if isErr {
+ t.Fatalf("gateway call failed: %s", text)
+ }
+ if approved {
+ if !strings.HasPrefix(text, "submitted") || len(f.sdk.executions()) != 0 {
+ t.Fatalf("call did not wait for approval: %s", text)
+ }
+ requests := f.listRequests(t, testUserID)
+ if len(requests) != 1 {
+ t.Fatalf("requests = %+v", requests)
+ }
+ // Execution must resolve the current pair again after approval.
+ userID, accountID = userID+"_reconnected", accountID+"_reconnected"
+ dbfx.Exec(t, "UPDATE "+table+" SET composio_user_id = $1, connected_account_id = $2 WHERE id = $3", userID, accountID, id)
+ args["body"] = "edited draft"
+ if out := f.approve(t, requests[0].ID, args); out.Status != "approved" {
+ t.Fatalf("approved call = %+v", out)
+ }
+ }
+ execs := f.sdk.executions()
+ if len(execs) != 1 {
+ t.Fatalf("executions = %d, want 1", len(execs))
+ }
+ if got := execs[0]; got.UserID != userID || got.ConnectedAccountID != accountID || !reflect.DeepEqual(got.Arguments, args) {
+ t.Fatalf("execution identity or tool arguments changed: %+v", got)
+ }
+ })
+ }
+ }
+}
+
+func TestConnectedApps_ExecutionRejectsMissingIdentity(t *testing.T) {
+ for _, scope := range []string{"personal", "team"} {
+ for _, approved := range []bool{false, true} {
+ for _, identity := range []string{"", " \t"} {
+ t.Run(fmt.Sprintf("%s/approved=%t/identity=%q", scope, approved, identity), func(t *testing.T) {
+ f := newAppsFixture(t)
+ table, id, _, _ := f.executionAccount(t, scope)
+ if w := f.putAgentApps(t, testUserID, []map[string]string{{"toolkit_slug": "gmail", "account_scope": scope, "level": "confirm_writes"}}); w.Code != http.StatusOK {
+ t.Fatalf("attach app: %d %s", w.Code, w.Body.String())
+ }
+ args := map[string]any{"user_id": "me"}
+ if approved {
+ _, text, isErr := f.gateway(t, f.token(t), "apps_run_tool", map[string]any{"tool": "GMAIL_SEND_EMAIL", "arguments": args})
+ if isErr || !strings.HasPrefix(text, "submitted") {
+ t.Fatalf("submit = %s", text)
+ }
+ }
+ dbfx.Exec(t, "UPDATE "+table+" SET composio_user_id = $1 WHERE id = $2", identity, id)
+ if approved {
+ requests := f.listRequests(t, testUserID)
+ if len(requests) != 1 {
+ t.Fatalf("requests = %+v", requests)
+ }
+ if out := f.approve(t, requests[0].ID, nil); out.Status != "failed" || out.Error == nil || !strings.Contains(*out.Error, "user ID is missing") {
+ t.Fatalf("missing identity approval = %+v", out)
+ }
+ } else if _, text, isErr := f.gateway(t, f.token(t), "apps_run_tool", map[string]any{"tool": "GMAIL_FETCH_EMAILS", "arguments": args}); !isErr || !strings.Contains(text, "user ID is missing") {
+ t.Fatalf("missing identity call = %s (error %v)", text, isErr)
+ }
+ if len(f.sdk.executions()) != 0 {
+ t.Fatal("missing identity reached upstream")
+ }
+ })
+ }
+ }
+ }
+}
+
+func TestConnectedApps_ExecutionAccountIsolation(t *testing.T) {
+ for _, scope := range []string{"personal", "team"} {
+ for _, approved := range []bool{false, true} {
+ t.Run(fmt.Sprintf("%s/approved=%t", scope, approved), func(t *testing.T) {
+ f := newAppsFixture(t)
+ table, id, _, _ := f.executionAccount(t, scope)
+ if w := f.putAgentApps(t, testUserID, []map[string]string{{"toolkit_slug": "gmail", "account_scope": scope, "level": "confirm_writes"}}); w.Code != http.StatusOK {
+ t.Fatalf("attach app: %d %s", w.Code, w.Body.String())
+ }
+ args := map[string]any{"user_id": "me"}
+ var requestID string
+ if approved {
+ f.gateway(t, f.token(t), "apps_run_tool", map[string]any{"tool": "GMAIL_SEND_EMAIL", "arguments": args})
+ requests := f.listRequests(t, testUserID)
+ if len(requests) != 1 {
+ t.Fatalf("requests = %+v", requests)
+ }
+ requestID = requests[0].ID
+ req := appsReqAs(t, f.member, http.MethodPost, "/api/app-requests/"+requestID+"/approve", nil)
+ testutil.Call(t, f.h.ApproveAppRequest, withURLParam(req, "id", requestID)).Want(http.StatusForbidden)
+ otherWorkspace := dbfx.Workspace(t, "Foreign approvals", fmt.Sprintf("apps-approval-%d", testSeq.Add(1)))
+ if _, err := f.h.ConnectedApps.Approve(context.Background(), parseUUID(otherWorkspace), parseUUID(testUserID), parseUUID(requestID), nil); !errors.Is(err, connectedapps.ErrRequestNotFound) {
+ t.Fatalf("cross-workspace approval = %v", err)
+ }
+ if len(f.sdk.executions()) != 0 {
+ t.Fatal("unauthorized approval reached upstream")
+ }
+ }
+ if scope == "personal" {
+ dbfx.Exec(t, "UPDATE "+table+" SET user_id = $1 WHERE id = $2", f.member, id)
+ } else {
+ otherWorkspace := dbfx.Workspace(t, "Foreign account", fmt.Sprintf("apps-account-%d", testSeq.Add(1)))
+ dbfx.Exec(t, "UPDATE "+table+" SET workspace_id = $1 WHERE id = $2", otherWorkspace, id)
+ }
+ if approved {
+ if out := f.approve(t, requestID, nil); out.Status != "failed" {
+ t.Fatalf("foreign account approval = %+v", out)
+ }
+ } else if _, text, isErr := f.gateway(t, f.token(t), "apps_run_tool", map[string]any{"tool": "GMAIL_FETCH_EMAILS", "arguments": args}); !isErr {
+ t.Fatalf("foreign account call succeeded: %s", text)
+ }
+ if len(f.sdk.executions()) != 0 {
+ t.Fatal("foreign account reached upstream")
+ }
+ })
+ }
+ }
+}
+
+func TestConnectedApps_ExecutionFailureLogs(t *testing.T) {
+ for _, approved := range []bool{false, true} {
+ for _, category := range []string{"request_failed", "tool_unsuccessful"} {
+ t.Run(fmt.Sprintf("approved=%t/%s", approved, category), func(t *testing.T) {
+ f := newAppsFixture(t)
+ _, _, userID, accountID := f.executionAccount(t, "personal")
+ if w := f.putAgentApps(t, testUserID, []map[string]string{{"toolkit_slug": "gmail", "account_scope": "personal", "level": "confirm_writes"}}); w.Code != http.StatusOK {
+ t.Fatalf("attach app: %d %s", w.Code, w.Body.String())
+ }
+ const private = "private_mail_or_token"
+ if category == "request_failed" {
+ f.sdk.executeErr = errors.New(private)
+ } else {
+ f.sdk.toolError = private
+ }
+ var logs bytes.Buffer
+ prev := slog.Default()
+ slog.SetDefault(slog.New(slog.NewJSONHandler(&logs, nil)))
+ t.Cleanup(func() { slog.SetDefault(prev) })
+ tool := "GMAIL_FETCH_EMAILS"
+ if approved {
+ tool = "GMAIL_SEND_EMAIL"
+ }
+ code, text, isErr := f.gateway(t, f.token(t), "apps_run_tool", map[string]any{"tool": tool, "arguments": map[string]any{"body": private}})
+ requestID := ""
+ if approved {
+ requests := f.listRequests(t, testUserID)
+ if len(requests) != 1 {
+ t.Fatalf("requests = %+v", requests)
+ }
+ requestID = requests[0].ID
+ if out := f.approve(t, requestID, nil); out.Status != "failed" {
+ t.Fatalf("upstream failure approval = %+v", out)
+ }
+ } else if code != http.StatusOK || !isErr || !strings.Contains(text, private) {
+ t.Fatalf("MCP error changed: HTTP %d, %s (error %v)", code, text, isErr)
+ }
+ var event map[string]any
+ for _, line := range strings.Split(strings.TrimSpace(logs.String()), "\n") {
+ var entry map[string]any
+ if json.Unmarshal([]byte(line), &entry) == nil && entry["msg"] == "connectedapps: tool execution failed" {
+ event = entry
+ }
+ }
+ if event["workspace_id"] != testWorkspaceID || event["task_id"] != f.taskID || event["request_id"] != requestID || event["toolkit"] != "gmail" || event["tool"] != tool || event["account_scope"] != "personal" || event["error_class"] != category {
+ t.Fatalf("failure log = %v", event)
+ }
+ for _, sensitive := range []string{private, userID, accountID} {
+ if strings.Contains(logs.String(), sensitive) {
+ t.Fatalf("sensitive value appeared in logs: %q", sensitive)
+ }
+ }
+ if n := dbfx.Count(t, `SELECT count(*) FROM app_tool_call WHERE task_id = $1 AND outcome = 'error'`, f.taskID); n != 1 {
+ t.Fatalf("recorded failures = %d, want 1", n)
+ }
+ })
+ }
+ }
+}
diff --git a/server/internal/integrations/composio/team.go b/server/internal/integrations/composio/team.go
index 5810416cf2..56fa50faa3 100644
--- a/server/internal/integrations/composio/team.go
+++ b/server/internal/integrations/composio/team.go
@@ -320,8 +320,15 @@ func (s *Service) GetTool(ctx context.Context, toolkitSlug, toolSlug string) (*s
return t, nil
}
-// ExecuteTool runs a tool against one connected account.
-func (s *Service) ExecuteTool(ctx context.Context, connectedAccountID string, tool sdk.Tool, args map[string]any) (*sdk.ExecuteToolResponse, error) {
+// ExecuteTool runs a tool against one connected account. Both identifiers must
+// come from the same authorized connection record, never from tool arguments.
+func (s *Service) ExecuteTool(ctx context.Context, connectedAccountID, composioUserID string, tool sdk.Tool, args map[string]any) (*sdk.ExecuteToolResponse, error) {
+ if strings.TrimSpace(composioUserID) == "" {
+ return nil, errors.New("composio: connected account user ID is missing; reconnect the account")
+ }
+ if strings.TrimSpace(connectedAccountID) == "" {
+ return nil, errors.New("composio: connected account ID is missing; reconnect the account")
+ }
tools, err := s.toolSDK()
if err != nil {
return nil, err
@@ -333,6 +340,7 @@ func (s *Service) ExecuteTool(ctx context.Context, connectedAccountID string, to
return tools.ExecuteTool(ctx, tool.Slug, sdk.ExecuteToolRequest{
Arguments: args,
ConnectedAccountID: connectedAccountID,
+ UserID: composioUserID,
Version: version,
})
}
diff --git a/server/internal/integrations/composio/team_test.go b/server/internal/integrations/composio/team_test.go
new file mode 100644
index 0000000000..8daab11858
--- /dev/null
+++ b/server/internal/integrations/composio/team_test.go
@@ -0,0 +1,87 @@
+package composio
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "sync/atomic"
+ "testing"
+ "time"
+
+ sdk "github.com/multica-ai/multica/server/pkg/composio"
+)
+
+func TestExecuteTool_ConnectedAccountIdentityOnWire(t *testing.T) {
+ for _, userID := range []string{"personal_user", "ws_team"} {
+ for _, version := range []string{"", "20261027_00"} {
+ t.Run(userID+"/"+version, func(t *testing.T) {
+ args := map[string]any{"user_id": "me", "max_results": float64(5)}
+ var calls atomic.Int32
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ calls.Add(1)
+ if r.Method != http.MethodPost || r.URL.Path != "/tools/execute/GMAIL_FETCH_EMAILS" {
+ t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
+ }
+ var wire struct {
+ UserID string `json:"user_id"`
+ ConnectedAccountID string `json:"connected_account_id"`
+ Version string `json:"version"`
+ Arguments map[string]any `json:"arguments"`
+ }
+ if err := json.NewDecoder(r.Body).Decode(&wire); err != nil {
+ t.Error(err)
+ }
+ if wire.UserID != userID || wire.ConnectedAccountID != "ca_selected" {
+ t.Errorf("missing or mismatched identity: %+v", wire)
+ http.Error(w, "User ID is required with connected account", http.StatusBadRequest)
+ return
+ }
+ wantVersion := version
+ if wantVersion == "" {
+ wantVersion = "latest"
+ }
+ if wire.Version != wantVersion || !reflect.DeepEqual(wire.Arguments, args) {
+ t.Errorf("tool inputs changed: %+v", wire)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"successful":true,"data":{"messages":[]}}`))
+ }))
+ defer srv.Close()
+ client, err := sdk.NewClient(sdk.Options{APIKey: "test-key", BaseURL: srv.URL, Timeout: time.Second})
+ if err != nil {
+ t.Fatal(err)
+ }
+ svc := newTestService(t, client, newFakeStore())
+ resp, err := svc.ExecuteTool(context.Background(), "ca_selected", userID, sdk.Tool{Slug: "GMAIL_FETCH_EMAILS", Version: version}, args)
+ if err != nil || !resp.Successful || calls.Load() != 1 {
+ t.Fatalf("execution = %+v, %v; upstream calls = %d", resp, err, calls.Load())
+ }
+ })
+ }
+ }
+}
+
+func TestExecuteTool_RequiresConnectionIdentity(t *testing.T) {
+ var calls atomic.Int32
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ calls.Add(1)
+ http.Error(w, "unexpected upstream call", http.StatusInternalServerError)
+ }))
+ defer srv.Close()
+ client, err := sdk.NewClient(sdk.Options{APIKey: "test-key", BaseURL: srv.URL, Timeout: time.Second})
+ if err != nil {
+ t.Fatal(err)
+ }
+ svc := newTestService(t, client, newFakeStore())
+ for _, pair := range [][2]string{{"ca_selected", ""}, {"ca_selected", " \t"}, {"", "stored_user"}, {" \t", "stored_user"}} {
+ resp, err := svc.ExecuteTool(context.Background(), pair[0], pair[1], sdk.Tool{Slug: "GMAIL_FETCH_EMAILS"}, map[string]any{"user_id": "me"})
+ if err == nil || resp != nil {
+ t.Fatalf("incomplete identity %q accepted: %+v, %v", pair, resp, err)
+ }
+ }
+ if calls.Load() != 0 {
+ t.Fatalf("incomplete identity reached upstream %d times", calls.Load())
+ }
+}
diff --git a/server/pkg/composio/tools.go b/server/pkg/composio/tools.go
index 808f93ef1d..599411502a 100644
--- a/server/pkg/composio/tools.go
+++ b/server/pkg/composio/tools.go
@@ -12,10 +12,8 @@ import (
//
// Spec: https://docs.composio.dev/reference/api-reference/tools/postToolsExecuteByToolSlug
//
-// Either ConnectedAccountID or (UserID + the tool's toolkit) is required so
-// Composio knows which credential set to use. The SDK does not enforce that
-// invariant up front; the upstream returns a 422 with a clear message when
-// missing.
+// Connected-account callers should send both ConnectedAccountID and its UserID.
+// The SDK leaves provider-specific identity validation to the upstream.
type ExecuteToolRequest struct {
// Arguments is the structured input to the tool. Shape varies per tool.
Arguments map[string]any `json:"arguments,omitempty"`
@@ -23,8 +21,8 @@ type ExecuteToolRequest struct {
// ConnectedAccountID pins execution to a specific connected account.
ConnectedAccountID string `json:"connected_account_id,omitempty"`
- // UserID lets Composio resolve the connected account by user when
- // the caller does not have the explicit `ca_` id handy.
+ // UserID identifies the Composio owner of the connected account. It is
+ // separate from any user_id inside Arguments (e.g. Gmail's "me").
UserID string `json:"user_id,omitempty"`
// Version pins the tool definition version. Pass "latest" or a dated