Commit Graph
5 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 0135b7b0ea agy-cli 0.1.32: the first model list after warming has agy's Claude and GPT models (#1064)
On a signed-in agy, `agy models` takes about 4.4s and `agy acp`'s
session/new about 3s. provider.models() needed three calls before
claude-opus-5-5, claude-sonnet-5-5 and gpt-oss-120b showed up, and
OpenCode 2.x calls it once.

What changed:
- packages/agy-cli/index.mjs:
  - The offered-model probe now starts in listAgyModels' .then, as soon as
    a non-empty list arrives and a caller asked for probeOffered. It no
    longer waits for the next models() call. A hung or failed `agy models`
    still never spawns the probe.
  - probeSignedIn reuses the `agy models` stdout it already has. The same
    parser (parseAgyModels, split out of listAgyModels) fills
    cachedModelCatalog, and the probe starts. Sign-in waits for the probe
    for at most 3s.
  - The offer (acpOfferedModels, acpOfferedKey, offeredProbeAt and any
    in-flight probe) is forgotten when agyPath changes and after a new
    sign-in finishes. A generation counter drops the answer of a probe
    that started before the reset.
  - provider.warming() returns a promise while a list or probe is still
    running, and null when nothing is.
- scripts/opencode2.mjs, copied byte for byte to every
  packages/*/opencode2.mjs: after the first background refresh, the
  adapter awaits hooks.provider.warming() once, for at most 60s, and then
  refreshes once more. It does not loop. Plugins without warming() behave
  as before.
- Not done: the issue's on-disk catalog cache (point 3), skipped as asked.

Known gap: agy-cli has no `config` hook, so under OpenCode 2.x the adapter
lists no provider for it. refresh() returns before it calls
provider.models(), so the follow-up refresh can't add agy's models on 2.x
until agy-cli gets a config hook.

Tests: test/testkit.mjs's fake agy takes a sessionNewDelayMs. The new
tests in test/catalog.mjs set 1.5s on both `agy models` and session/new
and wait for state through warming(), with no fixed sleeps:
- On a slow cold start, the first models() after warming lists Claude and
  GPT, from one probe spawn.
- authorize() on a signed-in agy fills the catalog, and the next models()
  runs no second `agy models`.
- The sign-in wait is bounded: with a 6s session/new, sign-in returns in
  about 4.5s.
- Changing agyPath probes again.
The hang test now awaits warming() before it counts acp spawns.
scripts/opencode2.test.mjs: the warming list is read a second time when
warming ends, and only once when nothing is warming.

Run on Linux (a separate test Mac was over its load limit):
- packages/agy-cli bun test: 17 pass, 0 fail.
- bun scripts/check.mjs agy-cli: ok.
- bun scripts/check.mjs (all packages): ok.
- Root bun test in a temp HOME: 8530 pass, 19 skip, 0 fail.

Broken by hand on Linux, each red, then restored green:
- No probe in the .then: the slow cold-start test.
- probeSignedIn drops the list: the authorize and bounded-wait tests.
- agyPath change keeps the old offer: the agyPath test.
- Unbounded sign-in wait: the bounded-wait test (7514ms).
- Probe also on a failed listing: the hang test.
- origin/main's index.mjs with the new tests: all four #1064 tests.
- Adapter reads the list once: the warming adapter test, and the
  copy-identity check.

Not tried: a real agy (no Google sign-in, no network). The reset after
login.finish has no unit test of its own.

Reported-by: hiee3
2026-11-13 10:59:13 +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
yetone 740e1af252 tests: grok's nocli puts PATH back when its file ends, so gumloop's Node children find node on CI
publish.yml has been red on main since 7ebab07c (run 43011771755, and
43012668584, 43012789287 after it): 4 of gumloop's regression tests
failed with `Executable not found in $PATH: "node"`, so dist and npm
were skipped and gumloop 0.1.0 and agy-cli 0.1.19 reached neither.

Cause: bun test runs every file of the root run in one process.
packages/grok/nocli.mjs sets PATH=/usr/bin:/bin (and HOME, USERPROFILE,
GROK_HOME, GROK_BIN_DIR) for grok's files and never put them back, so
every file after grok's ran with that PATH. On ubuntu CI node is
actions/setup-node's, under /opt/hostedtoolcache, so gumloop's
spawn("node") found none whenever bun ran grok's files before
gumloop's (CI's order). Locally bun ran gumloop first, so it passed.

Change:
- grok/nocli.mjs: the first noRealGrok of a file snapshots process.env
  and registers an afterAll that puts it back, removing what was added.
- gumloop/regression.test.mjs: node's absolute path is found once with
  Bun.which at load and spawned by path; not found, the Node tests fail
  as before (no skip).
- Siblings the same way (a file-level env change never put back), found
  by a full-run env audit: chat/chat.test.mjs (XDG_CONFIG_HOME pointing
  at its deleted temp dir, MAGPIE_API_KEY/GATEWAY_KEY/ADDR deleted) and
  cursor/calls.test.mjs (XDG_DATA_HOME) now restore them in afterAll.
  window-warmup's fake-gateway.ts/scheduler.test.ts XDG pins are left,
  filed as #996 (fake-gateway is also the --serve demo's).
  Other PATH writers (devin, gcp-ai, grok's own tests, sap-aicore,
  agy-cli, layerfs) already restore theirs; the audit saw PATH change
  only at grok's files.

Ran (magpie-desktop WSL, node only in ~/sdk/node/bin, bun 1.4.2):
- Red first, origin/main: `bun test --randomize --seed=3` (and 5) on
  grok/loop-check + gumloop/regression: the 4 CI failures, same error;
  also with --preload ./packages/grok/nocli.mjs.
- Same seeds with this change: 95 pass 0 fail (new gumloop test plus
  origin/main's copy of it).
- Broken by hand: afterAll(putBack) commented out -> both seeds red
  again, 4 fail.
- Root `HOME=$(mktemp -d) bun test` (with an env-audit preload): 8298
  pass, 19 skip, 0 fail, 8317 tests, 584 files; PATH back to the start
  value at the first file after grok's.
- Touched packages (chat, cursor, grok, gumloop, qoder) after the
  chat/cursor change: 1117 pass 0 fail, each XDG value back to start.

Not tried: ubuntu CI itself before pushing (publish.yml runs it next);
Windows (nocli sets PATH empty there, restored the same way).
2026-11-11 19:53:46 +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