Repository navigation
feat: scheduled tasks — Phase 2b: settings.yaml schedules + CLI management + metrics (#233) - #238
Merged
Merged
Conversation
…ier) + declarative reconcile Add an operator-tier-only 'schedules:' block to settings.yaml, mirroring the guardrails operator-tier-only discipline: capture from user-global + CLI tiers only, WARN + ignore on project-tier, strict unknown-key parse per declaration. - internal/adapter/permconfig/schema.go: SchedulesSection (YAML sequence) + ScheduleDecl (strict strictFields/UnmarshalYAML), top-level Config field - internal/adapter/permconfig/resolve.go: operatorSchedules field + captureSchedules (first-non-nil, CLI outranks user-global) + OperatorSchedules() accessor + project-tier WARN - internal/app/schedules.go: foldOperatorSchedules + toScheduleSpec mapper (defaults Mode=plan for non-mutating; fail-soft per decl) + reconcileSchedules (idempotent upsert; no delete — documented) - internal/app/build.go: DeclaredSchedules cfg field + fold + reconcile after scheduler start, gated on SchedulerEnabled - internal/adapter/server/schedule.go: UpdateSchedule preserves CreatedAt (pre-existing bug amplified by the reconcile path) - configgen: schedules subtree (TierOperator, ListBody) + skeleton/reference - Tests: operator-tier honoured, project ignored, strict-key, CLI outranks, reconcile idempotency (singleton:false), mutating-false-defaults-plan, CreatedAt preservation Part of #189. Closes the settings.yaml pillar of #233. Co-Authored-By: Juan Osorio Ortiz <[email protected]>
…ect/pause/resume/delete/fire) Add 'mecated schedules <verb>' subcommands that dial the running server's HTTP API (/v1/schedules...). Follows the existing manual os.Args dispatch + stdlib flag pattern (peer of 'mecated config init' / 'mecated skills promote'). - cmd/mecated/main.go: dispatchSubcommand refactor + 'schedules' dispatch - cmd/mecated/schedules_cmd.go: 7 verbs over the Phase 2a REST surface; --server-addr, --output json|text; schedulePath helper (url.PathEscape) + validateScheduleName guard (path-injection defense) - cmd/mecated/schedules_cmd_test.go: httptest-backed tests for all verbs, body-shape assertions, missing-flag errors, invalid-name rejection, JSON output, server-error propagation mecak8s deliberately omits CLI subcommands (parity with its existing policy); k8s users manage schedules via the gRPC/HTTP API. Part of #189. Closes the CLI management pillar of #233. Co-Authored-By: Juan Osorio Ortiz <[email protected]>
…fire latency) Add schedule-fire metrics via a callback seam (Config.ScheduleMetrics), keeping the scheduler package telemetry-import-free (mirrors EmitScheduleEvent). Composition closes over telemetry.Metrics.EmitSchedule. - internal/adapter/telemetry/metrics.go: scheduleFires counter (outcome label: fired/skipped/failed) + scheduleFireDuration histogram (in latencyInstruments for explicit-bucket views) + EmitSchedule(payload, duration); nil-safe - internal/adapter/scheduler/scheduler.go: Config.ScheduleMetrics callback + SetScheduleMetrics late-bind + emitScheduleMetrics chokepoint in fireClaimed (fired/failed, time.Since(claim-now)) and fireOne/FireNow skip paths (duration=0); extracted scheduleKindFired/Skipped/Failed constants - internal/app/build.go: ScheduleMetricsEmitter cfg field + wired in startScheduler - cmd/mecated + cmd/mecatui/embed: closure over metrics.EmitSchedule (mirrors MetricsRoleScoper); mecak8s/mecatequi nil (byte-identical metrics-silent default) - Tests: scrape assertions + fired/failed/skipped callback invocation with deterministic fake-clock durations Schedule metrics are NOT a role-family (no 'schedule' in roleFamily — fires mint fresh sessions whose own runs already carry role=main). The 'registered' polled gauge deferred (a separate observable-gauge seam; core scope covered). Part of #189. Closes the metrics pillar of #233. Co-Authored-By: Juan Osorio Ortiz <[email protected]>
…e declarative test Update living docs to reflect the three Phase 2b pillars (settings.yaml schedules: block, mecated schedules CLI, schedule metrics) and add an end-to-end test through app.Build for the declarative → store path. - docs/design/PRODUCTION-READINESS.md: ⛔ Phase 2b → ✅ shipped - docs/design/IMPLEMENTATION-NOTES.md: Phase 2b subsection (config + CLI + metrics) - docs/usage.md: settings.yaml schedules syntax + CLI examples (shipped status) - docs/architecture.md: declarative config + CLI section - internal/app/schedules_declarative_test.go: e2e through app.Build — operator-tier settings.yaml → foldOperatorSchedules → reconcileSchedules → store; idempotent re-reconcile (no churn); project-tier schedules ignored (operator-tier-only) Part of #189. Closes #233. Co-Authored-By: Juan Osorio Ortiz <[email protected]>
…de/workspace, profile-aware workspace + singleton honesty
Addresses the review findings on the Phase 2b schedules work (create path, CLI,
metrics, docs). A live end-to-end run against OpenRouter surfaced two of these.
- H1 (server): decode the schedule create/update HTTP body with protojson into
*mecatlv1.ScheduleSpec (the shape the struct's own comment already claimed)
instead of a stdlib-json decode of a hand-rolled struct. The old path returned
HTTP 400 on ANY one-shot trigger (RFC3339 string vs *timestamppb.Timestamp).
Deletes the now-unused scheduleSpecBody + toProto. Regression test: one-shot
create round-trip.
- CLI: add --mode and --workspace to `mecated schedules create` and default a
non-mutating schedule to plan mode (mirroring the declarative fold), so the
documented basic `create --cron ... --prompt ...` works instead of tripping the
server's non-mutating-must-be-plan invariant. --mode word -> protojson enum name.
- NEW: validate the workspace PROFILE-AWARE at the schedule create-seam
(validateScheduleSpec), mirroring the session create-seam — a default-profile
schedule requires a workspace, a no-fs schedule must not carry one. Fail-closed:
previously an empty-workspace schedule was accepted at create but failed at FIRE
time ("workspace is required"), i.e. a schedule that could never fire. Test
fixtures updated; new TestCreateScheduleWorkspaceProfileInvariant.
- M1 (honesty): foldOperatorSchedules WARNs when a declared singleton:false is
coerced to true (a bare bool cannot express the opt-out; deferred), and the docs
+ the ScheduleDecl doc-comment (the configref source) state the v1 limitation.
- L2 (CLI): validateScheduleName rejects bare "." / "..".
- L3 (metrics): cover the singleton-overlap skip metric emit path.
- N1/N2 (docs): CLI body-comment honesty; the fire duration is due->terminal, not
Claim->terminal (metrics.go + architecture / observability / impl-notes).
Verified: task lint + task test green (root + engine + GOWORK=off standalone);
mecademo full offline session; and a LIVE end-to-end run against OpenRouter
(create -> force-fire -> real agent turn "Hello from a scheduled task!" ->
stop=end_turn -> mecatl_schedule_fires_total{outcome="fired"}).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Phase 2b of the scheduled-tasks feature (#189): the
settings.yamlschedules:block (operator-tier),mecated schedulesCLI management subcommands, and schedule metrics. Closes #233.Phase 1 (#211) landed the durable foundation. Phase 2a (#237) landed the gRPC/HTTP
ScheduleService+EvSchedule*events. This PR adds the declarative + CLI + observability layer on top.What landed (4 commits, one dev-pipeline wave each)
6a30e77settings.yamlschedules:block — operator-tier ONLY (mirrors the guardrails discipline: capture from user-global + CLI tiers only, WARN + ignore on project-tier, strict unknown-key parse per declaration).SchedulesSection+ScheduleDeclin permconfig/schema.go.foldOperatorSchedules+toScheduleSpecmapper +reconcileSchedules(idempotent upsert, no-delete) in internal/app. configgen subtree.UpdateSchedulepreservesCreatedAt(pre-existing bug amplified by reconcile).ed908f4mecated schedules <create|list|inspect|pause|resume|delete|fire>CLI subcommands over the Phase 2a HTTP API.schedulePathhelper (url.PathEscape) +validateScheduleNameguard (path-injection defense). Follows the existing manual os.Args + stdlib flag pattern. mecak8s deliberately omits CLI subcommands (parity with existing policy).f69afd4Config.ScheduleMetrics, mirroringEmitScheduleEvent).mecatl.schedule.fires_total{outcome}counter +mecatl.schedule.fire_duration_secondshistogram. Scheduler stays telemetry-import-free; composition closes overMetrics.EmitSchedule. NOT a role-family (fires mint fresh sessions whose own runs carry role=main). The 'registered' polled gauge deferred (separate observable-gauge seam).8fad8d5⛔ → ✅, IMPLEMENTATION-NOTES Phase 2b subsection, usage.md syntax + CLI examples, architecture.md section. E2e test throughapp.Build(operator-tier settings.yaml → fold → reconcile → store; idempotent re-reconcile; project-tier ignored).Design
schedules:block is IGNORED with a WARN (a project repo cannot register schedules; mirror of the guardrails discipline). Enforced inpermconfig.Resolver:captureSchedulesruns only fromloadUserRules, neverloadProjectRules.reconcileSchedulescreates missing schedules and updates differing ones, but does NOT delete schedules removed from the YAML (an operator must delete explicitly via the API/CLI). Documented honestly. A future provenance-taggedOriginfield could enable symmetric reconcile.ScheduleDeclusesdecodeStrictMapping(the same helper asGuardrailsSection/Permissions). A typo likecronn:is a hard parse error.Config.ScheduleMetricsis a plainfunc(session.SchedulePayload, time.Duration)callback. Fire latency =time.Since(claim-now)measured on the injectedClock.Verification
task lint— 0 issues (golangci-lint v2 + go vet, root + engine modules)task test— full suite green, -race (root + engine + GOWORK=off engine-standalone)task api:check— green (no engine public API changed)task docs—llms.txtregenerated, strict link gate 0 brokengo run ./cmd/mecademo— full offline session (regression)internal/app/schedules_declarative_test.go) — operator-tier settings.yaml → reconcile → store; idempotent re-reconcile; project-tier ignoredLayering
No
engine/changes. The config block, reconcile, CLI, and metrics are all composition-layer (internal/app+internal/adapter/permconfig+cmd/mecated+internal/adapter/telemetry). The scheduler package staysEventSink-free and telemetry-import-free (the callback seam).What's NOT in this PR (tracked follow-ups)
mecatui/scheduleslash command + overlaysched--GC retention, NL→cron, carried-context, webhook triggers, driverScheduleStoreServicemecatl.schedulespolled "registered" gauge (a separate observable-gauge seam overScheduleStore.List; the core metrics scope — fires/skips/failures/latency — is covered)Co-Authored-By
Juan Osorio Ortiz [email protected]