Skip to content

Isolate default compaction state by strategy type - #1340

Merged
Quim Muntal (qmuntal) merged 1 commit into
microsoft:mainfrom
gabisonia:fix/compaction-state-key-isolation
Oct 30, 2026
Merged

Quim Muntal (qmuntal) merged 1 commit into
microsoft:mainfrom
gabisonia:fix/compaction-state-key-isolation

Conversation

@gabisonia

Copy link
Copy Markdown
Contributor

Compaction context providers currently share the default session key CompactionProvider, so different strategies can reuse each other's saved exclusions. For example, after truncation reduces six messages to two, a sliding-window provider with its trigger disabled also returns only two messages.

Derive the default state key from the concrete strategy's type name, matching the .NET 1.22.0 default. Different built-in strategy types now retain separate state; recreating the same strategy type recovers its existing state, including after session serialization. Explicit StateKey and custom SourceID keys retain their precedence and behavior. Message source attribution is unchanged.

Compatibility: the default persisted key changes. To retain state saved under the old default, set StateKey: "CompactionProvider" explicitly. Providers whose default keys match, including multiple instances of the same strategy type or types with the same unqualified name, still need distinct explicit keys for isolation. The API documentation describes these rules.

Validation:

  • The isolation regression fails against the original implementation and passes with this change.
  • Executed equivalent scenarios against the published .NET 1.22.0 assembly at revision 0c9944cc9f577d51277ac7c55dbc388b60a577af: the second strategy preserves all six messages, while the recreated original strategy retains its two-message view, both before and after session restoration.
  • Verified custom function, pointer, and unnamed-wrapper strategies, key overrides, and legacy-state restoration. A separate migration check read a session file written by the original implementation.
  • On the latest upstream main base: go test ./..., go test -race -shuffle=on ./agent/compaction, and repository-wide golangci-lint run pass on macOS arm64 with Go 1.26.1.
  • Formatting and git diff --check pass. Linux/Windows compaction test cross-compilation also passed during review; runtime coverage remains with CI.

This PR is independent of #1339.

Copilot AI balanced review requested due to automatic review settings October 29, 2026 23:43
@gabisonia
Irakli Gabisonia (gabisonia) requested a review from a team as a code owner October 29, 2026 23:43
@github-actions github-actions Bot added the area:agent Changes files in the agent area label Oct 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the change to isolate default compaction state by strategy type.

No open issues 🎉

What changed in this PR

This PR isolates compaction providers’ default session state by strategy type, preventing different strategies from inheriting each other’s saved exclusions.

Changes:

  • Derives default state keys from concrete strategy type names while preserving explicit StateKey, custom SourceID, and message attribution behavior.
  • Documents key collisions and how to retain legacy state using StateKey: "CompactionProvider".
  • Adds regression coverage for strategy isolation, provider recreation, session serialization, custom strategies, and legacy-state restoration.
File Description
agent/​compaction/​provider.go Implements strategy-based default state keys and documents compatibility rules.
agent/​compaction/​equality_test.go Verifies built-in strategy keys, override precedence, and unchanged source IDs.
agent/​compaction/​compaction_test.go Tests state isolation, recreation, serialization, custom strategies, and legacy restoration.

Review effort: Balanced

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

API consistency review

Result Scope
aligned user-visible behavior

Changed Go contract

No exported identifiers changed. compaction.ContextProviderConfig.StateKey docs and the default changed: with no StateKey and no explicit SourceID, the default session state key is now the concrete strategy's unqualified type name (previously the shared CompactionProvider). Explicit StateKey and SourceID precedence is unchanged, and source attribution is unchanged.

Upstream evidence reviewed

Implementation Source Contract checked
.NET CompactionProvider constructor stateKey ??= this._compactionStrategy.GetType().Name; the doc says to provide an explicit key when different strategies share a session.

Assessment

Go now matches the .NET default: the state key is derived from the strategy type name, and an explicit key overrides it. The SourceID-as-key fallback is Go-specific and has no .NET counterpart, so it is not a parity concern. The persisted default key change is a compatibility note that the PR documents. I did not compare the Python compaction provider.

Generated by Go API Consistency Review Agent · copilot · auto · 26.5 AIC · ⌖ 0.612 AIC · ⊞ 4.9K · ◷

@qmuntal
Quim Muntal (qmuntal) added this pull request to the merge queue Oct 30, 2026
Merged via the queue into microsoft:main with commit 73d2634 Oct 30, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Changes files in the agent area parity-approved Go API consistency review found no parity issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants