fix(automation): re-bind scheduled-flow jobs on os dev hot-reload#2313
Merged
Conversation
Editing a schedule-triggered flow under `objectstack dev` silently kept firing the OLD definition until a full server restart. The dev watcher recompiles dist/objectstack.json and MetadataPlugin reloads it into the MetadataManager (so GET /meta + UI HMR are fresh), but the AutomationEngine pulls its flow definitions and trigger/job bindings ONCE at boot — nothing re-registered them on reload. So the scheduled job bound at boot kept running the pre-edit flow (old runAs/schedule/logic) on its timer, with no signal the edit had no effect. MetadataPlugin now fires a generic `metadata:reloaded` hook after each artifact reload (the HMR POST handler and the server-side artifact-file watcher; never on the initial boot load). AutomationServicePlugin subscribes and re-syncs the engine from the metadata service — re-registering every current flow (idempotent: registerFlow re-binds the trigger, ScheduleTrigger.start cancels + reschedules the job) and unregistering flows removed from the artifact so their jobs stop. Covers all auto-triggered flow types (schedule / record-change / api), since record-change flows were also executing boot-time definitions after an edit. Production deployments are unaffected — nothing reloads the artifact there. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 2 package(s): 9 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
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.
Problem
Editing a schedule-triggered flow under
objectstack devsilently kept firing the OLD definition until a full server restart. The terminal prints✓ recompiled — server will auto-reload, but the scheduled job bound at boot keeps running the pre-edit flow (oldrunAs/ schedule / logic) on its timer — with no signal the edit had no effect.Root cause (a gap, not by design)
The dev watcher recompiles
dist/objectstack.json; the server's MetadataPlugin reloads it into the MetadataManager (soGET /meta+ UI HMR are fresh). But the AutomationEngine pulls its flow definitions and trigger/job bindings once at boot (ql.registry.listItems('flow')) and nothing re-registers them on reload.registerFlow/ScheduleTrigger.startare already idempotent and re-bind correctly — the reload path simply never called them.This is a whole bug class: record-change flows also executed boot-time definitions after an edit; scheduled flows are just the most visible because they fire on a timer with no user interaction.
Fix
@objectstack/metadata— factor_reloadAndAnnounce; both reload sites (HMR POST handler + server-side artifact-file watcher) fire a genericmetadata:reloadedhook after reloading (never on the initial boot load). MetadataPlugin stays decoupled from automation — it just announces.@objectstack/service-automation— subscribe tometadata:reloadedand re-sync the engine from the metadata service: re-register every current flow (idempotent → re-binds the trigger;ScheduleTrigger.startcancels + reschedules the job) and unregister flows removed from the artifact so their jobs stop. Covers all auto-triggered flow types (schedule / record-change / api).Production deployments are unaffected — nothing reloads the artifact there.
Tests
flow-hot-reload.test.ts(new, service-automation)runAsuser→system); deleted flow torn downplugin-hmr-reload.test.ts(new, metadata)metadata:reloaded; a throwing subscriber never breaks the reloadSource typechecks (tsup DTS build clean). Changeset included (both packages
patch, same fixed group).Discovered while dogfooding the #1888 schedule/runAs follow-up (#2308) — not caused by it.
🤖 Generated with Claude Code