[Feature]: Entity-preserving context condensation (anchor retention for exact IDs, hashes, and redacted values)

Open
#6,995 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@zsicheng0214 is already working on this.

Since Nov 19, 2026.

  • #6998 by @zsicheng0214 — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Read openhands-sdk/openhands/sdk/context/condenser/prompts/summarizing_system.j2, LLMSummarizingCondenser._build_summary_messages, and CondensationSummaryEvent.to_llm_message(); inspect Condensation and tests under tests/sdk/context/condenser/. Run the condenser unit tests first, then check event serialization and the TypeScript schema mirror. Done means the prompt preserves exact literals, the replacement message identifies the forgotten event span, and optional size metadata is covered by tests. An open linked pull request (#6998) is already addressing this issue.

Written by the indexing model from the issue text.

Description

priority:medium ready-for-dev
Is there an existing feature request for this?
  • I have searched existing issues and feature requests, and this is not a duplicate.
Problem or Use Case

During long-horizon tasks with large file reads, LLM-based condensation summarizes evicted turns into prose. While high-level task intent survives, exact load-bearing literals observed only in evicted turns (such as certificate thumbprints, SHA digests, ISO timestamps, ticket IDs, or pre-redaction audit values that were intentionally removed from workspace files) are routinely paraphrased or dropped by the summarizer.

In our evaluation on TraceTrial-Bench (arXiv:2610.32285, mechanism node C2 — C2-cert-rotation-redaction-001 & C2-depbump-redaction-002), OpenHands triggered native condensation as expected (hr_native_compaction_after_pressure passed), but 0/6 exact suffix/timestamp values survived in the active summary (hr_active_summary_preserved_sensitive_details=False), directly causing downstream deliverable failures (harness_caused).

Desired Behavior

Enhance the SDK condenser (LLMSummarizingCondenser / Condensation) with entity-anchor preservation:

  1. Update the condensation prompt and/or pre-extraction pass to explicitly preserve exact identifiers, hashes/thumbprints, timestamps, numeric totals, file paths, and anomaly/task IDs encountered in forgotten events inside a structured <preserved_facts> / key-value block within the summary.
  2. Expose condensation metadata on the Condensation event (e.g. range of condensed event IDs and character/token counts before vs. after) so the agent knows exact history boundaries were summarized rather than silently vanished.
Acceptance Criteria
  • LLMSummarizingCondenser preserves exact load-bearing identifiers, digests, timestamps, and numeric figures from condensed events in a dedicated structured section of the summary
  • Model-visible condensation notice clearly indicates the condensed turn/event span
  • Unit and benchmark regression tests verify exact literal survival across condensation boundaries

OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

Scope (verified against the repository): the summarization instructions live in openhands-sdk/openhands/sdk/context/condenser/prompts/summarizing_system.j2, rendered by LLMSummarizingCondenser._build_summary_messages; the model-visible replacement for forgotten events is CondensationSummaryEvent.to_llm_message() (currently a plain user message with no span indication); and the Condensation event already carries forgotten_event_ids and summary_offset. The work is therefore bounded to: (1) extending the rendered summarization prompt so it requires a dedicated structured section (e.g. <preserved_facts>) holding exact load-bearing literals from the summarized events, (2) making the model-visible summary state the condensed span, and (3) recording before/after size metrics on Condensation as optional fields.

Priority: medium. The issue records a reproduced failure of the real condensation workflow (a public TraceTrial-Bench run where native condensation preserved 0/6 measured literals and downstream deliverables failed), which meets the medium bar of a reproduced failure in the actual product/workflow; there are no user support reports or production incidents, so not high.

Non-goals: no deterministic pre-extraction/regex entity pass (prompt-level preservation first; revisit only if shown insufficient); no changes to NoOpCondenser, PipelineCondenser, or condenser sizing defaults (max_size/keep_first); no integration of TraceTrial-Bench into this repository; no changes to secret redaction (existing pydantic_secrets handling untouched). Note: literal survival through an LLM summarizer is stochastic, so the deterministic gates are the rendered-prompt instructions plus the repo's real-LLM condenser integration tests, not a hard "every literal survives" assertion.

Acceptance Criteria
  • The rendered summarization prompt sent to the condenser LLM instructs preserving exact load-bearing literals from the summarized events (identifiers, hashes/thumbprints, timestamps, numeric totals, file paths, and ticket/anomaly IDs) in a dedicated structured section of the summary.
  • After condensation, the user-role message the LLM sees in place of forgotten events states that a condensation occurred and identifies the span it replaces (e.g., the number or range of condensed events).
  • The Condensation event records before/after size metrics for the condensed span (character counts before vs. after, plus token counts where a token count is available) as optional fields with defaults, alongside the existing forgotten_event_ids.
  • Old persisted events still load: Condensation payloads without the new fields and existing CondensationSummaryEvent payloads deserialize and apply to views unchanged, per tests/sdk/event/test_event_serialization.py.
  • Unit tests under tests/sdk/context/condenser/ using the existing mocked-LLM fixture verify the rendered prompt instructions, the new metadata, and the span notice in the model-visible message; existing condenser unit tests still pass.
  • The new optional Condensation fields appear in the agent-server OpenAPI schema and the regenerated clients/typescript/ mirror.
  • The PR adds the integration-test label so the real-LLM condenser integration tests (tests/integration/tests/c02_hard_context_reset.py, c05_size_condenser.py) run against the updated summarization prompt and pass.
Dominant language
Python
Stars
1.4k
Forks
797
Avg merge
1d 17h
Merged PRs (30d)
354

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenHands/software-agent-sdk

All issues in OpenHands/software-agent-sdk

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.