Skip to content

fix: preserve account context across task run views - #2355

Merged
sidneyswift merged 1 commit into
mainfrom
cosmo/task-run-account-scope
Oct 25, 2026
Merged

sidneyswift merged 1 commit into
mainfrom
cosmo/task-run-account-scope

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Preserve the selected account across Recents/Home → run detail → Recents, using the existing authorized task-run API contract. Current-main successor for the account-override intent in #1735; that historical PR remains untouched.

  • Scope task-list, task-detail and linked-workflow caches by actor, read session, target and API origin. Cancel obsolete reads, reject delayed token/response results, and hide data while signed out, unresolved or denied.
  • Capture the current API origin and pass account_id on task list/detail requests. Preserve polling, terminal states, kickoff metadata and timings.
  • Explicit URL targets take precedence over workspace selection and are displayed. Unresolved workspace selection never falls back to self.
  • Preserve account context in run links and the back link. Only offer Open chat when the workspace selection matches the run target, since chat does not consume this URL override.
  • Prevent an empty selected-account history from falling back to the signed-in account's schedule or starter action.

Verification

  • 2,549 tests / 405 files passed with OS network denied.
  • Focused account/lifecycle/navigation/request coverage: 161 tests / 34 files passed.
  • Original-source regression replay: 38 failed / 2 passed. Home fallback tests separately reproduced 2 failures before the runtime correction.
  • Next type generation, full TypeScript, changed-file ESLint, formatting and whitespace checks passed.
  • Independent final native Codex review: no actionable findings. Exact-head unit CI, browser/OAuth/interaction jobs and Vercel preview all pass. GitHub Codex and CodeRabbit reviews completed without actionable findings. CodeRabbit's advisory function-length warning is intentionally deferred: the hook owns one read-scope lifecycle, and splitting its guards across extra abstractions is not needed for this fix.

Boundaries

No API, dependency, auth-provider or schedule mutation changes. Existing server task-run access checks remain authoritative. Linked workflow status cache isolation does not add backend ownership checks to that separate endpoint. Per-mounted-reader cache identity deliberately trades duplicate concurrent list reads for preventing cross-session cache reuse. Authenticated hosted behavior has not been exercised.

Preview: https://app-git-cosmo-task-run-account-scope-recoup.vercel.app

@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
app Ready Ready Preview Oct 25, 2026 7:33pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T19:34:09.312992Z a3a79b2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4d739ee and a3a79b2.

Files ignored due to path filters: 6
  • components/TasksPage/Run/__tests__/RunNavigation.scope.test.tsx is excluded by !**/*.test.* and included by components/**
  • components/TasksPage/Run/__tests__/RunPage.test.tsx is excluded by !**/*.test.* and included by components/**
  • hooks/__tests__/useHomeTasksModuleState.scope.test.tsx is excluded by !**/*.test.* and included by hooks/**
  • hooks/__tests__/useTaskRunScope.test.tsx is excluded by !**/*.test.* and included by hooks/**
  • lib/tasks/__tests__/getChatRunStatus.test.ts is excluded by !**/*.test.* and included by lib/**
  • lib/tasks/__tests__/taskRunRequests.scope.test.ts is excluded by !**/*.test.* and included by lib/**
Files selected for processing: 20
  • components/Home/HomeRunRow.tsx
  • components/Home/TasksModule.tsx
  • components/TasksPage/RecentRunsList.tsx
  • components/TasksPage/Run/RunBreadcrumb.tsx
  • components/TasksPage/Run/RunDetails.tsx
  • components/TasksPage/Run/RunPage.tsx
  • components/TasksPage/RunAccountNotice.tsx
  • components/TasksPage/RunCard.tsx
  • components/TasksPage/TasksTabs.tsx
  • hooks/__tests__/taskRunScope.fixture.tsx
  • hooks/useChatRunStatus.ts
  • hooks/useHomeTasksModuleState.ts
  • hooks/useTaskRunScope.ts
  • hooks/useTaskRunStatus.ts
  • hooks/useTaskRuns.ts
  • lib/tasks/getAccountScopedHref.ts
  • lib/tasks/getChatRunStatus.ts
  • lib/tasks/getRunHref.ts
  • lib/tasks/getTaskRunStatus.ts
  • lib/tasks/getTaskRuns.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Task-run reads now use a resolved account scope and pass scope details to status and runs requests. Task pages and home-task links carry account IDs. The Recents view and run page display scope notices and gate content on scope readiness.

Changes: Account-scoped task runs

Layer / File(s) Summary
Resolve task-run scope
hooks/useTaskRunScope.ts, hooks/__tests__/taskRunScope.fixture.tsx
The new scope hook resolves account selection and read readiness, tracks scope identity, and checks context during reads. The shared test fixture mocks authentication, account selection, and API origin.
Fetch runs within scope
hooks/useTaskRuns.ts, hooks/useTaskRunStatus.ts, hooks/useChatRunStatus.ts, lib/tasks/getTaskRuns.ts, lib/tasks/getTaskRunStatus.ts, lib/tasks/getChatRunStatus.ts
Task-run and chat-status hooks use scoped query keys, readiness, tokens, API URLs, and abort signals. Request functions accept API URL and cancellation options; task-status requests can include an account override.
Carry account context through task pages
lib/tasks/getAccountScopedHref.ts, lib/tasks/getRunHref.ts, components/Home/*, components/TasksPage/*, components/TasksPage/Run/*, hooks/useHomeTasksModuleState.ts
Task links and breadcrumbs include account context. The Recents view and run page show scope notices and gate content on readiness. Run details check account matching before displaying the chat link. Home-task state returns the account ID and limits the existing-report lookup to the specified conditions.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant TasksTabs
  participant useTaskRuns
  participant useTaskRunScope
  participant getTaskRuns
  participant TasksAPI
  TasksTabs->>useTaskRuns: Request task runs
  useTaskRuns->>useTaskRunScope: Resolve scope and readiness
  useTaskRunScope-->>useTaskRuns: Provide scoped read context
  useTaskRuns->>getTaskRuns: Read runs with scope and abort signal
  getTaskRuns->>TasksAPI: GET task runs
Loading

Possibly related PRs

  • recoupable/app#2343: It changes account-override resolution consumed by the task-run scope hook.
Merge Risk: Minimal · up to a3a79

The selected-account empty state does not fall back to the signed-in account. No identified issue needs to be resolved before merging.

Pre-merge checks: Passed 2 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Solid & Clean Code Warning The pull request adds a 64-line useTaskRunScope function (hooks/useTaskRunScope.ts:18-81), which exceeds the check's 20-line guideline. It also combines scope resolution, session generation, cache… Split useTaskRunScope into focused units. Extract pure scope resolution and scope-key creation, move login-generation and mounted-scope invalidation into a dedicated hook or helper, and move token acquisition plus stale-request checks int…
Passed Passed checks: 2 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Solid & Clean Code

Explanation

The pull request adds a 64-line useTaskRunScope function (hooks/useTaskRunScope.ts:18-81), which exceeds the check's 20-line guideline. It also combines scope resolution, session generation, cache-key construction, lifecycle invalidation, token acquisition, API-origin validation, and request execution. Its nested read callback spans lines 55-78. The change introduces a clear SRP and maintainability violation. The other changed components mainly pass the account context through and remain focused.

Resolution

Split useTaskRunScope into focused units. Extract pure scope resolution and scope-key creation, move login-generation and mounted-scope invalidation into a dedicated hook or helper, and move token acquisition plus stale-request checks into a reusable scoped-read helper. Keep useTaskRunScope as a small composition layer with one responsibility.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

Account paths follow the run
Scope checks start before reads begin
Requests carry their context through
Notices name the account in view
Breadcrumbs keep the path in tune

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

@sidneyswift
sidneyswift merged commit 73123d5 into main Oct 25, 2026
7 checks passed

This branch was successfully deployed

1 active deployment
Preview – app — a3a79b24 Deployed Oct 25, 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