evolver icon indicating copy to clipboard operation
evolver copied to clipboard

[BUG] Context [Execution] truncated — Capsule Preview diff bloats prompt to 70KB+

Open zhuyankarl opened this issue 6 months ago • 2 comments

Environment

  • Evolver version: 1.86.0
  • Node.js: v22.22.1
  • Platform: Linux x64

Problem

The gep_prompt_Cycle_*.txt files generated by dispatch.js consistently have Context [Execution]: truncated to just ...[TRUNCATED]... (39 bytes). This means the subagent receives NO execution instructions.

Root Cause

The Context [Injection Hint] section is bloated to ~54KB due to:

  1. Capsule Preview diff field — each capsule embeds a full git diff (~8.5KB), 3 capsules = 25KB of diffs not useful for strategy decisions
  2. Gene Preview learning_history and anti_patterns fields — verbose text
  3. Total prompt reaches 77KB, exceeding dispatch.js internal size limit → Execution truncated

Evidence

Context [Injection Hint]:: 54,850 bytes  (74% of total)
Context [Execution]:: 39 bytes  ← TRUNCATED
Total: 76,815 bytes

After stripping verbose fields: 35,971 bytes (53% reduction).

Suggested Fix

  1. Strip diff from Capsule Preview (or make opt-in)
  2. Strip learning_history/anti_patterns from Gene Preview
  3. Or: increase/remove internal prompt size limit

Workaround

Post-processing script strips verbose fields. Reduces tokens but cannot restore already-truncated Execution section.

zhuyankarl avatar May 30 '26 03:05 zhuyankarl

Thanks for the byte-accurate breakdown, @zhuyankarl — having the Hint vs Execution split called out in bytes pointed straight at the truncator math, and your strip-and-remeasure (54KB → 36KB, ~53% reduction) made the root cause unambiguous.

Confirmed in src/gep/prompt.js. There are two coupled defects here:

  1. formatAssetPreview currently inlines every field of every Capsule / Gene entry, including:

    • capsule.diff (~8.5KB each)
    • compact_diff
    • execution_trace
    • gene.learning_history
    • gene.evolution_history
    • gene.anti_patterns
    • failed_attempts

    With three capsules and a couple of genes, Context [Injection Hint] alone can exceed ~54KB.

  2. The truncator computes allowed execution bytes with:

Math.max(0, maxChars - prefix.length - 100)

Once prefix.length exceeds maxChars (default 50_000), the expression goes negative, Math.max clamps to 0, and Context [Execution] is truncated to an empty string — exactly matching the 39-byte header + ...[TRUNCATED]... output you observed.

Internal patch is already in flight as a two-layer fix:

  • Introduce PREVIEW_STRIP_FIELDS before formatAssetPreview() runs, removing the bloated fields from preview rendering while preserving:

    • ids
    • summaries
    • scores

    The resulting byte reduction matches your measurements.

  • Add an execution-context floor (EXEC_FLOOR = 8000) in the truncator.

    If the prefix still exceeds the limit, the prefix is truncated instead of Execution. That's the safer trade-off:

    • losing reference context is recoverable
    • losing execution instructions breaks the cycle entirely

Regression coverage was added in test/prompt.test.js:

  • a 9KB HEAVY_DIFF marker that must never appear in the rendered prompt
  • an EXEC_MARKER that must always survive truncation

Verified by surgically reverting only the src changes — all new assertions fail with the expected regression messages.

We’ll ship the patch through the normal release pipeline shortly and close this issue once the public mirror lands.

imxyanua avatar May 30 '26 16:05 imxyanua

Fixed and shipped in v1.87.4 (@evomap/[email protected], latest on npm).

Two-layer fix in src/gep/prompt.js, along exactly the lines you measured:

  1. PREVIEW_STRIP_FIELDS removes the bloated preview fields (capsule.diff, compact_diff, execution_trace, gene.learning_history, gene.evolution_history, gene.anti_patterns, failed_attempts) before formatAssetPreview() runs, while preserving ids / summaries / scores.
  2. An execution-context floor (EXEC_FLOOR = 8000): if the prefix still exceeds the budget, the prefix is truncated instead of zeroing out Context [Execution].

Verified against the published 1.87.4 binary — the #552 regression suite runs green on the shipped prompt.js:

# test/prompt.test.js (public issue #552)
ok - keeps Context [Execution] non-empty under heavy preview bloat (#552 regression)
ok - floor protection truncates the prefix, not Execution, when maxChars is tight
# tests 11  # pass 11  # fail 0

Please upgrade and confirm Context [Execution] is no longer ...[TRUNCATED].... Closing as fixed — reopen if it recurs. Thanks @zhuyankarl for the byte-accurate breakdown; the Hint-vs-Execution split pointed straight at the truncator math.

autogame-17 avatar Jun 03 '26 08:06 autogame-17