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.
This commit is contained in:
Dax Raad
2026-10-30 11:35:33 -04:00
Unverified
parent 85d7397093
commit da87c475a7
7 changed files with 21 additions and 19 deletions
+3 -3
View File
@@ -54,7 +54,7 @@ export class InvalidError extends Schema.TaggedError<InvalidError>()("Schedule.I
export class DisabledError extends Schema.TaggedError<DisabledError>()("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))
+1 -1
View File
@@ -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) =>
+1
View File
@@ -76,6 +76,7 @@ const enabledEntries = [
type: "document",
info: new Info({
timezone: "America/New_York",
experimental: new ConfigExperimental.Info({ schedules: true }),
}),
}),
]
+5 -4
View File
@@ -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"])
}),
)
+6 -6
View File
@@ -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"
}
},
+1 -2
View File
@@ -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) =>
+4 -3
View File
@@ -17,7 +17,7 @@ const client = (handler: (request: Request) => Promise<Response>) =>
}),
})
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.