Skip to content

🪪 feat: Authorize a Schedule in the Same Step That Creates It - #18489

Draft
danny-avila wants to merge 1 commit into
danny-avila/schedule-grant-anyfrom
danny-avila/schedule-create-authorize
Draft

danny-avila wants to merge 1 commit into
danny-avila/schedule-grant-anyfrom
danny-avila/schedule-create-authorize

Conversation

@danny-avila

Copy link
Copy Markdown
Collaborator

Summary

With interface.schedules.mcpConsent.enabled on, a new schedule was created with no authorization. It ran with every tool its agent has until its owner edited it or the operator's requireAfter date passed (#18274), so turning consent on did nothing for schedules created afterwards.

After this change a schedule is authorized in the same step that creates it.

  • The create form shows what the chosen agent could be allowed, with the same boxes and "Allow everything" control as the authorization dialog, and a lifetime.
  • The schedule is created with its grant in one write. Nothing is created if the choice no longer fits what can be offered.
  • A schedule created without a choice, by another client for instance, is marked as needing authorization from the start, so none of its tools runs until its owner confirms.

Where consent is off, the form and the create request are unchanged.

Stacked on #18486. Related to #18274, #13824.

How it works

POST /api/schedules/mcp-consent/offer   { agent_id }           # new
  -> the consent view for a schedule that does not exist yet:
     targets, tools.offered, approval, offer { digest, maxLifetimeHours }
     digest is bound to the owner and the agent, not to a schedule id

POST /api/schedules                     { ..., authorization? } # new optional field
  authorization  { offerDigest, lifetimeHours, allow, ask?, tools? }
  consent on  + authorization  -> service.grant(identity for the new id, choice)
                                  resolves the offer again, checks the digest and the choice,
                                  returns the grant; written as `mcpConsent` in the insert
  consent on  + none           -> `mcpConsentRequired: true` in the insert
  consent off                  -> the field is ignored
  choice refused               -> 409 { code } (403 for consent_forbidden), nothing inserted
packages/api    authorization/service.ts   draft(identity)  the offer with no stored schedule
                                           grant(identity, choice)  builds the grant, stores nothing
                                           build(...)  shared with confirm
                schedules/handlers.ts      createSchedule: grant or mark, in the insert
                                           computeCreateDigest covers `authorization` when sent
api             routes/schedules.js        wires `grant` and the offer route
client          MCP/GrantTools.tsx         useGrantChoice + the tool list, split out of GrantDialog
                Schedules/Authorize.tsx    the section in the create form, mounted per agent
                Schedules/ScheduleDialog   Create is disabled while something can be allowed and nothing is

The owner's choice is part of the create intent: a retry with the same clientRequestId must repeat it, and a request that omits the field digests exactly as before.

Type of change

  • Feature

Testing

Tested environments/configuration: WSL2, Node.js 24. No external services.

Automated tests:

  • packages/api/src/schedules/authorization/service.spec.ts (a schedule that is authorized as it is created): the draft offer reads no stored schedule and its digest holds for the id the schedule is then given, and differs for another agent; the grant is built for the new schedule with its own lifetime and nothing is stored; a changed offer, nothing allowed, a tool not on offer, and a lifetime past the limit are refused; asking first is refused where a run cannot pause; an owner who may not use the agent gets no offer.
  • packages/api/src/schedules/handlers.spec.ts: the grant is written in the same insert, for the id about to exist, and the choice is not stored as a field; no choice marks the schedule as needing authorization; a refused choice inserts nothing and reports its code; with consent off the choice is ignored and nothing is marked; the choice is part of the create intent and its absence leaves older retries matching.
  • api/server/services/Schedules/consent.spec.js (new): loads the real wiring; the offer handler exists, answers 404 without an agent and 403 for an owner whose role may not use schedules.
  • client/src/components/SidePanel/Schedules/__tests__/ScheduleDialog.spec.tsx: with consent off nothing is asked or sent; with it on the section appears for the picked agent, Create is disabled until something is ticked, and the payload carries the choice; picking another agent starts over, including for a tool both agents share; an agent with nothing to allow creates as before; a failed offer is said, can be retried, and does not block creating.
  • client/src/components/SidePanel/Schedules/__tests__/Consent.spec.tsx, KeyGrant.spec.tsx (existing): unchanged and passing against the split dialog.

Eight mutations (the required mark, stripping the choice from the stored fields, the create-intent digest, the offer digest check, the digest's subject, the form's submit condition, the payload, and the per-agent reset) each fail a test.

npx tsc --noEmit is clean in packages/api, packages/data-schemas, packages/data-provider and client.

Not verified: in a browser, or against a running server. There are no screenshots of the form section yet.

Performance

Opening the create form with consent on makes one extra request once an agent is picked: the offer, which walks the agent graph once. Creating a schedule with a choice resolves that offer once more on the server (one owner read, one configuration read, one graph walk) before the insert; creating without one adds nothing. Nothing is added to a run. I did not measure latency before and after.

Risk / compatibility

With consent on, every schedule created from now on is either authorized or held. A client that creates schedules without the new field gets schedules whose tools are refused until the owner authorizes them. Before, such schedules ran unrestricted until edited.

The form does not block creating when the offer cannot be loaded. The schedule is then created as needing authorization, and the form says so.

The create response does not distinguish "created and authorized" from "created, needs authorization". The schedule's card shows the latter.

Schedule consent is off by default.

Where consent is on, a new schedule was created unauthorized and stayed exempt until
its owner edited it or the operator's deadline passed. The create form now asks what the
schedule may use, from the offer for its agent, and the schedule is created with its
grant in one write. A schedule created without a choice is marked as needing
authorization from the start.

The grant dialog's tool list and choice are split out so the form shows the same thing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant