Commit Graph
1 Commits
Author SHA1 Message Date
yetone 04ff9a775c library: the sync at start lets go after each agent's part, for the page's reads and changes to go first (#1624, Hipple)
magpie writes the library into the agents again at every start
(app.go's library.Sync). That ran as change(): one hold of the library's
lock through every agent's instructions, servers, hooks and skills. Every
read of the Library page (Read, Glance, ReadInstructions) and every change
waits on the same lock, so the first one or two operations after opening
magpie waited for the whole sync, and later ones didn't: Hipple's "the
slow ones are the first one or two after opening, then under 1s" on
0.1.1223, 11 agents and 88 skills on Windows.

Sync now runs the same steps change's sync does (syncSteps, shared by
both, so the order stays one), each under the lock on a fresh load and
saved after it. A read or change that comes meanwhile waits for one
agent's part, not the rest. What a step learnt of the skills (hashes,
copies found untouched) goes on to the next only while nothing else took
the lock between; the lock counts its holders for that. A change by the
page still syncs as before, in one hold.

Measured: with the library's sync made slow (looks slowed), a Read
started during it came in with 0 of 6 agents' skills given back; on the
old Sync it came in after all 6, every time.

Run:
- TestReadDuringSyncWaitsForOnePart: -race -count=5 green; with Sync put
  back to change(nil) it fails 2 of 2 ("the read went after the whole
  sync").
- go test ./internal/library/ green; ./internal/cli/ green after
  rebasing onto 494609866 (TestAgentQwenDefault was red at the old base).
- gofmt -l, go vet darwin, GOOS=linux -tags nogui, GOOS=windows.

Not verified: on Hipple's Windows machine, or on the Windows box with 11
agents. That the start-up sync is what the first operations wait behind
there is inferred from the lock and the report's pattern, not measured.
The sync itself is still slow on its own: with 12 agents and 4 skills it
looks at paths ~7000 times, not memoized (linkmemo is read-only), which
is the next step.
2026-10-13 14:55:46 +08:00