Skip to content

fix(agent): accept a cancellation-only bearer for projectless runs - #5677

Merged
kojiwakayama merged 2 commits into
mainfrom
fix/inbox-4914-projectless-cancel-bearer
Dec 4, 2026
Merged

kojiwakayama merged 2 commits into
mainfrom
fix/inbox-4914-projectless-cancel-bearer

Conversation

@kojiwakayama

@kojiwakayama kojiwakayama commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The cancellation bearer of a projectless run is the requester's full session (veryfront-api mintRuntimeCancellationAuthToken ends in mintAuthenticatedUserToken). It is valid on every API surface for 30 to 60 minutes. The API cannot mint a narrow credential yet, because this runtime's verifier only accepts the session shape and would answer every projectless Stop with 403.

Refs veryfront/veryfront-issue-inbox#4914 (follow-up of #4912). This is the reader half and ships first. The producer half is a veryfront-api PR that stays off by default.

Root cause

verifyRunCancellationToken in src/agent/service/auth.ts accepts exactly two shapes, pinned by tests/fixtures/contracts/api-run-cancellation-jwt-payload.json: the project service account, and a plain user session with no tokenUse and the scopes read, write, delete. A projectless bearer with any tokenUse is refused.

Fix

  • verifyRunCancellationToken also accepts the cancellation-only shape: tokenUse: "projectless_run_cancellation", an empty scope, the run and its requester, no project, no service account. The exact-run binding, expiry, RS256 pinning and own-data-property reads are the shared readRunControlClaims path, unchanged.
  • The session shape stays accepted, so nothing changes for live traffic. Session scopes under the new use are refused, and an empty scope without the use is refused.
  • The contract fixture gains projectlessCancellationOnly with its digest pinned in the test. The existing projectScoped and projectless payloads and digests are unchanged, so the contract id stays v1. The same file goes into veryfront-api with the producer.

The claim set, in mint order: userId, tokenUse, scope, runId, agentId (plus iat and exp). No email and no jti, so every claim is compared literally.

Tests

New tests fail on main (2 failures before the verifier change: the token test and the route test).

  • src/agent/service/run-cancellation-authorization.test.ts: accepts the cancellation-only shape for its own run and refuses it for another; 15 refused variants (session scopes, any scope, missing or non-array scope, a scopes array, no use, another use, a project, a service account, no user, no run, expired, no expiry); inherited and accessor-backed claims; the route returns 202 for the run and 403 for another run. One test fails if the fixture shape is ever regenerated from the session mint (it would carry email, jti, session scopes and no use).
  • tests/integration/agent/run-cancellation-authorization.test.ts: the cancellation-only shape under real RS256 verification, and end to end through DELETE /api/runs/{run_id} on the hosted runtime (202 for its run, 403 for another).

Ran: deno task test:file on both files, on src/agent/service/run-control-sealed-ingress.test.ts and on tests/integration/agent/run-cancellation-authorization-intrinsics.test.ts; deno fmt --check, deno lint and deno check on the changed files; deno task lint:anti-slop; deno task lint:test-semantic-dispositions.

Not in this PR

  • The producer switch (veryfront/veryfront-api#7950, behind PROJECTLESS_RUN_CANCELLATION_TOKEN_MODE, default session). Turn it on only after a framework release with this change runs on every hosted runtime.
  • Removing the session shape from this verifier. That follows once every API producer mints the narrow bearer.
  • The runtime's base authenticator (authenticateRequest) admits any API-signed token with a userId on its other routes, as it does today for the project cancellation bearer and the session. The narrow bearer is refused by the API behind those routes and the producer bounds it to five minutes. Narrowing the base authenticator by token use is a separate change; whether it must land before the producer is switched is a rollout decision.

🤖 Generated with Claude Code

The API hands the runtime the requester's full session as the cancellation
bearer of a projectless run. Before the API can mint a narrow credential, the
runtime has to verify it.

verifyRunCancellationToken now also accepts the projectless_run_cancellation
use: the run and its requester, an empty scope, no project and no service
account. The session shape stays accepted, so the API can switch producers
behind its own flag after this ships. The shared contract fixture gains the
projectlessCancellationOnly shape with a pinned digest.

Refs veryfront/veryfront-issue-inbox#4914

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T14:39:59.104047Z 67b7806 Manual request
ℹ️ 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.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

📦 Client bundle boundary

Entrypoint Modules Source size Server leaks
src/index.client.ts 66 371 KiB ✅ 0
src/react/components/Head.tsx 5 74 KiB ✅ 0
src/react/router/index.tsx 5 74 KiB ✅ 0
src/react/context/index.tsx 5 74 KiB ✅ 0
src/react/fonts/index.ts 6 81 KiB ✅ 0
src/react/components/ui/index.ts 111 720 KiB ✅ 0
src/react/components/ui/adapter/contract.ts 1 18 KiB ✅ 0
src/react/components/ui/icons/index.ts 3 17 KiB ✅ 0
src/chat/index.ts 305 2055 KiB ✅ 0
src/chat/ag-ui.ts 61 464 KiB ✅ 0
src/chat/protocol.ts 1 11 KiB ✅ 0
src/chat/types.ts 46 248 KiB ✅ 0
src/chat/message-prep.ts 68 519 KiB ✅ 0
src/markdown/index.ts 6 30 KiB ✅ 0
src/mdx/index.ts 2 2 KiB ✅ 0
src/agent/identity-contracts.ts 1 3 KiB ✅ 0
src/schemas/index.ts 43 222 KiB ✅ 0
src/platform/env.ts 5 55 KiB ✅ 0
src/workflow/claude-code/react/index.ts 9 91 KiB ✅ 0
src/events/index.ts 37 631 KiB ✅ 0
src/events/ag-ui/public.ts 36 624 KiB ✅ 0
src/run-events/index.ts 54 323 KiB ✅ 0

A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in scripts/lint/client-bundle-baseline.json to burn down.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

@codex review

Copy link
Copy Markdown
Contributor

Review score: 86/100

Small, well-scoped reader-side change that lets the runtime accept a narrow projectless cancellation bearer while keeping the session shape. Tests are thorough. One code comment overstates the new token's reach.

  • Strength: the check is tight and fails closed. The new branch sits after the shared readRunControlClaims checks (exact-run binding, RS256, own-data reads). The guard for a missing project or service account is now hoisted and applies to both projectless shapes. tokenUse and the empty scope must appear together: session scopes under the new use are refused, and so is an empty scope without the use. I also checked verifyRunResumeToken (auth.ts:1015). It only admits run_scoped_service_account and project_scoped_service_account, so the new use cannot resume a run.
  • Strength: contract discipline. The fixture adds a third shape with a pinned digest and leaves the existing digests and the v1 id unchanged. The test "pins a projectless cancellation-only bearer that is not a session" catches a fixture regenerated from mintAuthenticatedUserToken. The tests cover 15 negative variants, inherited and accessor-backed claims, and the route path in both the unit and integration tests (202 for its own run, 403 for another).
  • Concern (fix the comment, not a blocker): the new comment claims more than the code enforces. The comment near auth.ts:372 says the token is "authority to stop that one run here and nothing else". But authenticateRequest (auth.ts:880) admits any API-signed JWT that has a userId. So on this runtime the narrow bearer authenticates every other hosted route as its requester, for as long as it is valid. This is no wider than today's session bearer, so it is not a regression, and the PR body says so under "Not in this PR". Please reword the comment to say the scope applies to verifyRunCancellationToken and that the base authenticator does not narrow by use yet.
  • Rollout suggestion. The comment above is the only reason the narrow token is safer than the session on this runtime. Consider making "base authenticator refuses projectless_run_cancellation outside the cancel route" a stated precondition for setting PROJECTLESS_RUN_CANCELLATION_TOKEN_MODE=cancellation_only, not just a separate follow-up. Without it, the runtime-side benefit is limited to the API refusing the use. Also put the expected lifetime of the narrow token in the fixture notes, so reviewers on the API side can confirm it is shorter than the 30 to 60 minute session.
  • Nit. PROJECTLESS_RUN_CANCELLATION_SCOPES = [] as const has type readonly []. It works with readonly string[], but an explicit : readonly string[] = [] reads more clearly next to the other scope constants.

Merge-ready once the comment is fixed. Both items above are about follow-up and rollout, not about this diff.


Generated by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 93fc322cc8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The comment said the bearer is authority to stop one run and nothing else.
That holds for verifyRunCancellationToken and for the API, not for the base
authenticator, which admits any API-signed token with a userId. Say so, type
the empty scope list like its siblings, and record the bearer lifetimes in the
contract fixture notes.

Refs veryfront/veryfront-issue-inbox#4914

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 67b7806ce7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@kojiwakayama
kojiwakayama added this pull request to the merge queue Dec 4, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

Merged via the queue into main with commit 2f3b62e Dec 4, 2026
451 checks passed
@kojiwakayama
kojiwakayama deleted the fix/inbox-4914-projectless-cancel-bearer branch December 4, 2026 15:41
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