Skip to content

[codex] Replace local chat delegation with backend snapshot answers#217

Draft
sergekh2 wants to merge 2 commits into
mainfrom
another-way
Draft

[codex] Replace local chat delegation with backend snapshot answers#217
sergekh2 wants to merge 2 commits into
mainfrom
another-way

Conversation

@sergekh2

@sergekh2 sergekh2 commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace Ask chat's desktop-side Claude Agent SDK delegation with a deterministic local repo snapshot collector.
  • Add /api/chat/threads/:threadId/delegated-work, where the backend validates the placeholder/task/repo, calls Anthropic, and persists the final answer.
  • Limit snapshot collection to branch, HEAD, git status, changed files, diffstat, recent commits, and branch-related PR metadata for configured repos.
  • Update shared contracts, docs, and tests for the new backend-proxied flow.

Security posture

  • The model no longer chooses local tools or shells out through the client.
  • The client does not send file contents or local filesystem paths.
  • The backend verifies the request matches the server-created delegation placeholder and caller-visible repo before calling Anthropic.
  • Snapshot text is treated as untrusted data in the backend prompt.

Validation

  • bun run typecheck in apps/desktop
  • bun run typecheck in apps/server
  • bun run typecheck in packages/shared
  • bun run test in apps/desktop
  • bun run test in apps/server
  • bun run gen:db-schema:check in apps/server
  • git diff --check
  • bun run lint in apps/desktop passed with one existing warning in AgentRuntimeFields.tsx

Note

Medium Risk
Changes the Ask delegation flow end-to-end (desktop IPC, shared API contracts, and new server route that validates repo visibility then calls Anthropic and writes chat history), so regressions could affect chat persistence/billing and access control. Snapshot data is bounded, but the new server-side composition path adds new validation and error-handling branches that need review.

Overview
Replaces Ask “delegation” from a desktop-run Claude Agent SDK to a bounded, metadata-only repo snapshot collected on desktop and summarized on the backend.

The desktop now collects a fixed ChatWorkSnapshot (git branch/HEAD/status, changed files, diffstat, recent commits, and optional gh pr list-based related PRs) and posts it to a new POST /api/chat/threads/:threadId/delegated-work endpoint; the server validates the placeholder message/task and that the repo is visible to the caller, then calls Anthropic to compose the final answer, records LLM spend, and finalizes the stored chat turn.

Updates shared types/contracts and UI copy to reflect snapshot-based answers, removes the old desktop chatDelegate agent runner, and adds tests for snapshot collection and the new delegated-work route (including budget/error and repo/task mismatch defenses).

Reviewed by Cursor Bugbot for commit 0aef48c. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e308509b-c668-453a-ae23-2562ebbd8b08

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch another-way

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 and usage tips.

Comment thread apps/server/src/chat/delegated-work.ts

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0aef48c. Configure here.

}
return { ok: true };
);
return result;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Concurrent delegated-work requests cause double LLM spend

Low Severity

There's a TOCTOU race between the SELECT that validates the delegation placeholder (checking isNotNull(delegation)) and the UPDATE that clears it. Two concurrent requests for the same delegation both pass validation, both call answerDelegatedWork (consuming LLM budget twice), and only the first UPDATE succeeds. The second UPDATE silently affects zero rows, and the code doesn't check the update result count, so the double-spend goes undetected.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0aef48c. Configure here.

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.

2 participants