Repository navigation
feat: bundle + supervise the FastAPI as a local sidecar (#192) - #207
Merged
Merged
Conversation
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
marked this pull request as ready for review
June 26, 2026 05:22
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.
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
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). AddsGET /health. Declares thefiberpath-apiconsole script.scripts/freeze_api.py): standalonefiberpath-apibinary, separate from the CLI so the uvicorn freeze surface can't destabilise it.freeze-apijob (3 OSes) +scripts/ci/smoke_api_sidecar.py(handshake →/health→/plan); thepackagejob bundlesbundled-api/into the Tauri app.api_sidecar.rs+api_path.rs+main.rs): spawn, read handshake, drain pipes, restart-on-death, kill-and-reap on Drop (mirrorsmarlin.rs); warmed at startup; exposesapi_base_url. HTTP readiness is the frontend's job.src/lib/apiClient.ts):api_base_url→/healthpoll → typedopenapi-fetchclient.Verification
/health→/plan); smoke script passes; tsc/ruff/mypy/cargo-fmt clean.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.