magpie wrote Long conversations' compaction threshold into each [model."magpie/..."] table's context_window. Grok Build reads context_window as the model's whole window and compacts at a percent of it: auto_compact_threshold_percent in [model.<id>], else [session]'s, else 85 (xai-org/grok-build 559751fd: xai-grok-shell/src/util/config/resolve/compaction.rs, DEFAULT_AUTO_COMPACT_THRESHOLD_PERCENT and resolve_auto_compact_threshold_percent; GROK_AUTO_COMPACT_THRESHOLD_PERCENT above all). So a 1M model held to 300K compacted at 255K and never had its real window. Now context_window is the catalog's whole window, and where magpie has it compact (grokCompactAt, the old grokWindow rule: the model's or provider's threshold, else settings.Working, none under Full window) goes in as auto_compact_threshold_percent of the window written, rounded down, at least 1 (grokPercent). None leaves Grok's own 85. - A table an older magpie wrote with the threshold as its window, on record in grok:<path>:windows, gets the whole window back. - A percent the user set in one of magpie's tables stays: what magpie gave is stashed in grok:<path>:percents, and one it has no record of giving is the user's (grokOwnPercent). A context_window set by hand still stays (grokOwnWindow). - A [session] auto_compact_threshold_percent is the user's for every model, so magpie writes no per-model one over it. Siblings: Codex (codexcat) already writes context_window and auto_compact_token_limit apart, and Claude Code has CLAUDE_CODE_MAX_CONTEXT_TOKENS beside CLAUDE_CODE_AUTO_COMPACT_WINDOW. Grok App (grokapp.go) writes the model's own window. Only Grok Build had the threshold in its window key. Run: - At cfca72eaf (this change onf9492fd8e), on mica (mote was over its cores): gofmt -l clean; go vet ./internal/agent ./internal/settings, GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... ok; go test -count=1 -timeout 45m ./... ok, go-exit=0. - At this head, rebased onf1a4de736(internal/agent changed in6abea5f8e): gofmt, vet and go test ./internal/agent ./internal/settings ./internal/gui on mica: gofmt clean, vet ok, all three ok (agent 195s, settings 16s, gui 137s). - Broken by hand: the new tests run against origin/main's grok.go (with a shim for grokHadIn) are red: TestGrokWindowIsTheModelsAndCompactsAtThePercent (pro 300000, want 1M), TestGrokKeepsTheUsersCompactPercent, TestGrokWindowFollowsLongConversations, TestGrokKeepsAWindowSetBeforeTheRecord. - Real grok 1.0.67 in a sandbox HOME/GROK_HOME: `grok models` and `grok inspect` take a table with context_window = 1000000 and auto_compact_threshold_percent = 30 with no config warning (a misspelt key is reported as "unknown field", so the check sees it). Not tried: a real Grok conversation running up to the threshold to watch it compact at 300K.
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
- Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
- Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
- Check that changed contracts appear in the owning reference and that source links still resolve.
- 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.