From da87c475a738d61918ec03e1dd0212e286034312 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Fri, 30 Oct 2026 11:35:33 -0400 Subject: [PATCH] fix(core): keep schedules off unless experimental.schedules is enabled Restores the opt-in default from before #60478. The schedule loop still runs in every server process and keeps its leader election; it only fires schedules in locations that enable the flag. --- packages/core/src/schedule.ts | 6 +++--- packages/core/src/tool/plugin/schedule.ts | 2 +- packages/core/test/schedule.test.ts | 1 + packages/core/test/tool-schedule.test.ts | 9 +++++---- packages/protocol/openapi.json | 12 ++++++------ packages/protocol/src/groups/schedule.ts | 3 +-- packages/server/test/schedule.test.ts | 7 ++++--- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/core/src/schedule.ts b/packages/core/src/schedule.ts index 946503ff163..dbfec7e6d90 100644 --- a/packages/core/src/schedule.ts +++ b/packages/core/src/schedule.ts @@ -54,7 +54,7 @@ export class InvalidError extends Schema.TaggedError()("Schedule.I export class DisabledError extends Schema.TaggedError()("Schedule.DisabledError", {}) { override get message() { - return "Scheduled tasks are disabled by experimental.schedules: false in config" + return "Scheduled tasks are disabled; set experimental.schedules in config" } } @@ -216,10 +216,10 @@ const layer = Layer.effect( const settings = (session: SessionSchema.Info) => Effect.gen(function* () { const config = yield* Effect.serviceOption(Config.Service) - if (Option.isNone(config)) return { enabled: true, timezone: undefined } + if (Option.isNone(config)) return { enabled: false, timezone: undefined } const entries = yield* config.value.entries() return { - enabled: Config.latest(entries, "experimental")?.schedules !== false, + enabled: Config.latest(entries, "experimental")?.schedules === true, timezone: Config.latest(entries, "timezone"), } }).pipe(instances.provide(session)) diff --git a/packages/core/src/tool/plugin/schedule.ts b/packages/core/src/tool/plugin/schedule.ts index f5147f3e620..781ef69a5bd 100644 --- a/packages/core/src/tool/plugin/schedule.ts +++ b/packages/core/src/tool/plugin/schedule.ts @@ -52,7 +52,7 @@ export const Plugin = { ctx.event, Effect.andThen(ctx.tool.reload(), ctx.command.reload()), ) - const enabled = () => Config.latest(loaded.entries, "experimental")?.schedules !== false + const enabled = () => Config.latest(loaded.entries, "experimental")?.schedules === true // A request keeps the tools it started with after config reloads, so each call rechecks the flag. const allowed = (sessionID: Session.ID) => diff --git a/packages/core/test/schedule.test.ts b/packages/core/test/schedule.test.ts index 024e919ac80..147850fd6af 100644 --- a/packages/core/test/schedule.test.ts +++ b/packages/core/test/schedule.test.ts @@ -76,6 +76,7 @@ const enabledEntries = [ type: "document", info: new Info({ timezone: "America/New_York", + experimental: new ConfigExperimental.Info({ schedules: true }), }), }), ] diff --git a/packages/core/test/tool-schedule.test.ts b/packages/core/test/tool-schedule.test.ts index 9796a15c9fe..63b7dd83e5a 100644 --- a/packages/core/test/tool-schedule.test.ts +++ b/packages/core/test/tool-schedule.test.ts @@ -141,14 +141,15 @@ const paths = (registry: Tool.Interface) => ) describe("ScheduleTools", () => { - it.effect("are registered by default unless experimental.schedules is false", () => + it.effect("are absent unless experimental.schedules is enabled", () => Effect.gen(function* () { + expect(yield* paths((yield* setup(undefined)).registry)).not.toContain(names[0]) const off = yield* setup(new ConfigExperimental.Info({ schedules: false })) expect(yield* paths(off.registry)).not.toContain(names[0]) expect(off.commands).toEqual([]) - const byDefault = yield* setup(undefined) - expect(yield* paths(byDefault.registry)).toEqual(expect.arrayContaining(names)) - expect(byDefault.commands.map((command) => command.name)).toEqual(["schedule"]) + const on = yield* setup(new ConfigExperimental.Info({ schedules: true })) + expect(yield* paths(on.registry)).toEqual(expect.arrayContaining(names)) + expect(on.commands.map((command) => command.name)).toEqual(["schedule"]) }), ) diff --git a/packages/protocol/openapi.json b/packages/protocol/openapi.json index fb34fdde1dc..d5f7cd24d33 100644 --- a/packages/protocol/openapi.json +++ b/packages/protocol/openapi.json @@ -12722,7 +12722,7 @@ } } }, - "description": "Schedule a prompt that wakes the Session once after a delay, at a time, every interval, or on a cron. Experimental: internal OpenCode schedule API; wire shape may change without notice (disable with experimental.schedules: false).", + "description": "Schedule a prompt that wakes the Session once after a delay, at a time, every interval, or on a cron. Experimental: needs experimental.schedules in the Session's config and may change without notice.", "summary": "Create schedule", "requestBody": { "content": { @@ -12811,7 +12811,7 @@ } } }, - "description": "List a Session's schedules, oldest first. Experimental: internal OpenCode schedule API; wire shape may change without notice (disable with experimental.schedules: false).", + "description": "List a Session's schedules, oldest first. Experimental: needs experimental.schedules in the Session's config and may change without notice.", "summary": "List schedules" } }, @@ -12889,7 +12889,7 @@ } } }, - "description": "Read one schedule. Experimental: internal OpenCode schedule API; wire shape may change without notice (disable with experimental.schedules: false).", + "description": "Read one schedule. Experimental: needs experimental.schedules in the Session's config and may change without notice.", "summary": "Get schedule" }, "delete": { @@ -12951,7 +12951,7 @@ } } }, - "description": "Delete a schedule. Experimental: internal OpenCode schedule API; wire shape may change without notice (disable with experimental.schedules: false).", + "description": "Delete a schedule. Experimental: needs experimental.schedules in the Session's config and may change without notice.", "summary": "Delete schedule" } }, @@ -13029,7 +13029,7 @@ } } }, - "description": "Stop a schedule from firing until it is resumed. Experimental: internal OpenCode schedule API; wire shape may change without notice (disable with experimental.schedules: false).", + "description": "Stop a schedule from firing until it is resumed. Experimental: needs experimental.schedules in the Session's config and may change without notice.", "summary": "Pause schedule" } }, @@ -13107,7 +13107,7 @@ } } }, - "description": "Resume a paused schedule. A one-shot that fell due while paused fires once; a repeating schedule resumes at its next slot. Experimental: internal OpenCode schedule API; wire shape may change without notice (disable with experimental.schedules: false).", + "description": "Resume a paused schedule. A one-shot that fell due while paused fires once; a repeating schedule resumes at its next slot. Experimental: needs experimental.schedules in the Session's config and may change without notice.", "summary": "Resume schedule" } }, diff --git a/packages/protocol/src/groups/schedule.ts b/packages/protocol/src/groups/schedule.ts index baa19eab9e4..fec9a101ac8 100644 --- a/packages/protocol/src/groups/schedule.ts +++ b/packages/protocol/src/groups/schedule.ts @@ -4,8 +4,7 @@ import { Schema } from "effect" import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api" import { ForbiddenError, InvalidRequestError, ScheduleNotFoundError, SessionNotFoundError } from "../errors.js" -const EXPERIMENTAL = - "Experimental: internal OpenCode schedule API; wire shape may change without notice (disable with experimental.schedules: false)." +const EXPERIMENTAL = "Experimental: needs experimental.schedules in the Session's config and may change without notice." const errors = [ScheduleNotFoundError, ForbiddenError] as const const params = { scheduleID: Schedule.ID } const annotations = (identifier: string, summary: string, description: string) => diff --git a/packages/server/test/schedule.test.ts b/packages/server/test/schedule.test.ts index 976e2040f0d..f17b24bca23 100644 --- a/packages/server/test/schedule.test.ts +++ b/packages/server/test/schedule.test.ts @@ -17,7 +17,7 @@ const client = (handler: (request: Request) => Promise) => }), }) -it.live("manages schedules by default through the experimental API and honors experimental.schedules: false", () => +it.live("manages schedules through the experimental API when enabled and honors experimental.schedules: false", () => Effect.gen(function* () { const dir = (yield* tmpdirScoped("opencode-schedule-api-")).path const global = path.join(dir, "global") @@ -25,6 +25,7 @@ it.live("manages schedules by default through the experimental API and honors ex const disabled = path.join(dir, "disabled") yield* Effect.promise(async () => { await Promise.all([global, enabled, disabled].map((item) => fs.mkdir(item, { recursive: true }))) + await fs.writeFile(path.join(enabled, "opencode.json"), JSON.stringify({ experimental: { schedules: true } })) await fs.writeFile(path.join(disabled, "opencode.json"), JSON.stringify({ experimental: { schedules: false } })) }) const handler = yield* ServerFetch.make({ @@ -152,7 +153,7 @@ it.live("ticks due schedules in standalone ServerProcess.start without lifecycle const api = OpenCode.make({ baseUrl: server.base, headers: server.headers }) yield* Effect.promise(async () => { - await fs.writeFile(path.join(dir, "opencode.json"), JSON.stringify({ permission: { shell: "allow" } })) + await fs.writeFile(path.join(dir, "opencode.json"), JSON.stringify({ experimental: { schedules: true }, permission: { shell: "allow" } })) const session = await api.session.create({ location: { directory: dir } }) const created = await api.experimental.schedule.create({ sessionID: session.id, @@ -182,7 +183,7 @@ it.live("elects one scheduler leader when two server processes boot against a du const dbPath = path.join(dir, "shared.db") const marker = path.join(dir, "runs.txt") yield* Effect.promise(() => - fs.writeFile(path.join(dir, "opencode.json"), JSON.stringify({ permission: { shell: "allow" } })), + fs.writeFile(path.join(dir, "opencode.json"), JSON.stringify({ experimental: { schedules: true }, permission: { shell: "allow" } })), ) // Seed an active schedule in a short-lived scope so it falls due while no server is running.