Skip to content

feat: Serverless startup without data or network on the boot path - #209

Merged
jrosskopf merged 9 commits into
mainfrom
claude/gracious-brahmagupta-552ilv
Oct 31, 2026
Merged

jrosskopf merged 9 commits into
mainfrom
claude/gracious-brahmagupta-552ilv

Conversation

@jrosskopf

@jrosskopf jrosskopf commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A review of a Cloud Run migration found its 6–17 min cold starts, multi-GiB containers and 20 min deploys came mostly from usage: every scale-to-zero instance filled the per-instance cache from BigQuery at boot. It also found real flAPI gaps. This PR makes everything on the boot path optional, with every default unchanged:

  • Warm-up control: ducklake.warmup: always | if-empty | never, per-endpoint cache.warmup, --cache-warmup / --no-cache-warmup / FLAPI_CACHE_WARMUP. A skipped cache with no table is unbuilt: its endpoint answers 503 cache_not_built; /health answers 200 degraded with an unbuilt list.
  • Extensions:
    • duckdb.default-extensions (was hard-coded) and FLAPI_EXTENSION_DIRECTORY.
    • FLAPI_EXTENSIONS_OFFLINE=1 (fail fast instead of downloading).
    • flapi extensions install for image builds.
    • Finding: flAPI's DuckDB loads no extension statically, so even core_functions was downloaded on the first query of every fresh container. It is now always installed and checked offline.
  • Runtime image: Dockerfile runtime target, published as :<tag>-runtime (:latest stays slim). CI checks that it starts with --network none.
  • flapi pack --with-extensions (or --extensions-dir): the packed binary carries its extensions under .flapi/extensions/, extracts them once (content-addressed) and starts offline.
  • Read-only replicas: ducklake.read-only: true attaches READ_ONLY, forces warm-up never, and runs no refresh, retention or compaction. Cache mutations through the config service get 409.
  • Refresh job: flapi cache refresh (--endpoint … | --all) refreshes once, prints JSON and exits 0/1/2. Run it as a job after dbt build instead of an always-on writer.
  • Docs:
    • New guide docs/guides/serverless.md.
    • CONFIG_REFERENCE, CLI_REFERENCE, DESIGN_DECISIONS § 11, caching spec, CHANGELOG.

Decisions taken:

  • /health reports unbuilt as 200 degraded, the same as stale.
  • A separate -runtime tag, plus pack embedding.
  • The local-catalog spike is deferred (DataZooDE/flapi#208).

Test plan

Written test-first. The red commits/runs failed on assertions against stubs; the green commits pass.

  • New C++ tests:
    • cache_warmup_mode_test.cpp
    • extension_installer_test.cpp
    • ducklake_reader_test.cpp (real writer job + read-only reader on one DuckLake catalog)
    • bundled_extensions_test.cpp
    • pack embedding cases in pack_test.cpp
  • Full C++ suite: 837 cases pass (1 skipped).
  • New integration tests test_serverless_startup.py (8), against the real binary:
    • --no-cache-warmup gives degraded /health and cache_not_built;
    • an invalid env value exits 1;
    • refresh job, then an if-empty server serving without rebuilding;
    • pre-installed extensions with offline mode and a dead proxy;
    • offline start with an empty directory fails fast;
    • a packed binary run from an empty directory with no network.
  • Existing integration tests:
    • 454 standalone tests pass;
    • 622 shared-server tests pass (14 skipped).
  • Repo guard scripts pass (known config keys, crow fields, C++ standard, ABI guard, router, auth prefix).
  • Runtime image install line and offline start verified locally without Docker (live in 2 s, serves the cached endpoint).
  • Multi-arch -runtime image build and its --network none start check run in CI only. Not run locally (no Docker daemon).

Closes #201
Closes #202
Closes #203
Closes #204
Closes #205
Closes #206
Closes #207


Generated by Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

- G1 warm-up modes: ducklake.warmup / cache.warmup / CLI+env override,
  Unbuilt readiness state, cache_not_built, /health degraded
- G2 extensions: duckdb.default-extensions, FLAPI_EXTENSION_DIRECTORY,
  FLAPI_EXTENSIONS_OFFLINE fail-fast, flapi extensions install helpers
- G4a ducklake.read-only: READ_ONLY attach, no maintenance, 409 on mutations
- G6 flapi cache refresh one-shot command
- Stubs only (declarations, TODO bodies) so the suite compiles and fails
  on assertions; implementation follows in the green commit
- Integration: test_serverless_startup.py + offline fixture
- CONFIG_REFERENCE: duckdb.default-extensions, ducklake.warmup,
  ducklake.read-only, cache.warmup, cache_not_built
- CLI_REFERENCE: --cache-warmup/--no-cache-warmup, flapi cache refresh,
  flapi extensions install, new env vars, unbuilt on /health
- New guide docs/guides/serverless.md; DESIGN_DECISIONS section 11;
  caching spec readiness states; CHANGELOG
- Dockerfile runtime target with pre-installed extensions; CI builds and
  publishes :<tag>-runtime and checks it starts with --network none
- The mock adapter returns QueryResult by value; query_executor.hpp was
  missing, so the test did not compile
- Mirror cache_manager_test.cpp's STL pre-include list for the
  private-to-public include hack
…een)

- G1: ducklake.warmup always|if-empty|never, cache.warmup, --cache-warmup,
  --no-cache-warmup, FLAPI_CACHE_WARMUP; Unbuilt readiness state answers
  503 cache_not_built, /health 200 degraded with an unbuilt list
- G2: duckdb.default-extensions list, FLAPI_EXTENSION_DIRECTORY,
  FLAPI_EXTENSIONS_OFFLINE (no INSTALL, autoinstall off, fail fast naming
  the missing extensions), flapi extensions install subcommand
- G2 finding: flAPI's DuckDB loads no extension statically, so
  core_functions was silently downloaded on the first query of every fresh
  container; it is now always collected, installed in the runtime image,
  and checked explicitly offline (extensions now load before the version
  query)
- G4a: ducklake.read-only attaches READ_ONLY, forces warm-up never, skips
  audit DDL, scheduled refresh, retention and compaction; config service
  answers 409 read_only_cache to refresh, update and GC
- G6: flapi cache refresh (--endpoint ... | --all) refreshes once, prints
  a JSON summary, exits 0/1/2
- Tests: 20 new C++ cases and 6 integration tests pass; full C++ suite
  (829 cases) and 454 standalone integration tests pass
- DuckLake does not create the catalog's parent directory, so the
  runtime-image CI check would fail in a fresh container
- Verified locally: pre-seeded extensions, FLAPI_EXTENSIONS_OFFLINE=1 and a
  dead proxy start live in 2 s and serve the cached endpoint
- flapi pack --with-extensions installs the config's extensions
  (core_functions, duckdb.default-extensions, connection INSTALLs) for the
  host platform and embeds them under the reserved .flapi/extensions/ prefix;
  --extensions-dir embeds an already filled directory (other platforms)
- At startup the bundle's extensions are extracted once to
  $TMPDIR/flapi-extensions/ext-<content hash>/ (staged + renamed, reused
  on restart, entries escaping the directory refused), dropped from the
  in-memory bundle map, used as extension_directory, and offline extensions
  default on; precedence config > FLAPI_EXTENSION_DIRECTORY > bundle,
  FLAPI_EXTENSIONS_OFFLINE=0 overrides
- An input tree may not use .flapi/ itself
- Tests first: pack_test (embed, reserved prefix, missing dir) and
  bundled_extensions_test failed against stubs, now pass; integration test
  packs the fixture and runs the binary from an empty directory with no
  network
- Full C++ suite 837 cases pass; docs: CLI_REFERENCE pack options, guide,
  DESIGN_DECISIONS, CHANGELOG, CLAUDE.md
- main.cpp called ::getpid() although its <unistd.h> include is POSIX-only;
  extension_installer.cpp included <unistd.h> unguarded
- Add CurrentProcessId() (getpid / _getpid) and use it in pack, bundle
  extraction and the DuckLake reader test
- extension_installer_test and bundled_extensions_test use the repo's
  existing _putenv_s shim for setenv/unsetenv on Windows
- osx-universal-build failed to compile bundled_extensions_test.cpp: on
  libc++ std::filesystem::file_time_type has an __int128 duration, which
  Catch2 cannot stringify when it decomposes REQUIRE(a == b)
- Compare first, assert the bool; the check itself is unchanged
- docker-build's offline start check ran the /dev/tcp probe through sh,
  which in ubuntu:24.04 is dash and has no /dev/tcp; the probe could never
  connect and the step failed after 30 s although the container was up
  (log: 8/8 extensions loaded offline, cache warmed)
- Reproduced locally: dash reports 'cannot create /dev/tcp/...', bash gets
  {"status":"live"} from the same listener
@jrosskopf
jrosskopf merged commit 23d7f51 into main Oct 31, 2026
23 checks passed
@jrosskopf jrosskopf mentioned this pull request Oct 31, 2026
2 of 3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment