Skip to content

Prevent cold-start bootstrap stampede with single-flight request locking#3

Draft
Copilot wants to merge 4 commits into
fix/bootstrap-in-request-pathfrom
copilot/mitigate-cold-start-bootstrap
Draft

Prevent cold-start bootstrap stampede with single-flight request locking#3
Copilot wants to merge 4 commits into
fix/bootstrap-in-request-pathfrom
copilot/mitigate-cold-start-bootstrap

Conversation

Copilot AI commented May 16, 2026

Copy link
Copy Markdown

Description

Cold-start requests were executing full bootstrap work (migrations, collection/form sync, plugin bootstrap) in request middleware, and concurrent cold-start traffic could duplicate that work before the completion flag flipped. This change serializes bootstrap execution per worker instance so concurrent requests await one in-flight bootstrap instead of stampeding.

Changes

  • Bootstrap concurrency control
    • Added a module-level in-flight promise lock in bootstrap.ts.
    • First request creates and runs bootstrap; concurrent requests await the same promise.
    • Lock is cleared in finally; successful bootstrap still sets bootstrapComplete = true.
  • Bootstrap reset behavior
    • resetBootstrap() now resets both completion and in-flight state for deterministic test isolation.
  • Regression coverage for cold-start concurrency
    • Added a deterministic concurrent-request unit test that proves heavy bootstrap services are invoked once under overlap.
    • Added/updated mocks to include form-collection sync in concurrency assertions.
if (!bootstrapInFlight) {
  bootstrapInFlight = (async () => {
    try {
      // migrations + sync + plugin bootstrap
      bootstrapComplete = true
    } finally {
      bootstrapInFlight = null
    }
  })()
}
await bootstrapInFlight

Testing

Unit Tests

  • Added/updated unit tests
  • All unit tests passing

E2E Tests

  • Added/updated E2E tests
  • All E2E tests passing

Screenshots/Videos

N/A (no UI changes)

Checklist

  • Code follows project conventions
  • Tests added/updated and passing
  • Type checking passes
  • No console errors or warnings
  • Documentation updated (if needed)

Generated with Claude Code in Conductor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants