fix(cloud-agent): restore sends and workflow issuance with scoped tokens - #6059
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe incremental fix in Files Reviewed (3 files)
Previous Review Summary (commit a927eea)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit a927eea)Status: 1 Issue Found | Recommendation: Address before merge Executive SummaryThe dedicated Cloud Agent balance endpoint and worker audience-based routing correctly restore scoped control-token balance checks, but pepper initialization is keyed to only the Overview
Issue Details (click to expand)WARNING
Files Reviewed (15 files)
Reviewed by deepseek-v4.1-flash · Input: 32.8K · Output: 5.9K · Cached: 352.5K Review guidance: REVIEW.md from base branch |
Enabling scoped Cloud Agent tokens caused follow-up sends and resumes to fail: balance preflight forwarded a Cloud Agent control token to the general API balance endpoint, which rejected its audience. Add a dedicated Cloud Agent balance endpoint and route control tokens there. Balance checks and current user/organization authorization remain enforced; the general endpoint still rejects control tokens.
The new endpoint explicitly allows Cloud Agent control tokens to perform this one balance lookup, while retaining user, organization, and balance checks. We could have made a narrow exception in the existing endpoint. A separate endpoint makes the authorization boundary clearer and easier to test. So simplicity helped, but preserving scoped access was the main reason.
Workflow issuance also failed for users whose token pepper had never been initialized!
Some accounts had never had that value created. The new scoped-token issuer requires it, so background jobs such as code reviews threw an error instead of starting. We missed that compatibility case. The fix creates the value only when it’s missing, saves it, and uses the saved value to issue the token.
This doesn’t rotate existing peppers or reset everyone’s tokens.