Skip to content
This repository was archived by the owner on Jul 30, 2026. It is now read-only.

fix(tui): unify cached snapshots to bound idle memory - #173

Merged
makoMakoGo merged 1 commit into
personal/local-clientsfrom
codex/fix-tui-snapshot-memory
Jul 19, 2026
Merged

fix(tui): unify cached snapshots to bound idle memory#173
makoMakoGo merged 1 commit into
personal/local-clientsfrom
codex/fix-tui-snapshot-memory

Conversation

@makoMakoGo

@makoMakoGo makoMakoGo commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • Build Usage projections, Sessions rows, source-space accounting, health, and the inventory signature from one confirmed source fold instead of retaining a full raw-message vector and scanning again for Sessions.
  • Replace the schema-38 usage-only cache with one atomically published schema-39 bundle containing Sessions and all four public Group By projections. A pinned file handle keeps lazy projection reads on the same generation across concurrent replacements.
  • Keep only the active usage projection, the compact Sessions snapshot, and the pinned bundle in the normal steady-state path. Retain TuiAcc only when cache persistence fails, with an explicit warning.
  • Bound glibc arenas for the TUI and trim transient parse allocations after publication. Background worker panics now clear loading state and mark the retained snapshot degraded instead of disabling later refreshes.

TUI behavior

  • Fresh cache: render every tab, including Sessions, from one generation without a source scan.
  • Stale cache: render the complete old generation immediately and perform one background refresh.
  • Cold or legacy cache: keep the UI operable while one background fold prepares every tab, then atomically install the new generation.
  • Group By: read the requested projection from the pinned generation without rescanning sources or replacing Sessions.
  • Refresh failure: keep the previous complete generation and surface an explicit degraded state.

Schema 38 is intentionally an explicit miss, so the first launch after upgrade performs one rebuild. On the measured corpus, the resulting schema-39 bundle is about 8.36 MB.

Verification

  • cargo test --workspace
    • CLI unit tests: 679 passed
    • Core unit tests: 1518 passed, 2 ignored
    • Integration and doc tests passed
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • cargo build --release -p tokscale-cli

Controlled release-build measurements used an isolated copy of the same local corpus:

  • Previous implementation: steady RSS 182,308 KiB
  • Schema-39 cold rebuild: peak 57,900 KiB; steady RSS 45,096 KiB
  • Fresh schema-39 cache: steady RSS 19,680 KiB

These figures describe this corpus and environment rather than a universal memory ceiling.

Summary by CodeRabbit

  • 新功能

    • TUI 新增会话视图,展示会话、来源、工作区、模型、令牌及成本等汇总信息。
    • 支持在不同分组方式间快速切换,无需重复扫描数据。
    • Usage 与 Sessions 使用一致的数据快照,刷新时保持内容同步。
  • 改进

    • TUI 缓存加载与刷新更快、更稳定。
    • 刷新失败时保留上一份可用数据,并显示相应状态。
    • 会话与来源统计会随数据刷新自动更新。

Build Usage and Sessions from one confirmed source fold, persist all public projections in an atomic schema-39 bundle, and release parse accumulators after snapshot publication.
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: da0e2e61-a867-4087-8f58-8176bcf4ad2a

📥 Commits

Reviewing files that changed from the base of the PR and between 0fa55fc and 4a02f12.

📒 Files selected for processing (19)
  • crates/tokscale-cli/src/commands/cache.rs
  • crates/tokscale-cli/src/tui/app.rs
  • crates/tokscale-cli/src/tui/cache.rs
  • crates/tokscale-cli/src/tui/data/mod.rs
  • crates/tokscale-cli/src/tui/mod.rs
  • crates/tokscale-cli/src/tui/session_data.rs
  • crates/tokscale-cli/src/tui/ui/sessions.rs
  • crates/tokscale-cli/src/tui/ui/view_footer.rs
  • crates/tokscale-cli/src/tui/view_state.rs
  • crates/tokscale-core/src/adapters/mod.rs
  • crates/tokscale-core/src/aggregate/config.rs
  • crates/tokscale-core/src/aggregate/engine.rs
  • crates/tokscale-core/src/aggregate/mod.rs
  • crates/tokscale-core/src/aggregate/tui_sessions.rs
  • crates/tokscale-core/src/fs_atomic.rs
  • crates/tokscale-core/src/lib.rs
  • crates/tokscale-core/src/lib_tests.rs
  • docs/adr/0008-single-copy-memory-pipeline.md
  • docs/adr/0026-group-by-view-scope-contract.md

Walkthrough

该变更将 TUI 数据加载改为统一 bundle 流程,新增会话聚合与 source-space 统计,升级 schema-39 多投影视图缓存,并让 TUI 通过缓存或内存投影管理 Group By、会话快照、后台刷新与失败降级。

Changes

TUI bundle pipeline

Layer / File(s) Summary
Core aggregation and confirmed source accounting
crates/tokscale-core/src/adapters/mod.rs, crates/tokscale-core/src/aggregate/*, crates/tokscale-core/src/lib.rs, crates/tokscale-core/src/lib_tests.rs
聚合引擎新增 TUI sessions 视图、会话条目输出、confirmed source-space 统计及带诊断的 TUI bundle 加载接口。
Schema-39 bundle persistence and lazy projections
crates/tokscale-cli/src/tui/cache.rs, crates/tokscale-core/src/fs_atomic.rs, docs/adr/*
缓存升级为 schema 39 bundle,支持范围校验、四类投影懒加载、health 注入、原子发布与 inode pinning。
Prepared loading and background bundle application
crates/tokscale-cli/src/commands/cache.rs, crates/tokscale-cli/src/tui/data/mod.rs, crates/tokscale-cli/src/tui/mod.rs
缓存预热、启动加载和后台刷新统一执行 TUI bundle,并处理 persisted、loaded、unchanged、失败及 worker panic 路径。
Projection-backed UI and session snapshots
crates/tokscale-cli/src/tui/app.rs, crates/tokscale-cli/src/tui/session_data.rs, crates/tokscale-cli/src/tui/view_state.rs, crates/tokscale-cli/src/tui/ui/*
App 使用 Cache/Memory projection backend 管理 Group By,Sessions 页面改用不可变快照,并同步调整状态、计数和选择项协调。

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related issues

Possibly related PRs

Poem

小兔抱着 bundle 跳,
四片投影整齐好。
Group By 换页不用跑,
Sessions 快照稳稳抱。
刷新失败旧代留,
schema 三九月光照。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次将 TUI 缓存快照统一并降低空闲内存的主要改动。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-tui-snapshot-memory

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Jul 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 41 untouched benchmarks


Comparing codex/fix-tui-snapshot-memory (4a02f12) with personal/local-clients (0fa55fc)

Open in CodSpeed

@makoMakoGo
makoMakoGo merged commit 04e0798 into personal/local-clients Jul 19, 2026
9 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant