Conversation
|
The two-part root-cause analysis here is convincing — the stale ecto1 token plus the nested-proto overwrite bug at Before this can merge, though: the two test files you touched both explicitly disable the new |
…nvelope when patching (diegosouzapw#10727) Two things were making this provider hang after 4 WS messages: 1. The ecto1 token goes stale fast. meta.ai embeds a fresh token in the page HTML on every load, and the gateway only accepts a recent one. A token pasted from DevTools is usually already dead by the time the WS connects, so the gateway answers with a 0x0e frame and goes quiet. Plain HTTP cannot read the page either -- meta.ai serves a JS challenge that 403s non-browser clients. 2. The proto patch broke the payload. Field [1,1,5] is a double-wrapped nested proto (field 5 -> field 5 -> field 1 -> UUID). The old code replaced the whole value with a bare UUID string, dropping the envelopes. Gateway sees a structurally invalid payload and rejects again. Changes: - fetchFreshAccessToken(): Heisenberg GraphQL to refresh ecto_1_sess, then the existing browserPool to load meta.ai headless, wait out the JS challenge (networkidle), and grab the token. Cached per cookie hash for 4 min. Falls back to the user-provided static token. - buildWsPromptFrame(): convId patch now traverses [1,1,5,5,1] and swaps only the innermost UUID, keeping both envelopes. - Fresh templates (mode_thinking, flags, varint 26). - Unit coverage for the proto byte transform and the token fetcher cache/fallback with mocked browserPool seams.
ab7474d to
c72baa9
Compare
|
Wrote the synthetic proto test you asked for, and it caught a second bug in the patch. c72baa9 walks Re-ran live with the fix: 81 messages, streamed reply, frame 4 is 0x0d (accepted) instead of 0x0e. Full output in the PR body. |
…iegosouzapw#12914) Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
|
After applying this, I found it works, but ran into an issue with the websocket not getting closed and had to apply this |
|
WS cleanup is handler-layer — out of scope for this fix. Feel free to open a separate PR based off this branch if you want it tracked. |
Two things were making this provider hang after 4 WS messages:
The ecto1 token goes stale fast. meta.ai embeds a fresh
ecto1:...token in the page HTML on every load, and the gateway only accepts a recent one. A token pasted from DevTools is usually already dead by the time the WS connects, so the gateway answers with a 0x0e frame and goes quiet. Plain HTTP can't read the page either — meta.ai serves a JS challenge that 403s non-browser clients, which is why we couldn't just fetch it server-side.The proto patch broke the payload. Field
[1,1,5]is itself a nested proto (field 5→field 5→field 1→ UUID). The old code replaced the whole value with a bare UUID string, dropping the envelopes. Gateway sees a structurally invalid payload and rejects again. This only surfaced once [WIP] Add FastAPI OpenAI-compatible LLM gateway with routing #1 was fixed: fresh token, still 0x0e. Diffing patched against the raw template is what localized it.What changed:
fetchFreshAccessToken()— Heisenberg GraphQL call to pick up a rotatedecto_1_sesswhen the server sends one, then the existingbrowserPoolto load meta.ai headless, wait out the JS challenge (networkidle), and grab the token from the page. Cached per cookie hash for 4 min (tokens last ~5 min) so we don't launch a browser on every request. Falls back to the static token the user provided.buildWsPromptFrame()— convId patch now traverses[1,1,5,5,1]and swaps just the innermost UUID, keeping both envelopes.mode_thinking, flags, varint 26) — the old ones also carried a stale UA.Test coverage
tests/unit/muse-spark-ws-proto-patch-10727.test.ts(new) — 5 tests:[1,1,5]envelope still wraps{5:{1:uuid}}(40 bytes, not a collapsed 36-byte bare string), byte-length identity when round-tripping the template's own values, and that prompt/requestId patches leave sibling markers (KADABRA,mode_thinking) intact. Confirmed failing against the pre-fix patch code (3 of the 5), green with the fix.accessTokenfrom the page, serves the second call from the 4-min cache without re-acquiring a context, and returns a sanitized failure when the page has no token.tests/unit/muse-spark-ws-timeout-diagnostics-10727.test.ts— updated; the browser path is mocked so the readyState diagnostics keep running hermetically.Live-session validation (WS handshake can't run in CI)
The WS flow can't be exercised in CI (it needs a real authenticated session), so it was verified against live meta.ai with a local harness — a standalone replay of the executor's frame builder, not a repo script. It takes the
ecto_1_sesscookie asMETA_COOKIE; the auth token is extracted from the loaded page, the same wayfetchFreshAccessTokendoes it.Under the same credentials, with a fresh token, only the patching differing:
[1,1]write, pre-fix) →MSG #4: 3b 0e0000, then silence[1,1,5,5,1]→0x0d, streamed to completionA stale token produces the same
0x0eat msg #4 regardless of patching — which is why the two bugs had to be fixed in this order to see either one clearly.Closes #10727