mstar.api_server.rust_frontend#

The Rust axum frontend in front of APIServer.

mstar-server (rust/server/) owns the HTTP surface — routes, OpenAI translation, SSE/NDJSON streaming, uploads, CORS — and speaks a flattened msgpack protocol over the Rust ZMQ transport to this bridge, which drives the existing Python data plane (APIServer.submit_request / iter_result_chunks / abort_submission; preprocessing and the conductor protocol are untouched):

frontend -> bridge: {t:”submit”, rid, sub, text, file_paths,

input_modalities, output_modalities, model_kwargs, prompt_parts, streaming} | {t:”abort”, rid, sub}

{t:”ping”, rid, sub}
{t:”metrics”, rid, sub, refusals:{route, status, count}}
bridge -> frontend: {t:”chunk”, rid, sub, modality, data(bin), metadata}
{t:”err”, rid, sub, msg} | {t:”done”, rid, sub}
{t:”pong”, rid, sub}
{t:”metrics”, rid, sub, data(bin), metadata}

A metrics request carries the frontend’s cumulative refusal counts as three parallel lists (route template, status, count), which the API server exports as mstar_http_refusals_total. The reply is what GET /metrics serves on the Python frontend: the text rendered from APIServer.metrics with its content_type in metadata, or empty metadata when metrics are off (a 404; the counts are then ignored).

sub names one submission and is never reused. A client may resubmit its rid as soon as it drops a stream, and that stream’s done or late chunks can cross the retry, so everything about a submission is addressed by sub. The frontend refuses a rid still in flight with a 409 itself and sends a dropped stream’s abort before it frees the rid, so the abort arrives here before the retry’s submit.

The submit shape is APIServer.submit_request’s signature verbatim — the protocol was designed by flattening it. prompt_parts travels for a chat only, one map of PromptPart’s fields per part. The bridge mesh lives in its own socket dir (private to the frontend/bridge pair), so entity names never collide with the conductor/worker mesh.

Opt-in: mstar-serve --rust-frontend replaces uvicorn.run with the mstar-server binary + this loop. Everything else in the process (preprocess worker, conductor spawn, tensor transport) is identical. The frontend enforces the API key (--api-key / MSTAR_API_KEY) itself; the bridge socket is private to the pair.

Module Attributes

BRIDGE_RECV_WAIT_S

Upper bound on one blocking receive, so stop() is noticed promptly and the loop stays responsive to shutdown.

OPENAI_ADAPTER_ENV

The model's adapter class in ADAPTER_REGISTRY; mstar-server picks its OpenAI translation by it (Adapter::from_python).

Functions

find_server_binary([explicit])

Resolve the mstar-server binary: explicit arg, MSTAR_SERVER_BIN, $PATH, then the in-repo release build.

launch_rust_server(binary, model_name, port, ...)

openai_adapter_class(model_name)

The class name of model_name's OpenAI adapter, "" when it has none.

Classes

RustFrontendBridge(server, bridge_dir)

The serve loop between the Rust frontend and APIServer.

mstar.api_server.rust_frontend.BRIDGE_RECV_WAIT_S = 0.05#

Upper bound on one blocking receive, so stop() is noticed promptly and the loop stays responsive to shutdown. Not a latency knob: an arriving message ends the wait immediately.

mstar.api_server.rust_frontend.OPENAI_ADAPTER_ENV = 'MSTAR_OPENAI_ADAPTER'#

The model’s adapter class in ADAPTER_REGISTRY; mstar-server picks its OpenAI translation by it (Adapter::from_python).

class mstar.api_server.rust_frontend.RustFrontendBridge(server, bridge_dir)[source]#

Bases: object

The serve loop between the Rust frontend and APIServer.

Parameters:

bridge_dir (str)

run()[source]#

Blocking serve loop (the uvicorn.run replacement).

Return type:

None

stop()[source]#
Return type:

None

mstar.api_server.rust_frontend.find_server_binary(explicit=None)[source]#

Resolve the mstar-server binary: explicit arg, MSTAR_SERVER_BIN, $PATH, then the in-repo release build.

Parameters:

explicit (str | None)

Return type:

str

mstar.api_server.rust_frontend.launch_rust_server(binary, model_name, port, bridge_dir, upload_dir, api_key=None)[source]#
Parameters:
  • binary (str)

  • model_name (str)

  • port (int)

  • bridge_dir (str)

  • upload_dir (str)

  • api_key (str | None)

Return type:

Popen

mstar.api_server.rust_frontend.openai_adapter_class(model_name)[source]#

The class name of model_name’s OpenAI adapter, “” when it has none.

Parameters:

model_name (str)

Return type:

str