Skip to content

ENG-664: persist + replay anton's history summary instead of resending full history - #192

Draft
ea-rus wants to merge 9 commits into
stagingfrom
feat/eng-664-conversations-resend-the-full-history
Draft

ENG-664: persist + replay anton's history summary instead of resending full history#192
ea-rus wants to merge 9 commits into
stagingfrom
feat/eng-664-conversations-resend-the-full-history

Conversation

@ea-rus

@ea-rus ea-rus commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Every turn, cowork rebuilt initial_history from all of a conversation's messages. Anton already compacts old turns into a summary once context pressure crosses threshold, but that summary lived only in the throwaway per-turn ChatSession — cowork saved just the assistant's text, so the next turn rebuilt from raw rows and the summary was gone. Input kept growing every turn until it hit the context window, and once a conversation was long enough, every turn paid for a fresh summarization call that was immediately discarded.

  • Conversation gains history_summary / history_summary_cutoff_id (migration b3d7f1a9c5e2, no FK on the cutoff id — a stale/missing id falls back to full history rather than blocking message deletion).
  • ConversationService.update_history_compaction persists the summary + cutoff. History replay reuses the existing get_ordered_messages — a stable order is what makes the cutoff meaningful (the bare conversation.messages relationship has none).
  • AntonHarness._seed_history builds initial_history as [summary] + [messages after cutoff] when the saved compaction is still valid, else full history (automatic fallback when the summary/cutoff looks stale). Inserts the same assistant separator anton's own _summarize_history uses when the tail would otherwise start with a user-role message (avoids two consecutive user messages, which most providers reject).
  • AntonHarness._persist_history_compaction reads session.last_compaction after a turn and saves it, in its own try/except in stream_response's finally so a persistence failure never masks the turn's real outcome. Reads session.last_compaction via getattr(..., None) — an anton build predating this property no-ops here instead of raising; cowork-server and anton deploy independently.
  • New history_compaction_enabled setting (default True, mirrors memory_enabled) — off reverts to full-history-every-turn and skips persistence; deleting a conversation's saved summary has the same effect for just that one conversation.

Test plan

  • Migration applies/downgrades/re-applies cleanly on a fresh sqlite DB.
  • New tests/test_history_compaction.py: _seed_history (full history / valid cutoff / stale cutoff fallback / tail-starts-with-user separator), _persist_history_compaction (no-op cases, first compaction, offset math with the separator, old-anton version-skew no-op), settings flag default/override.
  • New tests/test_history_compaction_plateau.py: a 30-turn simulation against the real ChatSession + ConversationService + AntonHarness code (only the LLM calls are mocked) — chars/turn levels off (~800–950) instead of growing unboundedly (disabled control run reaches 4265 by turn 30); an early-turn fact stays recoverable via the summary after compaction. Guarded by skipif(not hasattr(ChatSession, "last_compaction")) so it skips cleanly until the anton pin carries fix(settings): reduce settings desync — single source of truth + atomic writes #249.
  • Fixed three existing tests (test_channel_context.py, test_trace_tags_forwarding.py, test_anton_turn_capture.py) whose _build_chat_session mocks returned the old 2-tuple.
  • Full suite: 671 passed, 1 skipped. (Two test_build_llm_client.py failures appear only when running against a local anton source checkout — a provider-key-resolution discrepancy unrelated to this change; both pass under the pinned anton used in CI.)

🤖 Generated with Claude Code

Dependent on mindsdb/anton#249
Fixes https://linear.app/mindsdb/issue/ENG-664/conversations-resend-the-full-history-every-turn-and-throw-away-the

@ea-rus
ea-rus changed the base branch from jorge/eng-648-utility-model-settings to staging July 27, 2026 14:15
@ea-rus
ea-rus changed the base branch from staging to jorge/eng-648-utility-model-settings July 27, 2026 14:17
@ea-rus
ea-rus force-pushed the feat/eng-664-conversations-resend-the-full-history branch from 27562f7 to acaa001 Compare July 28, 2026 10:24
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ea-rus
ea-rus changed the base branch from jorge/eng-648-utility-model-settings to staging July 28, 2026 10:24
@github-actions

Copy link
Copy Markdown

No PR environment for this pull request

Add the deploy label and push to create one. It is torn down when the label is removed or the PR closes, so any URL you saw here earlier is gone.

Updated on every push to this PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant