Skip to content

fix(memory): release inactive streaming turn builds - #1157

Merged
xintaofei merged 1 commit into
spacering-net:mainfrom
kogekiplay:fix/memory-streaming-cache-lifetime
Nov 15, 2026
Merged

xintaofei merged 1 commit into
spacering-net:mainfrom
kogekiplay:fix/memory-streaming-cache-lifetime

Conversation

@kogekiplay

@kogekiplay kogekiplay commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Closing a conversation after it has rendered a streamed reply leaves the reply's complete constructed turns in the module-level lastStreamingBuilds cache. Completing the turn, replacing the live message, and the public store reset leave the same cache root behind. The eight-entry LRU bounds the number of replies, but has no payload bound and retains inactive replies until eight later builds evict them (or the global reset helper runs).

The retaining chain is lastStreamingBuilds -> BuiltStreamingTurns.turns -> MessageTurn.blocks, including text and tool-result payloads. This cache was introduced by 323c7cabc and is intended to reuse unchanged rounds of an active stream.

This change scopes reuse to each runtime session's current live-message id. Runtime transitions release obsolete message builds; conversation removal and migration release the old conversation's builds, and the public reset clears the cache. Completed reply objects remain in localTurns, and unrelated live streams keep their existing object identities.

Validation:

  • Six lifecycle regression cases cover close, completion/promotion, replacement, reset, migration, and active-stream reuse across unrelated updates. The four original close/completion/replacement/reset regressions all fail against unmodified main.
  • Full frontend suite: 787 files / 11,681 tests passed.
  • TypeScript, changed-file ESLint, Prettier and git diff --check passed.
  • Production frontend build passed.
  • A separate Node worker with explicit GC tested three tiny synthetic streamed replies. After all runtime sessions were removed, the original code retained all three turn objects while a persisted-turn control was collectible. The three became collectible only after LRU eviction. With this change, all three were collectible immediately after session removal. No desktop GC, debugger attach, or native heap snapshot was used.

Post-install verification on macOS:

  • A local 0.44.0 candidate containing this fix, the default-off diagnostics from feat(memory): add opt-in frontend lifecycle diagnostics #1151, and the independent connection-inventory fix from fix(acp): report live connection status #1152 completed one controlled 96-line / 7,215-character streamed text reply. Closing its tab returned frontend/backend connection counts, runtime-session count, subscriptions and live-text size to their previous values.
  • The same WebContent process nevertheless stayed near a 579 MiB physical-footprint floor for a complete 30-minute post-close window, versus a pre-output window with a median near 278 MiB. These are candidate workloads without a matched unpatched desktop control; first-use allocation, the full desktop shell and other retaining paths remain unseparated.
  • A second same-size native reply did not add another comparable persistent increment: footprint fell from about 581 MiB before creation to 394 MiB after tab close, then settled around 408–418 MiB in later windows. Visible output matched, but model timing/chunking was not controlled. The non-monotonic response leaves first-use allocation, collection timing and other retaining paths unseparated.
  • All ten CI jobs passed for ab6809292ed72c1b97ae3698985982a83059717c.

Evidence boundary: this is confirmed bounded retention of inactive streaming builds, with object reachability verified by the isolated probe above. The native desktop observation does not establish its contribution to the reported long-term WebContent physical-footprint growth, and the higher post-close footprint remains under investigation. This PR does not claim that the broader memory problem is resolved. A matched unpatched desktop workload and a native retaining/allocation source remain to be established.

@xintaofei

Copy link
Copy Markdown
Collaborator

Review: approved, ready for production as the scoped fix it describes. I made no changes on top.

Approach. Pruning lastStreamingBuilds in the store's dispatch wrapper (src/stores/conversation-runtime-store.ts:4423) enforces what the cache's own doc already says (:1666): each runtime session keeps at most one build, the one for its current liveMessage.id. What I checked:

  • Every state write goes through dispatch except resetConversationRuntimeStore, which already clears the cache (:5432).
  • All three production builders key by ${conversationId}:${liveMessage.id}: the timeline (:4354), COMPLETE_TURN (:2648) and late reports (:2309).
  • Pruning runs after the reducer, so promotion still hands the cached objects to localTurns. Late reports compare with JSON.stringify and dedupeTimeline dedupes by key, so neither relies on object identity.
  • The ${id}: prefix can't match a different conversation (1 vs 11, or the negative draft ids from draftRuntimeConversationId).
  • When MIGRATE_CONVERSATION is a no-op (from === to, or a missing source on canvas mounts), it only prunes the target down to its active build.

A second, independent review reached the same conclusion: no blocking issues.

Verification

  • I ran the new tests against main's store: 5 of 6 fail (close, completion, replacement, reset, migration). The active-reuse guard passes on both, as it should.
  • tsc --noEmit, pnpm lint . and pnpm build pass.
  • pnpm test: 11,677/11,681 passed. The 4 failures are 5 s timeouts in unrelated files (forge-page.selection, aux-panel-git-changes-tab) under heavy load, and both files pass when run on their own.
  • CI on this head is 10/10 green.

Non-blocking notes

  • Low severity, already present before this PR: when the same conversation is open in a workspace tab and on a canvas card, each connection makes its own live-message id (src/contexts/acp-connections-context.tsx:1684, :2362). Both sinks write the same runtime session (src/components/conversations/conversation-detail-panel.tsx:963, src/components/canvas/canvas-conversation-surface.tsx:527). If the ids keep alternating, this PR adds cache misses on top. No content is lost and promotion is unaffected. Row keys already follow turn ids, so the extra cost is small. It deserves its own look.
  • Optional: explicit active-cache assertions for migration no-ops and negative draft ids.

I agree with the PR's evidence boundary: this doesn't establish the cause of the long-term WebContent footprint growth.


🤖 Generated with Codeg

@xintaofei
xintaofei merged commit a89ab49 into spacering-net:main Nov 15, 2026
10 checks passed
xintaofei added a commit that referenced this pull request Nov 15, 2026
This release keeps tasks running while agents finish background work, makes configuration sync safer and adds appearance settings to it, adds Claude Code cache mode settings, reduces memory retained after closing conversations, and updates several agents.

## New

- **Tasks and automation runs now wait for background work to finish.** Previously a run could end, and its background commands or sub-agents be cut off, as soon as the agent's reply finished. Now the run stays open until that work completes and the agent's follow-up reply arrives, and that reply becomes the run's summary. The task card shows how many background jobs are still running and offers a "Stop waiting" action.
- **Configuration sync now includes appearance settings**: light/dark mode, theme color, zoom, fonts, background display and custom styles.
- **New Cache mode settings in the Claude Code config panel**, with switches for the one-hour prompt cache of the main conversation and of sub-agents.

## Improved

- **Updated Claude Code (claude-agent-acp 0.107.0) and OpenCode to 2.3.0, DeepSeek to 0.11.0, Cursor to 2026.11.13, Kimi Code to 2.6.2, Qoder to 1.1.89, ZCode to 0.85.2 and Command Code to 1.89.1.** The DeepSeek settings follow the new version's setup: it uses the Anthropic-compatible endpoint by default and requires Node.js 22.19.0 or later.

## Fixed

- **Configuration sync no longer overwrites settings uploaded from another machine.** Fresh installs and machines that have not synced in a while no longer replace a newer remote snapshot. Instead, you can see where the snapshot came from and choose to restore it or replace it. Opening codeg in a new browser also no longer resets the server's appearance settings. (#1149, reported by @zinsser901224)
- **Reduced memory retained after closing a conversation that showed a streamed reply.** (#1157 by @kogekiplay)
- **Connected agent sessions are no longer shown as "connecting".** (#1152 by @kogekiplay)

Thanks to @kogekiplay for contributing to this release, and to @zinsser901224 for reporting the sync issue.

-----------------------------

# 发布版本 0.45.0

这一版让任务等智能体的后台工作完成后再结束,提升配置同步的安全性并支持同步外观设置,新增 Claude Code 缓存模式设置,减少关闭会话后的内存残留,并更新多个智能体。

## 新增

- **待办任务和自动化运行会等后台工作完成后再结束。** 以前智能体一回复完,运行就可能结束,后台命令或子智能体也会被中断。现在会等这些工作完成、智能体发出后续回复后再结束,并以这条回复作为运行总结。任务卡片会显示仍在运行的后台工作数量,也可以随时「停止等待」。
- **配置同步现在包含外观设置**:明暗模式、主题色、缩放、字体、背景显示和自定义样式。
- **Claude Code 配置面板新增「缓存模式」设置**,可分别开关主会话和子智能体的一小时提示词缓存。

## 改进

- **Claude Code(claude-agent-acp)更新至 0.107.0,OpenCode 更新至 2.3.0,DeepSeek 更新至 0.11.0,Cursor 更新至 2026.11.13,Kimi Code 更新至 2.6.2,Qoder 更新至 1.1.89,ZCode 更新至 0.85.2,Command Code 更新至 1.89.1。** DeepSeek 设置已适配新版的配置方式:默认使用 Anthropic 兼容接口,并要求 Node.js 22.19.0 及以上版本。

## 修复

- **配置同步不再覆盖其他设备上传的配置。** 新安装或久未同步的设备不会再替换云端较新的快照,而是显示快照的来源,由你选择恢复还是替换。在新浏览器中打开 codeg 也不会再重置服务器上的外观设置。(#1149,由 @zinsser901224 反馈)
- **减少关闭显示过流式回复的会话后的内存残留。**(#1157 by @kogekiplay)
- **修复已连接的智能体会话被显示为「连接中」的问题。**(#1152 by @kogekiplay)

感谢 @kogekiplay 为本次发布做出的贡献,也感谢 @zinsser901224 反馈同步问题。
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.

2 participants