Skip to content

Centralize account-authorized task run reads - #1037

Merged
sidneyswift merged 2 commits into
mainfrom
codex/account-bound-task-reads
Oct 17, 2026
Merged

sidneyswift merged 2 commits into
mainfrom
codex/account-bound-task-reads

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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 existing canReadTaskRun policy. 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:

  • Task/MCP task suites: 160 tests across 28 files passed.
  • OAuth compatibility: 203 passed, one optional PostgreSQL test skipped; includes the existing loopback HTTP protocol lab.
  • pnpm typecheck:mcp-oauth and pnpm lint:check passed.
  • Ignoring the ownership predicate made 11 behavior checks fail, including each transport, while the import-boundary tests and changed-file lint still passed. Restored the guard and verified the focused checks.
  • Full tsc --noEmit --incremental false reports the same 196 diagnostics (byte-identical output) on this branch and exact base 067238da4ba650013263cc24675d4f09749da771 with 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.

@vercel

vercel Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api Ready Ready Preview Oct 17, 2026 12:42am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: recoupable/api/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 730307b7-1058-405c-af0f-2b7a8a46ff74
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread lib/tasks/README.md Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

This branch was successfully deployed

1 active deployment
Preview — b627b530 Deployed Oct 17, 2026 by vercel[bot]
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.

1 participant