Skip to content

fix(context): remove silent age-based tool reclaim#240

Open
tracycam wants to merge 2 commits into
cortexkit:masterfrom
tracycam:fix/remove-silent-age-reclaim
Open

fix(context): remove silent age-based tool reclaim#240
tracycam wants to merge 2 commits into
cortexkit:masterfrom
tracycam:fix/remove-silent-age-reclaim

Conversation

@tracycam

@tracycam tracycam commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #239.

Summary

  • Remove execute-watermark/age-based synthetic tool reclaim from the OpenCode and
    Pi transform paths.
  • Remove the equivalent selector and watermark advancement from the Rust module.
  • Keep explicit ctx_reduce, configured smart_drops supersession, and emergency
    pressure relief unchanged.
  • Keep legacy watermark storage fields as inert compatibility data, so existing
    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:

  • an explicit agent ctx_reduce request;
  • a configured smart_drops supersession rule; or
  • emergency context-pressure protection.

Compatibility and impact

  • No schema migration is required.
  • Existing tool_reclaim_watermark and last_execute_ordinal values are preserved
    but no longer read or advanced for selection.
  • Context may retain more old tool output when neither explicit reduction nor a
    supersession rule applies. Emergency cleanup remains the final pressure guard.
  • Documentation and generated schema/reference text now describe smart_drops
    without 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.
  • Config docs/schema consistency tests — 4 passed.
  • bun run typecheck — plugin, Pi plugin, and CLI passed.
  • Rust selection golden regenerated (10 cases / 13 arc decisions).
  • rustfmt --edition 2021 --check passed for the modified Rust sources.
  • bun run build passed for the OpenCode plugin, Pi plugin, and CLI.
  • Manual validation of the equivalent deployed patch completed successfully.

cargo test could not start in the validation checkout because the existing local
path dependency /home/rate/commons/crates/cortexkit-cache-core/Cargo.toml was not
available. No replacement dependency was downloaded.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with 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‑in smart_drops supersession, or emergency pressure; legacy watermark fields remain inert.

  • Refactors

    • Removed the positional reclaim path: deleted tool-reclaim, stopped advancing/reading tool_reclaim_watermark in packages/plugin, packages/pi-plugin, and crates/mc-module; dropped the age-based selector from Rust and TS; updated logs to “smart-drops reclaim”.
    • Kept smart_drops and edit supersession (execute-only when already mutating); pi-plugin and postprocess no longer call/advance the watermark; added tests to ensure a legacy watermark never drops tools on execute or hard‑fold.
    • Updated docs/schema (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

    • No schema migration. Legacy tool_reclaim_watermark/last_execute_ordinal values persist but are ignored.
    • Behavior change: older tool outputs are not dropped by position; they remain until ctx_reduce, smart_drops supersession, or emergency cleanup.

Written for commit c46d1b8. Summary will update on new commits.

Review in cubic

Greptile Summary

Removes silent age-based tool reclaim while preserving explicit reduction, opt-in supersession, emergency cleanup, and legacy persisted watermark fields.

  • Deletes positional watermark selectors and advancement from the OpenCode, Pi, and Rust transform paths.
  • Retains smart_drops behind its existing mutation-safe execution gates.
  • Updates tests, generated selection fixtures, configuration schema, and documentation for explicit-only routine reclaim.

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

Filename Overview
packages/plugin/src/hooks/magic-context/transform-postprocess-phase.ts Removes positional reclaim and watermark advancement while retaining flag-gated supersession and existing mutation accounting.
packages/pi-plugin/src/context-handler.ts Mirrors the explicit-only reclaim behavior in Pi and leaves smart-drop and emergency paths independently gated.
crates/mc-module/src/selection.rs Removes the age-based selector and legacy watermark input from Rust reduction selection.
crates/mc-module/src/transform.rs Stops reading and advancing the legacy watermark while preserving its persisted compatibility field.
packages/plugin/src/hooks/magic-context/tool-reclaim.ts Deletes the internal positional reclaim implementation after all repository importers and call sites were removed.
packages/plugin/src/hooks/magic-context/transform-postprocess-phase.test.ts Replaces age-reclaim expectations with coverage proving legacy watermark values remain inert.
packages/pi-plugin/src/context-handler.test.ts Adds integration coverage confirming an upgraded session watermark cannot drop unrequested tool output.

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 .-> H
Loading

Reviews (1): Last reviewed commit: "test(pi): format explicit reclaim regres..." | Re-trigger Greptile

@tracycam
tracycam marked this pull request as ready for review July 23, 2026 07:39
Copilot AI review requested due to automatic review settings July 23, 2026 07:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_drops as 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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 19 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Age-based synthetic reclaim can silently discard still-relevant tool output

2 participants