3 Commits
Author SHA1 Message Date
yetone 1823ff3a13 proc: deepzora and gumloop ask the shared proc.mjs whether a lock's owner lives (#1164)
#1198 (yetihan) moved 15 packages' liveness checks onto scripts/proc.mjs,
so a Linux zombie no longer holds a lock. Two were left on a bare
kill(pid, 0), which answers for a zombie as for a live process:

- deepzora's bridge lock (bridge.mjs lock(), the same code as
  reasonix-desktop's, which #1198 fixed): a zombie owner left "Another
  bridge operation is running" until the zombie was reaped.
- gumloop's ledger lock peers (gumloop.mjs isAlive): a zombie peer was
  counted live, so its ticket was waited on.

Both now import a synced proc.mjs (scripts/sync-proc.mjs lists 17
copies; both package.json files ship it). gumloop's crash-window test
writes its instrumented copy into a temp dir, so proc.mjs is copied
beside it. A new guard in scripts/proc.test.mjs fails when any package
file outside tests and proc.mjs calls kill(pid, 0).

deepzora 0.2.1, gumloop 0.1.2.

Run (mote, HOME=$(mktemp -d)):
- bun test scripts/proc.test.mjs packages/deepzora packages/gumloop:
  111 pass, 0 fail. node --test scripts/proc.test.mjs: 9 pass.
- deepzora node --test deepzora.test.mjs: 13 pass.
- node scripts/sync-proc.mjs --check: ok. bun scripts/check.mjs: ok.

Broken by hand: main's bridge.mjs and gumloop.mjs with the new tests:
the guard names both files, and the copies test fails on deepzora.

Not tried: a real zombie owner for these two (#1198's fork-based
zombie check covers proc.mjs itself); a real Gumloop or DeepZora
account. gumloop under node --test fails 3 of 3 on bun:test imports,
the same on origin/main.
2026-11-16 12:31:01 +08:00
yetone edc6dbcd6e gumloop 0.1.1: two hosts' charges are never lost (#1011)
Cause: the bakery lock's wait for a peer is bounded at LOCK_WAIT_MS
(250ms). When it ran out, Store.change returned undefined and the
charge's callback never ran: the chat succeeded and its charge was
dropped. Two hosts charging back to back on a busy runner (a GC or
scheduling stall in the holder, or many contenders) hit that, which
is the 199 of 200 in publish run 43040437938. An unreadable ledger
dropped the change the same way. Mutual exclusion itself held: an
instrumented copy logged one lock timeout per missing charge and no
unexplained loss.

Fix: Store.update. A change whose lock wait runs out, or whose read
fails, hasn't run, so it is kept in memory (capped at 1000) and runs
once, in order, the next time the store holds the lock and can read
the ledger: on its next update, from an unref'd retry timer (25ms
doubling to 5s, each waiting 25ms), or from the exit hook, which waits
up to 2s. A failed read still never writes. A throwing callback still
leaves the disk as it was. change, anchor and setPrices go through it.
charge and the credit refusal date their record when the call ended,
not when a kept change runs. The crash-phase tests' instrumented
module goes to a file: as a data: URL on the command line it passed
Windows' 32K limit.

Tests: the live-owner, leftover-record and choosing tests now hold
that the waiting changes land (they asserted the drop). New: a Node
and a Bun host that exits while its charge waits for a busy peer
still writes it.

Ran (worktree at a69931ec + this change):
- stress: 8 processes x 60 changes, holder pauses up to 200ms: old
  code lost 17-71 (mote), 93-108 (Windows) charges, each a lock
  timeout; new 480/480 on mote, Linux and Windows, Node and Bun,
  with 39-146 timeouts each.
- old gumloop.mjs under the new tests: 6 red.
- broken by hand: no exit flush -> both exit tests red; no retry
  timer -> the live-owner test red.
- packages/gumloop bun test x20: mote 20/20, magpie-desktop (Linux)
  20/20, xiaomi-gpu (Windows, temp HOME/USERPROFILE) 20/20.
- bun scripts/check.mjs ok; root bun test on magpie-desktop (Linux, under
  the suite lock): 8374 pass, 19 skip, 0 fail
- rebased on 2b87fad9 (no gumloop change between): packages/gumloop
  bun test x5 on mote 5/5, bun scripts/check.mjs ok.

Not tried: a host killed (not exited) with kept changes loses them;
no network filesystem.
2026-11-11 23:46:22 +08:00
sj1547139223 7ebab07c2a gumloop 0.1.0: API key sign-in, account models and credit estimates (#967)
Gumloop as a provider for magpie and OpenCode: API key + user ID sign-in, the
account's own model list (bare catalog ids mapped back to provider routes, per
account), streaming and tool calls, a missing system prompt supplied for Muse
and MiniMax M3.1 Flash, and a locally calibrated credit estimate (an estimate,
not an invoice). The ledger is written only under magpie's config directory
(kept in memory in OpenCode), a failed read is unknown and never written over,
and updates go through a filesystem ticket lock (bakery) across plugin hosts.
Only a 403 that names the key reads as an expired sign-in, and only Gumloop's
assumed 403 credit_limit_exceeded reads as out of credits. The last change
checks lock contention at least once after a stall, so an uncontended update
that took more than 250 ms to publish its ticket is no longer dropped.

Ran, at the reviewed head 2173d784 (WSL magpie-desktop, Bun 1.4.2, fresh
HOME; Windows 11, Bun 1.4.2, fresh HOME and USERPROFILE):
- bun test packages/gumloop: 87 pass, 0 fail (3x WSL, 2x Windows); the
  200-charge overlap test 10x WSL and 5x Windows green; check.mjs exit 0.
- Merged with origin/main 017cd73e: package 87 pass, check.mjs exit 0, root
  bun test 8294 pass, 0 fail.
- A 300 ms stall injected before the contention loop in production (no test
  hook): the three charge tests stay green; with the loop back to `while`
  they all go red (the charge is dropped).

Broken by hand, one at a time, each restored and touched:
- loop back to `while`: 3 red, the new stall test among them;
- no staleness check, no ticket-0 wait, no ledger .tmp cleanup, a 2000 ms
  wait, ENOENT counted as stale: each red, as in the earlier reviews;
- the old hook-only deadline reset put back together with `while`: the new
  test stays green (the hook hid the bug), so the reset must stay out;
- retryFs back to the shared deadline: green (a Windows sharing error after
  a stall; not reproducible on Linux).

Not tried: Gumloop's real API, a real magpie or OpenCode session with the
plugin. The npm first publish of the new package is the owner's.

Co-authored-by: sj1547139223 <146150939+sj1547139223@users.noreply.github.com>
2026-11-11 19:25:00 +08:00