Skip to content

feat: support Linux ARM64 auto-detection, default to BELUGA, and sanitize Swagger UI dummy inputs - #22

Closed
iceblue03 wants to merge 1 commit into
kodelyx:mainfrom
iceblue03:feat/arm64-arch-detect-and-robustness
Closed

iceblue03 wants to merge 1 commit into
kodelyx:mainfrom
iceblue03:feat/arm64-arch-detect-and-robustness

Conversation

@iceblue03

Copy link
Copy Markdown

Summary

This Draft PR enables FlowEngine to automatically detect host CPU architecture (aarch64 / arm64) to pick ARM64 binaries, switches the default image model to BELUGA, and adds input sanitization for dummy values generated by Swagger UI (such as "cookies": "string" and "model": "string").


Motivation & Problem Statement

  1. Architecture-Blind Binary Search:
    In engine.py, _find_binary previously only inspected platform.system() and unconditionally searched for flow-linux regardless of whether the system was running x86_64 or ARM64. On ARM64 Linux systems (e.g. Raspberry Pi, AWS Graviton), executing the bundled x86_64 flow-linux failed with Exec format error.
  2. Crash on Swagger UI Default Values:
    When testing /v1/generate/image via the FastAPI Swagger UI (/docs), Swagger pre-populates optional string fields with the placeholder "string". Passing "cookies": "string" caused the underlying Go binary to fail with open string: no such file or directory and returned an unhandled 502 error to the user.
  3. Align Default Image Model with Upstream:
    Upstream Flow backend currently accepts BELUGA consistently, whereas legacy narwhal requests frequently yield empty frames.

Detailed Changes

  • flow_agent/engine.py:
    • _find_binary: Reads platform.machine(). If on Linux ARM64 (aarch64, arm64), it prioritizes flow-linux-arm64 and flow-arm64 before falling back to flow-linux.
    • Added _is_valid_cookie_arg() helper to strip dummy values ("string", "null", empty string) before appending the --cookies CLI argument.
    • generate_image: Updated default model to beluga and auto-sanitizes legacy/placeholder values to beluga.
  • flow_agent/api.py:
    • FlowImageRequest & ImageGenerationRequest:
      • Updated default model field to "beluga".
      • Added @field_validator("model", mode="before") to sanitize placeholders or unsupported models to "beluga".
      • Added @field_validator("cookies", mode="before") to transform Swagger placeholders into None.

AI Disclosure

Transparency Statement:
This contribution was developed and verified through pair-programming between the author and Antigravity (Google DeepMind agentic AI coding assistant).
All bug reproductions, schema validators, and architecture dispatch routines were actively executed and validated against live FastAPI and native ARM64 engine invocations.


Hardware & Verification Details

Test Environment

  • Device: Raspberry Pi (aarch64)
  • OS: Debian GNU/Linux 13 (trixie) / Raspberry Pi OS v8
  • Kernel: Linux 6.18.50+rpt-rpi-v8 #1 SMP PREEMPT aarch64 GNU/Linux
  • Python: Python 3.13.5

Verification Results

  1. Architecture Dispatch Test:
    • On aarch64, verified that FlowEngine._find_binary correctly resolves flow-linux-arm64 when present, or native ARM64 flow-linux.
  2. Swagger Dummy Payload Test:
    • Sent POST /v1/generate/image with payload:
      {
        "prompt": "beach",
        "aspect": "1:1",
        "count": 1,
        "model": "narwhal",
        "all_accounts": false,
        "cookies": "string"
      }
    • Before: HTTP 502 (open string: no such file or directory / empty frame).
    • After: HTTP 200 OK (status: succeeded, rendered high-resolution image in 37.1s).

…tize Swagger UI dummy inputs

- engine: inspect platform.machine() to prioritize ARM64 binaries on Linux ARM64
- engine: filter out dummy cookie values (e.g. 'string', 'null') before passing CLI args
- engine/api: update default image model to BELUGA and add sanitization fallback
- api: sanitize Swagger UI default placeholder ('string') in request models to None
@iceblue03
iceblue03 marked this pull request as ready for review October 17, 2026 16:32
Copilot AI balanced review requested due to automatic review settings October 17, 2026 16:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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