e4e9eb0928becfa4e48484dde85ef5032671d582
6
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
1c59acd36d |
plugin: a fetch whose head never comes is given up on; Devin min 0.1.45 (wu_chong4136 on X)
wu_chong4136 on X: with the Devin plugin a session sometimes hung for
10 to 20 minutes with no reply, until the effort or the context was
changed. The Devin plugin returns its fetch's head only once Devin sends
the reply's first content, and the host's headRead waited for that head
with no bound, while the gateway kept the agent alive on keepalives. A
request Devin took and never answered therefore hung silently. The body
already had bodyIdleWait (30m between bytes, #4934); the head had none.
- host.go headRead: the same bodyIdleWait bounds the wait for the head.
On it the fetch ends with "the plugin sent no reply in 30m0s; that
fetch was given up on", Fetch settles the call, and the host writes
"abort", so the plugin's fetch signal ends its vendor request too. The
gateway answers the agent its retryable 502 (an SSE error event on a
stream). This holds for every plugin fetch, not only Devin's.
- ReplyWaitForTest lets the gateway test shorten the wait.
- Devin mover min 0.1.45 (on npm, `npm view --prefer-online`): the
plugin itself gives up after 5 minutes of quiet from Devin (no head,
or no frame between reads) with a retryable 504. A real probe saw
Devin's first frame at 2.5s and at most 13s between frames.
(magpie-community/plugins e30f8ed0)
- provider-plugins.md says so.
Tests:
- TestHostHeadWaitEndsAFetchNeverAnswered: a head that never comes ends
in "sent no reply", the host is sent "abort", and the call is
released; TestHostHeadWaitSparesAHeadInTime: a head in time is kept.
- TestPluginHeadNeverSentEndsInAnError (gateway, through the fake
plugin in Bun): a vendor that reads the request and never answers
gives the agent the error on a stream and on a whole reply, and every
vendor request the plugin made is closed afterwards (asked 30, open 0).
Run:
- mote: the three tests above, ok.
- Broken by hand (headRead without the timer case): the host test fails
("held its reader for ever") and the gateway test hangs to its 60s
timeout in io.ReadAll.
- mica: gofmt -l clean; go vet for darwin, GOOS=linux and GOOS=windows
on internal/plugin, internal/gateway, internal/provider: ok.
- mica: go test -tags nogui -timeout 45m ./... at this tree (rebased on
|
||
|
|
0bffc1c5db |
fix(plugin): a silent stream's read gives the fetch up after thirty minutes (#4934)
What changed: a reply body's Read now ends bodyIdleWait (five minutes) after the last byte the plugin sent, gives the fetch up and says so, when nothing more comes. The wait is between bytes, not the reply's whole length: every chunk resets it, so a stream a slow model keeps fed goes on however long it talks. Why: a network drop mid-stream can leave a local proxy's socket open but soundless, and a plugin body's read ended only on a chunk, an answer, a close, a cancelled ctx or the host's death — none ever came, so the request hung until the client cancelled it, with no error frame and no retry (#4934). The gateway's relay already ends a stream whose read fails with a protocol-valid error event; what the plugin leg lacked was any read that fails. Five minutes is the silence the gateway itself holds a client through (keepaliveLongest) before leaving a stuck stream to a timeout; this is that timeout for a plugin's reply. The wait for the reply's head is another wait and stays as it was — this issue is a stream already past its first token. Run: the new TestHostBodyIdleEndsASilentStream failed before the fix (a read held for ever) and passes after; TestHostBodyIdleSparesAFedStream locks the between-bytes reading. go test ./internal/plugin/ ./internal/gateway/ ./internal/provider/ -tags nogui, the host tests under -race, gofmt, go vet and go build all pass, with pre-existing failures on this machine only (TestHostToldTheGatewayAddress, also red on a clean upstream/main; TestCodexPoolSaysTheClientsVersion, the known flake, green on a rerun). Review, changed from ggbdpq's patch: the wait is thirty minutes, not five. Five minutes cut replies that are silent for their whole generation and come in one burst at the end (a model at its highest effort, a relay that buffers its reply): those run past ten minutes, and the gateway already keeps a translated reply's client alive through thirty (translatedQuietLongest). A dead connection's read now ends at that bound instead of never; the reporter's 4m52s case still waits on the client to cancel first, which is the trade. The text above that says five minutes and keepaliveLongest is the patch's first version. Broken by hand at the reviewed head: the idle timer (its start and its reset) set to 1000h, TestHostBodyIdleEndsASilentStream red after its 5s bar; restored, green. TestHostBodyIdleSparesAFedStream guards against a whole-reply deadline, not a mutation of this code: with the reset taken out it stays green (a stopped timer never fires). Run at the pushed tree (this stack of nine on origin/main |
||
|
|
f8cd964aec |
plugin: a fetch past the host's 128 streams waits for one, not a local 502 (#3890)
The plugin host holds streamBudget/streamWindow = 128 streaming calls'
windows. begin(true) failed the 129th at once with errTooManyCalls, before
anything reached the plugin child, and the gateway counted it as a 502
try and sent the request again. The reporter's 192 concurrent MiniMax
streams through one plugin all came back 200, but over 298 local 502
tries that never reached MiniMax (65 requests retried).
Fetch now takes its window through beginStream: when all 128 are held
it waits for one to come free, outside h.mu (the transition that frees
one takes it), while its request's context lives, the host is up, and
for streamWait (1 minute) at most, past which it is errTooManyCalls as
before. RPCs keep their reserve and still never wait; begin(false) and
begin(true) are unchanged for their other callers.
Tests:
- TestHostFetchWaitsForAStreamWindow (internal/plugin): one window;
a second fetch waits, runs once the first is released, gives up on
a cancelled context and after streamWait, and leaves no window taken.
- TestPluginStreamsPastTheBudgetWait (internal/gateway, new file): 192
concurrent streams through the real Bun plugin host to a local vendor
that holds each open until 128 are live. Every request is 200 on one
try, the vendor sees 192 requests and never more than 128 at once.
Run at this head (on
|
||
|
|
55209c5529 |
plugin tests: TestHostStreamCreditBoundsTheQueue waits for the given-up call to leave the host, which it does once its abort's write is known, after the child may already have read it (red on ubuntu CI at 2b5f19fc; a 50ms pause before the write is known fails the old check every time)
Co-Authored-By: Claude <noreply@anthropic.com> |
||
|
|
c38728145b |
plugin: a slow reader pauses its stream instead of racing a watchdog (#812)
* plugin: a slow reader pauses its stream instead of racing a watchdog #664 gave a plugin reply a soft watermark (softQueuedBytes 4 MiB, softQueuedEvents 4096) and a 10-second idle watchdog: past the watermark, a reader that made no progress for stallIdle had its call failed with errStalledReader, and hardQueuedBytes/hardQueuedEvents (64 MiB / 65536) cut the reply outright. Both are guesses at how long a reader may take, and both end a reply that reader was still consuming. The host now hands each fetch a credit window instead. Go grants streamWindow (512 KiB) up front and returns credit as the reader takes bytes, so the child stops producing at the window instead of being timed out; the window is charged per delivered byte plus frameOverhead (2048), so a run of tiny frames cannot fill it with metadata. streamBudget (64 MiB) and maxFrame (64 KiB) bound a whole reply and a single frame, and a child that sends past its window is a protocol violation (errProtocolOverrun) rather than a slow reader. The plugin side grew the matching gate (makeGate, gate.take/spend/add, waitDrain): a fetch holds at the window until Go credits it, and its pending writes are cancellable. Cancellation and shutdown now have one owner per call - a five-state lifecycle (sending, active, draining, aborting, released) whose single transition helper disposes the queue, detaches the watcher, commits the terminal answer, creates the abort and returns capacity exactly once - so a host failure, a Close, a cancelled context and an already-delivered reply can no longer race each other over who cleans up. A reply the host already delivered keeps its bytes and its vendor outcome when the host dies. Tests: the JS cancellation cases run the production sections with controlled stdout backpressure (stopped gate, split chunk, terminal suppression, acquired-body cancel, 30,000 cancelled bootstrap waits with no retained waiter or ready reaction); the Go cases drive lifecycle orderings directly (terminal-before-failure, failure-before-terminal, abort acknowledged before capacity returns, blocked enqueue), and the shutdown, body-close and mid-setup-cancel cases block on explicit channels instead of sleeping. TestFlowBigReplyProd reads 100 MiB non-SSE and SSE through the real host and checks lengths and SHA-256, including a 12 s reader pause. CI installs Bun 1.4.2 on Linux and runs that case in its own step, since the plugin sandbox skips when bun is not on PATH. * plugin: the stream-head credit test waits for the credits before the reply ends (CI, macos-latest: TestHostStreamHeadChunksFinal failed on the macOS runner with "the credits were given back didn't happen", while the same package passed on ubuntu-latest and locally) — the test sent the child's final answer together with its 50 chunks, so the call could be marked stopped and its pending credits dropped before waitFor saw them; a completed fetch needs no credit, so waiting longer could not recover them and the expectation was a race, not a real accounting bug. The final answer is now withheld until io.ReadFull has taken the 140 payload bytes in order and exactly 140 + 49*frameOverhead credits have been observed with frameOverhead still owed, and only then does the child answer and the test assert a zero-byte EOF read. No production code changed. Tests: go test -run '^TestHostStreamHeadChunksFinal$' -count=500 ./internal/plugin/ and -count=200 -race pass; go test -count=1 and -race -count=1 ./internal/plugin/... pass; gofmt -l and git diff --check clean. |
||
|
|
fa1e3947f9 |
plugin: isolate stalled streams and guard GUI refreshes (#664)
* plugin,gui: a stalled stream can't wedge the host, stale reads can't draw, and the browser suite runs in CI internal/plugin: the host has one reader of the child's stdout, and it handed each message to its call by sending on that call's channel. A caller that stopped draining a streamed body (a slow HTTP client on a plugin-backed chat stream) filled the channel; the reader then blocked, and every other call through the host -- all plugin providers and accounts, moved built-ins included -- stopped being dispatched until the stalled stream was drained. A second call's answer arrived only after the first was drained. Each call now queues its head and chunks in a bounded backlog (4 MiB of chunks, 4096 of them) drained by its own reader, so the host's reader never waits on one consumer; a call whose consumer stops reading is given up on alone, with the limit as why. Aborts go through a goroutine too (abortLoop), so a child that stopped reading its stdin can't make an abort wait either. host_test.go covers the stalled consumer, the bounds and the abort path. internal/gui: loadUsage() and refreshUsage() both read the Overview's usage?period=, and neither checked after the await that its answer was still the newest: a 24 h answer landing after a 7 d one drew the old period's figures under the new period's name, and leaving the tab could still write the Overview's cost into the shared header. Both now claim one shared read generation before the request and draw only when it is still the newest and the page, tab and period are unchanged. providersWhileFetching() also stopped for good after one failed poll or reload; it now asks again. usage-stale-answer.test.cjs and providers-fetching-retry.test.cjs lift the real functions out of app.js and drive them with a faked api/page/timers, so they need no browser; usage-refresh-flight.test.cjs gains the browser case for the same race. Makefile/.github: `make test-ui` runs every internal/gui/tests/*.test.cjs through Node's test runner -- auto-discovered, UI_TEST_CONCURRENCY files at a time (default 2) -- and a new `ui` job in Test runs it on ubuntu-latest with Playwright's Chromium and WebKit. A missing browser fails the job; it never skips to a pass. internal/gui/tests/README.md points at `make test-ui` instead of a hand-kept command line. Verified: node --test on the two new files 21/21; go test -count=1 ./internal/plugin/ ok; go test -race -count=1 ./internal/plugin/ ok; go vet ./internal/plugin/ and go build ./... clean; node --check on the changed JS; actionlint on the workflow. Not verified: the full browser suite is not green yet. `make test-ui` is 1641 passed / 70 failed of 1711 across 225 files, and 12 of the 19 failing files fail the same way on a pristine main (a known baseline: a fixture boots the page in web mode while asserting the desktop window's narrow behaviour). The `ui` job will be red until those baselines are dealt with -- nothing is skipped or masked -- and the job has not yet run on a GitHub-hosted runner. * plugin: distinguish stalled readers from large responses * plugin: clarify best-effort abort delivery |