Skip to content

feat: bundle + supervise the FastAPI as a local sidecar (#192) - #207

Merged
CameronBrooks11 merged 5 commits into
mainfrom
feat/local-api-sidecar
Jun 26, 2026
Merged

CameronBrooks11 merged 5 commits into
mainfrom
feat/local-api-sidecar

Conversation

@CameronBrooks11

@CameronBrooks11 CameronBrooks11 commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

Closes #192. The #193 frontend swap (commands.ts → this client, retire hand-maintained types) is the follow-up on top — kept separate so each is reviewable, while preserving the no-regression guarantee: this PR is pure addition (the GUI still uses the Tauri CLI path; the sidecar is spawned but not yet consumed), so merging it changes no behaviour.

What

  • Serve-entry (python -m fiberpath_api): binds an ephemeral 127.0.0.1 port, prints a JSON port handshake on stdout, serves uvicorn pinned to its pure-Python stack (asyncio+h11). Adds GET /health. Declares the fiberpath-api console script.
  • Freeze (scripts/freeze_api.py): standalone fiberpath-api binary, separate from the CLI so the uvicorn freeze surface can't destabilise it.
  • CI: freeze-api job (3 OSes) + scripts/ci/smoke_api_sidecar.py (handshake → /health → /plan); the package job bundles bundled-api/ into the Tauri app.
  • Rust supervisor (api_sidecar.rs + api_path.rs + main.rs): spawn, read handshake, drain pipes, restart-on-death, kill-and-reap on Drop (mirrors marlin.rs); warmed at startup; exposes api_base_url. HTTP readiness is the frontend's job.
  • Frontend plumbing (src/lib/apiClient.ts): api_base_url → /health poll → typed openapi-fetch client.

Verification

  • Local: built+ran the frozen 56 MB binary (handshake → /health → /plan); smoke script passes; tsc/ruff/mypy/cargo-fmt clean.
  • CI (all green): freeze on Windows/macOS/Linux, Rust clippy + cargo test, and Build Installers on all 3 OSes (the app bundles + builds with the sidecar embedded).

Needs a real-app smoke-test (sidecar actually spawns + serves the GUI) once the #193 swap makes the GUI consume it.

Foundation for running the API as a supervised local sidecar (#192):

- python -m fiberpath_api (fiberpath_api/__main__) binds 127.0.0.1 to an
  OS-assigned port, prints a one-line JSON handshake
  ({"event":"listening","host","port"}) to stdout so the supervising shell
  can discover the base URL, then serves uvicorn on the pre-bound socket.
- Add GET /health -> {"status":"ok"} as the readiness probe.
- Declare the fiberpath-api console script (also the freeze entry point).
- Regenerate openapi.json + the TS client to include /health (drift gate).

Verified end-to-end locally: handshake reports the port, GET /health and
POST /plan both respond through the spawned sidecar.

Part of #192.
- scripts/freeze_api.py freezes fiberpath_api.__main__ into a standalone
  `fiberpath-api` binary (mirrors freeze_cli.py; kept separate so the
  uvicorn/FastAPI freeze surface can't destabilise the CLI binary).
- Pin uvicorn to its pure-Python stack (asyncio + h11, no websockets,
  lifespan off) in the serve-entry, so the freeze has no native-extension
  auto-imports to chase.

Verified locally: the frozen 56 MB binary prints the port handshake,
serves GET /health, and answers POST /plan end-to-end.

Part of #192.
- CI: freeze-api job builds the fiberpath-api binary on each OS, smoke-tests
  it (scripts/ci/smoke_api_sidecar.py: handshake -> /health -> /plan), and
  the package job bundles it into the Tauri app (tauri.conf resources +
  bundled-api/).
- Rust: api_sidecar.rs supervises the sidecar (spawn, read the port
  handshake, drain pipes, restart-on-death, kill-and-reap on Drop) mirroring
  marlin.rs; api_path.rs resolves the bundled/system binary mirroring
  cli_path.rs. main.rs warms it in the background at startup and exposes the
  base URL via the api_base_url command. HTTP readiness is the frontend's job.

Part of #192. Rust compiles/tests in CI (cargo); the freeze + smoke test are
verified locally.
src/lib/apiClient.ts: getApiClient() invokes the api_base_url command to
learn the sidecar URL, polls GET /health until ready, then builds the typed
openapi-fetch client. Memoised; a failed start resets the memo to retry.

Part of #193 (the compute-command swap onto this client follows).
- Add fiberpath_gui/bundled-api/.gitkeep so the tauri-build `../bundled-api/*`
  resource glob matches (mirrors bundled-cli); an empty glob fails the build
  script in the GUI build job, which doesn't populate the dir.
- Use ASCII in the sidecar smoke test's final print; the U+2713 check mark
  crashed on Windows' cp1252 stdout (UnicodeEncodeError) after the test had
  otherwise passed.
@CameronBrooks11 CameronBrooks11 changed the title feat: local API sidecar — bundle, supervise, and consume (#192 + #193) feat: bundle + supervise the FastAPI as a local sidecar (#192) Jun 26, 2026
@CameronBrooks11
CameronBrooks11 marked this pull request as ready for review June 26, 2026 05:22
@CameronBrooks11
CameronBrooks11 merged commit 0132d78 into main Jun 26, 2026
21 checks passed
@CameronBrooks11
CameronBrooks11 deleted the feat/local-api-sidecar branch June 26, 2026 05:23
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.

build(gui): bundle + supervise the FastAPI as a hardened local sidecar (transport; part A)

1 participant