Skip to content

fix(lcm): count replay metadata in token budgets - #4712

Closed
ScriptedAlchemy wants to merge 2 commits into
masterfrom
fix/lcm-replay-token-accounting
Closed

ScriptedAlchemy wants to merge 2 commits into
masterfrom
fix/lcm-replay-token-accounting

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Replay selection estimated tool-call metadata with bytes/4, while the returned replay estimate and overflow flag counted only visible content. A retained tool transaction could therefore exceed the requested budget while reporting that it fit; recovery could also mistake removable tool arguments for fixed prompt overhead.

This change uses one canonical replay-envelope counter for raw transaction selection, pinned anchors, the returned estimate, and overflow-overhead subtraction. Tool arguments and other retained metadata use the existing o200k tokenizer. Role framing and local provenance remain outside that envelope, and content-only source summarization budgets retain their existing meaning.

The latest-objective preservation check now also recognizes an objective already emitted among pinned anchors. Previously it could append the same objective twice without reserving the extra budget.

Regressions cover atomic eviction of tool-heavy transactions, honest best-effort status when the newest transaction cannot fit, avoiding double reservation of tool arguments as prompt overhead, and preserving a pinned objective exactly once under an exact replay cap.

Validation

  • Pinned rustfmt and git diff --check pass.
  • Added focused unit and real session/compression regressions. The duplicate-objective change also received an independent source review.
  • Rust tests have not executed in this environment. The locked asupersync dependency's code generation was killed by SIGKILL at the container's 8 GiB memory limit with two workers, one worker, and the repository's existing one-worker bounded-test profile. No dependencies, assertions, or build profiles were changed.
  • The lower-memory command cargo check --profile bounded-test -p tracedecay-lcm --lib --tests --locked passed asupersync, then stopped with 12 E0599 errors in unchanged tracedecay-graph-db, before reaching the changed LCM target. Cargo's pinned Grafeo lacks four allocation-accounting methods supplied by the repository's existing Bazel patch. MODULE.bazel applies that patch; Cargo does not. The manifest, lockfile, graph-db sources, and dependency cache were not changed.

This PR remains draft pending executable regression coverage. The root session and Hermes Cargo targets share the same baseline dependency blocker; repeating those checks would not validate the changed code.

Implemented and reviewed with GPT-6 Astra Pro in ChatGPT.

@changeset-bot

changeset-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f385a05

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

Consolidated into #4742 (integrate/open-pull-requests) at the captured head shown in its description, as requested. Continue review and further fixes on #4742. This closure does not assert CI readiness; the replacement remains draft. Source branch retained.

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.

1 participant