Skip to content

feat(muse-proxy): direct mode — minted-key Responses path (#2753) - #2759

Merged
dezren39 merged 1 commit into
mainfrom
muse-proxy-direct-mode
Oct 30, 2026
Merged

dezren39 merged 1 commit into
mainfrom
muse-proxy-direct-mode

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Closes #2753

What

Direct mode for bin/muse-proxy.mjs: a third, first-tried path in front of the warm muse serve (#480) and muse exec paths, which pay ~26k tokens of CLI harness scaffolding per call.

  • Exchange: reads providers.meta.access_token (the dca:… account OAuth token) from $MUSE_AUTH_PATH || ~/.config/muse/auth.json and POSTs it to {MUSE_PROXY_META_API_BASE || https://api.meta.ai}/muse-code/key (x-api-version: 1.0.0, {"onboard": false}) for the minted plan inference key. Key cached in memory 10 min; on upstream 401 the cache is invalidated, the key re-exchanged once, and the request retried once. Store with only providers.meta.api_key → that key is used without exchanging. Key material is never logged. is_subs_active === false / require_payment === true → hard 502 naming the subscription state, no CLI fallback.
  • Chat → Responses translation: attestation is per-route (verified live 2026-10-30: /v1/chat/completions with the minted key → 403 client_attestation_denied regardless of headers; /v1/responses → 200 with bare Authorization only, no impersonating headers). System → instructions; user/assistant/tool/function messages → Responses input items (function_call / function_call_output); OpenAI tools/tool_choice → Responses shapes; max_tokens/max_completion_tokens → max_output_tokens; reasoning effort mapped (none → omitted, max/ultra → xhigh, the Responses ceiling); store: false.
  • Responses → chat translation, non-stream and SSE: output_text → content, function_call → tool_calls, finish_reason incl. length on max_output_tokens incompletion, usage mapped incl. prompt_tokens_details.cached_tokens. Stream errors are SSE-framed + [DONE] (the muse-proxy: streaming execution failure is sent as unframed JSON on a 200 SSE response — clients see an empty successful stream #670 pattern).
  • POST /v1/responses passthrough: client body forwarded byte-for-byte with only Authorization swapped to the minted key.
  • Fallback discipline: ANY upstream HTTP response (402/429/403/…) is returned as-is — never a second burn through the CLI door. Warm/exec take over only when direct never got an upstream response (no credential, exchange transport failure, upstream fetch throws). MUSE_PROXY_DIRECT=0 disables direct mode.
  • /health gains a direct section (enabled, credentialFound, mintedKeyCached, subsTier, subsActive — booleans/strings only).

Capability only: no proxy service or OpenCode provider is re-enabled (the muse provider stays disabled per Drew, 2026-10-25).

Test harness note

startProxy now also plants the stub muse at $HOME/.local/bin/muse. On NixOS hosts /run/current-system/sw/bin/muse exists and the proxy prefers it over PATH, so the harness silently tested the real CLI (real plan calls, ~10–30 s per test). With the stub planted at the preferred path the suite is hermetic on the laptop: 3.2 s total.

Validation (laptop, node --test bin/muse-proxy.test.mjs)

19/19 pass — 13 pre-existing + 6 new direct-mode tests:

  • exchange shape + minted-key Authorization, one exchange across two chat calls, translation (instructions/input/tools/tool_choice/reasoning clamp/usage incl. cached tokens), /health direct section
  • Responses SSE → chat chunks (text deltas, tool_call head + argument deltas, finish_reason tool_calls, [DONE])
  • upstream 429 passthrough with zero muse exec invocations
  • /v1/responses passthrough byte-for-byte except Authorization
  • MUSE_PROXY_DIRECT=0 and missing-auth.json keep the exec behavior

Live smoke test (laptop, throwaway port 19747, real api.meta.ai, 2 prompts, effort low)

  • non-stream "say ok" → 200, content ok, usage 10 prompt / 209 completion / 219 total tokens, model muse-spark-1.3-low
  • streaming "say ok" → 200, content ok, finish stop, usage 10 prompt / 270 completion / 280 total tokens

Input cost is 10 tokens vs ~26k through the CLI harness. (Completion counts include the model's reasoning tokens at effort low.)


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner October 30, 2026 14:01
@dezren39
dezren39 merged commit 46ce9b9 into main Oct 30, 2026
@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f75325ff-4919-4d7f-9a8a-7df93ddb1f44
Commits

Reviewing files that changed from the base of the PR and between 9ffa739 and ae998c1.

Files selected for processing: 2
  • bin/muse-proxy.mjs
  • bin/muse-proxy.test.mjs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dezren39
dezren39 deleted the muse-proxy-direct-mode branch October 30, 2026 14:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T14:02:49.872509Z ae998c1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

muse-proxy: direct mode — exchange the Muse CLI account token for the minted plan key and forward chat completions verbatim

1 participant