Skip to content

Compaction: preserve opaque identifiers in summaries#25553

Merged
Takhoffman merged 5 commits intoopenclaw:mainfrom
rodrigouroz:codex/pr20038-01
Feb 27, 2026
Merged

Compaction: preserve opaque identifiers in summaries#25553
Takhoffman merged 5 commits intoopenclaw:mainfrom
rodrigouroz:codex/pr20038-01

Conversation

@rodrigouroz
Copy link
Contributor

@rodrigouroz rodrigouroz commented Feb 24, 2026

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: compaction summaries could drift or reconstruct opaque identifiers (IDs, URLs, hashes) instead of preserving exact values.
  • Why it matters: post-compaction context can become unreliable when exact identifiers change.
  • What changed: compaction summarization now always prepends identifier-preservation instructions; added focused tests; added one changelog entry.
  • What did NOT change (scope boundary): no safeguard-mode quality guard/retry logic, no post-compaction memory sync behavior.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • Compaction summaries are instructed to preserve opaque identifiers verbatim by default.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22 + pnpm
  • Model/provider: n/a (unit tests)
  • Integration/channel (if any): n/a
  • Relevant config (redacted): default

Steps

  1. pnpm vitest run src/agents/compaction.identifier-preservation.test.ts
  2. pnpm tsgo
  3. Verify changed files are limited to compaction prompt path + tests/changelog.

Expected

  • Identifier-preservation tests pass and typecheck remains clean.

Actual

  • Local tests passed; pnpm tsgo passed.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: instruction text is injected with and without custom instructions; split/merge summarization keeps the same instruction.
  • Edge cases checked: custom instructions still append under "Additional focus".
  • What you did not verify: live provider behavior in long-running sessions.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert this PR.
  • Files/config to restore: src/agents/compaction.ts
  • Known bad symptoms reviewers should watch for: none expected; only prompt guidance changed.

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: stronger prompt constraints could alter summary style.
    • Mitigation: scope is limited to identifier retention and covered by focused tests.

Greptile Summary

This PR hardens compaction summarization to preserve opaque identifiers (UUIDs, IDs, tokens, hostnames, IPs, ports, URLs, file names) by prepending identifier-preservation instructions to all summarization prompts.

Key changes:

  • Added buildCompactionSummarizationInstructions() helper that always prepends identifier-preservation guidance before any custom instructions
  • Modified summarizeChunks() to use buildCompactionSummarizationInstructions() instead of passing raw customInstructions
  • Fixed merge-path instruction handling in summarizeInStages() to avoid duplicating "Additional focus:" headers
  • Added comprehensive test coverage for all instruction injection paths
  • Unrelated fix: added explicit type parameter <string> to Set in ui/src/ui/external-link.ts:7

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-scoped to prompt instruction assembly with comprehensive test coverage. The implementation correctly prepends identifier-preservation guidance to all summarization paths (chunk, split, and merge). The merge-path fix properly avoids duplicating headers. The unrelated TypeScript typing improvement is a harmless clarification. Tests verify all edge cases including split/merge paths and custom instruction handling.
  • No files require special attention

Last reviewed commit: c4bf3ff

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

CHANGELOG.md Outdated
- Ollama/Qwen: handle Qwen 3 reasoning field format in Ollama responses. (#18631) Thanks @mr-sk.
- OpenAI/Transcripts: always drop orphaned reasoning blocks from transcript repair. (#18632) Thanks @TySabs.
- Fix types in all tests. Typecheck the whole repository.
- Agents/Compaction: harden summarization prompts to preserve opaque identifiers verbatim (UUIDs, IDs, tokens, host/IP/port, URLs), reducing post-compaction identifier drift and hallucinated identifier reconstruction.
Copy link
Contributor

Choose a reason for hiding this comment

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

Changelog entry in released version section

This new entry is placed under the 2026.2.17 section (an already-released version) rather than Unreleased or 2026.2.23 (Unreleased) at the top. Is this intentional for the PR stack ordering, or should it be moved to the unreleased section?

Prompt To Fix With AI
This is a comment left during a code review.
Path: CHANGELOG.md
Line: 624

Comment:
**Changelog entry in released version section**

This new entry is placed under the `2026.2.17` section (an already-released version) rather than `Unreleased` or `2026.2.23 (Unreleased)` at the top. Is this intentional for the PR stack ordering, or should it be moved to the unreleased section?

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I moved this entry from the released 2026.2.17 block to 2026.2.24 (Unreleased) under ### Fixes

@rodrigouroz
Copy link
Contributor Author

@greptileai can you re verify and update the PR description?

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 24, 2026

Additional Comments (1)

src/agents/compaction.ts
Duplicate "Additional focus:" header in merge path

When params.customInstructions is set and the split+merge path fires, mergeInstructions is built with an "Additional focus:\n" wrapper (line 339), then passed as customInstructions to summarizeWithFallbacksummarizeChunksbuildCompactionSummarizationInstructions, which adds a second "Additional focus:\n" wrapper (line 27). The resulting prompt looks like:

Preserve all opaque identifiers exactly as written …

Additional focus:
Merge these partial summaries into a single cohesive summary. …

Additional focus:
<user's custom instructions>

This won't break anything at runtime, but the redundant header is noisy. Consider either:

  • Having buildCompactionSummarizationInstructions handle the merge case too (accepting a structured options object), or
  • Wrapping the merge instructions through buildCompactionSummarizationInstructions explicitly and appending merge-specific text separately.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/compaction.ts
Line: 338-340

Comment:
**Duplicate "Additional focus:" header in merge path**

When `params.customInstructions` is set and the split+merge path fires, `mergeInstructions` is built with an `"Additional focus:\n"` wrapper (line 339), then passed as `customInstructions` to `summarizeWithFallback``summarizeChunks``buildCompactionSummarizationInstructions`, which adds a second `"Additional focus:\n"` wrapper (line 27). The resulting prompt looks like:

```
Preserve all opaque identifiers exactly as written …

Additional focus:
Merge these partial summaries into a single cohesive summary. …

Additional focus:
<user's custom instructions>
```

This won't break anything at runtime, but the redundant header is noisy. Consider either:
- Having `buildCompactionSummarizationInstructions` handle the merge case too (accepting a structured options object), or
- Wrapping the merge instructions through `buildCompactionSummarizationInstructions` explicitly and appending merge-specific text separately.

How can I resolve this? If you propose a fix, please make it concise.

@rodrigouroz
Copy link
Contributor Author

Thanks @greptileai, I added a regression test with your suggestion. Please edit the PR description after you have verified again.

@openclaw-barnacle openclaw-barnacle bot removed the app: web-ui App: web-ui label Feb 24, 2026
rgr4y added a commit to rgr4y/openclaw that referenced this pull request Feb 24, 2026
…penclaw#25553)

Hardens summarization prompts to retain UUIDs, IDs, tokens, host/IP/port,
URLs, and file names verbatim, reducing post-compaction identifier drift and
hallucinated identifier reconstruction.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@openclaw-barnacle openclaw-barnacle bot added docs Improvements or additions to documentation gateway Gateway runtime size: M and removed size: S labels Feb 27, 2026
@Takhoffman Takhoffman merged commit 0fe6cf0 into openclaw:main Feb 27, 2026
29 of 30 checks passed
@Takhoffman
Copy link
Contributor

PR #25553 - Compaction: preserve opaque identifiers in summaries (#25553)

Merged via squash.

  • Merge commit: 0fe6cf0
  • Verified: pnpm install --frozen-lockfile, pnpm build, pnpm check, pnpm test:macmini
  • Changes made:
    CHANGELOG.md
    docs/concepts/compaction.md
    docs/gateway/configuration-reference.md
    src/agents/compaction.identifier-policy.test.ts
    src/agents/compaction.identifier-preservation.test.ts
    src/agents/compaction.ts
    src/agents/pi-embedded-runner/extensions.ts
    src/agents/pi-extensions/compaction-safeguard-runtime.ts
    src/agents/pi-extensions/compaction-safeguard.ts
    src/config/config.compaction-settings.test.ts
    src/config/schema.help.quality.test.ts
    src/config/schema.help.ts
    src/config/schema.labels.ts
    src/config/types.agent-defaults.ts
    src/config/zod-schema.agent-defaults.ts
  • Why these changes were made:
    Make compaction identifier-preservation behavior configurable while keeping strict identifier retention as the default.
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

Thanks @rodrigouroz!

execute008 pushed a commit to execute008/openclaw that referenced this pull request Feb 27, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
xiexikang pushed a commit to cclawd007/cclawd that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
(cherry picked from commit 3b0f73e)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
(cherry picked from commit 3b0f73e)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
(cherry picked from commit 3b0f73e)
vincentkoc pushed a commit to Sid-Qin/openclaw that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
vincentkoc pushed a commit to rylena/rylen-openclaw that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
newtontech pushed a commit to newtontech/openclaw-fork that referenced this pull request Feb 28, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
safzanpirani pushed a commit to safzanpirani/clawdbot that referenced this pull request Mar 2, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
venjiang pushed a commit to venjiang/openclaw that referenced this pull request Mar 2, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
sachinkundu pushed a commit to sachinkundu/openclaw that referenced this pull request Mar 6, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
… thanks @rodrigouroz

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants