fix(gateway): serialize bootstrap setup with an advisory lock (#1430) #1431
Open
fred
wants to merge 1 commits from
fix/bootstrap-race into next
pull from: fix/bootstrap-race
merge into: :next
:next
:mosaic-cli-b2-comms-socket
:config/minimal-subset
:mosaic-cli-p0
:mosaic-cli-d1d3-aliases
:mosaic-cli-r3-bodyfile
:mosaic-cli-p4-fleet-logins
:mosaic-cli-p1b-viewers
:mosaic-cli-b5-baseline
:mosaic-cli-p3-board
:mosaic-cli-p2-socket-res
:feat/m4-1b-ii-hierarchy-commands
:mosaic-cli-p1-wrappers
:mosaic-cli-p1-dispatch
:docs/ruling-4b-company-visibility
:feat/m4-1b-hierarchy-gateway
:feat/m4-1a-hierarchy-schema
:feat/p6-e2e-ci-gate
:feat/p5-spa-cutover
:fix/1451-appservice-dockerfile-scripts
:contract/onboarding-wizard
:contract/custody-schema
:contract/api-artifacts
:fix/appservice-dockerfile-scripts
:docs/t78-cli-capability-migration
:contract/rollup-projection
:contract/hierarchy-schema
:fix/invariant-r-version-probe-retry
:contract/mode-conversion
:contract/tool-gateway-mapping
:contract/rbac-grants
:contract/identity-lifecycle
:chore/s1-docs-hygiene
:docs/ri-050-release-evidence
:feat/webui-p4-2-settings-admin
:fix/bootstrap-race
:fix/teams-enumeration-scope
:fix/1407-next-image-parity
:docs/prd-north-star-rewrite
:rescue/ms-gate-001-gatekeeper
:fix/1394-recover-token-headless
:fix/1390-uninstall-headless
:fix/1403-n1n2-followup
:fix/1391-validationpipe-boot-check
:archive/salvage-20260825/wp5b-consumer-compat
:wp5b-consumer-compat-2
:archive/salvage-20260825/t63-fix-2648
:archive/salvage-20260825/t63-fix-1389
:archive/salvage-20260825/i1380ff-fix
:i1380-guard
:fix/send-message-exact-target-pin
:t51p2wp0b
:archive/ms24-fork
:fix/ci-queue-wait-no-ci-merge-path
:fix/credentials-gitea-seat-slots
:feat/onboarding-scripts-framework
:pr-1367
:fix/1357-issue-view-comments
:fix/1356-tea-login-fail-closed
:fix/1362-harness-aware-delivery-confirm
:fix/gitea-guessed-login-credential
:docs/w4-document-contract
:fix/d29-lease-revoke-noop
:peggy/agent-send-unverified-label
:fix/pr-merge-fork-ci-status
:riv001-clean
:docs/1216-trunk-parameterization
:fix/1257-adopt-draft-transition
:fix/1256-fleet-pane-path-node
:fix/1017-enumeration-guard-population
:fix/1182-fail-closed-launch
:fix/1327-setuppath-idempotency
:merge/main-into-next
:ci/push-ci-comment-model
:ci/pin-ci-base-image
:fix/ci-queue-wait-no-status
:fred/code-review-pinned-tool-rules
:fred/guides-seat-identity-fleet-comms
:fred/credential-fail-closed-seat-slots
:fix/fleet-greenfield-blockers
:feat/ri-050-qr-evaluator
:archive/salvage-20260825/zane/doctor-greenfield-hint
:archive/salvage-20260825/fix/ri-050-registry-secrets
:archive/salvage-20260825/docs/ri-050-release-evidence
:docs/ri-050-forge-docs-fastfollow
:fix/ri-050-registry-secrets
:test/ri-050-publish-gate-negative
:archive/salvage-20260825/fix/ri-050-verify-pglite-path
:fix/ri-050-verify-pglite-path
:docs/ri-050-qr-probe-inventory
:archive/salvage-20260825/zane/doctor-brain-home
:feat/ri-050-web-stale-safety
:archive/salvage-20260825/pr-1298
:archive/salvage-20260825/zane/mosaic-home-support
:docs/ri-050-mission-bootstrap
:fix/ri-050-forge-fail-closed
:feat/ri-050-publish-gate
:fleet/continuation-record-2026-08-17
:feat/ri-050-prd-authority
:fix/ri-050-macp-fail-closed
:fix/1280-identity-first-resolution
:feat/w-f4-store
:fix/1264-fleet-unattended-first-start
:fix/1269-ci-chain-unblock
:fix/1256-fleet-runtime-preflight
:fix/1257-e7-draft-transition
:fix/1240-fleet-transport-check
:fix/1017-wire-start-agent-session
:e2e-compose
:fix/1241-launch-failure-visible
:fix/1237-fleet-v2-dispatch
:fix/1236-installer-dir-modes
:fix/installer-path-and-node
:feat/wf-fleet-mvp
:fix/installer-provisions-node
:fix/lease-test-env-isolation
:release/0.0.50-integration
:feat/wf5-main-merge
:feat/wf5-securestorage
:feat/1216-trunk-resolver
:docs/1214-branch-process
:docs/ia-merge-current
:fix/869-lease-probe-timeout
:main
:feat/workspace-hygiene-tool-enforcement
:feat/1080-pr-edit
:fix/1179-required-security-di
:feat/p3-slice0-task5-chat-runtime-router-shaggy
:feat/p3-slice0-task5-chat-runtime-router
:feat/wf1-composition
:feat/p3-slice0-task4-web-catalog-selection
:feat/lease-promotion-and-harness-isolation
:ci/provision-pi-runtime
:feat/p3-slice0-task3-catalog-selection
:feat/p3-slice0-task2-harness-registry
:adopt/965-mos-ste-writing-standard
:fix/991-comment-url-scheme-normalise
:feat/wf2-bundle-migration
:feat/wf4-plugin-acquisition
:feat/wf5-refresh-safety
:fix/1145-coord-di-compiled-boot
:feat/p3-slice0-task1-harness-contracts
:docs/webui-phase-p-structure
:feat/1150-pi-goal-extension
:feat/webui-p3-chat
:fix/1146-ci-queue-purpose
:fix/1138-conditional-federation
:feat/webui-p2-data-auth
:fix/gateway-runner-image
:feat/webui-p1-vite-skeleton
:fix/break-c-hooks-and-web-image
:docs/webui-fleet-claude-bridge-plan
:fix/wizard-gateway-failure
:fix/next-node-gate
:fix/mosaic-init-rce
:greenfield/fomo-lin
:fix/1099-pipefail-wake
:fix/1099-pipefail-tests
:fix/1099-pipefail-sweep
:fix/framework-shell-portability
:fix/1043-pane-git-identity
:fix/1081-issue-close-silent-comment-failure
:fix/1090-enrollment-wallclock-tolerance
:feat/1082-tea-stale-token-diagnostic
:fix/detect-platform-silent-128-outside-repo
:feat/1050-install-state-machine-red-fixture
:fix/pr-merge-message-field
:feat/1051-mosaic-brain-installer
:feat/1045-mosaic-cred
:remediation/state
:fix/1056-upgrade-rollback-control-race
:fix/1019-ci-queue-timeout-harness
:feat/rm-02-gate-registry
:fix/rm-01-reproducible-checkout
:remediation/mission-setup
:fix/hygiene-inert-format-gate
:fix/1019-queue-guard-stdin
:feat/mos-ste-writing-standard
:fix/1017-enumeration-guard
:fix/1007-suite-hermeticity
:feat/push-guard-null-case-verification
:feat/wake-preimage-provenance
:mos-comms-live
:docs/heartbeat-framework-layering-ms-lead
:feat/869-c4-version-coupling
:feat/869-c2-install-ordering-guard
:feat/869-c5-doctor-activation-check
:feat/per-agent-gitea-identity
:fix/875-belongs-case-insensitive-slug
:fix/ci-queue-wait-404-branch-absent
:feat/869-c1-activation-probe
:feat/869-c3-broker-supervisor
:fix/865-tea-cli-comment-invocation
:feat/glpi-skills
:fix/860-deflake-mutator-lease-gate
:fix/850-detect-platform-port-normalization
:fix/856-worktree-deps-preflight
:fix/835-pr-review-approve-reject-comment-flag
:fix/848-truthful-evidence
:fix/812-pr-review-comment
:fix/849-recovery-runtime-fixture-race
:docs/758-ledger-m5-001-sync
:feat/834-tc-server-side-doc
:feat/833-constrained-recovery-command
:feat/827-gate0-probe
:governance/gate0-probe3-amendment
:fix/795-codex-pr-diff
:fix/795-ci-base-jq
:fix/795-ci-base-git
:feat/791-pr3-fleet-regen
:feat/791-pr2-snapshot-restore
:fix/807-glpi-206
:fix/808-agent-send-false-sender
:feat/791-upgrade-config-protection
:feat/790-mosaic-yolo-claudex-pr2
:feat/790-mosaic-yolo-claudex
:feat/758-v1-v2-migrator
:fix/766-exact-fleet-comms
:test/758-reconciler-lifecycle-gates
:docs/771-kbn101-db-role-split
:test/758-example-profile-dispositions
:feat/758-shared-role-resolution
:feat/mos-logical-identity-fencing
:feat/769-kbn100-unified-schema
:docs/753-kbn010-threat-gate
:feat/758-roster-v2-compiler
:feat/756-official-discord-plugin
:fix/mos-option2-qualification-format
:docs/issue-758-m0
:docs/mos-option2-qualification
:mos-comms
:feat/tess-interaction-agent
:fix/tess-docs-format
:draft/mosaic-platform-prd
:fix/installer-provider-gate-and-local-gateway-redis
:release/mosaic-cli-0.0.37
:feat/framework-constitution-alpha
:fix/git-wrapper-repo-detection
:fix/woodpecker-wrapper-legacy-mosaic
:fix/t-a292e96f-gitea-pr-metadata
:fix/gitea-pr-metadata-login-t-a292e96f
:fix/t_a292e96f-pr-metadata-gitea
:fix/t_3a368a52-gitea-usc-login
:fix/bootstrap-hotfix
:fix/populate-known-packages-list
:fix/idempotent-init
:archive/salvage-20260825/fix/ci-prisma-generate
:archive/salvage-20260825/feat/ms-gate-001-gatekeeper-local
:archive/salvage-20260825/feat/ms-gate-001-gatekeeper
:archive/salvage-20260825/feat/ms24-ci-webhook
:archive/salvage-20260825/fix/mission-control-proxy-routes
:archive/salvage-20260825/fix/deploy-missing-env-and-networks
:archive/salvage-20260825/fix/mission-control-query-provider
:archive/salvage-20260825/test/ms23-p2
:archive/salvage-20260825/feat/ms23-p2-audit
:archive/salvage-20260825/feat/ms23-p2-roster
:archive/salvage-20260825/feat/ms23-p1-proxy
:archive/salvage-20260825/feat/ms23-p1-registry
:archive/salvage-20260825/feat/ms23-p1-internal-provider
:archive/salvage-20260825/feat/ms23-p1-interface
:archive/salvage-20260825/chore/ms23-tasks-p0-complete
:archive/salvage-20260825/test/ms23-p0
:archive/salvage-20260825/chore/ms23-tasks-p005-006
:archive/salvage-20260825/feat/ms23-p0-tree
:archive/salvage-20260825/chore/ms23-tasks-p004-005
:archive/salvage-20260825/feat/ms23-p0-controls
:archive/salvage-20260825/chore/ms23-tasks-p0-002-004
:archive/salvage-20260825/feat/ms23-p0-stream
:archive/salvage-20260825/fix/ms23-prisma-rm-symlink
:archive/salvage-20260825/fix/ms23-prisma-kaniko-symlink
:archive/salvage-20260825/fix/ms23-prisma-script-path
:archive/salvage-20260825/fix/ms23-prisma-docker-vs-ci
:archive/salvage-20260825/fix/ms23-prisma-schema-local
:archive/salvage-20260825/fix/ms23-prisma-api-pkg
:archive/salvage-20260825/fix/ms23-prisma-cli
:archive/salvage-20260825/fix/ms23-orchestrator-prisma-generate
:archive/salvage-20260825/feat/ms23-p0-ingestion
:archive/salvage-20260825/feat/ms23-p0-schema
:archive/salvage-20260825/fix/agent-template-auth-module
:archive/salvage-20260825/feat/ms22-p2-discord-router
:archive/salvage-20260825/test/ms22-p2-agent-tests
:archive/salvage-20260825/chore/ms22-p2-docs-update
:archive/salvage-20260825/feat/ms22-p2-agent-routing
:archive/salvage-20260825/chore/ms22-p2-update-docs
:archive/salvage-20260825/feat/ms22-p2-user-agents
:archive/salvage-20260825/feat/ms22-p2-agent-crud
:archive/salvage-20260825/fix/security-audit-multer
:archive/salvage-20260825/ci/portainer-deploy
:archive/salvage-20260825/fix/ms21-missing-user-auth-migration
:archive/salvage-20260825/infra/fix-mosaic-db-init-extensions
:archive/salvage-20260825/infra/migrate-to-openbrain-db
:archive/salvage-20260825/fix/flaky-queue-test
:archive/salvage-20260825/fix/deploy-service-names
:archive/salvage-20260825/fix/deploy-service-update
:archive/salvage-20260825/fix/deploy-user-v2
:archive/salvage-20260825/fix/deploy-user
:archive/salvage-20260825/fix/orchestrator-widget-endpoints
:archive/salvage-20260825/fix/dashboard-widget-mock-data
:archive/salvage-20260825/fix/ci-glibc-image
:archive/salvage-20260825/fix/dockerfile-npmrc
:archive/salvage-20260825/fix/matrix-native-binary
:archive/salvage-20260825/fix/kaniko-cache
:archive/salvage-20260825/fix/base-image-kaniko-v2
:archive/salvage-20260825/fix/base-image-kaniko
:archive/salvage-20260825/feat/custom-base-image
:archive/salvage-20260825/ci/pnpm-cache
:archive/salvage-20260825/fix/interceptor-tests
:archive/salvage-20260825/fix/kanban-tests
:archive/salvage-20260825/feat/wire-chat
:archive/salvage-20260825/feat/usage-widget
:archive/salvage-20260825/feat/usage-widget-review
:archive/salvage-20260825/fix/security-hardening
:archive/salvage-20260825/fix/project-domain-attach
:archive/salvage-20260825/fix/project-domain-v2
:archive/salvage-20260825/feat/kanban-add-task
:archive/salvage-20260825/fix/logs-page-clean
:archive/salvage-20260825/fix/logs-page
:archive/salvage-20260825/fix/workspace-members
:archive/salvage-20260825/fix/ci-lint-632
:archive/salvage-20260825/fix/lint-from-632
:archive/salvage-20260825/fix/file-manager-tags
:archive/salvage-20260825/fix/csrf-debug-log
:archive/salvage-20260825/fix/controller-type-imports
:archive/salvage-20260825/fix/system-admin-env
:archive/salvage-20260825/fix/gateway-cors-trusted-origins
:archive/salvage-20260825/fix/fleet-provider-form-dto-v2
:archive/salvage-20260825/fix/ms22-audit
:archive/salvage-20260825/fix/orchestrator-widgets
:archive/salvage-20260825/fix/fleet-provider-form-dto
:archive/salvage-20260825/fix/orchestrator-widgets-preexisting
:archive/salvage-20260825/fix/csrf-bearer-bypass
:archive/salvage-20260825/fix/ms22-missing-authmodule-imports
:archive/salvage-20260825/fix/container-lifecycle-config-module
:archive/salvage-20260825/fix/swarm-compose-ms22-vars
:archive/salvage-20260825/chore/ms22-p1-complete
:archive/salvage-20260825/feat/ms22-p1k-idle-reaper
:archive/salvage-20260825/feat/ms22-p1j-docker
:archive/salvage-20260825/feat/ms22-p1e-onboarding-api-work
:archive/salvage-20260825/feat/ms22-p1c-config-api
:archive/salvage-20260825/chore/ms22-prd-tracking
:archive/salvage-20260825/feat/ms22-p1b-crypto
:archive/salvage-20260825/docs/ms22-architecture
:archive/salvage-20260825/feat/ms22-openclaw-docker
:archive/salvage-20260825/feat/ms22-openclaw-gateway-module
:archive/salvage-20260825/chore/ms21-complete
:archive/salvage-20260825/chore/ms21-final-tasks-done
:archive/salvage-20260825/fix/ms21-ui-001-qa
:archive/salvage-20260825/feat/ms22-openclaw-docker-backup-20260301
:archive/salvage-20260825/chore/ms22-phase0-complete
:archive/salvage-20260825/feat/ms21-ui-teams-rbac-v3
:archive/salvage-20260825/test/ms22-integration
:archive/salvage-20260825/feat/ms22-ingest-clean
:archive/salvage-20260825/feat/ms21-ui-users-members
:archive/salvage-20260825/feat/ms22-ingest
:archive/salvage-20260825/feat/ms22-task-agent
:archive/salvage-20260825/chore/ms22-tasks-tracking
:archive/salvage-20260825/feat/ms21-ui-teams-rbac
:archive/salvage-20260825/fix/openbao-otel-cve
:archive/salvage-20260825/ci/unified-pipeline
:archive/salvage-20260825/feat/ms22-conversation-archive
:archive/salvage-20260825/feat/ms22-agent-memory
:archive/salvage-20260825/feat/ms22-findings
:archive/salvage-20260825/feat/ms22-knowledge-schema
:archive/salvage-20260825/chore/tasks-final
:archive/salvage-20260825/chore/tasks-update
:archive/salvage-20260825/feat/ms21-session-invalidation
:archive/salvage-20260825/feat/ms21-rbac-settings
:archive/salvage-20260825/feat/ms21-rbac
:archive/salvage-20260825/feat/ms21-ui-user-dialogs
:archive/salvage-20260825/feat/ms21-ui-workspace-members
:archive/salvage-20260825/feat/ms21-ui-teams
:archive/salvage-20260825/chore/ms21-tasks-ui-progress
:archive/salvage-20260825/feat/ms21-ui-workspaces
:archive/salvage-20260825/feat/ms21-ui-users
:archive/salvage-20260825/chore/ms21-tasks-schema-fix
:archive/salvage-20260825/feat/ms21-import-api
:archive/salvage-20260825/test/ms21-migration-tests
:archive/salvage-20260825/feat/ms21-teams-page
:archive/salvage-20260825/feat/ms21-users-page
:archive/salvage-20260825/chore/ms21-task-update-p1-p3
:archive/salvage-20260825/feat/ms21-admin-module
:archive/salvage-20260825/fix/websocket-reconnect
:archive/salvage-20260825/merge/develop-to-main
No Reviewers
No labels
Milestone
No items
No Milestone
Projects
Clear projects
No projects
Assignees
code-be-01 (Mosaic fleet seat code-be-01)
code-be-02 (Mosaic fleet seat code-be-02)
code-infra-01 (Mosaic fleet seat code-infra-01)
fargo
fred
gate-merge-01 (Mosaic fleet seat gate-merge-01)
happy
jason.woltje (Jason Woltje)
marcie
merge-gate
ops-01 (Mosaic fleet seat ops-01)
ops-02 (Mosaic fleet seat ops-02)
ops-03 (Mosaic fleet seat ops-03)
ops-ci-01 (Mosaic fleet seat ops-ci-01)
ops-deploy-01 (Mosaic fleet seat ops-deploy-01)
orch-01 (Mosaic fleet seat orch-01)
pepper
resume
rev-code-01
rev-code-02
rev-security-01
rev-security-02
rev-security-03 (Mosaic fleet seat rev-security-03)
sanity
scooby (Scooby)
scrappy
shaggy
tiny
velma
veronica (Mosaic fleet seat veronica)
vision
woodpecker
Clear assignees
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: mosaicstack/stack#1431
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What
POST /api/bootstrap/setupchecked the zero-user count and then created the first admin with nothing making the two atomic (TOCTOU race). Two concurrent setup requests could both observe zero users and each create an admin user plus an admin API token.Setup now runs inside
db.transactionthat first takespg_advisory_xact_lock(BOOTSTRAP_SETUP_LOCK_KEY). The second concurrent caller blocks on the lock until the first transaction commits, re-reads the count, and gets 403. The lock is transaction-scoped and lives in the database, so it serializes across gateway replicas as well as within one process.BetterAuth's
createUserstill writes on its own connection (unchanged); the verification reads moved onto the transaction and see the committed row under READ COMMITTED.Tests
bootstrap.e2e.spec.ts: mock db gainedtransaction/execute; the 201 path now asserts the advisory lock is taken before the zero-user count; new suite pins 403 +createUsernever called when users already exist. 5/5 pass.pnpm typecheck(gateway): clean.Provenance
webui-audit mission, A3 security review finding (cross-review confirmed), S1 quick-fix list in the lane REPORT.md.
Closes #1430
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.