Skip to content

fix(flow): activate schedules via Scheduler Service (#479, 0.66.1)#480

Merged
ZdenekSrotyr merged 4 commits into
mainfrom
fix/flow-schedule-scheduler-activation
Jul 15, 2026
Merged

fix(flow): activate schedules via Scheduler Service (#479, 0.66.1)#480
ZdenekSrotyr merged 4 commits into
mainfrom
fix/flow-schedule-scheduler-activation

Conversation

@natocTo

@natocTo natocTo commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Ticket: https://linear.app/keboola/issue/AJDA-3000/support-16939-flow-schedule-fail-after-migration

Why

Closes #479.

kbagent flow schedule only wrote the keboola.scheduler Storage configuration and never called the Scheduler Service, so the schedule showed state: enabled but the cron trigger never fired until the schedule was re-saved in the UI. flow schedule-remove had the mirror problem: it deleted the Storage config but left the service-side registration behind. The failure was silent — the command reported success.

What changed

  • flow schedule now registers the config with the Scheduler Service (POST /schedules) after the upsert — also for --disabled, which deregisters the trigger. The result carries activated: true/false and warnings.
  • Activation failure (e.g. token without the schedule-management privilege) is non-fatal: the config stays written, a warning is surfaced (human mode: Warning: ...; JSON: warnings array), exit code stays 0.
  • flow schedule-remove deregisters each schedule from the service (DELETE /configurations/{id}, 404 tolerated) before deleting its Storage config.
  • Fixed stale docstrings claiming no Scheduler Service client is needed (flow_service.py, schedule_service.py, AGENT_CONTEXT).

Layers

  • Client: new scheduler_client.pySchedulerClient(BaseHttpClient), URL derived connection.scheduler., auth X-StorageApi-Token, methods activate_schedule / remove_schedule. Modeled on ai_client.py.
  • Service: FlowService gains an injected scheduler_client_factory (same DI pattern as ai_client_factory); set_flow_schedule / remove_flow_schedule call the service after/before the Storage writes.
  • Command: commands/flow.py prints activation state and warnings; no signature changes.
  • No new command → no permissions.py / server/routers / SKILL.md table changes (routes call the same service and inherit the fix).

Tests & docs

  • New tests/test_scheduler_client.py (pytest-httpx: URL derivation, request envelopes, auth header, 403/404 mapping).
  • test_flow_service.py: activation after create AND update, --disabled still calls the service, 403 → activated: false + warning without raising, remove deregisters before delete_config, 404 tolerated, other failures warn but don't block.
  • test_flow_cli.py: warnings in human + JSON output, exit stays 0.
  • make check green: 4236 passed, lint/format/ty/command-sync/error-codes clean.
  • Docs synced per the plugin synchronization map: changelog.py (0.66.1), CLAUDE.md, AGENT_CONTEXT, commands-reference.md, gotchas.md (since v0.66.1 entry incl. the 'schedules created by older versions stay dormant' migration note), keboola-expert.md §3 gotcha + VERSION GATE.

Verification (real stack)

Manual smoke test against a dev project on connection.north-europe.azure.keboola.com:

  1. flow schedule --cron '0 6 * * *'activated: true; GET {scheduler_url}/schedules confirmed the registration exists on the service (previously it did not, which is exactly the bug).
  2. flow schedule-remove --yes → config deleted AND GET /schedules shows the registration is gone.

self-review skipped: kbagent Claude Code plugin not installed in this environment.

flow schedule only wrote the keboola.scheduler Storage config, so the
schedule showed enabled but the cron trigger never fired until re-saved
in the UI. Register the config with the Scheduler Service after the
upsert (POST /schedules) and deregister it in schedule-remove
(DELETE /configurations/{id}) before deleting the config. Activation
failure is non-fatal: the config stays written, the result carries
activated=false plus a warning, and the exit code stays 0.
@natocTo natocTo marked this pull request as draft July 9, 2026 11:09
@natocTo natocTo requested a review from padak July 9, 2026 11:33
@natocTo natocTo marked this pull request as ready for review July 9, 2026 11:33
Deduplicate the scheduler-config target matching used by
list_flow_schedules, set_flow_schedule, and remove_flow_schedule into
_schedules_targeting_flow, skip SchedulerClient construction in
remove_flow_schedule when no schedule targets the flow, and trim
scheduler_client docstrings to match sibling clients.
@natocTo natocTo force-pushed the fix/flow-schedule-scheduler-activation branch from a00df6d to 096dcdc Compare July 9, 2026 12:05
@natocTo natocTo requested a review from Copilot July 9, 2026 15:03

This comment was marked as resolved.

Say 'deactivated' instead of 'activated' in the success line when
--disabled was used, and soften the activation-failure warning: a
previously registered schedule may keep running with its old state, so
the service 'may not reflect the updated configuration' rather than
'will NOT fire'.
@ZdenekSrotyr ZdenekSrotyr self-requested a review July 15, 2026 14:05
devin-ai-integration[bot]

This comment was marked as resolved.

set_flow_schedule only caught KeboolaApiError around
scheduler.activate_schedule(), so a non-API failure (e.g.
json.JSONDecodeError from a malformed 2xx response body) would crash
the command even though the Storage config was already written
successfully -- breaking the documented "activation failure is
non-fatal" contract. Mirrors the existing broad-catch pattern in
_fetch_flow_schema for the same reason.

@ZdenekSrotyr ZdenekSrotyr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it looks good, thank you!

@ZdenekSrotyr ZdenekSrotyr merged commit 073ca2d into main Jul 15, 2026
4 checks passed
@ZdenekSrotyr ZdenekSrotyr deleted the fix/flow-schedule-scheduler-activation branch July 15, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(flow schedule): CLI writes keboola.scheduler config but never activates it via Scheduler Service (cron never fires)

3 participants