091153bf (#3185) has Forget close the channel Written gives and make the
next one, and de49433f's wake, for another process's write that Watch
sees, does the same. A test that saves inside a synctest bubble writes
through Forget too, and a channel made in a bubble is that bubble's:
the next write from outside it, in another bubble or in none, closing
it is a fatal error. TestUnreadLoginsWriteErrorsKeepCredentials saves
in a bubble per case, so internal/provider's test binary dies in its
second bubble, on CI's ubuntu and macOS runs at 8299409e and 81a58d2f
and still at c158b043 (run 40265917236; a local -run prints the same
frames):
fatal error: close of synctest channel from outside bubble
goroutine 6032 [running, synctest bubble 2]:
github.com/yetone/magpie/internal/filememo.Forget()
internal/filememo/filememo.go:91
github.com/yetone/magpie/internal/provider.Changed()
internal/provider/hold.go:146
github.com/yetone/magpie/internal/provider.writeLogins(...)
internal/provider/logins.go:272
Now Written makes the channel when there is none, and Forget and wake
close it only when one was taken, and make none (endWaits). Nothing
changes for the loops: the channel a loop takes is closed by the next
write, magpie's or another process's, and two loops taking it between
writes share one. A write with nothing taken since the last one had no
wait to end. Only the loops that follow magpie's files take it
(middleware's observer, OTel's session watch, pluginrt.KeepFresh,
awake's loop and the agent's Codex daemon check), so every channel is
made outside a bubble, and a bubble's write may close it.
A loop that took Written inside a bubble would make the channel that
bubble's in the same way, and it would outlive the bubble. None does. A
bubble lives only inside a synctest.Test call, and those are all in the
tests of internal/filememo, provider, plugin, otlp and gateway
(TestConcurrentClassification*, its only ones). With a probe in Forget,
wake and Written over those (a bubble's clock starts at 2000-01-01
00:00 UTC), provider's tests write twice in bubbles, filememo's new
test once in each of its four, and nothing takes Written in one.
provider's, plugin's and filememo's test binaries link none of those
five loops, so none of them can; otlp's and gateway's bubbles run an
exporter's send and classify. Written's comment says so.
internal/gateway's claudeRoom closes and remakes its freed channel the
same way, and no bubble reaches it either: #3690.
What was run (tree 8d629438, on origin/main c158b043, go1.26.8,
linux/amd64):
- TestWrittenAcrossBubbles (new), for Forget and for wake, each in
bubbles of its own: two waits taken outside, two bubbles that each
write, then a write outside; both waits are closed by the bubbles'
writes, and the next one by the write after. Broken by hand, each put
back after: c158b043's filememo.go under it, "fatal error: close of
synctest channel from outside bubble"; Forget making the next channel
again, the same; wake as on c158b043 (close, then make), the same, in
wake's half; Written making a new channel on each call (two loops no
longer share one), "Forget in a bubble left a wait taken outside it
open"; endWaits without its nil check, "panic: close of nil channel".
With the change ok, and -race -shuffle=on -count=20 ok. TestWritten
and TestWatchWakesOnOthersWrites, unchanged, ok.
- TestUnreadLoginsWriteErrorsKeepCredentials: on c158b043 the fatal
error in 4 of 4 runs; with the change it and the tests beside it
(-run '^(TestUnreadLogins|TestReadableLoginsNotKeptAside)') ok at
-count=20, and internal/provider whole ok with Bun 1.4.2.
- The probe above, not committed (with -v, since go test hides a passing
package's output), over the tests with bubbles: Forget in a bubble 4,
two in provider and two in filememo's new test; wake 2, filememo's;
Written 0. Over the loops' packages (middleware, pluginrt, awake,
agent), which have no synctest tests: nothing. In that run
internal/plugin's TestPiPackage was red at its plugins' start
("starting plugins: context deadline exceeded"), #2865, and
internal/agent with tests of #3141, #3398 and #3641; internal/plugin
was ok in the suite below.
- gofmt -l clean; GOOS=linux, windows and darwin go vet -tags nogui
./..., GOOS=windows go vet ./..., GOOS=linux and darwin go build -tags
nogui ./... and GOOS=windows go build ./...: exit 0 each. go vet and
go build ./... without a tag on linux stop at pkg-config here (no
GTK, WebKitGTK or fontconfig headers on this box, exit 1).
- Full suite, outside graftcp (the proxy this box wraps commands in),
through systemd-run, umask 077, Bun 1.4.2 first on PATH as on CI,
-timeout 45m, log kept: 66 ok, provider among them, and 6 red, none
in what this changes:
- agent TestInstalledVersion,
TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
TestQoderSettingsFromAnIDEPluginIsNotTheCLI,
TestOmpDetectedWithPiDir and TestZedAppPath: #3141;
TestCodexDriftReached: #3398;
TestReasonixCLIRequiresSupportedNativeVersion and
TestReasonixCLIRecoversAfterProbeTimeout: #3641.
- davsync TestSync: #3420.
- edit TestWriteAtomicReadOnlyHardLink and testenv TestProgram: this
box's umask 077, #3640.
- gateway TestPluginToldWhereTheAgentWorks: this box's /tmp/.git,
#3675.
- gui TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie:
#3649.
Not tried: macOS and Windows, vet and build only here (nothing in the
change depends on the OS; CI's macOS job runs every package's tests, its
Windows job compiles them); an idle `magpie serve`'s wakeups as 091153bf
measured them (the loops take and are woken by the channel at the same
points), and Watch with a second process writing:
TestWatchWakesOnOthersWrites writes the files from the test.
Merged from JoeyWu-tech's fix/3632-filememo-synctest (0576b5893, ggbdpq's
pick on the issue), cherry-picked onto origin/main a1222c539. Run on mote
at this tree:
- go test -race -shuffle=on -count=10 ./internal/filememo/: ok.
- TestWrittenAcrossBubbles with a1222c539's filememo.go put back: fatal
error: close of synctest channel from outside bubble. With the fix: ok.
- go test ./internal/provider/: no fatal; only #3854's three TestFetch*
reds are left, the same as on main. internal/awake, middleware, otlp,
pluginrt (the other Written users): ok. internal/agent -run CodexDaemon: ok.
- GOOS=linux and GOOS=windows go vet ./internal/filememo/ ./internal/agent/: ok.
skygunner's c9e34bbd has the same mechanism and wasn't taken.