Skip to content

[Bug]: Resume snapshot ignores byte budget — advertises <2KB, injects ~196KB #1022

Description

@EvolveAegis

[Bug]: Resume snapshot ignores byte budget — advertises <2KB, injects ~196KB

Description

buildResumeSnapshot in src/session/snapshot.ts accepts a maxBytes parameter but never reads it — the function body has a comment // maxBytes ... IGNORED at line 30. The errors, git, and subagents sections iterate ALL events with no truncation. The precompact hook (hooks/precompact.mjs:7) advertises <2KB XML but calls buildResumeSnapshot without passing maxBytes, then stores the result verbatim via upsertResume.

To Reproduce

git clone https://github.com/mksglu/context-mode
cd context-mode && npm install
git checkout 589d8214  # verified version

# Minimal repro: 5 error events × 40KB each
node -e "
const { buildResumeSnapshot } = require('./src/session/snapshot.ts');
const events = Array.from({length: 5}, (_, i) => ({
  type: 'error',
  data: { message: 'E'.repeat(40000), timestamp: Date.now() + i }
}));
const snapshot = buildResumeSnapshot({ events });
console.log('snapshot size:', snapshot.length, 'bytes');
console.log('advertised budget: <2KB');
console.log('ratio:', (snapshot.length / 2048).toFixed(1) + 'x');
// Assert: snapshot > 100KB despite maxBytes being a parameter
"
# Expected: ~200,862 bytes (196 KB), ~98x the advertised <2KB

Expected Behavior

The maxBytes parameter should cap the snapshot size, or the <2KB claim in precompact.mjs should be removed.

Actual Behavior

maxBytes is accepted but explicitly ignored (// IGNORED in source). All error/git/subagent events are included verbatim with no truncation.

Additional Context

  • The fix pattern already exists in-repo: files (MAX_ACTIVE_FILES=10) and recent_user_messages (400 chars × 3) DO enforce caps in the same file.
  • This was verified against commit 589d8214 (v1.0.169) on 2026-07-28.
  • Happy to submit a PR if the maintainers are open to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions