Skip to content

fix(mpc): actionable optimizer error when the ftw-optimizer sidecar is unavailable - #700

Merged
frahlg merged 1 commit into
srcfl:masterfrom
HuggeK:fix/optimizer-sidecar-unavailable-message
Jul 30, 2026
Merged

frahlg merged 1 commit into
srcfl:masterfrom
HuggeK:fix/optimizer-sidecar-unavailable-message

Conversation

@HuggeK

@HuggeK HuggeK commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #699.

Problem

On the containerized core (ghcr.io/srcfl/ftw, an alpine image with no
Python
), whenever the auto/process optimizer transport is selected and the
ftw-optimizer sidecar is unavailable, core tries to spawn the bundled
python3 -m ftw_optimizer.worker and fails with:

optimizer transport: start optimizer "python3": exec: "python3": executable file not found in $PATH

That string is surfaced as the optimizer's error / fallback_reason (and in
logs), so an operator sees a "missing Python" error that (a) reads as a missing
core dependency — contradicting the module architecture, where Python lives
only in the optimizer image — and (b) hides the real remedy: start the
ftw-optimizer sidecar. Core still plans safely on the Go DP fallback, so this
is an observability defect, not a safety one.

Note: master now ships docker-compose.yml with FTW_OPTIMIZER_TRANSPORT
defaulting to unix, so the stock container deployment no longer touches
the process worker at all. This fix hardens the auto/process modes that
remain — native / all-in-one builds, and anyone who opts back into auto —
where the bare exec error is still what an operator would see.

Fix

Resolve the worker interpreter with exec.LookPath before fork/exec in
ProcessTransport. When it is absent, return a sentinel
errOptimizerWorkerMissing whose message names the remedy instead of the raw
exec error:

optimizer worker "python3" unavailable: optimizer worker interpreter not found
on PATH; this core build has no bundled Python optimizer — run the
ftw-optimizer sidecar (see docs/self-update.md)
  • The change is at the source of the message, so it propagates unchanged through
    external_optimizer.go → service.go FallbackReason, logs and the
    components API.
  • LookPath accepts an absolute path too, so native/all-in-one deployments that
    set FTW_OPTIMIZER_PYTHON are unaffected — only the missing-interpreter
    message changes.
Why not just install Python into core?

The optimizer is deliberately a separate, independently updatable image
(Dockerfile.optimizer); core stays a slim Go binary so optimizer dependency
churn never enlarges the safety-critical runtime (docs/architecture.md,
Dockerfile:1-3). The bundled python3 process transport only makes sense for
native/all-in-one deployments; on the container it can never run, which is
exactly why the error needed to be actionable rather than literal.

Testing

Rebased onto master; go build ./... and go vet ./internal/mpc/ are clean.

go test ./internal/mpc/ covers the missing-worker path at all three entry
points:

  • TestProcessTransportReportsMissingWorkerActionably — RoundTrip with an
    absent interpreter wraps errOptimizerWorkerMissing and names the
    ftw-optimizer sidecar.
  • TestProcessTransportHealthReportsMissingWorker — the Health path (read by
    /api/components) now asserts the same actionable sentinel instead of the old
    bare start optimizer … string.
  • TestAutoTransportSurfacesMissingWorkerFromProcessFallback — new, per
    review feedback: with the auto transport (down sidecar + process fallback),
    the wrapped errOptimizerWorkerMissing survives the auto layer via
    errors.Is, so service.go's FallbackReason carries the actionable text
    all the way to the operator.
One pre-existing test fails only on a Windows dev box

TestUnixTransportHandshakeAndRoundTrip fails locally with
listen unix /tmp/…: bind: A socket operation encountered a dead network — it
binds an AF_UNIX socket at a /tmp path, which Git-Bash on Windows can't do.
It's unrelated to this change (which only touches ProcessTransport /
AutoTransport) and passes on Linux CI.

Operator note

This makes the failure legible; it does not install the optimizer. To actually
use the CVXPY optimizer, start the sidecar (docker compose up -d ftw-optimizer, or Update Center → Optimizer). Core stays on the Go planner
until it is healthy.

🤖 Generated with Claude Code

@HuggeK
HuggeK marked this pull request as ready for review July 28, 2026 14:34

@miravoss26 miravoss26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the diff. Clean, well-scoped fix: ensureStartedLocked now resolves the worker interpreter with exec.LookPath before fork/exec, so an absent Python worker on the containerized core returns the actionable errOptimizerWorkerMissing ("run the ftw-optimizer sidecar") instead of a bare exec: "python3": not found in $PATH that reads as a missing core dependency. Pure observability change: the Go DP fallback path is untouched, and there's a regression test that pins the wrapped-error behavior.

  • Correctness: same failure outcome, clearer message at the source, so it propagates through FallbackReason + logs + the components API as the description says. LookPath accepting an absolute path keeps the FTW_OPTIMIZER_PYTHON native builds working. errors is already imported on the file, so the new sentinel compiles. Looks right to me.
  • Security: nothing flagged. Stdlib only (no new deps), no secrets, no authz or network surface. The docker-compose diff is comment-only.
  • Landing blocker: GitHub shows this as CONFLICTING with the base, so it needs a rebase before it can merge.
  • No CI checks are attached to this PR that I can see. Worth confirming go build ./... && go test ./internal/mpc/ is green locally before it lands.

Safe to merge from my read once it's rebased and the build's confirmed green. Not in my auto-merge allowlist, so I'm leaving the merge to a human.

@miravoss26 miravoss26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the whole diff. Clean, well-scoped fix: ensureStartedLocked now LookPaths the worker before fork/exec, so the containerized core (ships no Python) returns a wrapped errOptimizerWorkerMissing pointing at the ftw-optimizer sidecar instead of a bare exec: "python3": not found in $PATH. Two things I checked and liked: the lookup sits after the t.cmd != nil guard so it's cold-start only, and FTW_OPTIMIZER_PYTHON native builds keep working since LookPath takes absolute paths too.

Security screen: clean. No secrets, no new deps (stdlib os/exec), no network or authz changes; the command string is operator config, not user input. The %w wrap plus the new regression test cover the errors.Is path.

One optional question, not a blocker: does the auto transport still fall back to the Go DP planner on the new errOptimizerWorkerMissing the way it did on the old bare exec error? The existing fallback tests look like they cover any process-transport error, so likely yes. A one-liner asserting auto-fallback specifically on the missing-worker error would nail the regression shut.

Safe to merge from my read.

…s unavailable

The containerized core ships no Python, so the auto/process optimizer transport can never start the bundled python3 worker there. Instead of surfacing a bare 'exec: "python3": not found in $PATH' — which reads as a missing core dependency and hides the real remedy — ProcessTransport now resolves the interpreter with exec.LookPath before fork/exec and returns an actionable errOptimizerWorkerMissing that points operators at the ftw-optimizer sidecar. The message propagates unchanged to FallbackReason, logs and the components API. Native/all-in-one builds that set FTW_OPTIMIZER_PYTHON are unaffected (LookPath accepts an absolute path). Also corrects the docker-compose.yml comment that claimed core falls back to a bundled Python worker it does not have.

Fixes srcfl#699

Co-authored-by: HuggeK <[email protected]>
@HuggeK
HuggeK force-pushed the fix/optimizer-sidecar-unavailable-message branch from 97afac0 to 7e302d1 Compare July 29, 2026 13:20
@HuggeK

HuggeK commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @miravoss26 — both points addressed:

  • Rebase (landing blocker): rebased onto master (now at 7e302d1). The only conflict was the docker-compose.yml optimizer comment, which master has since superseded — it now defaults FTW_OPTIMIZER_TRANSPORT to unix and rewrote that comment, so I dropped my compose edit and the PR is now Go-only. GitHub shows the PR MERGEABLE.
  • Auto-fallback on the missing-worker error (your optional ask): added TestAutoTransportSurfacesMissingWorkerFromProcessFallback. With a down sidecar (primary) plus a real ProcessTransport fallback that can't find its interpreter, the wrapped errOptimizerWorkerMissing survives the auto layer (autoTransportError.Unwrap → errors.Is stays true) and the error string still names the ftw-optimizer sidecar — i.e. service.go's FallbackReason carries the actionable text end-to-end. I also updated the pre-existing TestProcessTransportHealthReportsMissingWorker (the Health//api/components path) to assert the same sentinel rather than the old bare start optimizer … string, so all three entry points (RoundTrip, Health, auto) are pinned.

go build ./... and go vet ./internal/mpc/ are clean; go test ./internal/mpc/ is green apart from TestUnixTransportHandshakeAndRoundTrip, which only fails on my Windows dev box (it binds an AF_UNIX socket at a /tmp path — a Git-Bash-on-Windows limitation, unrelated to this change, green on Linux CI).

@frahlg
frahlg merged commit cbbabae into srcfl:master Jul 30, 2026
13 checks passed
@HuggeK
HuggeK deleted the fix/optimizer-sidecar-unavailable-message branch August 30, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants