fix(org-import): migrate runtime schedules from removed predecessor on recreate #2007

Merged
hongming merged 1 commits from fix/schedule-migration-on-recreate into main 2026-05-29 09:28:59 +00:00
Owner

internal#2006 — recreate orphaned runtime schedules. createWorkspaceTree mints a new id when the prior ws is removed; reconcile re-derives template state but runtime-created schedules orphan on the removed row. Fix migrates them from the most-recent removed predecessor (matched by stable role, fallback name+parent) onto the new ws before the template upsert. +3 tests. Part 1/3 of the schedule recreate-resilience work (monitor + cleaner follow).

internal#2006 — recreate orphaned runtime schedules. createWorkspaceTree mints a new id when the prior ws is removed; reconcile re-derives template state but runtime-created schedules orphan on the removed row. Fix migrates them from the most-recent removed predecessor (matched by stable role, fallback name+parent) onto the new ws before the template upsert. +3 tests. Part 1/3 of the schedule recreate-resilience work (monitor + cleaner follow).
hongming added 1 commit 2026-05-29 09:03:28 +00:00
fix(org-import): migrate runtime schedules from removed predecessor on recreate
ci-arm64-advisory / fast-checks (pull_request) Waiting to run
CI / Canvas Deploy Reminder (pull_request) Blocked by required conditions
Lint shellcheck (arm64 pilot) / shellcheck-arm64 (pilot) (pull_request) Successful in 10s
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 4s
CI / Detect changes (pull_request) Successful in 6s
CI / Python Lint & Test (pull_request) Successful in 4s
E2E API Smoke Test / detect-changes (pull_request) Successful in 6s
E2E Chat / detect-changes (pull_request) Successful in 10s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 7s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 3s
Harness Replays / detect-changes (pull_request) Successful in 3s
Lint forbidden tenant-env keys / Scan workspace_secrets writers for forbidden env keys (pull_request) Successful in 4s
Lint no tenant GITEA or GITHUB token write / Scan for repo-host token write into tenant workspace surface (pull_request) Successful in 6s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m44s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 3s
gate-check-v3 / gate-check (pull_request) Successful in 6s
verify-providers-gen / Regenerate providers artifact and fail on drift (pull_request) Successful in 28s
qa-review / approved (pull_request) Failing after 9s
security-review / approved (pull_request) Failing after 3s
sop-checklist / na-declarations (pull_request) N/A: (none)
sop-checklist / all-items-acked (pull_request) Successful in 5s
sop-checklist / review-refire (pull_request) Has been skipped
sop-tier-check / tier-check (pull_request) Successful in 5s
CI / Canvas (Next.js) (pull_request) Successful in 3s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 2s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 1m22s
CI / Platform (Go) (pull_request) Successful in 4m58s
E2E Chat / E2E Chat (pull_request) Successful in 3s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 7s
CI / all-required (pull_request) Successful in 23m53s
Harness Replays / Harness Replays (pull_request) Successful in 2s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 1m25s
audit-force-merge / audit (pull_request) Successful in 7s
a44a110d60
internal#2006 — recreating an agent orphans its schedules.

Root cause: createWorkspaceTree's INSERT … ON CONFLICT (parent_id,name)
WHERE status != 'removed' only matches NON-removed rows, so when an agent
is recreated after its prior workspace was marked removed, a brand-new
workspace id is minted. Reconcile then re-derives template-sourced state
(MODEL, template schedules via the upsert loop), but schedules a user added
at runtime (source='runtime', via the canvas/API) bind to the ephemeral
workspace_id and are abandoned on the removed row — they silently stop
firing (the 2026-05-29 agents-team incident: all 5 *-autonomous-tick
schedules, source=runtime, orphaned on removed ids; canvas showed
"missing schedulers").

Fix: after a fresh insert, migrate runtime-created schedules from the
most-recent removed predecessor of the same agent onto the new workspace.
The predecessor is matched by the stable `role` (survives the name
auto-suffixing that yields "Agent (2)"), falling back to name+parent.
Template-sourced schedules are NOT migrated (reconcile re-derives those);
runs before the template upsert loop so a same-named template schedule
still wins; skips names already present on the new workspace; best-effort
(logs, never errors the import).

Tests: predecessor-found re-points; no-predecessor (first create) does NOT
run the UPDATE; name-fallback branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
core-lead approved these changes 2026-05-29 09:04:09 +00:00
core-lead left a comment
Member

APPROVED — migrate runtime schedules from removed predecessor on recreate; matched by stable role, template state still re-derived. +3 tests, build green.

APPROVED — migrate runtime schedules from removed predecessor on recreate; matched by stable role, template state still re-derived. +3 tests, build green.
core-be approved these changes 2026-05-29 09:04:10 +00:00
core-be left a comment
Member

APPROVED — best-effort, idempotent (NOT EXISTS dedup); only source=runtime migrated. Closes the recreate-orphan gap.

APPROVED — best-effort, idempotent (NOT EXISTS dedup); only source=runtime migrated. Closes the recreate-orphan gap.
hongming merged commit feb2b8cfb8 into main 2026-05-29 09:28:59 +00:00
Sign in to join this conversation.
No Reviewers
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#2007