fix(sessions): use system prompt and fallback model for compaction#497
fix(sessions): use system prompt and fallback model for compaction#497sytone wants to merge 1 commit into
Conversation
… fix gpt-4.1 empty content - Move compaction instruction to Context.SystemPrompt (was null) so models like gpt-4.1 receive the summarization directive as a system role, not user content - Split BuildSummarizationPrompt into (systemPrompt, userMessage) tuple - Add TryGetSummaryAsync extracted helper with improved debug logging of all content types returned by the provider - Add ResolveFallbackModel: when primary model returns empty content, retry with the first available default-list model that isn't the primary; last-resort fallback to any other registered model - 3 new tests: ContextHasSystemPrompt, PrimaryReturnsEmpty_RetriesWithFallbackModel, PrimaryAndNoFallback_AbortsCleanly - 1639/1639 gateway tests pass Closes #496
Review -- fix(sessions): use system prompt and fallback model for compactionCI: All checks passing Root cause addressed: Context.SystemPrompt was null when calling the compaction model. gpt-4.1 refused a user-only prompt and returned 0 content items. The #366 abort guard protected history but compaction never succeeded. Fix quality:
LGTM -- ready to merge. |
|
CI: ✅ All checks passing LGTM — ready to merge. |
sytone
left a comment
There was a problem hiding this comment.
Farnsworth Review — PR #497
CI: ✅ All checks passing
Merge conflicts: ✅ Clean (MERGEABLE)
Conventional commit title: ✅ fix(sessions): use system prompt and fallback model for compaction
Test coverage:
- ✅ System prompt populated for compaction request
- ✅ Fallback model retry on empty content
- ✅ Non-empty content path (no retry)
- 3 new tests; 1639/1639 pass
Spec completeness vs #496: Root cause correctly identified (gpt-4.1 refuses user-only prompt). System prompt + fallback model retry is the right fix. ResolveFallbackModel fallback chain is sound.
LGTM. Ready to merge.
|
Closing as part of a planned hard-reset of the in-flight branch set so the new domain-model refactor can land on a clean trunk. Audit verdict: close Rationale: Compaction is fundamentally rewritten in Phase 3a (mark-not-delete). This patch will not apply meaningfully to the new shape; re-fix on the new compactor. The new plan (in session state) reshapes core types: Citizen (User+Agent union), Vogen-generated value objects, ThreadId removed in favour of composite ChannelAddress, mark-not-delete compaction, centralised If this work is still wanted, refile as a new issue/PR against the post-refactor contracts. |
Closes #496
Problem
gpt-4.1via thecopilotprovider returns structurally empty content on every compaction attempt. The#366abort guard fires correctly (history is preserved), but compaction never succeeds — sessions grow indefinitely.Root cause:
CallLlmForSummaryAsyncsentSystemPrompt: nullin theContext. Models likegpt-4.1that require a system-role directive for summarization refuse the user-only prompt and return 0 content items.Changes
LlmSessionCompactor.csBuildSummarizationPromptnow returns a(systemPrompt, userMessage)tuple instead of a single string. The summarization instruction is sent asContext.SystemPrompt, not as part of the user message.CallLlmForSummaryAsynccallsResolveFallbackModeland retries with the first available alternative fromDefaultSummaryModelIds(excluding the primary). Last-resort fallback to any registered model that isn't the primary.TryGetSummaryAsyncnow logs all content type names (not just count) for easier diagnosis of future empty-response events.LlmSessionCompactorTests.csCompactAsync_ContextHasSystemPrompt— assertsContext.SystemPromptis non-null/non-emptyCompactAsync_PrimaryReturnsEmpty_RetriesWithFallbackModel— verifies fallback model is called and produces successful compactionCompactAsync_PrimaryAndNoFallback_AbortsCleanly— verifies clean abort when no fallback available (history unchanged)1639/1639 gateway tests pass.