Repository navigation
Centralize account-authorized task run reads - #1037
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
All reported issues were addressed across 11 files
Architecture diagram
sequenceDiagram
participant Client as HTTP Client
participant MCPKey as API-Key MCP Client
participant MCPOAuth as OAuth MCP Client
participant Route as GET /api/tasks/runs
participant Handler as getTaskRunHandler
participant Auth as Auth/Access Checks
participant Read as readTaskRunForAccount
participant Trigger as retrieveTaskRun
participant Policy as canReadTaskRun
participant DB as Scheduled Actions DB
Note over Client,Route: REST Transport
Client->>Route: GET /api/tasks/runs?runId=xxx&account_id=yyy
Route->>Auth: Validate credentials (API key or Bearer)
alt Valid credentials
Route->>Auth: canAccessAccount(current, target)
alt Account override authorized
Auth-->>Route: Access granted
Route->>Handler: getTaskRunHandler(request)
else Override denied
Auth-->>Route: 403 Access denied
Route-->>Client: 403 {error: "Access denied to specified account_id"}
end
else Missing credentials
Auth-->>Route: 401
Route-->>Client: 401 {error: "Exactly one of x-api-key or Authorization must be provided"}
end
Handler->>Read: readTaskRunForAccount({runId, accountId})
Read->>Trigger: retrieveTaskRun(runId)
Trigger-->>Read: Provider run or null
alt Run found
Read->>Policy: canReadTaskRun(run, accountId)
alt Owned (payload/tags/schedule)
Policy->>DB: selectScheduledActions (if schedule ref)
DB-->>Policy: Ownership confirmed
Policy-->>Read: True
Read-->>Handler: Run object
Handler-->>Route: 200 {status: "success", runs: [run]}
else Foreign/unowned
Policy-->>Read: False
Read-->>Handler: null
Handler-->>Route: 404 {error: "Task run not found"}
end
else Run missing
Read-->>Handler: null
Handler-->>Route: 404 {error: "Task run not found"}
end
Route-->>Client: Response
Note over MCPKey,Read: API-Key MCP Transport
MCPKey->>MCPKey: get_task_run_status(runId)
MCPKey->>MCPKey: resolveAccountId(apiKey)
MCPKey->>Read: readTaskRunForAccount({runId, accountId})
Read->>Trigger: retrieveTaskRun(runId)
Trigger-->>Read: Provider run
Read->>Policy: canReadTaskRun(run, accountId)
Policy-->>Read: True/False
alt Owned
Read-->>MCPKey: Full run JSON
MCPKey-->>MCPKey: {success: true, ...run}
else Foreign
Read-->>MCPKey: null
MCPKey-->>MCPKey: {success: false, message: "Task run not found"}
end
Note over MCPOAuth,Read: Delegated OAuth MCP Transport
MCPOAuth->>MCPOAuth: get_task_run_status(runId)
MCPOAuth->>MCPOAuth: Verify OAuth authority (scopes, account, client, grant)
alt Invalid delegation or account override
MCPOAuth-->>MCPOAuth: Denied (no provider call)
else Valid delegation
MCPOAuth->>Read: readTaskRunForAccount({runId, accountId})
Read->>Trigger: retrieveTaskRun(runId)
Trigger-->>Read: Provider run
Read->>Policy: canReadTaskRun(run, accountId)
Policy-->>Read: True/False
alt Owned
Read-->>MCPOAuth: Run object
MCPOAuth-->>MCPOAuth: Status projection (id, status, taskIdentifier, timestamps)
else Foreign
Read-->>MCPOAuth: null
MCPOAuth-->>MCPOAuth: Permission denied error (no run details)
end
end
Note over Route,Policy: ESLint boundary blocks raw retrieveTaskRun imports in transports
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: Refactors REST, API-key MCP, and delegated OAuth task-run reads onto one account-authorized helper, preserving existing response shapes and error behavior; adds focused ownership/import-boundary tests and an ESLint guard.
View guided diff | Turn on auto-fix | Re-trigger cubic
Task-run reads previously required REST, API-key MCP, and delegated OAuth to fetch a provider run and remember to apply ownership policy separately. All three now use
readTaskRunForAccount, which returns only a run allowed by the existingcanReadTaskRunpolicy. OAuth keeps its smaller status projection; account overrides, scopes, errors, and other response shapes are unchanged.A scoped ESLint rule directs transport imports through the authorized operation. Added route and delegated registration tests pin account resolution, exact output, and foreign-run denial. The task-domain verification recipe documents the two distinct internal raw consumers and the remaining deployed-client checks.
Validation on a fresh frozen-lockfile install using Node 24.18.0:
pnpm typecheck:mcp-oauthandpnpm lint:checkpassed.tsc --noEmit --incremental falsereports the same 196 diagnostics (byte-identical output) on this branch and exact base067238da4ba650013263cc24675d4f09749da771with the same dependencies.Task entry-point tests use synthetic credential, provider, and database boundaries. A credential-free GET to the READY PR preview returned HTTP 401 with the exact expected authentication error and
x-matched-path: /api/tasks/runs. No paid job, deployed owned/foreign-run test, or live named-client verification was performed.