Skip to content

feat(compact): reuse stable+context assembler prefix - #115

Merged
divo12 merged 3 commits into
feat/prompt-cache-controlfrom
feat/compact-same-assembler
Aug 12, 2026
Merged

divo12 merged 3 commits into
feat/prompt-cache-controlfrom
feat/compact-same-assembler

Conversation

@divo12

@divo12 divo12 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

User description

Summary

Stack

Base: feat/prompt-cache-control (#113) → this PR (Batch C).

Test plan

  • uv run pytest tests/test_prompts/test_system_prompt.py tests/test_services/test_compact/test_summariser.py tests/test_factory.py -q
  • CI green

Made with Cursor


CodeAnt-AI Description

Share stable session context with conversation compaction

What Changed

  • Compaction summaries now use the same stable standing orders as live sessions, allowing provider prompt caches to recognize the shared prefix
  • Workspace governance, skills, and memory information remains available to the summarizer in the user context instead of being mixed into the cached system content
  • Tool results are included in transcript excerpts so summaries retain relevant tool output
  • Session prompt assembly now exposes the shared stable-and-context prefix without role-specific instructions

Impact

✅ Lower prompt processing cost during compaction
✅ Consistent summarization instructions across live turns and compaction
✅ Fewer missing tool-result details in conversation summaries

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Compaction shares Dream-owned common standing orders via
CompactionPromptParts / OpenAIChatMessage envelopes (workspace context
stays on the user message). Stacked on cleaned #113; no context pie
reimplementation.

Co-authored-by: Cursor <cursoragent@cursor.com>
@codeant-ai

codeant-ai Bot commented Aug 12, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 1f95c73 Aug 12, 2026 · 10:55 10:58

@codeant-ai

codeant-ai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divo12 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Aug 12, 2026
Comment thread src/dream/_factory.py Outdated
# with live turns) and keeps workspace catalogues in the user message.
compact_prompt = CompactionPromptParts(
stable_prefix=assemble_stable_context_prefix(
stable=StablePromptBlock(role=None),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The compact request uses only the common standing orders, while live planner/generator/evaluator sessions use a role-specific <stable> block. Because the cache breakpoint is placed at the end of each complete stable block, these requests have different cache-prefix boundaries and will not reuse the live-turn cache as intended. Build the compact prefix from the same stable block or explicitly share a breakpoint at the common portion. [performance]

Severity Level: Major ⚠️
- ⚠️ Planner compaction misses live-turn cache reuse.
- ⚠️ Generator compaction incurs additional prompt processing.
- ⚠️ Evaluator summarisation may increase provider latency and cost.

Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/dream/_factory.py
**Line:** 824:824
**Comment:**
	*Performance: The compact request uses only the common standing orders, while live planner/generator/evaluator sessions use a role-specific `<stable>` block. Because the cache breakpoint is placed at the end of each complete stable block, these requests have different cache-prefix boundaries and will not reuse the live-turn cache as intended. Build the compact prefix from the same stable block or explicitly share a breakpoint at the common portion.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment thread src/dream/_factory.py Outdated
memory_catalogue="",
),
),
workspace_context=context_block.render(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Passing the entire rendered context places workspace-controlled AGENTS.md, governance, tool, skill, memory, and subagent text into the summariser's user prompt. The summariser's “reference only” wording does not prevent instruction-like content from influencing the generated rolling summary, so a workspace catalogue can inject or distort durable context that is later fed back into the session. Restrict this input to non-instructional catalogue data or treat it as untrusted data during summarisation. [security]

Severity Level: Major ⚠️
- ❌ Malicious AGENTS.md can distort rolling summaries.
- ⚠️ Compacted summaries persist injected workspace instructions.
- ⚠️ Later live turns consume the contaminated summary.

Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/dream/_factory.py
**Line:** 831:831
**Comment:**
	*Security: Passing the entire rendered context places workspace-controlled AGENTS.md, governance, tool, skill, memory, and subagent text into the summariser's user prompt. The summariser's “reference only” wording does not prevent instruction-like content from influencing the generated rolling summary, so a workspace catalogue can inject or distort durable context that is later fed back into the session. Restrict this input to non-instructional catalogue data or treat it as untrusted data during summarisation.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +111 to +112
if isinstance(block, ToolResultBlock):
return block.content

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The caller passes the unconstrained result of response.json() to _summary_text_from_payload, whose implementation assumes a mapping and calls .get(). A non-object JSON response from a gateway will raise AttributeError instead of the summariser's intended controlled RuntimeError, causing compaction to fail with an unrelated error. Validate that the decoded payload is a mapping before parsing it. [logic error]

Severity Level: Major ⚠️
- ⚠️ Full compaction omits tool failure metadata.
- ⚠️ Rolling summaries may misstate failed operations.
- ⚠️ Subsequent turns lose continuity about failed tools.

Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/dream/services/compact/_summariser.py
**Line:** 111:112
**Comment:**
	*Logic Error: The caller passes the unconstrained result of `response.json()` to `_summary_text_from_payload`, whose implementation assumes a mapping and calls `.get()`. A non-object JSON response from a gateway will raise `AttributeError` instead of the summariser's intended controlled `RuntimeError`, causing compaction to fail with an unrelated error. Validate that the decoded payload is a mapping before parsing it.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

divo12 and others added 2 commits August 12, 2026 16:32
Use live stable_block.render() for compact cache prefix alignment,
restrict workspace context to skill/memory catalogues only, add typed
OpenAIAssistantToolMessage wire types, CompactionChatRequest, and
validate summariser JSON payloads before parsing.

Co-authored-by: Cursor <cursoragent@cursor.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divo12 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@divo12
divo12 merged commit 226466b into feat/prompt-cache-control Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant