fix(context): remove silent age-based tool reclaim#240
Open
tracycam wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the silent, positional/age-based “two-pass” tool-result reclaim behavior across the TypeScript (OpenCode + Pi) and Rust (mc-module) paths, so tool output is only reclaimed via explicit ctx_reduce, opt-in smart_drops supersession, or emergency pressure relief—while keeping legacy watermark fields inert for compatibility.
Changes:
- Removed the execute-watermark + later positional sweep (“two-pass reclaim”) from TS and Rust, including watermark advancement/reads.
- Kept
smart_dropsas an opt-in supersession-based reclaim path, gated to only act on already-mutating passes (cache-safe). - Updated tests and docs/schema to reflect “no age-based tool dropping,” and regenerated the Rust selection golden.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates user-facing description to clarify tool output isn’t silently dropped by age. |
| packages/plugin/src/hooks/magic-context/transform-postprocess-phase.ts | Removes positional reclaim and runs smart_drops supersession reclaim only when enabled and already mutating. |
| packages/plugin/src/hooks/magic-context/transform-postprocess-phase.test.ts | Replaces two-pass reclaim tests with “legacy watermark is inert” coverage and adjusts expectations accordingly. |
| packages/plugin/src/hooks/magic-context/tool-reclaim.ts | Deletes the synthetic positional reclaim implementation. |
| packages/plugin/src/hooks/magic-context/supersession-reclaim.ts | Updates comments/docs to remove references to layering on positional reclaim. |
| packages/plugin/src/hooks/magic-context/apply-operations.ts | Updates synthetic-op semantics/comments to reflect smart-drops (synthetic) behavior. |
| packages/plugin/src/features/magic-context/storage.ts | Stops re-exporting the watermark-advance helper. |
| packages/plugin/src/features/magic-context/storage-meta.ts | Stops re-exporting the watermark-advance helper. |
| packages/plugin/src/features/magic-context/storage-meta-session.ts | Removes advanceToolReclaimWatermark implementation (legacy field remains stored via meta). |
| packages/plugin/src/config/schema/magic-context.ts | Updates smart_drops schema description to remove age-based reclaim wording. |
| packages/pi-plugin/src/context-handler.ts | Removes positional reclaim in Pi path and keeps smart_drops as opt-in supersession reclaim. |
| packages/pi-plugin/src/context-handler.test.ts | Adds/updates tests asserting legacy watermark does not trigger unrequested tool drops. |
| packages/docs/src/content/docs/reference/configuration.md | Updates reference docs for smart_drops to reflect no age-based reclaim. |
| crates/mc-module/testdata/selection-golden.json | Removes two-pass case and legacy execute watermark fields from golden fixtures. |
| crates/mc-module/src/transform.rs | Removes last-execute watermark participation in selection; updates tests to treat legacy watermark as inert. |
| crates/mc-module/src/selection.rs | Removes two-pass selector and updates docs/tests to match “four selectors” and smart-drops behavior. |
| crates/mc-module/gen/gen-selection-golden.ts | Stops driving the removed two-pass selector when generating the TS↔Rust differential golden. |
| CONFIGURATION.md | Updates smart_drops documentation to remove references to age-based auto-drop layering. |
| assets/magic-context.schema.json | Updates generated schema text for smart_drops to match the new semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fixes #239.
Summary
Pi transform paths.
ctx_reduce, configuredsmart_dropssupersession, and emergencypressure relief unchanged.
databases and serialized module state do not need a migration.
Why
The retired two-pass path stamped the current tool-tag/ordinal frontier on one
execute pass, then silently selected every older tool arc during a later mutating
execute or hard-fold pass. Selection was based on position rather than an explicit
drop request, semantic supersession, or emergency pressure. That made still-useful
tool output disappear as a side effect of an otherwise unrelated context mutation.
After this change, normal tool-result removal has an attributable trigger:
ctx_reducerequest;smart_dropssupersession rule; orCompatibility and impact
tool_reclaim_watermarkandlast_execute_ordinalvalues are preservedbut no longer read or advanced for selection.
supersession rule applies. Emergency cleanup remains the final pressure guard.
smart_dropswithout implying general age-based cleanup.
Validation
bun test packages/plugin/src/hooks/magic-context/transform-postprocess-phase.test.ts— 41 passed.
bun test packages/pi-plugin/src/context-handler.test.ts— 81 passed.bun run typecheck— plugin, Pi plugin, and CLI passed.rustfmt --edition 2021 --checkpassed for the modified Rust sources.bun run buildpassed for the OpenCode plugin, Pi plugin, and CLI.cargo testcould not start in the validation checkout because the existing localpath dependency
/home/rate/commons/crates/cortexkit-cache-core/Cargo.tomlwas notavailable. No replacement dependency was downloaded.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Remove the silent age-based tool reclaim and its watermark across TS and Rust. Tool output is now reclaimed only by explicit
ctx_reduce, opt‑insmart_dropssupersession, or emergency pressure; legacy watermark fields remain inert.Refactors
tool-reclaim, stopped advancing/readingtool_reclaim_watermarkinpackages/plugin,packages/pi-plugin, andcrates/mc-module; dropped the age-based selector from Rust and TS; updated logs to “smart-drops reclaim”.smart_dropsand edit supersession (execute-only when already mutating);pi-pluginand postprocess no longer call/advance the watermark; added tests to ensure a legacy watermark never drops tools on execute or hard‑fold.CONFIGURATION.md,README.md,assets/magic-context.schema.json,packages/docs) to state that age never selects a tool; regenerated the Rust selection golden without the two‑pass case.Migration
tool_reclaim_watermark/last_execute_ordinalvalues persist but are ignored.ctx_reduce,smart_dropssupersession, or emergency cleanup.Written for commit c46d1b8. Summary will update on new commits.
Greptile Summary
Removes silent age-based tool reclaim while preserving explicit reduction, opt-in supersession, emergency cleanup, and legacy persisted watermark fields.
smart_dropsbehind its existing mutation-safe execution gates.Confidence Score: 5/5
The PR appears safe to merge, with no actionable correctness or security failures identified in the changed paths.
The OpenCode, Pi, and Rust implementations consistently remove positional selection and watermark advancement while preserving explicit pending operations, opt-in supersession, emergency cleanup, persisted-field compatibility, and corresponding regression coverage.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Tool output in context] --> B{Explicit ctx_reduce request?} B -- Yes --> C[Apply queued reduction] B -- No --> D{smart_drops enabled and output superseded?} D -- Yes --> E[Drop or compress during mutating execute pass] D -- No --> F{Emergency context pressure?} F -- Yes --> G[Apply emergency pressure relief] F -- No --> H[Retain tool output] I[Legacy reclaim watermark] -. inert compatibility data .-> HReviews (1): Last reviewed commit: "test(pi): format explicit reclaim regres..." | Re-trigger Greptile