Repository navigation
fix(harness): respect disabled memory hooks during compaction - #2699
RICARDO51167 wants to merge 4 commits into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes issue #2694 where disableMemoryHooks() did not fully suppress long-term memory flush during compaction. The fix introduces an immutable withFlushBeforeCompact(boolean) copy method on CompactionConfig and derives an effective config in both the normal compaction middleware path and the emergency context-overflow path (forceCompactAndRetry), forcing flushBeforeCompact=false when memory hooks are disabled.
The approach is clean and minimal: the original CompactionConfig is never mutated (immutable copy via copyBuilder()), the withEffective() method is refactored to share the same helper (DRY), and memoryHooksDisabled is threaded through as a final boolean on the HarnessAgent instance. Javadoc is well-updated on all touched APIs. Test coverage is thorough — four integration scenarios covering both compaction paths plus a dedicated unit test for the withFlushBeforeCompact contract and immutability guarantee.
No critical issues found.
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes issue #2694 where disableMemoryHooks() did not fully suppress long-term memory flush during compaction. The fix introduces an immutable withFlushBeforeCompact(boolean) copy method on CompactionConfig and derives an effective config in both the normal compaction middleware path and the emergency context-overflow path (forceCompactAndRetry), forcing flushBeforeCompact=false when memory hooks are disabled.
The approach is clean and minimal: the original CompactionConfig is never mutated (immutable copy via copyBuilder()), the withEffective() method is refactored to share the same helper (DRY), and memoryHooksDisabled is threaded through as a final boolean on the HarnessAgent instance. Javadoc is well-updated on all touched APIs. Test coverage is thorough — four integration scenarios covering both compaction paths plus a dedicated unit test for the withFlushBeforeCompact contract and immutability guarantee.
No critical issues found.
|
This PR currently conflicts with git fetch upstream
git checkout codex/issue-2694-disable-compaction-flush
git rebase upstream/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Once the conflicts are resolved, comment Automated notification by github-manager-bot |
e8c81bf to
c7eaab2
Compare
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Solid, well-tested fix. disableMemoryHooks() now really means "no memory flush", including inside compaction, and the new withFlushBeforeCompact / copyBuilder() extraction makes both projections expressible. The four behavioural tests in HarnessAgentCompactionMemoryHooksTest cover both hook states, the normal and the overflow flush path, and the explicit-disable case; EN and ZH docs are updated consistently. CI is green, CLA signed, mergeable.
No blocking issue found. The one gap worth tracking is that the emergency path (forceCompactAndRetry) still rebuilds its config from scratch, so it honours the new flush flag but drops the rest of the caller's compaction settings — the same class of asymmetry this PR removes for flush. Details inline.
Automated review by github-manager-bot
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-review after the new commit 21793739 ("preserve compaction config on overflow") — the previous review covered c7eaab2b and still stands. Moving dynamic-default resolution out of CompactionMiddleware into ConversationCompactor.resolveEffectiveConfig fixes a real gap: the overflow-recovery path in HarnessAgent.forceCompactAndRetry used to build a throwaway CompactionConfig, so a user-tuned triggerTokens / keepTokens / truncate / prune / offload config was silently dropped exactly when the context was already overflowing. Inheriting effectiveCompactionConfig.withTriggerMessages(1) is the right shape, the shallow-copy javadoc on the new withTriggerMessages is consistent with withEffective, and the added coverage in CompactionConfigTest / ConversationCompactorTest / HarnessAgentCompactionMemoryHooksTest matches the change. CI is green (7/7).
Findings
- [Warning]
HarnessAgent.java:1076—effectiveCompactionConfigis nullable; the overflow path now depends on an implicitcompactionHook != nullinvariant. - [Warning]
HarnessAgent.java:1085—MemoryFlushManagerswitches from the agent model to the compaction model; confirm that is intended. - [Info]
ConversationCompactor.java:219— public entry point now resolves dynamic defaults for every caller; worth a changelog note. - [Info]
ConversationCompactor.java:272—effectiveKeep = 0fallback collapses to message-based keep on the recovery path (pre-existing, not a regression).
Suggestions
Both warnings are small and non-blocking: a local null guard (or Objects.requireNonNull with a message) next to withTriggerMessages(1), and one sentence in the PR description about the flush-model change. Neither changes the correctness of the fix itself, so no re-review is needed unless you disagree with the model-choice point.
Automated review by github-manager-bot
| : "default"; | ||
|
|
||
| CompactionConfig forceConfig = CompactionConfig.builder().triggerMessages(1).build(); | ||
| CompactionConfig forceConfig = effectiveCompactionConfig.withTriggerMessages(1); |
There was a problem hiding this comment.
effectiveCompactionConfig is still a nullable field — build() only assigns it inside if (!disableCompaction && compactionConfig != null) (line 2611), and the previous code built a throwaway config here so this path could never NPE. Today the invariant holds only implicitly: recoverFromOverflow() gates on compactionHook != null, and both are assigned in the same block. Since this is the emergency overflow-recovery path, a future builder branch that wires compactionHook without the field (or a second constructor path) would surface as an NPE exactly when the agent is already in trouble. Could you make the coupling explicit, e.g. a local fallback (CompactionConfig base = effectiveCompactionConfig != null ? effectiveCompactionConfig : CompactionConfig.defaults();) or Objects.requireNonNull(effectiveCompactionConfig, "compactionHook requires a compaction config"), plus a comment stating compactionHook != null implies the field is set?
There was a problem hiding this comment.
Addressed in ea9e78a: forceCompactAndRetry now uses Objects.requireNonNull with a clear message, and the adjacent comment documents the compactionHook/config invariant.
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Approving on ea9e78a5. That commit answers every point from my review on 21793739, and answers them in the way I would have picked:
forceCompactAndRetryno longer reads a nullable field implicitly —Objects.requireNonNull(effectiveCompactionConfig, ...)makes the "compactionHook and the effective config are created together" invariant explicit at the boundary, with the comment saying so.- The flush-model question is settled rather than papered over: memory extraction stays on
getModel(), only summarisation followsCompactionConfig.model, and that split is now stated in bothdocs/v2/enanddocs/v2/zhplus pinned byflushCallscounters inHarnessAgentCompactionMemoryHooksTest. Reverting the flush to the agent model also keeps this PR's blast radius to "emergency compaction reuses the user's compaction settings", which is the change the title advertises. - The
effectiveKeep = 0fallback is now logged, so a model that reports no context window is at least visible on the recovery path instead of silently degrading to a message-count cutoff. - Release notes got an
Unreleasedentry for theConversationCompactorresolution change — the part that affects callers who use it directly rather than through middleware.
Underlying fix is unchanged from the previous two passes and still correct: resolveEffectiveConfig in the compactor means the overflow-recovery path can no longer diverge from normal compaction, which was the actual bug in #2694.
CI is green on this head (ubuntu + windows build, validate, module-sync, codecov/patch, license/cla). Two non-blocking suggestions are inline — one about asserting the positive half of the flush-model split, one about a second release-notes bullet.
Automated review by github-manager-bot
oss-maintainer
left a comment
There was a problem hiding this comment.
Re-reviewed the new commit (82e112b4) since my previous approval. The delta is test-only plus release-notes lines: emergencyCompactionUsesAgentModelForFlushAndConfiguredModelForSummary now pins which model sees which prompt (flushPromptSeen asserting the memory-extraction prompt reached the reasoning model, and assertNull on the configured compaction model) instead of only counting calls, and RoutingModel records the rendered flush prompt to support it. Renaming the test to match what it now asserts is the right call — the old name promised coverage of the offload setting that the assertions do not check.
The strengthened assertions match the behaviour I verified in the previous pass (flush goes to the agent model, summary goes to the configured model), so the intent of the fix stays pinned. LGTM.
Automated review by github-manager-bot
AgentScope-Java Version
2.0.3-SNAPSHOT
Description
Fixes #2694.
disableMemoryHooks()already disabled per-call memory flush and background consolidation, but normal compaction and the emergency context-overflow path could still flush long-term memory.This PR:
CompactionConfigthat forcesflushBeforeCompact=falsewhen memory hooks are disabled;CompactionMiddlewareinstances;Verification:
mvn -pl agentscope-harness -am -Dtest=HarnessAgentCompactionMemoryHooksTest,CompactionConfigTest,CompactionMiddlewareTest -Dsurefire.failIfNoSpecifiedTests=false testmvn spotless:apply spotless:checkmvn testmvn verifyChecklist
mvn spotless:applymvn test)