TestGatewayHookMixedPiPackage: 'starting plugins: context deadline exceeded' under load
internal/plugin TestGatewayHookMixedPiPackage went red in a full go test ./... -timeout 45m run (macOS, load average ~250–500, on ccb2eea15 + the #2776 sessions commits, which don't touch internal/plugin):
--- FAIL: TestGatewayHookMixedPiPackage (718s)
starting plugins: context deadline exceeded
Run alone it passed in 164s. The 718s went to starting the plugin host while Bun's install cache was slow under load. The test came in with the async gateway hooks (#2118, 9b04c4e20).
A red under load is a timing assumption a user can meet on a busy machine: plugin start-up under a fixed deadline. To find: what the deadline is, whether the test waits on a real bun install, and whether it should be given an already-installed package (a test never reaches the network).
Seen again at origin/main 1a3b92688 (+ GUI-only commits), load ~500: TestGatewayHookMixedPiPackage (959s) and, with the same cause, TestHostOnBunLackingLibsSaysWhich: bunmusl_test.go:237: Providers on a bun lacking libstdc++: starting plugins: context deadline exceeded.
Seen again in a sibling test at load ~420 on 14 cores (full run at 1a3b92688 + the #2850 change): TestHostOnBunLackingLibsSaysWhich (62.63s) — bunmusl_test.go:237: Providers on a bun lacking libstdc++: starting plugins: context deadline exceeded. Alone it passes (ok internal/plugin 3.1s). Same plugin-host start deadline as this issue, so noting it here rather than a new one; I'm not taking it.
Seen again in the same kind of run: go test -p 4 ./... -timeout 45m, load ~500. It passes alone (ok 110.8s). Output:
--- FAIL: TestGatewayHookMixedPiPackage (796.85s)
gateway_test.go:299: mixed package lost Pi providers: [] starting plugins: context deadline exceeded
FAIL github.com/yetone/magpie/internal/plugin 1915.590s
Evidence only.
Seen on the plugin-host perf branch (1a3b92688 + 4 commits), go test -p 4 ./internal/plugin -count=1 -timeout 45m at load ~470:
--- FAIL: TestGatewayHookMixedPiPackage (902.05s)
gateway_test.go:299: mixed package lost Pi providers: [] starting plugins: context deadline exceeded
FAIL github.com/yetone/magpie/internal/plugin 2145.169s
Run alone it passed in 545.6 s. Its pinned pi install takes most of the 4-minute start deadline under this load.
TestPiPackage goes red with this too, on linux:
pi_test.go:138: Plugins = [], starting plugins: context deadline exceeded
--- FAIL: TestPiPackage (127.40s)
That run was go test -tags nogui -count=1 -v -timeout 45m ./internal/plugin/ at c158b043 plus the #3632 filememo patch and a print-only probe in filememo (nothing in internal/plugin), go1.26.8, Bun 1.4.2, load 26 on 160 cores. The rest of the package passed, TestGatewayHookMixedPiPackage too (20.79s), and a full suite at the same tree 7 minutes later had internal/plugin ok.
I think both tests have one cause, and it's npm rather than load. 127s is the host's 2 minute init bound (host.go:986), not the test's 4 minutes, so the install was done in under 8s and the host start is what ran out. pi.js looks for pi in the package's own folder first (pi.js:510). testdata/pi and the mixed test's temp copy have no node_modules above them (unless one sits higher up on the machine), so Bun auto-installs: the host asks npm for pi's latest, then its tree (115 manifest requests per start), and init waits on that. It also runs that copy. In a traced run on 098ac969 the host opened install-cache/@earendil-works/[email protected]@@@1/dist/index.js (npm's latest), not the 1.2.0 that testdata/pi-lock installs, so #1879's pin doesn't reach the host.
To check, I pointed BUN_CONFIG_REGISTRY at a local relay that passes tarballs through at once and holds manifests for 150s, on origin/main 098ac969. The frozen install went through and both tests went red with this message:
gateway_test.go:299: mixed package lost Pi providers: [] starting plugins: context deadline exceeded
--- FAIL: TestGatewayHookMixedPiPackage (151.40s)
pi_test.go:138: Plugins = [], starting plugins: context deadline exceeded
--- FAIL: TestPiPackage (160.14s)
With nothing held, both pass.
installPinnedPi's bun install --frozen-lockfile is on the network as well. The sandbox's install cache starts empty, so every run fetches all 118 tarballs, and testenv.Offline only covers Go's transport. When that install is slow the tests skip instead of failing: at 9fc382e6 on 10-25 both skipped after 240s with pi couldn't be installed: signal: killed.
A pi package added from a folder in the app should hit the same auto-install, but I haven't tried that. I'm not taking the fix for now.
Red again on mote at 9cf1cda55 (origin/main 2ec345364 + an internal/gateway-only change), full go test -tags nogui -timeout 45m ./..., load ~35: --- FAIL: TestGatewayHookMixedPiPackage (267.11s) gateway_test.go:333: mixed package lost Pi providers: [] starting plugins: context deadline exceeded. Alone at the same tree: ok in 139.95s, i.e. the test itself takes over two minutes to start the Pi package's plugins, so the start deadline has little room under a full run. Not taking it.
I took a go at this one, the patch is here: https://github.com/JoeyWu-tech/magpie/tree/fix/2865-pi-pinned (one commit, fd4adab4, on origin/main acdc85ac, applies on f7f2d75f as is; git format-patch --no-signature --full-index --stdout acdc85ac..fd4adab4 | sha256sum is 4b0cc14b448932854ac319f91628cde97d06d525dde3a8f93260e609f0d7cd4c). It's test-only: both tests now put their pi package inside the plugins folder, so pi.js and the extension's own imports resolve to the pinned pi, and Bun no longer auto-installs npm's latest while the host starts. With npm manifests held 150s through a local relay, both tests were red on main and now pass with no manifest asked (host start 0.5s, timed with a print-only probe). TestPiPackage also checks the pi version the extension's import reaches, which goes red on main's layout (the extension's import reached pi 1.4.0, not the 1.2.0 the lock installed). I left the app alone: a pi package added from a folder with no node_modules above it should hit the same auto-install, and fixing pi.js's resolve alone isn't enough (jiti then imports the extension natively and Bun fetches pi-ai for it), so the options for that are in the commit body for you to pick. Only tried on Linux, not in the real app.
Same class, another test: TestPiPackage went red at main 86fef947e (v0.1.2258) when go test ./internal/gateway/ ./internal/plugin/ ran together on the Mac mini (load ~26): pi_test.go:138: Plugins = [], starting plugins: context deadline exceeded after 226s of its 4-minute budget, most of it spent installing pi. Alone it passes in 30.6s, and the plugin package alone at the same head is ok (235s). Not taking it; this is the data for whoever does.
Most of your 226s went to installPinnedPi's install, which my first commit left alone, so there's a second commit on the same branch: afed9fea (test-only, on acdc85ac, applies on f2eb56c6; git format-patch --no-signature --full-index --stdout acdc85ac..afed9fea | sha256sum is 4958b640705da6885454146f24ff3bf3278fe5e6e100a0fbf0931218bb42a969). The install now uses a Bun cache in the temp folder, outside testenv's home on purpose, per user, a new folder every two days so temp cleaners can't take files from it, and never ~/.bun. Through a local npm relay that counts requests, the first TestPiPackage run asked for pi's 118 tarballs and the next asked for none; with the cache taken out by hand it asked for all 118 again, and since the uncached runs took anywhere from 29s to 227s, the counts are the evidence rather than the times. Nothing in the pi tests goes red without the cache, and I only ran this on Linux, not under a load like yours.
Landed in a246ad4cf and d0a61b856 (JoeyWu-tech's patches) and released in v0.1.2362. On macOS (mote) the pi tests ran twice: TestGatewayHookMixedPiPackage 21.41s then 0.96s with the kept cache, TestPiPackage 1.2s each; the package back at testdata/pi makes TestPiPackage red (pi 1.4.0 reached, not the locked 1.2.0). The cache lives in the temp folder outside the test HOME on purpose (agent-wiring.md says so). Closing; reopen if the deadline comes back under load.