Repository navigation
⏳ feat: End the Exemption of Schedules Their Owner Never Authorized - #18274
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e9e942832
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const { consent } = createEvaluation(deps.enrollment); | ||
| const execution = createScheduleMCPExecution({ | ||
| storage: deps.methods, | ||
| requiresGrant: consent.service.requiresGrant, |
There was a problem hiding this comment.
Resolve consent requirements with fail-closed configuration
When consent or its deadline is configured through a tenant/role/user override, an override-store failure can let an unauthorized schedule execute MCP tools. This callback uses the host created by createEvaluation, whose limits resolver calls enrollment.getAppConfig(options) without failClosed: true. The production config service catches override-resolution failures and returns the base config (packages/api/src/app/service.ts:1145–1148), potentially removing the consent requirement. requiresGrant then returns false and caches that permission for the run. Unlike the enrolled authorization path immediately below, this path never requests fail-closed configuration. Pass failClosed: true when resolving these limits so a lookup failure becomes dependency_unavailable rather than unrestricted access.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5c82336. requiresGrant is now taken from an evaluation whose getAppConfig always passes failClosed: true (createScheduleMCPRuntimeHost in packages/api/src/schedules/authorization/runtime.ts), so an override store that cannot be read throws instead of handing back the base configuration. The execution already turns a failed lookup into dependency_unavailable and asks again at the next call, so the outage refuses the MCP call instead of lifting the requirement.
Evidence: runtime.spec.ts › a schedule its owner never authorized › "reads the configuration fail-closed, so an override outage cannot lift the requirement". Passing the plain evaluation's requiresGrant again makes it fail.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
0e9e942 to
5c82336
Compare
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
/quality risk scopes=api |
Quality reportGate: open. The selected checks completed. Scores and risk levels are advisory. Status: completed (success). Actions run, attempt 1.
Change riskTakeaway: 4 changed lines have no test. Highest CRAP among changed functions:
Changed lines with no test
|
| Function | Complexity | Coverage | CRAP | Location |
|---|---|---|---|---|
updateSchedule |
67 | 73% | 151.4 | packages/api/src/schedules/handlers.ts:904 |
view |
39 | 89% | 41.1 | packages/api/src/schedules/authorization/service.ts:255 |
authorize |
32 | 88% | 33.9 | packages/api/src/schedules/authorization/execution.ts:207 |
getLimits |
26 | 100% | 26.0 | packages/api/src/schedules/service.ts:504 |
resolve |
12 | 94% | 12.0 | packages/api/src/schedules/authorization/execution.ts:124 |
getLimits |
8 | 80% | 8.5 | packages/api/src/schedules/authorization/host.ts:45 |
requiresGrant |
4 | 100% | 4.0 | packages/api/src/schedules/authorization/execution.ts:163 |
requiresGrant |
4 | 100% | 4.0 | packages/api/src/schedules/authorization/service.ts:28 |
requiresGrantFor |
4 | 100% | 4.0 | packages/api/src/schedules/authorization/service.ts:425 |
createScheduleMCPConsentService |
2 | 100% | 2.0 | packages/api/src/schedules/authorization/service.ts:239 |
4 more functions below the threshold (or cut for size) are in report.md.
CRAP = complexity² × (1 − coverage)³ + complexity
Jobs (1)
| Check | Result |
|---|---|
| Change risk (api) | success |
All data (quality-report artifact) · Run page
The gate opens only when the workflow, source selection, tooling verification, and every report job succeed. A report job fails on a failed test in its workspace's own Jest run, a tool error, a job timeout, or an incomplete mutation report, including a mutation shard that reaches its execution budget. A cancelled workflow keeps the gate closed. Scores are advisory. A change-risk file marked incomplete or unavailable, for example by a failed api/ source-alias suite, does not close the gate.
Summary
With
interface.schedules.mcpConsent.enabledon, a scheduled chat is restricted to the MCP tools its owner allowed only if the owner opened the authorization dialog and confirmed. A schedule nobody confirmed keeps using every MCP tool its agent has, unattended, indefinitely. That covers schedules created before consent existed and every schedule created since, so turning consent on changes nothing until each owner acts.This PR ends that exemption in two ways:
interface.schedules.mcpConsent.requireAftertakes an ISO 8601 instant. Unset, there is no deadline and today's behaviour is unchanged.From then on each MCP call of that schedule is refused with
consent_missing, both at the readiness check and in a run, until the owner confirms. The run itself still starts, so a schedule that uses no MCP tools is unaffected. Nothing changes where consent is off.The authorization dialog tells the owner which of the two applies, and a refused run now tells the owner to authorize the schedule where it used to say "Reconnect this MCP server".
Fifth step of the unattended-authority work, after #18058, #18255, #18260 and #18273. Related to #13824 and #16157.
How it works
Both the per-fire readiness check and a run resolve a schedule's authority through
createScheduleMCPExecution, so the rule lives there once. It is evaluated lazily: a scheduled run that calls no MCP tool reads nothing extra, and one that does reads the owner and config once.A lookup that fails is not treated as permission. The call is refused with
dependency_unavailableand the next call looks again.The question is asked with the configuration read fail-closed. The config service falls back to the deployment's base when it cannot read a tenant, role or user override, and the base may not require consent at all; asked fail-closed, that outage refuses the call instead of lifting the requirement.
The mark is not cleared by a grant; a schedule that has a grant is never asked the question. Revoking the grant is refused as
consent_revoked, as before.Type of change
Testing
Tested environments/configuration: WSL2, Node.js 24. Storage tests run against
mongodb-memory-server. No external services.Automated tests:
packages/api/src/schedules/authorization/runtime.spec.ts(a schedule its owner never authorized), through the real runtime host, limits resolver and readiness check: runs with no deadline and before one; refused from the deadline on, at readiness and in a run; refused once edited; left alone where consent is off; runs again once the owner confirms; the lookup happens once per run and not at all for a run with no MCP call; a failed lookup refuses the call without leaking the error, and the next call looks again; the configuration is read fail-closed, so an override outage cannot lift the requirement.packages/api/src/schedules/authorization/service.spec.ts: only a schedule with no grant is ever "required".packages/api/src/schedules/handlers.spec.ts: the mark is written on an edit; not on a pause or resume, not where consent is off or absent, not for a schedule that has a grant or is already marked; it is never sent to the client.packages/data-schemas/src/methods/scheduleConsent.spec.ts: the mark persists through the fenced update and is reported in the consent snapshot.packages/data-provider/src/types/scheduleConsent.spec.ts:requireAfteraccepts an instant with an offset and rejects a bare date, a local time and a number.client/src/components/SidePanel/Schedules/__tests__/Consent.spec.tsx: the dialog shows the deadline note, the refused note, or neither.client/src/components/SidePanel/Schedules/__tests__/errors.spec.ts: a missing, expired, revoked or stale grant points the owner at the authorization dialog and no longer offers "Open agent to reconnect"; a rejected credential still does.Each condition was broken in turn and a test confirmed to fail.
npx tsc --noEmitis clean inpackages/api,packages/data-schemas,packages/data-providerandclient.Screenshots / recordings
The real
Consentcomponent under the app's stylesheet in Chromium, fed fixed consent data in place of the API. "Before" is the component from #18273 for the same schedule. The Cancel button shows its key because the capture does not initialise the shared package's i18n; the app does.Dark:
Risk / compatibility
Default is unchanged for the deadline. With
requireAfterunset no schedule is stopped by date.The edit rule applies as soon as this ships wherever consent is on. An owner who edits a never-authorized schedule will see its next run refuse MCP tools until they confirm. The edit itself succeeds; the readiness check that runs during the edit still sees the schedule as exempt.
A schedule that cannot be authorized stays stopped. If its agent uses an MCP server the operator has not declared under
mcpConsent.resources, there is nothing to confirm. Declare every server scheduled agents rely on before setting the date. This is documented inpackages/api/src/schedules/README.md.New schedules are not marked at creation. A schedule created after this ships is exempt until its first edit or the deadline. Requiring authorization at creation needs a create flow that saves the schedule before it can be enabled, which I left out of this PR.
Mixed versions: a replica without this change ignores the mark and the deadline and keeps running such schedules unrestricted, which is today's behaviour.
The status line "Authorization required" for a schedule with no grant predates this PR and still shows when nothing is required yet.