Skip to content

Make compact budget trimming linear - #8

Merged
royalpinto007 merged 1 commit into
AgentPostmortem:mainfrom
vsolano9:fix-3-linear-compaction
Sep 4, 2026
Merged

Make compact budget trimming linear#8
royalpinto007 merged 1 commit into
AgentPostmortem:mainfrom
vsolano9:fix-3-linear-compaction

Conversation

@vsolano9

Copy link
Copy Markdown
Contributor

Closes #3.

compact() now analyzes the transformed payload once and subtracts each removed message token count from a running total, preserving the existing payload/report contract without recounting the full shrinking transcript on every loop iteration.

The 500-message regression preserves the exact last four messages and report arithmetic while reducing counter calls from 125,748 to 1,496.

Validation:

  • full 6-test suite on exact Node 18.20.8 and 20.20.2
  • focused performance regression repeated 20 times
  • 672 differential option/payload combinations against untouched upstream, byte-identical
  • clean installed-tarball smoke on Node 18
  • source/test syntax checks, five-file package inspection, and git diff --check

The package remains zero-dependency and deterministic.

Measure the transformed payload once and subtract each removed message token count from a running total instead of recounting the shrinking payload on every loop iteration. Add a 500-message regression that pins output, report arithmetic, and linear counter work.

Closes AgentPostmortem#3
@royalpinto007
royalpinto007 merged commit 3dd7a8c into AgentPostmortem:main Sep 4, 2026
1 check passed
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.

compact --max re-tokenises the whole payload on every dropped message

2 participants