Commit Graph
7 Commits
Author SHA1 Message Date
ggbdpqandyetone 3ed3605ba0 netproxy: a global proxy switch drops the idle connections of the sync and the icon fetch (#4824)
ggbdpq's patch (gua2100 on Discord), reviewed and landed with test
changes.

What changed
- netproxy.Watch gives the dispatch's per-request check for a moved
  global proxy (#4523) to transports magpie keeps for itself. The sync
  (davsync) uses http.DefaultTransport, so when one of its requests
  finds the proxy moved, it now drops the idle connections itself.
  Before this, only a DefaultClient request dropped them, and a backup
  kept going through the old proxy's HTTP/2 connection.
- FetchIcon now closes the pool of the client that only the fetch used.
  Nothing closed it before.
- Review changes: the davsync test restores settings.json afterwards,
  and the icon test's wait for idle is bounded at 20s, not 2s, to leave
  room under load.

Run at the pushed head (on mote, base 4d55a0a02)
- go test -race passes for netproxy, davsync and provider's touched
  tests.
- go test -tags nogui -count=1 -timeout 45m ./... passes every package
  except two reds already filed and not touched here:
  - internal/cli TestEveryRouteHasACommandOrIsNamed (#4826, red on main
    since e87140242);
  - internal/gateway TestCodexPoolSaysTheClientsVersion (#4807, another
    test's Codex identity, passes alone).
- gofmt -l is clean. go vet ./... passes for darwin, for GOOS=linux
  (-tags nogui) and for GOOS=windows, and so do the linux and windows
  builds.

Broken by hand
- With stall.go's move check off, TestGlobalSwitchDialsTheSyncThroughTheNewProxy
  is red: "1 connections through A, 0 through B".
- With FetchIcon's CloseIdleConnections removed,
  TestFetchIconLeavesNoIdleConnection is red: "the fetch's connection is
  still idle".
- With Watch never reporting a move, TestGlobalSwitchDropsTheOldProxyConnections
  and TestWatchSeesTheGlobalProxyMove are red.

Not tried: a real proxy switch with a real WebDAV/S3 target or icon
host, or Windows/Linux at run time (vet and build only).

Co-authored-by: yetone <yetoneful@gmail.com>
2026-11-02 09:11:30 +08:00
ggbdpq a73df419d8 davsync: a GitHub blob POST on a slow but live line is no longer cut off at 30 s
What changed: the stall watchdog saw a request as one whose body may
outlast the whole metadata limit only by method (GET, PUT), and gave every
other request a flat 30 s (#657's rule held for WebDAV and S3, whose
remaining requests move a few KB at most). GitHub's uploads ride a POST:
each blob POST hauls up to 16 MiB of file as about 21 MB of base64, and a
flat 30 s needs 550 KB/s to get one part through (#4576: on a slower line
the sync failed on the same POST at every attempt, automatic, at start and
manual, and never recovered -- the usage day file froze in the morning
while the machine kept working). A request hauling a big body (64 KiB or
more) now gets the same moving-aware budget as a PUT: the watchdog is put
back each time bytes move, and after the body is all handed over the
answer gets 60 s on top of as long as the write took. The metadata
requests (the GitHub tree, commit and ref POSTs and PATCH, WebDAV
PROPFIND/MKCOL/MOVE/DELETE -- kilobytes at most) keep their 30 s in all.

Run: TestGitHubSlowBlobUploadIsNotCutShort (a 272 KB base64 body through a
line at 320 KB/s, watchdogs shortened to 1 s/300 ms) fails on the old code
with "the server didn't answer in 300ms (POST)", the shape of #4576's
error, and passes now; TestGitHubSmallPostKeepsTheLimit pins the small
POSTs to the old limit either way. go test -tags nogui ./internal/davsync,
vet and builds for darwin, GOOS=linux and GOOS=windows pass. Not tried
against a real slow line to GitHub.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-02 05:38:10 +08:00
JoeyWu-tech d5d72a82af imagemcp, davsync: slow-download tests leave room for growing the download's buffer (#3419)
TestFourKImageByURLIsSaved, TestStalledDownloadSaysWhereTheImageIs and
TestSlowTransferIsNotCutShort shorten a download watchdog to 1 s or
300 ms. Each watchdog is put back when bytes come, and the time it
counts includes this process storing them: FetchImage's buf.Write, and
the GET's io.ReadAll, which in Go 1.26 fills fresh chunks half the size
of what has come. At the real 60 s that is nothing. At 1 s and 300 ms
these went red here, beside a full suite on a Linux box, with the line
never stopped:
  big_image_test.go:153: after 4.096s: image 1 was drawn but couldn't
    be downloaded (nothing came for 1s, after 4.2 MB)
  big_image_test.go:207: image 1 ... (nothing came for 300ms, after
    8.2 MB), the 4K image that comes in full
  big_image_test.go:207: image 1 ... (nothing came for 300ms, after
    0.0 MB), the same
  stall_test.go:180: slow download: the server sent and took nothing
    for 1s (GET): the line or the server stopped (twice)
A probe beside a full suite wrote 256 KB pieces into a bytes.Buffer up
to 10 MB, as FetchImage does. Of 262,440 writes, 20 were held over
300 ms: 19 grew the buffer from 8 to 16 MB (up to 1.3 s), and one was a
fresh buffer's first write (2.7 s). A goroutine sleeping 10 ms beside
them woke at most 57 ms late, so the time went into the memory, not
into waiting to run. A second probe touched fresh memory: 16 MB was
held up to 454 ms, 4 MB up to 278 ms, 1 MB and 256 KB at most 1 ms.

Now:
- TestFourKImageByURLIsSaved: the stall is 5 s (was 1 s), and the 4K
  image comes in 256 KB pieces 200 ms apart (was 100 ms), about 8 s,
  so the download still outlasts the stall that plays #1576's 2-minute
  cap. The check that it was the slow one is now "longer than the
  stall" (was 3 s).
- TestStalledDownloadSaysWhereTheImageIs: the stall is 1 s (was
  300 ms), the stuck server sends 1 MB before it stops (was 3 MB), and
  the image that comes in full is the small png the other tests serve
  (was the 9.8 MB 4K one, whose buffer the 8.2 MB red was growing).
- TestSlowTransferIsNotCutShort: the backup is 2 MB at 512 KB/s, 64 KB
  every 125 ms (was 24 MB at 6.4 MB/s), still about 4 s each way under
  the same 1 s watchdog; the largest fresh chunk the read back fills is
  then under 1 MB.

What was run (tree 8e4ecb44, on b437e4ad):
  -count=10 of the three tests: ok (TestFourKImageByURLIsSaved 8.2 s on
  average, TestStalledDownloadSaysWhereTheImageIs 2.0 s,
  TestSlowTransferIsNotCutShort 9.9 s)
  broken by hand, with this change:
    FetchImage's stall not put back when bytes come (a 5 s cap on the
    whole download):
      big_image_test.go:157: after 5.003s: image 1 was drawn but
      couldn't be downloaded (nothing came for 5s, after 6.2 MB)
    FetchImage's stall never ending a download (the stopped one is
    kept until its server gives up, and saved):
      big_image_test.go:209: <nil>: Generated with ..., saved to: ...
    davsync's watchdog not put back when bytes move:
      stall_test.go:177: slow upload: ... the server sent and took
      nothing for 1s (PUT)
    no room once the PUT's body is all handed over (allSent):
      stall_test.go:177: the same
  gofmt -l internal/imagemcp internal/davsync: nothing
  GOOS=linux, darwin, windows go vet -tags nogui ./internal/imagemcp
  ./internal/davsync: exit 0
  full suite, go test -tags nogui -count=1 -timeout 45m ./...
  (go1.26.8, 469 s): 62 packages ok, internal/imagemcp and
  internal/davsync among them. 13 reds in 7 packages, none in a file
  this change touches:
    internal/agent TestInstalledVersion, TestOmpDetectedWithPiDir,
    TestCopilotFolderFromAnIDEPluginIsNotTheCLI and
    TestQoderSettingsFromAnIDEPluginIsNotTheCLI: proc.Look keeps "not
    found" for a tool written in the tick of its folder's last change
    (#3141).
    internal/agent TestReasonixCLIRequiresSupportedNativeVersion and
    TestReasonixCLIRecoversAfterProbeTimeout: their fixture build under
    /tmp meets a /tmp/.git that isn't a repository of this user's
    ("error obtaining VCS status: exit status 128").
    internal/claudebridge TestCallbackGoesPastTheAgentsProxy,
    internal/gateway TestClaudeToolCallbackOnANonLoopbackAddress,
    internal/gui TestGatewayHeldByAContainer and
    TestGatewayFixQuitsOnlyAMagpie: the processes this run started had
    their outgoing connections sent through a proxy (graftcp).
    internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv
    TestProgram: umask 077 here; the fixtures' own modes go through it
    (0444 is written as 0400).
    internal/netproxy TestBunProxyLoginWithReservedCharacters: Bun
    1.3.11 on PATH names port 80 in the request line (#3397).

Not changed:
  - The watchdogs. At their real 60 s a buffer's growth is far inside
    them; only a test's shortened one meets it.
  - pii's TestFetchStall (200 ms): its watchdog times a fresh 256 KB
    buffer and one read of 1000 bytes, at most 1 ms in the probe. Not
    seen red here.
  - davsync's TestStalledTransferFailsPromptly and
    TestMetadataRequestHasALimit (300 ms): a stall that comes early
    still passes them, since they check that a stall is told, and soon.
  - A pause like the 2.7 s one would still trip the 1 s watchdogs of
    TestStalledDownloadSaysWhereTheImageIs and
    TestSlowTransferIsNotCutShort. It came once in the probe's 7.5
    minutes.
Not tried: macOS, Windows.

Landed by yetone in a batch of Coffemon's patches from the issues.
What was run, go1.26.8, on origin/main cc81ad4ea, then again at
70a0c387c (gofmt, the three vets, the changed tests, umask 077):
- mote (macOS 27): gofmt -l clean; go vet, GOOS=linux go vet -tags
  nogui and GOOS=windows go vet ./...: ok. edit and testenv at umask
  077; agent, provider, library and gateway with an empty .git above
  TMPDIR; davsync, imagemcp, plugin, library, edit, testenv whole; the
  changed tests in agent, provider, gateway and gui; the timing tests
  -count=10 (gateway, davsync, imagemcp) and -count=5 (agent): all ok.
  TestCoreScriptBudget ok: core 1,536,751 of 1,537,034, app.js
  1,312,975 of 1,315,316, no budget raised.
- Red on the old code: on origin/main, TestWriteAtomicReadOnlyHardLink
  at umask 077 and two Reasonix tests under an empty .git; on Linux
  (wsl-run) TestProgram at umask 077 with the old program.go. With
  each fix's code taken back to main's, the Gemini imageConfig tests,
  TestPluginToldWhereTheAgentWorks, TestSkillRepoTraced,
  TestTaggedHooksAlone, TestMainURL/TestMainView and update-auto,
  plugin-github-hooks, plugins-more-discover, plugin-namesake were
  red. Broken by hand: claudeKeyed always true (both
  OwnEndpointNeverAsked tests red), claudeAsk a no-op
  (TestClaudeFirstWriteAsksTheProxy red), GitAt taking any .git folder
  (the three TestGitOnDisk tests red).
- GUI: 123 files (plugins*, update-*, panel/tray/start/context, i18n,
  gui-zh-tw/ja/de and every file that evals app.js parts) in WebKit on
  Linux (wsl-run). 11 files had reds (click-scroll, panel-fold,
  plugin-card-update, plugin-github, plugin-move*, segs-glide,
  tray-totals, update-*), and run again side by side they fail the
  same on origin/main d80d75f30 (79 pass, 26 fail here; 78 and 27
  there). They are click-scroll guards ("the click must not scroll
  the page"), varying by language from run to run (#4385).
  copilot-ghe's route-after-close red is #1949, seen on main 244d80e23
  too. In Chromium on mote, Chromium segfaulted partway through files
  (#4125): context-map, context-scroll-end and context-tune fail the
  same on origin/main 0911a65e7, so the batch's own files
  (plugin-namesake, update-auto, plugins-more-discover,
  plugin-github-hooks) ran in Chromium on Linux: 62 of 62.
- Full suite (go test -tags nogui -count=1 -timeout 45m ./..., mote)
  at 472a0608f (on 70a0c387c): every package ok but internal/gateway,
  whose five reds were #4362's (Antigravity turned-away and
  TestCodexSpentGrokFailingIsTold), fixed on main in d80d75f30. After
  the rebase on 244d80e23 the five pass, and gofmt, the three vets
  and the targeted runs above were run again: ok. In Linux the
  sign-in, copilot, plugin-github*, plugins-more-discover,
  plugin-namesake, plugin-gateway, update-auto, quota-refresh-order
  and i18n files ran in both engines: 475 pass, 4 fail (copilot-ghe
  #1949, plugin-github's click scroll, both red on main too).
- Rebased again on c7171a256, over its budget fix e94bf7a08: gofmt, vet of
  gui, gateway, provider and plugin, TestCoreScriptBudget (core
  1,536,265 of 1,536,586 with the batch's last commit, statusTErr and settingsErr), the Gemini,
  GitOnDisk and plugin tests, and in Linux both engines i18n-keys,
  update-mirror, plugin-namesake, plugins-more-discover,
  plugin-github-hooks and update-auto (138 of 138): ok.
Not tried: the whole GUI suite (mote's WebKit wouldn't launch and its
Chromium segfaulted, #4125); macOS WebKit; the real app's window.
2026-10-30 15:53:22 +08:00
yetoneandClaude Opus 5.5 30a8ce2915 davsync tests: TestSlowTransferIsNotCutShort's watchdog is a second, not 300 ms, over ~24 MB each way
A line that never stops is all this test sends, so a 300 ms watchdog only
catches the runner itself pausing: red on macOS in run 37693090857 at
7.99s, near the end of the GET, where a full run takes 7.23s and 8 runs
under 3x CPU oversubscription here all passed. The server's 40 ms gap is
still 25x inside the watchdog, the PUT's tail is still twice it, and with
allSent's extension taken out the test still fails ("took nothing for 1s
(PUT)").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 06:21:51 +08:00
yetone e22d5eef81 davsync tests: the slow transfer's line is narrow both ways, so a download on macOS doesn't burst through the tuned-up buffers past the 300ms watchdog (TestSlowTransferIsNotCutShort red on macos-latest in main's run 37693090857: "took nothing for 300ms (GET)"; b1cba654 narrowed only the upload's way) 2026-10-08 06:17:28 +08:00
yetone b1cba65477 davsync tests: the slow transfer runs on a line with small buffers, and the PUT's tail is the server's to hold (TestSlowTransferIsNotCutShort red on ubuntu in PR #1030's run 37466034290: "the server sent and took nothing for 300ms (PUT)")
The test scales the watchdog from 60 s down to 300 ms and sends 20 MB at 6.4 MB/s, taking each of magpie's reads of the body as the line moving. On Linux the line's buffers aren't scaled with it: the kernel hands a writer room in bursts, waking it once a third of its send buffer has drained, and it tunes that buffer up to 4 MB (the receiver's window opens in steps the same way). A probe on magpie's body reads in a golang:1.26.3 container showed gaps of 130–290 ms between two of them while the line never stopped, every run; one over 300 ms failed the test. That is the test's ratio, not the watchdog's: at the real 60 s, a burst that long needs a line under ~25 KB/s. Not a race (the same in -race and without).

narrowLine serves the fake WebDAV server and gives the client with both ends' buffers held to 128 KB (SetWriteBuffer on the client's connection, SetReadBuffer on the server's), so a burst is a chunk or two. The MBs that used to sit in the buffers after magpie had handed the body over, which is what allSent's longer wait is for, are now the server's own tail: it answers the PUT twice the watchdog after the body is in. The server also grows its buffer to the body's length up front.

On Linux (golang:1.26.3, 14 CPUs): before, 5 of 30 runs failed (-race -count=10 -cpu 1,2,4); after, 30 of 30 pass, and -race -count=20 -cpu 1,2,8 of TestSlowTransferIsNotCutShort, TestStalledTransferFailsPromptly and TestMetadataRequestHasALimit with four busy loops beside them pass. With allSent changed to put the watchdog back by stallAfter alone, the test fails 3 of 3 ("took nothing for 300ms (PUT)"), so the tail is still tested. go test -race ./internal/davsync (darwin), go vet and gofmt -l pass. No change outside the test.
2026-10-06 23:25:27 +08:00
yetone f1224a055e sync: a backup on a slow line is no longer cut off at 2 minutes; a server that stops moving is (#657, irx999: a 43 MB backup with many skills to a WebDAV server on a 2.4 Mbps VPS, 305 KB/s, needs 2.4 minutes and every sync failed) — a sync had a fixed deadline in all (2 minutes from the gateway's loop and magpie webdav/s3 sync, 90 s from Settings › Sync now), so a large backup on a slow line never got through, however steadily it moved. WebDAV and S3 requests now go through a watchdog instead (stall.go): the backup's GET and PUT fail once nothing has moved either way for 60 s, each byte of the body sent or read putting it back, and after a PUT's body is all handed over the answer gets 60 s on top of as long as the write took (at least 4 minutes), for what still sits in the system's buffers to leave; the other requests (PROPFIND, MKCOL, HEAD, MOVE, DELETE) have 30 s in all. A stall says so ("the server sent and took nothing for 1m0s (PUT)"). Sync now and the CLI have no deadline; the gateway's loop keeps an hour as a backstop; a wait for another magpie's sync stays 30 s. TestSlowTransferIsNotCutShort (20 MB up and down at a steady trickle, over 5 times the watchdog each way), TestStalledTransferFailsPromptly (a server stopping mid-PUT and mid-GET fails within a second) and TestMetadataRequestHasALimit fail on the old code (no watchdog: the stalled ones hang) and pass. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. Not tried against a real slow WebDAV server. 2026-10-03 16:10:02 +08:00