Commit Graph
23 Commits
Author SHA1 Message Date
yetone 75d40ba48b ci: race gateway tests run in chunks taken in turn; 64 MB bodies are 20 MB under -race
The macOS -race gateway step split 3772 tests by sorted name into one
fixed share per core (3 on macos-latest), and the shares ran out of their
20 minutes with no test hung: run 42354008450 at 191f3c0af ended at 12m,
16m and over 20m (shard 2 in TestMediaJSONPastOldBodyLimit/images), and
42350695944 ran all three at ~19m20s. Two causes: the shares were uneven,
and a few tests scan tens of MB byte by byte, which the race detector
makes 14 to 30 times as slow.

Measured on mote (M5 Pro), -race, -test.v, old script, per test (plain
run in brackets): TestLoopGuardLeavesOrdinaryRepliesAlone 104s (7.6s),
TestLargeRequestEndpoints 104s (3.6s), TestRequestTailAfterOldLimit 33s
(4s), TestCodexBodyReadsPastOldLimit 14.6s (0.55s),
TestMediaJSONPastOldBodyLimit 10.7s (0.7s), TestCodexCompressedTailError
10.2s. Sums of test time per share: 487s, 641s, 761s.

- build/race-shards.sh: the tests go in ~118 chunks of about 32 (test N
  in chunk N mod m, so TestCodex..., TestCompaction... spread out), and
  each of the N workers takes the next chunk when it is done (xargs -P).
  Workers end within a chunk of each other. Each chunk logs in its own
  ::group:: with its time; the five slowest are printed at the end. A
  chunk whose process didn't finish counts as failed.
- oldBodyLimit (the pre-#118 64 MB) is 20 MB under -race
  (race_on_test.go), 64 MB in the plain run. 20 MB still passes every cut
  below 64 MB (bodyKept's 4 MB, the 8 MB and 16 MB reads); the plain Test
  step on ubuntu and macOS still sends the full 64 MB.
- TestLoopGuardLeavesOrdinaryRepliesAlone is skipped under -race: one
  goroutine feeds one loopGuard (loop_guard.go starts none), so there is
  no race to find; the plain run reads the whole corpus.

After, per test on mote under -race: TestLargeRequestEndpoints 40.7s,
TestRequestTailAfterOldLimit 13.05s, TestCodexBodyReadsPastOldLimit
5.1s, TestMediaJSONPastOldBodyLimit 4.46s, TestCodexCompressedTailError
3.1s, TestLoopGuard skipped: ~210s less race time.
A/B in one window on mote (same commit, binaries built from base and
change, 3 workers, load 15 to 30): old script with old tests 12m59s
wall (red: TestTranslatedStreamKeepsClientAlive, the load-timing test
of #2711/#2737); new script with new tests 10m57s, green, slowest
chunk 62s. On 3-core CI the wall should be about the total over three
plus a chunk, instead of the slowest share.

Broken by hand (wsl-run, Linux): defaultBodyLimit 16<<20 under -race
turns TestCodexBodyReadsPastOldLimit, TestLargeRequestEndpoints and
TestRequestTailAfterOldLimit red (body rejected / 413); defaultBodyLimit
48<<20 in the plain run turns the same three red. So the race run guards
the read-whole path past 16 MB and the plain run still guards 64 MB.
TestCodexCompressedTailError and TestMediaJSONPastOldBodyLimit stay green
with either cap: they never guarded the limit (true before this change).

Run: gofmt -l; on mote GOOS=linux go vet -tags nogui ./..., GOOS=windows
go vet ./..., go vet ./..., go vet -race ./internal/gateway; the seven
touched tests plain on mote (all pass, 21.9s); the whole gateway package
under -race through the new script on mote twice (one red,
TestBurstTellsNoSpeed/responses_from_chat_burst, the load timing of
#2719; the second run green).
Not tried: the race run with a 48 MB cap (it would pass: under -race
nothing now covers 20 to 64 MB, the plain step does); a CI run before
the push.

Fixes #5361
Fixes #5320
2026-11-07 19:45:30 +08:00
yetone 56602426d3 ci: Test gives the packages 30m, where internal/gateway ran into go test's default 10m on macOS (#2108)
The Test step ran `go test ./...` at the default -timeout 10m. On the
last 8 finished main runs internal/gateway took 448-600s on
macos-latest (375-450s on ubuntu), and timed out at 600s in 3 of them
(40676722560 at b3edcabf2, 40655569734, 40654333385), a red that names
no failing test. LESSONS' "A full run gives the slow packages room"
asks for a longer timeout on full runs already.

This is room, not the fix: the gateway package's run time stays open as
#2108. No app change; nothing run locally for a workflow edit. The next
main run's macOS job shows it.
2026-10-28 19:43:39 +08:00
yetone c644d9f1d2 update: the downloaded binary is moved into place again while something still holds it after the trial start, not failed at once (#2272, JasonBuildAI)
InstallBinaryAside starts the download suspended (trialStart), ends
it, sets the running exe aside and renames the download over it. A
program that checks an executable as its process starts (an antivirus)
can hold the file a moment after the process has ended, and the rename
then fails with a sharing violation; the report says the first install
of every update failed this way. The rename (and the put-back of the
old exe on failure) now goes through moveIn, which tries again over
asideWaits (100 ms to 1.5 s) while Windows says the file is held
(errors 32/33), as moveAside already does for the running exe. Any
other failure is returned at once. The Windows CI step now runs the
trial tests too (TestTrialStart and the new ones).

What was run:
- Windows box (Windows 10.0.26200 x64, Defender real-time on, a
  cross-compiled update.test.exe in a temp dir with a sandbox
  USERPROFILE/APPDATA/LOCALAPPDATA/TEMP):
  - TestInstallBinaryWaitsForHeldDownload (new; the download held open
    for 150 ms): old update.go FAIL "rename ...magpie.exe.new
    ...magpie.exe: The process cannot access the file because it is
    being used by another process."; new PASS (0.31 s).
  - TestInstallBinaryRightAfterTheTrial (new; real trialStart, then the
    install) and TestTrialStart pass on old and new code there.
  - The whole update package passes; the CI pattern
    ^(TestInstallBinary|TestMoveAside|TestTrialStart) passes.
  - Rollback tests now use 1 ms waits so a file held for good fails
    fast.
- The real update, in a sandbox: v0.1.1243's magpie-windows-amd64.exe
  run as `magpie update` twice in separate sandbox homes: both updated
  to 0.1.1244, exit 0.
- macOS: gofmt -l clean; go vet darwin, GOOS=linux -tags nogui,
  GOOS=windows clean; go test -p 4 ./... (see the last commit of this
  push for the result).
Not reproduced: the hold itself. On this box the real trial-then-
install path succeeded every time (10/10 with a 12 MB exe, 10/10 with
a 74 MB magpie.exe, 2/2 real updates), and origin/main's TestTrialStart
passed 3/3. The fix is verified with an injected hold, not a real
antivirus one.
2026-10-15 10:10:18 +08:00
CaramelizedCUDAandClaude Code d85ef1908a ci: Bun on every test runner, and the plugin stderr tests on Windows
The end-to-end plugin test needs bun on PATH, and setup-bun only ran on
Linux, so macOS skipped it (run 38250283461: "no bun on PATH"). Windows
skips the Test step, so the stderr tests were only compiled there. Both
now run: setup-bun on all three runners, and a Windows step that runs
the two stderr tests with -v, so a skip shows in the log.

Run before this commit: the change is CI-only and is checked by the
workflow run on this branch.

Reviewed for magpie: the workflow change only drops setup-bun's Linux-only condition (same pinned oven-sh/setup-bun@v2, bun 1.4.2) and adds one Windows step running the two tests; no new trigger, permission, secret or action. The contributor's run 38263044397 shows both tests passing on windows-latest with bun 1.4.2, and macOS green with bun installed.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-12 23:33:56 +08:00
yetone 79f9b3752b sessions: a Codex archived copy rewritten at the same size in the clock tick of its last comparison is compared again, not taken from the cache, on Windows too (#1299, wizzy-yang)
The copy cache trusted a change time it had seen as proof the file had not
changed. NTFS stamps ChangeTime from Windows' clock tick, not the precise
clock: on the Windows box, 300 ms of back-to-back same-size writes got a
new ChangeTime only every ~0.5 ms (2147 of 2691 writes kept the previous
stamp; diffs 0.5/1.0/1.5 ms). A rewrite in the tick of the comparison kept
the stamp the cache saw, so the cached relation was reused. That, not write
merging, is why TestCodexArchivedSameSizeRewriteInvalidatesDiscovery failed
19 of 300 runs on Windows, alone as well as in the full package.

A comparison is now cached only when both files' change times are more than
a second older than the moment it started (codexStampSettle); a file changed
more recently is compared again next time. A later rewrite then lands in a
later tick and changes the stamp. Change times are compared as times
(Windows FILETIME converted).

TestCodexSameTickRewriteIsNotCached gives every write one change time and a
clock 10 ms into that tick. With the settle rule taken out (cacheable = both
stamps present), it fails: "a rewrite in the tick of the comparison reused
its stale relation". With it, it passes, and the second half checks settled
copies are still compared once, not every time.
TestCodexArchivedDiscoveryCacheAndAppend moves its clock a minute on so the
just-written copies count as settled.

The Windows CI step now runs the Codex copy tests (CodexArchived,
CodexSameTick, CodexPlainTwin), which it had never run.

Run: Windows 11 box (cross-built sessions.test.exe, sandbox USERPROFILE/
APPDATA/TEMP): old binary 19/300 failures of the reported test; new binary
0/1000 for the three Codex copy tests, and the Windows CI regex x5 with
testdata passes. macOS: go test -race ./internal/sessions, -race -count=30 of
the Codex copy tests, go vet (darwin, GOOS=linux, GOOS=windows), gofmt -l.
Not run: Linux with a coarse ctime clock (kernels before 6.13); the rule
covers it the same way.
2026-10-08 19:04:18 +08:00
yetoneandClaude Opus 5.5 a2bdb7f8ba ci: the GTK and WebKitGTK install on Linux gives up after 15 minutes, where a stuck apt held main's Test run for 2.5 hours (b0d456c3) and every later push queued and was replaced behind it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 06:02:22 +08:00
yetone 5fb5cdacc4 ci: Test fails on a Go file gofmt would change — unformatted files reached main 8 times from 10-01 to 10-06 (#427's toml_literal_test.go, fdf8b01e's subscription_usage.go today), and each took a gofmt commit of its own (aac0cd24, 8fbd39f8). The step runs gofmt -l on every tracked .go file, on Linux only, as Windows checks files out with CRLF. gofmt -l is empty on main now, and it lists a file with a misformatted func. No app change. 2026-10-06 16:24:50 +08:00
yetone 690d4c921a ci: a Test run on main finishes instead of being cancelled by the next push, and the workflow's token can only read
On 10-05 and 10-06 nearly every Test run on main was cancelled by the
next push, so a release had no finished run to wait for and Linux-only
failures shipped (LESSONS.md: "Don't tag until a CI Test run ... has
finished green"). cancel-in-progress is now false on main only: a running
run completes, and GitHub still replaces a queued one with the newest.
PRs keep cancelling their older runs. The workflow had no permissions
block, so it got the repository default token; it needs only to read.
2026-10-06 03:56:55 +08:00
forever 88b87ac13f fix(agent): reject Cursor launchers in VS Code detection (#931) 2026-10-06 01:02:09 +08:00
yetone 652e5e1ec5 ci: the gateway's race suite runs over one process per core, not one at a time (wizzy-yang, #923)
The Race step took 690s on ubuntu and 908s on macOS, almost all of it
internal/gateway: its 1046 tests can't call t.Parallel (t.Setenv rules
it out), so the package ran on one core under the race detector.
build/race-shards.sh compiles nothing itself: it takes the package's race
test binary (go test -race -c), splits its tests round-robin by name over
N processes run at once, prints each process's log in a folded group and
fails when any does. The gateway's TestMain already isolates every
process in its own temporary home, keychain stand-ins and PATH, so the
processes share nothing. The step runs it with one process per core
(getconf _NPROCESSORS_ONLN: 4 on ubuntu, 3 on macOS), the same -race
binary and the same 20-minute timeout; redact keeps its own go test -race.
Every test still runs under the race detector, once.

Locally (Apple silicon, 4 processes) the gateway's race suite passed in
4:39 against 567s of test time run one after another; one test,
TestLargeRequestEndpoints (seven 64 MB bodies, 198s), now bounds it.
2026-10-05 23:54:03 +08:00
tsuixl f5d777c58b fix(dsh): 保留家级模型选择并修正补丁配置继承 (#838) 2026-10-05 07:48:17 +08:00
tsuixl 066ecaae7d 修复 Windows MCP 连接拒绝分类并补充 CI 回归 (#805) 2026-10-05 07:44:11 +08:00
Snowyy 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.
2026-10-05 01:36:20 +08:00
Zhizhen He 0c6b4c290a sessions: preserve Windows link kinds and only copy cross-device moves (#663)
Return the original rename error unless the move crosses filesystems.
Permission and sharing errors must not start a copy-and-delete operation
that can leave the destination behind or remove source contents.

Preserve the source Windows symlink's file or directory kind rather than
inferring it from a target that may not exist at the destination yet.
Keep relative targets, Developer Mode handling and long-path support.

Cover rename failures, Linux cross-device moves and Windows link kinds,
and run the focused session tests natively in Windows CI.
2026-10-03 17:11:26 +08:00
XYenonandAmp 69368007b0 termux: support Android builds and installation (#644)
* termux: build natively and run plugins on Bun 1.4.2

Select nogui for Android builds, open browser and OAuth links with
termux-open-url, and write an executable Termux:Boot script that starts
the gateway with shell-quoted paths.

Bun 1.3 has no official Android build. Upgrade the default plugin runtime
to 1.4.2, add the official Android arm64 and amd64 download targets, and
update SHA-256 checksums for every supported platform.

Document Termux installation, startup and source updates.

Validation on Termux arm64:
- Native build and go vet pass.
- A fresh config downloads and verifies Android Bun 1.4.2 and loads a
  test plugin.
- Boot startup can be enabled and disabled.
- The Web page, authenticated state API, unauthenticated API rejection,
  gateway healthcheck and Web quit action work.
- Browser argument preservation, boot path quoting and permissions, and
  plugin tests pass.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a10014-56c1-73d3-b3ee-2ea569713989

* site: install Android builds in Termux

Detect Termux through TERMUX_VERSION or its PREFIX and select the Android
CLI asset instead of a Linux binary. Install into PREFIX/bin by default,
keep MAGPIE_BIN_DIR overrides, and suggest the Web or terminal interface
without Linux desktop setup instructions.

When the release has no Android asset, explain how to build from source.
Add android/arm64 to release-cli and stop the build loop on failure.
Document the installer and its release-asset requirement.

Shell syntax and all 11 site tests pass, covering platform selection,
custom paths, missing assets, checksum rejection and existing Linux
installation paths. The Android arm64 release build succeeds on Termux;
with a simulated release feed, the installer verifies and installs that
binary into PREFIX/bin and the installed command runs successfully.

Amp-Thread-ID: https://ampcode.com/threads/T-01a10014-56c1-73d3-b3ee-2ea569713989
Co-authored-by: Amp <amp@ampcode.com>

* ci: check Android releases and the installer

Build both linux/amd64 and android/arm64 through make release-cli in the
CLI test matrix. Run the site and installer tests in the Linux job with
Node 22, and check the installer's shell syntax.

The release workflow in yetone/magpie-releases already calls the source
Makefile's release-cli target, uploads dist/magpie-cli-*, and generates
checksums for every artifact. The Android target added to TARGETS is
therefore included without changing that workflow.

Replace the full Termux README section with a short platform note beside
the Linux and Windows installation requirements, removing duplicate
commands, the fork URL and temporary release availability details.

Both CLI release builds, all 11 site tests, shell syntax checks and
actionlint validation pass locally.

Amp-Thread-ID: https://ampcode.com/threads/T-01a10014-56c1-73d3-b3ee-2ea569713989
Co-authored-by: Amp <amp@ampcode.com>

---------

Co-authored-by: Amp <amp@ampcode.com>
2026-10-03 14:29:32 +08:00
TryWorld 21d5d1c43a test(update): execute native Windows install checks in CI (#637) 2026-10-03 13:28:16 +08:00
Snowyy 5422306fac usage: guard cache transitions and Windows long-path reads (#598) 2026-10-03 02:19:11 +08:00
mofelee 38b4a9d984 feat: export gateway and agent conversation waterfalls to Langfuse (#581) 2026-10-03 01:43:32 +08:00
Snowyy 3d8c6f24c5 usage: capture Windows change time for cached logs (#594)
* usage: capture Windows change time for cached logs

* ci: show native Windows usage test outcomes
2026-10-03 01:15:29 +08:00
Zhizhen HeandClaude Code 3fe606e4b3 providers: account usage no longer writes its map from two goroutines at once — an account fetched less than a minute ago went into the map the other accounts' fetches were still writing to, which Go answers with a fatal concurrent map writes, not a panic anything recovers from; LoginUsage and Grok's copy of it now write that hit under the lock their fetches use (#119)
Co-authored-by: Claude Code <noreply@anthropic.com>
2026-09-27 23:32:15 +08:00
Zhizhen HeandClaude Code 41de0d87eb gateway: count_tokens counts the masked prompt, and a count that cannot be had is told apart — the count Claude Code asks for before every turn went to the vendor as the conversation was written, so Mask secrets was defeated on every one; it now goes masked, the same prompt the turn it counts sends. An endpoint that doesn't implement counting (404/405/501, or a 400 that says so, in English or Chinese) falls back to the local estimate as before; a limited key or a broken connection yields to the next checked key and rests the one that failed, as a generation would, while a client's own cancellation rests nothing; and a real error — a wrong key, a prompt past the model's context, an image it won't take — reaches the agent. The gateway tests are isolated from the machine now (a temp HOME, inert stubs for the sign-in CLIs and the keychain) so a cache that outlives a test can't reach a real login, and the redaction tests' cold starts run in parallel. (#103)
Co-authored-by: Claude Code <noreply@anthropic.com>
2026-09-27 18:58:23 +08:00
yetone 497f2cac6e ci: Windows compiles the tests rather than running them — they fake a home through $HOME, which Windows doesn't read 2026-09-25 02:11:01 +08:00
yetone fb258266ee ci: vet and test on Linux, macOS and Windows for every push to main and every pull request, and build the terminal-only magpie 2026-09-25 02:08:26 +08:00