1ccacad63281094de8a3372d5a507d38f9969e5c
7
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
e4197144a8 |
perf: every package's package-level regexps compile on first use
v0.1.3516 made gateway's and redact's patterns lazy. The other 299 package-level regexp.MustCompile calls, in 148 files across agent, provider, gui, library, codexcat, sessions, usage, plugin and the rest, now go through lazyre.New too, so a launch that never reaches them (`magpie statusline`, run by Claude Code on every message) doesn't compile them. Fields, maps and params that held them are *lazyre.RE. Measured on mote (M5 Pro), sandbox HOME, v0.1.3516-equivalent build (t42) against this one (t43): - GODEBUG=inittrace=1 sum: 7.39 MB / 69,837 allocs -> 4.62 MB / 46,765 - `magpie statusline`, 3 runs each: instructions retired ~212M -> ~176M, peak memory footprint 19.2-19.4 MB -> 16.8-17.0 MB Run: go vet ./... (darwin) ok; GOOS=windows go vet on each of the 30 changed packages ok; GOOS=linux go vet ok except ., internal/cli and internal/gui, which stop in wails v3's cgo files when cross-compiled (the same at main). New TestAllLazyPatternsCompile at the root compiles all 574 registered patterns (ok), so a bad pattern fails a test rather than a first use. Not run before push: the changed packages' own test suites; they run on mote after it. |
||
|
|
6712e367e8 |
agent: a look at the stash shares one read of it
Each /api/state and /api/drift poll asked the stash (stash.json) for one value hundreds of times, through Detected, Drift and the agents' wiring checks, and each ask read the file and parsed it again. In a real-account heap profile (20 rounds of drift, state and providers) stashLoad was 24-34 MB of what was allocated. stashShared reads it through filememo.Read, so every look shares one parse until the file changes, by magpie or by another process. Every read-only caller uses it now, the 24 files here and QwenPaw's unstashPeek. stashLoad, which callers change and write back, still gives each its own map, cloned from the same parse. Real use: the owner's real-account sandbox, offline (proxy to :9), 20 warm rounds of /api/drift, /api/state and /api/providers: - allocated 477 MB ( |
||
|
|
2597c96365 |
agent: Codex's config.toml is decoded once a read for a sync's own looks
A sync to Codex decoded the whole config.toml again for each thing it checked: codexMultiAgentV2On, putThreadTables, codexEnableEfforts and codexAsyncNow each ran toml.Unmarshal over the file. Codex writes a [projects."…"] table for every folder it was opened in; the owner's config is 1.5 MB with 10,932 tables, and with 10,000 such tables one sync allocated 21 MB. codexTopOf decodes only the top tables these look at (features, model_providers, desktop, profile, profiles) and keeps the result in filememo by the file's mod time and size, so a sync and the polls after it share one decode until the file changes. A missing file is an empty config, as before. TestCodexSyncDecodesTheConfigOnce: 10,000 project tables, one sync to settle, then five more; each must allocate under 12x the file and leave config.toml unwritten. Now ~5 MB a sync. Red on the old code: 51,257 KB a sync over an 868 KB file, past the 10,421 KB bound. Run at this head on mote: gofmt clean; go vet (darwin, GOOS=windows, GOOS=linux) ok; go test -timeout 45m ./internal/agent ./internal/gateway ok. |
||
|
|
5d955a4d4b |
tune: Codex can take the compaction advice in the background, its own limit kept (herman_hong)
herman_hong on Discord: Tuned for you advises Codex compact at ~120K.
A foreground compaction kept them waiting, so they had set 384K by hand.
Now that Codex compacts in the background, they want the advice there
and the 384K kept as the backstop.
Codex has this since 0.163.0 (checked in codex-rs at rust-v0.166.0, not
in 0.162.1): [features.async_compaction] enabled and
model_async_compact_threshold_percent, an integer share (1 to 100) of
the model's window, 65 by default. It is Stage::UnderDevelopment, runs
only with remote compaction v2 (which magpie already sets on its
provider), and starts none once the foreground limit is reached. magpie
already writes it from Settings' Background compaction (#2490), with
the version gate and the user's own keys kept. This drives that setting
from tune:
- agent: knob TuneAsync ("async_compact") on codex. TuneRead gives the
share, TuneApply turns Background compaction on at it (stashing what
Settings had the first time), and TuneUndo puts that back unless the
user changed it since. The foreground limit (Long conversations, or
the user's model_auto_compact_token_limit) is never touched. Async
keys the user wrote in config.toml come first (codexAsyncOwn): the
row says so and Apply errors. A table magpie wrote itself doesn't
count as the user's.
- gui/tune.go: advice.async holds the advice as a share of the window,
rounded down. With timed compactions it uses the token-cheapest
window, since a background compaction keeps no one waiting. It is
offered only when it would start before the foreground limit (the
lesser of the limit now and 90% of the window). held lists Codexes
too old for a share.
- context.js: the row gets a text button, "Use 120K in the background",
whose tip gives the share and says the foreground limit stays. After
Use a chip says so, with Undo background. A config.toml of the
user's, or a Codex too old, gets a one-line caveat and no button.
The too-old line is shared with Settings' row (codexHeld). No select,
no layout change. zh, zh-TW, ja and de are in i18n.js.
- The core script budget goes up by 1,571 bytes for the row
(core_budget_test.go says why). app.js is 278 bytes smaller.
Run (at this change on origin/main 6893cfbe3; rebased on
|
||
|
|
41357f3935 |
codex: the ChatGPT desktop app on Linux is found, and a switch reaches it
pota on Discord: magpie switches the ChatGPT (Codex) desktop app's account on macOS and Windows but not on Linux. OpenAI ships the app for Linux since 08-11 (preview; learn.chatgpt.com/docs/linux/linux-app): a deb, an rpm and an Arch package, which install /usr/lib/chatgpt. Its app-server is /usr/lib/chatgpt/resources/codex ... app-server, run with the user's HOME and no CODEX_HOME, so it reads ~/.codex like the CLI. isCodexAppServer took only .app/Contents/ and Windows paths, so on Linux nothing found the app: no "still signed in as" notice after a switch, no restart of its app-server, and no version on the Agents row. - provider: linuxCodexApp takes an absolute .../chatgpt/resources/codex as the app's own app-server (findCodexApp, CodexAppStale, the switch's restart all read it). - agent: restartOnLinux; codexAppOpen knows on Linux whether the app is open (any /usr/lib/chatgpt/ChatGPT process, not its codex alone or another program's ChatGPT). desktopApps["codex"].linux reads the version from resources/linux-package-metadata.json, HasApp/AppVersion see it, and codexReaders counts the bundled codex's --version as a reader of Codex's config. version() no longer stops at an empty store read before the other sources. Real run, WSL magpie-desktop (Ubuntu 24.04), OpenAI's chatgpt_amd64.deb 26.1027.30824 (bundled codex-cli 0.166.0-alpha.5.1) under Xvfb, sandbox HOME, fake unsigned JWT accounts alice/bob (no real credentials), magpie web on 127.0.0.1:3591: - POST /api/login/switch alice: 200, auth.json alice; /api/providers then says codexApp "bob@example.com" (the stale notice). - POST /api/codex/daemon/restart-app: 200 in ~3s; the old app-server ended (app log "Codex CLI process exited classifiedAsExpected=true code=0"), a new one started with the sandbox HOME, the notice cleared. - /api/agents/cli: "codex":{"app":"26.1027.30824"}. - The same run with linuxCodexApp reverted: no notice, restart-app 400, the app-server untouched (pota's case). Run at |
||
|
|
1184862583 |
agent: Codex background compaction writes the bare async_compaction = true where a Codex older than 0.163 reads the config (多喝热水)
多喝热水 (Discord #help, Windows, v0.1.1384, Codex desktop with ChatGPT
sign-in): Codex wouldn't open, "config.toml:154:1: invalid type: map,
expected a boolean". That line is the [features.async_compaction] table
|
||
|
|
1978eabe58 |
agent: Codex's background compaction is turned on from Settings › Long conversations (#2490, #2493)
Codex 0.163 can compact a long conversation in the background while a
turn goes on ([features.async_compaction]). A new row under Long
conversations turns it on, with the share of the window it starts at
(empty: Codex's own 65%). magpie writes it into each Codex config it
routes (codex_async.go):
- [features.async_compaction] enabled = true and
model_async_compact_threshold_percent. Codex reads the threshold only
in that table; one at the top level is ignored (tried).
- capabilities = { remote_compaction = "v2" } on [model_providers.magpie].
Codex starts a background compaction only on a provider with v2, which
it gives OpenAI and Azure alone. Tried with Codex 0.163 against a
sandbox gateway and a fake upstream reporting 70% use: without the
capability, no compaction in a whole turn; with it, compaction_trigger
requests ran beside the turn's steps and the next step's input held
the summary. The capability is written for a feature the user turned
on by hand too (#2493 asked whether magpie supports it: it didn't).
putProvider carries the table's capabilities over when a model switch
writes it again.
- What magpie wrote is in the stash (codex.async). A value the user set,
or changed since, is never written over and stays when the switch is
turned off; a bare async_compaction = true, an inline or a dotted
table is the user's as written. A config that doesn't parse is not
written to.
Not tried: Codex signed in with ChatGPT (openai_base_url to magpie on
the built-in provider, v2 by default), only the custom provider path.
Tests: TestCodexAsyncCompactionWritten, ...KeepsTheUsers and
...KeepsUsersCapability (internal/agent), each red with the matching
part removed by hand (no writing; no capability carry-over; no
ownership check on enabled). codex-async-compact.test.cjs: Chromium and
WebKit, en/zh/zh-TW/ja/de, red with the 1-100 check removed;
compact-at, i18n-keys, settings-general, settings-search pass.
TestSettingsSaveKeepsWhatItDoesNotSend holds the two new fields.
gofmt clean; go vet -tags nogui on darwin, linux, windows.
Full suite: go test -tags nogui -timeout 45m ./... (pipefail, suite-lock) at the four #2494/#2504/#2505/#2490 commits on origin/main
|