Repository navigation
Conversation
jwitmann
force-pushed
the
feat/context-management
branch
from
October 28, 2026 07:13
4e34c08 to
eaf36dc
Compare
Author
|
Status + roadmap check-in. #52 itself is ready for review (16 commits, green gates, shared-doc binding note now included per the contributing guide). Behind it I have a sequenced stack, each as its own PR after this one merges — nothing will be opened until you weigh in:
Two questions before I open anything else:
Happy to rework #52 itself first if the direction needs adjusting — cheaper now than after four more PRs. |
A host-reported failed compaction arms a per-session backoff (ten minutes, then growth-gated re-arm); both request paths check it before admitting. Requests are single-flight while one is outstanding, the hook clears the backoff when an attempt runs, and the shared runtime is pinned to globalThis so reloads keep the state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Implements the Context Management roadmap item of Operator Memory: deterministic, local-only context reduction for the OpenCode V2 adapter. Magic Compact's README names Operator Memory its successor ; so this is the context-management feature arriving there, built by porting Magic Compact's trim machinery onto Operator's Brain-backed design.
Design summary
Three deterministic triggers, all off by default:
session.execution.succeeded, gated bycompactFloorTokens).Each deduplicated per session with cross-process state hydrated from the receipt log.
Trim replaces bulky completed tool I/O with omission notices (stored per-payload under
~/.operator/state/omitted/, recoverable through theoperator:read_omittedtool) and re-applies identically on every over-threshold request.Compaction is requested through
ctx.session.compactand shaped prompt-only (Brain partition pathsreferenced, never inlined); the hook never rewrites messages and never sets
result, per the live findings below. TheBrain is a hard prerequisite: without an initialized partition the feature stays off and logs one refusal receipt per session.
Every trim and compaction appends one JSON line to
~/.operator/state/context-log/<sessionID>.log. No network, no quota, no metering, no model-driven pruning decisions.Configuration
Single opt-in switch, off by default (vanilla behavior unchanged). A full user reference follows in the docs follow-up. The block lives in the
pluginsentry'soptions— global (~/.config/opencode/opencode.json) for every project, or a projectroot
opencode.json/opencode.jsoncfor one project (configs merge; a local directory plugin entry resolves<dir>/index.js, so point it at the builtdistdirectory):{ "operator": { "contextManagement": { "enabled": false, "ratio": 0.8, "hardCapTokens": 250000, "keepRecentTurns": 3, "compactOnComplete": true, "compactFloorTokens": 32000 } } }Requires an initialized Brain (
/operator:user-initor/operator:project-init); without one the feature stays off with arefusal receipt.
Verification evidence
origin/mainat734bb11(helper@v1.9.0). Branch holds 15feat(core|opencode-v2)commits only, no merges. Diff scope:packages/core/,packages/opencode-v2/,bun.lock(32 files).bun run check packages/core— green (format, lint, typecheck, 9 files / 73 tests pass).bun run check packages/opencode-v2— green (format, lint, typecheck, 10 files / 63 tests pass).bun run check(root) — green, 42 files / 296 tests pass.@opencode/plugin2.0.14, modelopencode-go/qwen3.8-flash): inert when disabled; refusal with no Brain; trim with receipts and byte-identical re-trim;read_omittedround-trip; single task-complete compaction across its own follow-up run; continued sessions open on compacted history with recall verified. Detailed run log (sessions, receipts, host rows) held with the design notes.Notes for reviewers
~/.operator/state/) are a new precedent: core previously only read. They are operational state, deliberately outside the Brain partitions (never cataloged, safe to delete).resultshort-circuit and the keep-tail budget — both destroyview history on v2.0.22. The removal commits are in the branch history; the spec no longer contains them.
opencode runcan lose a race with standalone server teardown (mid-run compactions complete reliably).