From a5c10d594dfef7b02f08d52e91d521f8035901d6 Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Thu, 30 Apr 2026 16:38:55 +0000 Subject: [PATCH] =?UTF-8?q?fix(streaming):=20persist=20context=5Flength=20?= =?UTF-8?q?on=20session=20=E2=80=94=20completes=20#1318=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pre-release Opus + nesquena review on v0.50.246 caught that PR #1341 added the data-structure scaffolding (Session.__init__ accepts the 3 fields, save() persists them, compact() exposes them, GET /api/session returns them) but did NOT add the writer that actually populates them. Without a writer, the user-visible bug (context-ring shows 0% after page reload) was NOT fixed by #1341 alone — the fields stayed None forever because nothing wrote to s.context_length anywhere. Adds the writer at api/streaming.py:2188 (post-merge per-turn save block, before s.save()) so the values from agent.context_compressor land on disk and survive page reloads. Also moves the SSE usage payload comment to clarify that the live SSE payload and the session-level persistence are now distinct paths (payload below, persistence above). Adds tests/test_pr1341_context_window_persistence.py — 6 structural + round-trip tests covering Session __init__/save/compact, the routes response, and the streaming.py writer placement. Closes #1318 (the actual user-visible bug, not just the scaffolding). --- CHANGELOG.md | 2 +- api/streaming.py | 15 +- .../test_pr1341_context_window_persistence.py | 142 ++++++++++++++++++ 3 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 tests/test_pr1341_context_window_persistence.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c60500e..aca5c160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - **Activity panel no longer auto-collapses when new tool/thinking events arrive** — Both `ensureActivityGroup()` (which re-creates the group with `tool-call-group-collapsed` on every destroy/recreate) and `finalizeThinkingCard()` (which force-adds the collapsed class on every tool boundary) ignored the user's manual expand. Tracks the user's last explicit toggle on the live activity group in a per-turn singleton (`_liveActivityUserExpanded`), restored on re-create and respected by the finalize path. Cleared between turns by `clearLiveToolCards()`. (`static/ui.js`, `tests/test_issue1298_cancel_and_activity.py`) — fixes #1298 (issue 1) - **Stale Mermaid render errors no longer leak into every chat** — Mermaid's render-failure path leaves a temporary `
` body-level node containing a "Syntax error in text" SVG. The previous code never removed it, so once any Mermaid block failed (or got mis-detected as Mermaid), every subsequent tab kept the syntax-error SVG visible regardless of content. Also tightens Mermaid detection so line-numbered tool output (`123|line`) and code blocks that don't start with a recognized Mermaid keyword are no longer mis-parsed as Mermaid; failed blocks are marked so a later render pass can't retry them. (`static/ui.js`, `tests/test_issue347.py`) @dso2ng — PR #1337 - **Static asset cache busts automatically on every release** — `