fix(opencode): reuse host OAuth transport - #46
Conversation
Signed-off-by: MemScribe Maintainers <OLDyade@users.noreply.github.com>
FenjuFu
left a comment
There was a problem hiding this comment.
Read through it — the core goal (reuse OpenCode's host-owned OAuth transport without ever reading or copying the token) is achieved cleanly, and I like that the @earendil-works/pi-ai@0.82.1 dep is untouched and everything is adapted on the MemFlywheel side. CI is fully green including e2e-k8s. Approving.
One thing I want to flag on withProviderFetch, not a blocker but worth confirming:
globalThis.fetch = fetchImpl;
try { return run(); } finally { /* restore */ }This swaps the global fetch for the synchronous duration of run(). It's correct only under the assumption stated in the comment — that the provider SDK captures fetch while streamSimple synchronously constructs its client. If streamSimple ever deferred the fetch grab to a later microtask, the finally would restore the original before the real network work, and the host transport would be silently bypassed. Two asks:
- Is that synchronous-capture assumption pinned by the
@earendil-works/pi-ai@0.82.1version, i.e. would a future SDK bump silently break it? A comment noting the version dependency would help the next person. - Because it's a global swap, two extraction/dream loops running concurrently could observe each other's
fetchduring that window. MemFlywheel serializes writes under a lock, so this is probably unreachable today — but if background loops can ever overlap, this is a latent cross-talk. Worth a one-line note on the invariant it relies on.
Neither blocks merge; they're about making the invariant explicit so it doesn't rot on a future dependency bump.
Summary
@earendil-works/pi-ai@0.82.1dependency unchanged and adapt the transport entirely inside the OpenCode integrationValidation
pnpm run test— 260 tests passedpnpm run format:checkgit diff --checkopenai/gpt-5.5and registrypi-ai@0.82.1:readon the memory body and recalled the exact valueDependency boundary
This PR does not require a pi-ai fork, upstream PR, or unpublished dependency. The fix is fully contained in MemFlywheel.