Skip to content

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

Merged
ghchinoy merged 1 commit into
mainfrom
fix/harden-turbo-fieldfare-112
Dec 2, 2026
Merged

ghchinoy merged 1 commit into
mainfrom
fix/harden-turbo-fieldfare-112

Conversation

@jigyasujuneja

Copy link
Copy Markdown
Collaborator

Refs #112 (tracks alongside #108; follow-up hardening to #106 and #107).

Summary

Wire contract and parity (scripts/turbo_fieldfare_server.py)

  • Updated POST /v1/systemone (and /systemone) to match deploy/cloudrun/server/structured_server.py: parses canonical {"state", "questions"} bodies with jev_schema and jev_state, enforces check_media_keys, rejects non-empty images with HTTP 400, returns jev_answer shapes plus model, usage, and diagnostics, and attaches _timing_headers(body).
  • Updated POST /v1/chat/completions to require exactly two messages (system or developer followed by user), accept text-only content part lists via message_text while rejecting image/audio/video parts with HTTP 400, and return structured {"error": {"message", "type"}} JSON across all error paths.
  • Rejected steps > 1 with HTTP 422 on /v1/systemone and HTTP 400 on /v1/chat/completions (matching think > 0), and added ensure_ascii=False when serializing dict states so non-Latin text is not \uXXXX-escaped.

HTTP/1.1 hardening and input validation (scripts/turbo_fieldfare_server.py)

  • Set Handler.timeout from HTTP_IDLE_TIMEOUT (default 120 s, 0 disables) to match structured_server.py (issue perf(decisionindex,gateway): parallelize independent multi-pass /v1/systemone batches and Round-1 brackets #96).
  • Added _discard_body() on 401 and 415 refusals, and closed connections (Connection: close) on Transfer-Encoding, invalid or negative Content-Length (400), oversized bodies (413, default 16 MiB), or truncated reads so keep-alive connections stay synchronized.
  • Required Content-Type: application/json on POST routes carrying JSON (empty POST /ready still works without it).
  • Added bounded concurrency via MAX_INFLIGHT / INFLIGHT_WAIT_S returning HTTP 503 (overloaded).
  • Refused non-loopback --addr binds unless DGEM_SERVER_KEY is set, and fixed parse_addr + server socket family for bracketed IPv6 addresses ([::1]:8080).
  • Added parse_seed() inside the request try block to preserve seed=0 and reject booleans, non-integers, and non-scalars with HTTP 400/422.

Probe lifecycle, timing, and #107 follow-ups

  • Added start_timeout_s and read_timeout_s deadlines using reader threads and queues so a hung probe never blocks close(). Verified response id, mapped probe {"error": ...} payloads and max_context overflows to HTTP 4xx, invalidated on malformed JSON, and added backoff-guarded auto-restart.
  • Replaced "ready" in line.lower() with word-boundary checks rejecting "already", "not ready", and "unready".
  • Shut down httpd with exit code 1 when initial worker.start() fails in main().
  • Replaced self._tls.timing_acc with a lock-guarded instance accumulator so prefill_ms, denoise_ms, and head_ms accumulate across read_many() (samples > 1) and ThreadPoolExecutor (isolate: "all" / "auto"), and guarded JSON null timing values with or 0.0.
  • Restored sys.modules in load_structured_server() so pybase64 / transformers stubs do not leak across combined unittest runs.
  • Honored an explicit DEFAULT_SEED_TOKEN environment variable (still defaulting to "fixed" when unset, validated against SEED_TOKENS).

Shell scripts, Go status, and CI

  • scripts/serve_turbo_fieldfare.sh: honored TURBO_FIELDFARE_SRC for probe and model fallback paths, and exited 1 when /ready times out after 60 s instead of exiting 0.
  • scripts/download_turbo_fieldfare.sh: honored TURBO_FIELDFARE_SRC for TurboFieldfareRepack discovery and printed a clearer NOT VERIFIED warning when the verifier is absent.
  • scripts/stop_turbo_fieldfare.sh: validated numeric PID and verified ps -o command= contains turbo_fieldfare_server.py before signaling, and narrowed pkill -f patterns so they do not match swift build, open editors, or wrapper shells.
  • cmd/mcp.go: preserved an explicitly configured --model flag or non-default model value instead of overwriting it from local /v1/models.
  • .github/workflows/build.yml: added python -m unittest -v scripts/test_turbo_fieldfare_server.py and bash -n scripts/*turbo_fieldfare*.sh to test-matrix.
  • pkg/client/turbo_fieldfare_test.go and cmd/backend_local_test.go: updated the mock error shape and comment, added TestLocalBackendStatusPreservesExplicitModel, and added TestTurboFieldfarePythonAdapterContract exercising client.Decide against scripts/turbo_fieldfare_server.py (python3 >= 3.10).

Still open on #112 (not changed here)

  • Pinning the turbo-fieldfare-dgem fork URL and commit in scripts/setup_turbo_fieldfare.sh (pending publication of the fork).
  • Updating scripts/download_turbo_fieldfare.sh:36 --verify-install syntax to --verify-install --input-gturbo <path> (left untouched until confirmed against the fork so existing fork builds do not break).

Note on open PR #111

Verification

  • python3 -m py_compile scripts/turbo_fieldfare_server.py scripts/test_turbo_fieldfare_server.py
  • python3 -m unittest -v scripts/test_turbo_fieldfare_server.py (20/20 OK, 0 resource warnings)
  • python3 -m unittest scripts/test_turbo_fieldfare_server.py deploy/cloudrun/server/test_server_key.py deploy/cloudrun/server/test_media_fields.py (31/31 OK)
  • bash -n scripts/*turbo_fieldfare*.sh
  • Isolated /tmp checks verifying download_turbo_fieldfare.sh NOT VERIFIED warning + TURBO_FIELDFARE_SRC discovery, and stop_turbo_fieldfare.sh skipping unrelated PIDs
  • env -u DGEM_VERTEX_URL go vet ./...
  • env -u DGEM_VERTEX_URL go test -race ./pkg/client/... ./cmd/... (includes TestTurboFieldfarePythonAdapterContract and TestLocalBackendStatusPreservesExplicitModel)

@ghchinoy
ghchinoy merged commit 608a306 into main Dec 2, 2026
17 checks passed
@ghchinoy
ghchinoy deleted the fix/harden-turbo-fieldfare-112 branch December 2, 2026 15:49
ghchinoy added a commit to ghchinoy/dgem-official-fork that referenced this pull request Dec 2, 2026
… diagnostics.timing.reused_tokens

Addresses GoogleCloudPlatform#108 (rebased cleanly onto GoogleCloudPlatform#113):
- Accumulates readout.get('reusedTokens') or 0 into the lock-guarded
  self._timing_acc dict in scripts/turbo_fieldfare_server.py so prefix KV
  cache telemetry accumulates accurately across isolate:all and samples>1
  worker threads and tolerates JSON null values.
- Adds test_reused_tokens_accumulates_across_isolated_and_multi_sample_reads
  in scripts/test_turbo_fieldfare_server.py.
ghchinoy added a commit to ghchinoy/dgem-official-fork that referenced this pull request Dec 2, 2026
…rk link, --verify-install, NOTICE, RAM tiers, and provenance

Addresses PR GoogleCloudPlatform#109 review items (rebased cleanly onto merged GoogleCloudPlatform#113):
- Link public ghchinoy/turbo-fieldfare (feat/diffusiongemma-probe) fork,
  build TurboFieldfareRepack in launch steps, and fix --verify-install
  syntax to '--verify-install --input-gturbo <path>' in both docs and
  scripts/download_turbo_fieldfare.sh.
- Add mlx/mlx-lm and ~50 GB temp BF16 download space to prerequisites.
- Clearly state turbo-fieldfare capability boundaries vs diffgemma
  (structured text decisions only; no dgem ask plain chat, think>0,
  steps>1, or images; 4,096 default context; fixed seed_token default).
- Update NOTICE with MIT license for mmastrac/diffgemma, upstream vLLM
  copyright line, scope notes, neutral wording (no default/optional drift),
  and bundle NOTICE in .github/workflows/release.yml archives.
- Align Tier B minimum RAM to 24 GB (>= 22 GiB auto-select), align script
  warnings with combined probe+adapter footprints, state Apple M5 32 GB
  macOS 26.7.3 provenance (marking 8 GB row projected), clarify -u vs
  DGEM_LOCAL_URL, and title Section 3 Prerequisites (diffgemma).
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.

2 participants