Skip to content

fix(runtime): deliver the history-compact instruction as a trailing user message - #4797

Open
ggbdpq wants to merge 1 commit into
apache:mainfrom
ggbdpq:fix/history-compact-trailing-instruction
Open

fix(runtime): deliver the history-compact instruction as a trailing user message#4797
ggbdpq wants to merge 1 commit into
apache:mainfrom
ggbdpq:fix/history-compact-trailing-instruction

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the root cause of #4634: the history summarizer delivered SUMMARIZATION_SYSTEM_PROMPT as provider instructions (system role). Agentic coding models such as kimi-coding-plan / k3-256k ignore that shape and keep answering the conversation, so every fold failed open with malformed_summary_missing_section, and the distinct system prompt also forfeited the main loop's prefix cache for every discarded summarizer call.

The instruction now rides as the request's trailing user message — the request already ended with one for chat-template models (#4559); generateSummary appends a single user message combining the sectioned prompt (or its shorten/repair variant) with the existing summary request, and AiSdkGenerateTextOptions drops the now-unused instructions field.

Scope: direction 1 from the issue. Of the contributing defects listed there, the missing output cap is already fixed on current main by #4653 (DEFAULT_HISTORY_COMPACT_MAX_OUTPUT_TOKENS, landed 09-03, after the reporter's build); extending the failure circuit to provider_error/output_length and bounding the summarizer input budget remain open follow-ups best split into their own issues.

Verification

Claim Command Result
Targeted suites green npm --workspace @maka/core run build && npm --workspace @maka/storage run build && npm --workspace @maka/runtime run build, then node --test on history-compact-summarizer / effective-history-compaction / mid-turn-capacity-backend dist tests 139 tests, 139 pass, 0 fail
Red-green: the new test fails without the fix git stash push -- packages/runtime/src/history-compact-summarizer.ts, rebuild, rerun the summarizer suite 53 tests, 3 fail (the new trailing-instruction test + the two variant-prompt captures); restored → 53/53 pass
New regression test delivers the summarization instruction as the trailing user message (#4634) asserts no instructions field reaches generateText and the final user message carries both the sectioned prompt and the summary request
Format npm run format:check exit 0, 1,942 files clean
License headers npm run check:asf-headers both changed files pass

AI use

Implemented with ZCode (GLM-5.3-Flash): read the issue's reproduction data, traced the summarizer request shape in packages/runtime/src/history-compact-summarizer.ts, and made the minimal request-shape change with a red-green regression test. The commit carries the Generated-by trailer.

Checklist

  • Root-cause fix in the shared summarizer builder; no per-provider branching requested by the issue
  • Regression test fails on the old code (verified via stash/rebuild)
  • Test style follows the existing file (node:test + assert/strict, issue number in the test name)
  • No new dependencies; docs unchanged

…ser message

The history summarizer sent SUMMARIZATION_SYSTEM_PROMPT as provider
instructions (system role). Agentic coding models such as kimi k3-256k
ignore a system prompt in this shape and keep answering the conversation
instead, so mid-turn compaction failed open forever with
malformed_summary_missing_section (51 consecutive failed-open decisions
observed; 180 history_compact calls and zero checkpoints on one
workspace). A distinct system prompt also started the summarizer request
outside the main loop's cached prefix, so every discarded attempt paid a
full uncached pass (up to 88s observed).

Fold the instruction into the trailing user message the request already
ends with (apache#4559): generateSummary now appends one user message combining
the sectioned prompt (or its shorten/repair variant) with the summary
request, and AiSdkGenerateTextOptions drops the instructions field.

Fixes apache#4634

Generated-by: GLM-5.3-Flash (ZCode)
@github-actions github-actions Bot added the effort/S Under 100 readable lines label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/S Under 100 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant