Skip to content

fix(local): harden turbo-fieldfare HTTP adapter, /v1/systemone parity, and CI coverage (#106 follow-up) #112

In review

Description

@jigyasujuneja

Follow-up hardening items spotted in scripts/turbo_fieldfare_server.py and the companion shell scripts after #106 (fc3ecfc) and #107 (a028ab0) merged (tracking alongside #108). Worth landing before switching turbo-fieldfare to the default local engine in #110.

Line numbers below are on main at a028ab0.

Wire contract and parity

  • /v1/systemone accepts a custom {"schema", "state"} payload and returns raw decide() output (scripts/turbo_fieldfare_server.py:567-584). deploy/cloudrun/server/structured_server.py:1834-1880 expects {"state", "questions"} parsed via jev_schema and jev_state, and returns jev_answer shapes. Direct callers using the documented /v1/systemone contract get HTTP 422. Port jev_schema, jev_state, check_media_keys, and jev_answer (refusing images with 400), or drop the route until it matches.
  • /v1/systemone silently ignores images, audio, and video keys instead of calling ss.check_media_keys and rejecting non-empty images with HTTP 400.
  • steps > 1 is silently dropped in _run_probe_read (scripts/turbo_fieldfare_server.py:294-313), while diagnostics.steps still echoes the requested step count. Reject steps > 1 with 4xx (like think > 0) until multi-step readout exists.
  • json.dumps(state_content) at scripts/turbo_fieldfare_server.py:366 omits ensure_ascii=False, escaping non-Latin text to \uXXXX (regressing structured_server.py:1573-1574).
  • Chat route parity gaps (scripts/turbo_fieldfare_server.py:396-430): ignores the developer role (structured_server.py:1886), treats text-only content part lists as multimodal, accepts arbitrary message counts, and returns {"error": "<str>"} instead of {"error": {"message", "type"}}.

HTTP/1.1 hardening and input validation

  • Handler sets protocol_version = "HTTP/1.1" with no timeout (scripts/turbo_fieldfare_server.py:436-437). This reintroduces issue perf(decisionindex,gateway): parallelize independent multi-pass /v1/systemone batches and Round-1 brackets #96, where idle or half-open sockets pin handler threads indefinitely (structured_server.py:1659-1662 sets HTTP_IDLE_TIMEOUT, default 120 s).
  • do_POST returns 401 on auth failure (scripts/turbo_fieldfare_server.py:503-505) and 400 on invalid Content-Length (:507-511) without draining the body or setting self.close_connection = True. On a keep-alive socket, the unread body gets parsed as the next request. Port _discard_body() from structured_server.py:1719-1741.
  • rfile.read(length) (scripts/turbo_fieldfare_server.py:512) has no maximum body size, and a negative Content-Length silently reads b"{}" instead of returning 400.
  • Requests queue without bound on self._decide_lock (no MAX_INFLIGHT / 503 overloaded cap like structured_server.py:1810-1813). Any Content-Type is parsed as JSON (allowing no-preflight text/plain cross-origin POSTs to 127.0.0.1:8080), and binding a non-loopback --addr (0.0.0.0) does not require DGEM_SERVER_KEY.
  • seed = int(req_body.get("seed") or 42) (scripts/turbo_fieldfare_server.py:429, 571) coerces seed=0 to 42. Line 571 sits outside try:, so a non-integer seed on /v1/systemone drops the connection with an unhandled exception, and a non-scalar seed on /v1/chat/completions raises TypeError (HTTP 500 instead of 400).
  • parse_addr (scripts/turbo_fieldfare_server.py:591-595) uses rpartition(":"), leaving brackets on "[::1]:8080" and breaking IPv6 loopback binds.

Probe lifecycle and shell scripts

  • read_canvas (scripts/turbo_fieldfare_server.py:187-223) holds self._lock during a blocking stdout.readline() with no timeout (one hung read wedges the server and deadlocks close()), never checks response id, never pre-checks len(prompt_tokens) + len(canvas_tokens) <= max_context (returning 500 instead of 422/400), raises KeyError (HTTP 500) on {"error": ...} probe replies, and leaves _ready = False permanently on crash with no auto-restart.
  • Startup readiness checks "ready" in line.lower() (scripts/turbo_fieldfare_server.py:172), which matches "already" or "not ready". Match an exact sentinel line instead.
  • _boot_worker (scripts/turbo_fieldfare_server.py:679-691) logs fatal probe startup errors and exits the background thread while leaving httpd.serve_forever() alive serving 503. As a result, scripts/serve_turbo_fieldfare.sh:118-139 waits 60 s and exits 0, so make local-up continues against a dead engine.
  • scripts/stop_turbo_fieldfare.sh:20-41 signals the PID file without checking the command line and runs pkill -f "TurboFieldfareDiffusionProbe", which can also kill swift build or open editors.
  • scripts/setup_turbo_fieldfare.sh:47-60 builds ../turbo-fieldfare-dgem with no public fork URL or pinned commit, and scripts/download_turbo_fieldfare.sh:36 passes the .gturbo path positionally to --verify-install (upstream drumih/turbo-fieldfare expects --verify-install --input-gturbo <path>). Both download_turbo_fieldfare.sh and serve_turbo_fieldfare.sh also ignore $TURBO_FIELDFARE_SRC.

Telemetry and #107 follow-ups

  • self._tls.timing_acc (scripts/turbo_fieldfare_server.py:282, 324-328) drops prefill_ms, denoise_ms, and head_ms to 0.0 whenever samples > 1 or isolated question groups run on worker threads (also flagged on feat(local): propagate TurboFieldfareDiffusionProbe reusedTokens into diagnostics.timing.reused_tokens #111).
  • scripts/test_turbo_fieldfare_server.py is not run in .github/workflows/build.yml:84-105, uses Any without importing from typing import Any (lines 79, 96, 105, 356), and load_structured_server() writes pybase64 and transformers stubs into process-wide sys.modules (scripts/turbo_fieldfare_server.py:58-65).
  • cmd/mcp.go:1063-1065 overwrites an explicit --model flag with the first entry from local /v1/models.
  • ss.DEFAULT_SEED_TOKEN = "fixed" (scripts/turbo_fieldfare_server.py:289, added in fix(local): set CANVAS_STEP=64 and DEFAULT_SEED_TOKEN=fixed in turbo_fieldfare_server #107) overrides an operator's DEFAULT_SEED_TOKEN=random env var (structured_server.py:171), and samples=4 templates (such as templates/support_triage.json.tmpl:27) run 4 identical slow reads locally under "fixed". Also worth asserting in scripts/test_turbo_fieldfare_server.py:410-427 that "random" produces non-PAD canvas tokens.
  • pkg/client/turbo_fieldfare_test.go and cmd/backend_local_test.go test against hand-written mocks; adding one contract test fed from turbo_fieldfare_server.py output would catch response drift.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions