Files
magpie/docs/subsystems
crayon 6671091676 sessions: Grok Build's sessions are deletable, its search index's rows going with them (#3003, #4595)
#3003 (acsfreerun) asked for a Delete on Grok Build's sessions; #4595 kept
them listed with no Delete, because a session is a folder but Grok Build
copies each session's text into $GROK_HOME/sessions/session_search.sqlite,
which a folder delete would leave behind: its search would go on finding a
session Grok Build no longer lists.

Deletable("grok") now says yes, and sessionPaths' "grok" branch moves the
whole folder (updates.jsonl, summary.json, the locks, prompt_context.json,
terminal/, everything else it kept) and its subagents' folders, which
grokFiles folds into the session it ran in. What the cwd's folder holds for
every session there (prompt_history.jsonl), another session's folder and the
index stay. The trash, Restore, Purge, the recent-write ErrActive guard and
WSL handling are the ones Delete already has.

grokSearchRowsDrop (grok_search.go) deletes the deleted session's row in
session_docs, and its subagents', inside one BEGIN IMMEDIATE with a 5 s busy
timeout, so it waits for Grok Build's own write instead of failing; the
session_docs_ad trigger takes the row out of session_docs_fts. It runs before
the first file is moved: a row that can't be taken out (a database that isn't
one, a lock held past the timeout) stops the delete and the session stays
whole, rather than a folder gone from the list and still found by search. No
index file, or one without those tables, deletes as before. Restore brings
the folder back; the index row is not put back, so Grok Build's search finds
a restored session only if Grok Build indexes the folder again.

Tests, in-repo and on fixtures, never on a real ~/.grok: the sessions
package's fixture tree gained a lock file per session, a subagents/ entry, a
terminal/ file and the cwd's prompt_history.jsonl, and a small
session_search.sqlite is built in-test from the real file's schema (v4,
session_docs over FTS5 session_docs_fts with the three triggers).
TestGrokDeleteRestore (delete, folder and row and FTS entry gone, another
session's row kept, ErrActive, Restore, Purge),
TestGrokDeleteLeavesTheSessionWhenItsIndexRowCantGo and
TestGrokSearchRowsDrop; TestGrokSessionDeleteOnThePage drives the page's own
handlers (GET /api/sessions/manage?agent=grok says deletable, POST
/api/sessions/delete moves it, the trash lists it, POST /api/sessions/restore
puts it back).

docs/subsystems/gateway-sessions.md: the delete paragraph, and Grok Build out
of the "sessions magpie cannot delete" list.

Run (mote, this tree, on origin/main 289184a40): gofmt -l clean; go vet -tags
nogui ./... ok (one pre-existing cgo deprecation warning in internal/proc);
go test -count=1 ./internal/sessions/... ok (55.9 s); go test -count=1
./internal/gui -run 'Session|Manage|Forget|Trash|Delete' ok, 63 tests, the
new one among them; go test -tags nogui -count=1 on the same two selections
ok. go test -count=1 ./internal/gui (whole package, 216 s) fails
TestDockReopenKeepsTheWindowsSpace and TestCoveredWindowStaysUp with "timed
out waiting until the window is minimised"; both are red the same way in a
worktree at 289184a40 without this change, so they are this Mac's window
server, not this commit.

Broken by hand: without `"grok"` in Deletable, TestGrokDeleteRestore is red on
"Grok Build's sessions are not deletable"; green with it.

Not tried: a real Grok Build binary deleting one of its own sessions, so
whether it re-indexes a restored folder is unverified (said in the doc).

Isolation: the test binaries put HOME, USERPROFILE, XDG_* and every agent's
own variable (GROK_HOME included) in a temp folder (testenv.Isolate), and the
new tests name GROK_HOME and XDG_CONFIG_HOME themselves. A copy of this
machine's real ~/.grok/sessions (a 14.9 MB session_search.sqlite with 54
rows, one session of 76 files, one parent session of 477 files with two real
subagent folders) was exercised in the scratch folder only: delete, index row
and FTS entry gone, restore to the same file counts, purge; the developer's
own ~/.grok/sessions was snapshotted (every path, size and mtime; the index's
sha256; its session ids) before and after the runs and differs only where the
running Grok Build windows write themselves.
2026-11-19 23:57:01 +08:00
..
2026-11-10 03:25:44 +08:00

Subsystem design references

These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.

Subsystem Reference
Built-in subscriptions moving to plugins Provider and plugin ownership
Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) Plugin runtime
Plugins that run on the gateway's requests and replies Gateway middleware
Tools that plugins give, offered to every agent as an MCP server Plugin tools
Plugins that await context recall and observe completed replies Asynchronous gateway request hooks
Claude subscription turns across Claude Code runs Claude subscription bridge
How the gateway picks a provider, key or account, and falls back Gateway routing and fallback
Gateway Session Aggregation Gateway Session Aggregation
Connecting an agent's config to the gateway, drift, disconnect, WSL twins Agent wiring
Providers, keys, subscription accounts, refresh and allowance Providers and accounts
Instructions, MCP servers, skills and RTK written into agents Library
One MCP server, magpie, given to every agent in place of the Library's servers MCP router
Memory shared by every agent: the memory MCP server, the digest in instructions, the Memory tab Memory
One skill, magpie-skills, listing the Library's skills in place of each agent's own Skill router
Tray, panel, window, magpie web and the page's JSON API GUI app shell
Encrypted backups and setup synchronization over WebDAV, S3 or GitHub Sync and backup

A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.

Maintain a reference

Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.

Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.

For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.

Describe a PR's semantic changes

For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.

For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.

This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.

Review a change

  1. Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
  2. Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
  3. Check that changed contracts appear in the owning reference and that source links still resolve.
  4. Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.

A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.