Repository navigation
Conversation
web and worker migrate the same database, but only the worker checked that the database really matches schema.prisma. `migrate deploy` compares the migrations directory against the _prisma_migrations bookkeeping table and never inspects the schema, so a migration recorded as applied but never executed is invisible to it. web therefore kept serving traffic against a schema the worker refuses to run against — and if web deployed first, it applied migrations with no guard around it, closing the repair window before the worker ever looked. The guard now lives in packages/outpost/db/schema-drift-guard.sh and both start.sh files source it. Its behaviour is unchanged: the same timeout bound, the same OUTPOST_ALLOW_SCHEMA_DRIFT release valve, the same distinction between "the schema differs" (exit 2) and "the check never ran" (any other exit), and the same stdout/stderr split that keeps NOTE and WARNING lines out of an alert keyed on stdout. The CI step that exercises the guard against a stub CLI now runs both services, so a change that breaks one of them fails there. Refs CopilotKit#183 Co-Authored-By: Claude Code <noreply@anthropic.com>
BusyBox timeout returns the supervised command's status, so a child that catches TERM and exits zero could make a timed-out drift check look successful. Kill the read-only diff at the deadline and normalize the resulting status instead. Capture deploy and diff statuses in conditionals rather than toggling errexit, so sourcing the guard does not change the caller's shell settings. Cover both cases in CI, including the BusyBox timeout used by the images. Co-Authored-By: Claude Code <noreply@anthropic.com>
This branch has not been deployed
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
apps/web/start.shran a bareprisma migrate deployand nothing else. The worker, which migrates the same database, refused to boot against a schema it did not match. So a drifted deploy half-succeeded: the worker stayed down while web kept serving traffic against that schema — and if web deployed first, it applied the migrations with no guard around it at all, closing the repair window before the worker ever looked.This extracts the worker's guard into a shared script and applies it to both services.
Refs #183
What changed
packages/outpost/db/schema-drift-guard.shand is sourced by bothapps/worker/start.shandapps/web/start.sh. It retains the timeout bound,OUTPOST_ALLOW_SCHEMA_DRIFTrelease valve, distinction between "the schema differs" (exit 2) and "the check never ran" (any other exit), and stdout/stderr split. The timeout now uses SIGKILL for the read-only diff: BusyBox can otherwise report success when a timed-out process catches SIGTERM and exits zero. The sourced guard also preserves its caller's shell error setting. The comments moved with it.migrate deployonly compares the migrations directory against the_prisma_migrationsbookkeeping table and never inspects the schema, so a migration recorded as applied but never executed is invisible to it. web now refuses to serve against that database, exactly like the worker.COPYline; the worker's image already copies the wholepackages/tree.start.shagainst a stub CLI, asserting every branch: clean schema boots, drift blocks the boot, the override boots, an unrecognised override does not, a tool failure blocks, a deploy failure blocks, a bad timeout value does not fail the step closed, diagnostics reach stderr, and an overridden boot does not page.The migration itself is still run by each service separately — two concurrent migrators against one database is the existing arrangement, and consolidating that is a separate change.
One thing a reviewer might reach for: the comment in
20260812220000_create_missing_systemconfig_table/migration.sqlsays the repair's assertion cannot be deferred to the worker's drift guard because "apps/web/start.sh runs a baremigrate deployagainst this same database with no guard". That is now false. The migration file is still left alone — Prisma records a checksum of each migration, so editing one that has already been applied changes migration history and can cause checksum errors. The comment stands as a record of what was true when it was written.Tests
The CI step above is the regression test. It runs each service's
start.shagainst a stub CLI and asserts every branch, preserves the caller'serrexitsetting, and runs the timeout innode:24-alpineagainst a child that catches SIGTERM and exits zero. It passes underbash,dashandbusybox shlocally.End-to-end against a real PostgreSQL 16 and the real prisma CLI, with
apps/web/start.shandapps/worker/start.shrun against it:schema.prismaTicketOUTPOST_ALLOW_SCHEMA_DRIFT=1turbo run typecheck --filter=@copilotkit/outpost-workerand the worker's 84 tests pass;pnpm lintpasses. Fullpnpm testpasses on rerun (11/11 packages). An earlier run hit the pre-existing flakypackages/outpost/ai/src/github-evidence-auth.test.ts("1 of 2 exchanges arrived"), which this change does not touch and which fails on some runs and passes on others.Note for reviewers
The guard's own comments carry the reasoning, including why ANY difference is fatal rather than classified: an earlier revision failed only on missing objects, so a sibling service mid-rollout would not block the worker — and that classifier silently passed real drift (missing enum values and wrong column types both escaped it) while printing "schema matches" against a drifted database. A guard that can be wrong in the reassuring direction is worse than no guard, so the crude check stands and
OUTPOST_ALLOW_SCHEMA_DRIFTis the release valve.One consequence worth naming: since both services now refuse to start on drift, a deploy that leaves the database skewed blocks both of them, not just the worker. That is the intended reading of the issue — a half-deployed pair is what the guard exists to prevent — but it does mean an operator mid-incident needs
OUTPOST_ALLOW_SCHEMA_DRIFT=1on both services, not just the worker. The skew itself is more likely now, too: the two services already migrate concurrently (Prisma's advisory lock serialises the migrations, anddocs/deployment.mdsays so), and a drift check that runs while the sibling is applying a migration sees the intermediate state. That was already true of the worker; web now shares it.OUTPOST_ALLOW_SCHEMA_DRIFT=1is the valve for that window.🤖 Generated with Claude Code