Skip to content

fix(harness): unify compaction overflow recovery and redact session log media sources - #3568

Open
dargoner wants to merge 2 commits into
agentscope-ai:mainfrom
dargoner:fix/compaction-recovery-redact-events
Open

dargoner wants to merge 2 commits into
agentscope-ai:mainfrom
dargoner:fix/compaction-recovery-redact-events

Conversation

@dargoner

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (based on main @ 5f7f8e6)

Description

Background

Hardening work on the context-compaction pipeline surfaced three gaps in overflow recovery and observability:

  1. Divergent recovery paths. Normal compaction and the emergency context-overflow retry used different code paths. The emergency retry could commit the compaction candidate history before the retry succeeded, and when the retry failed, the retry error masked the original overflow cause.
  2. Session log media leakage. SessionRecorder redacted top-level text, but media embedded inside ToolResult blocks (base64 payloads, inline file bytes) was still written into the session log request/prepared events.
  3. Weak lifecycle observability. Compaction start/end events were not emitted as consistent pairs across the normal and emergency paths, and cancellation between the two paths was not isolated.

Changes

  • Unify compaction overflow recovery (CompactionMiddleware, ConversationCompactor, HarnessAgent): one recovery path for normal and emergency compaction; an emergency retry no longer commits candidate history early; when the retry fails, the first overflow is preserved as the primary cause via initCause.
  • Redact session log media sources (SessionRecorder): request/prepared events recursively redact media nested inside ToolResult blocks while preserving the surrounding structure.
  • Compaction lifecycle events (HarnessAgent, CompactionMiddleware): start/end event pairs are emitted consistently with cancel isolation hardened; failure logs are redacted.
  • Memory middleware follow-ups (MemoryFlushMiddleware, MemoryMaintenanceMiddleware, MemoryFlushManager): log redaction in failure paths.
  • Docs: session-log.md, context.md and memory.md (EN/ZH) updated for the new event semantics and log fields.

Tests

  • Core: ReActSessionLogTest 5 → 7 cases (media-source redaction).
  • Harness: HarnessAgentTest 55 → 57, ConversationCompactorTest 8 → 19, CompactionMiddlewareTest 11 → 23.
  • Full agentscope-core + agentscope-harness suites: BUILD SUCCESS (harness 1270 tests, 0 failures; the 18 skips are Windows/docker environment markers).
  • mvn spotless:check passes; docs npm test / npm run check pass.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

@dargoner
dargoner force-pushed the fix/compaction-recovery-redact-events branch from 53e24d2 to 436bd3b Compare October 29, 2026 11:58
@mintlify

mintlify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit e78b44f.

Approve preview

@jujn jujn added the P2 重要不紧急 label Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants