fix: run migrations on tenant schemas at startup and harden worker poller#237
Merged
Conversation
…ller Tenant schemas were never migrated when new migrations were deployed. Only the public schema was migrated at startup, and tenant schemas only got migrations when first provisioned. This meant existing tenants missed any new columns (e.g. task_payload, worker_id, claimed_at on async_operations), causing the worker poller to crash silently. Changes: - Run migrations on all existing tenant schemas at startup when a tenant_extension is configured. Each schema migration is wrapped in try/except so one failure doesn't block others. - Add try/except in WorkerPoller.recover_own_tasks() so a broken schema doesn't prevent the polling loop from starting. - Add try/except in WorkerPoller._claim_batch_for_schema() so a broken schema doesn't prevent claiming tasks from other schemas.
nicoloboschi
approved these changes
Jan 29, 2026
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
publicschema)Problem
When new migrations are deployed, only the
publicschema gets migrated at startup. Existing tenant schemas are left behind on their old migration version. This caused the worker poller to crash silently when it tried to query columns (e.g.worker_id,task_payload) that didn't exist in tenant schemas.The crash was completely silent because
poller.run()is started viaasyncio.create_task()and the exception inrecover_own_tasks()(called before any try/except block) killed the coroutine with no logging.Changes
memory_engine.py— After running public schema migrations, iterate all tenants from the tenant extension and run migrations on each schema. Wrapped in try/except per-schema so one failure doesn't block others.worker/poller.py— Defense-in-depth:recover_own_tasks(): try/except per-schema so a broken schema doesn't prevent the polling loop from starting_claim_batch_for_schema(): try/except wrapper so a broken schema doesn't prevent claiming tasks from other schemasTest plan