Skip to content

fix(desktop-control): ignore free pages in SQLite state size limit - #1301

Merged
iruriQ merged 1 commit into
BytePioneer-AI:mainfrom
NikeAdmin:fix/desktop-global-state-sqlite-size
Nov 27, 2026
Merged

iruriQ merged 1 commit into
BytePioneer-AI:mainfrom
NikeAdmin:fix/desktop-global-state-sqlite-size

Conversation

@NikeAdmin

Copy link
Copy Markdown

Summary

Fix Invalid or oversized Desktop global state file when a valid Desktop SQLite state database grows beyond 32 MiB because of reusable free pages. The reported database was 48,848,896 bytes, passed SQLite integrity checks, and contained only 265,395 bytes of setting values; 11,849 of its 11,926 pages were free.

  • Keep the regular-file check for SQLite, but apply the 32 MiB read limit to the combined stored bytes of scope, key, and value instead of the physical database file size.
  • Check the payload size inside the existing read transaction, before materializing rows in JavaScript. Keep read-only access, schema-version handling, SQLite precedence, and the legacy JSON file-size limit.
  • Add regression coverage for a database inflated by deleted rows, stale legacy JSON, atom-state reconstruction, and aggregate multibyte payloads above the limit in both formats.

The loader does not compact or write the Desktop-owned database. This is limited to packages/desktop-control; no Harness semantics, public contracts, Rust code, or dependency versions change.

Minimal reproduction: create a version-1 settings database with a small valid setting, insert and delete a setting larger than 32 MiB without running VACUUM, then call readDesktopGlobalState. Previously, the loader rejected the database before reading its current settings. It now reads those settings while retaining the payload limit.

Related issues

N/A — encountered locally while displaying conversations in codexhost.

UI Demo

No visual changes: only the read-only Desktop global-state loader and regression tests change.

Test plan

Automated

  • Before the fix: node node_modules/vitest/vitest.mjs run --config tests/vitest.config.js packages/desktop-control/test/desktop-global-state.test.ts — 1 failed / 2 passed. The free-page regression failed with the original Invalid or oversized Desktop global state file error.
  • After the fix: node node_modules/vitest/vitest.mjs run --config tests/vitest.config.js packages/desktop-control/test/desktop-global-state.test.ts packages/desktop-control/test/remote-project-metadata.test.ts — 2 files, 5 tests passed. This covers successful reads from an inflated database, rejection of oversized JSON and SQLite payloads, and existing remote-project metadata behavior.

Local data validation

  • macOS 15.7.9 / arm64, Node.js 24.14.0; installed codexhost 0.28.1 via npm, local Codex Harness CLI 0.147.0; no SSH or Remote Control involved.
  • Called the patched TypeScript reader against a backup of the original affected 48,848,896-byte database, without compacting it: read succeeded with 46 top-level setting groups. SHA-256 before and after confirmed the database was unchanged. No private state or database files are included in this PR.
  • Full Codex Desktop version/build was not independently confirmed. Installing this branch into a running Desktop and end-to-end UI validation were not performed; the active session was kept running. Linux, Windows, and other Harnesses were not manually tested.
  • Full-repository checks are left to CI, following AGENTS.md.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • 修复大型状态文件的读取处理:数据库文件因空闲空间较大时,仍可读取其中的有效设置。
    • 对 JSON 和 SQLite 中超出大小限制的状态内容继续拒绝读取,避免加载过大的状态数据。

全局状态读取现在允许 SQLite 文件超过通用文件大小上限,但仍会检查状态负载的 UTF-8 字节总数。新增测试覆盖大型 SQLite 文件、JSON 和 SQLite 状态负载超限的情况。

Changes: 全局状态读取大小限制

Layer / File(s) Summary
状态读取大小检查与测试
packages/desktop-control/src/desktop-global-state.ts, packages/desktop-control/test/desktop-global-state.test.ts
checkStateFile 支持指定文件大小上限。读取 SQLite 时,符号链接目标的文件检查使用 Infinity;读取设置行前会校验 scope、key 和 value 的 UTF-8 字节总数。测试覆盖文件大于 32 MiB 但状态可读、读取前后文件大小不变,以及 JSON 和 SQLite 状态负载超限时拒绝读取。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: sduhantao-maker

Merge Risk: Minimal · up to 7eb7c

This change lets Desktop global state load from SQLite databases that are large only because of free pages, while still bounding the actual stored payload. No concrete merge-blocking risk was found, and the change does not write to or compact the database.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(desktop-control): ignore free pages in SQLite state size limit”与变更内容一致。变更将 SQLite 的 32 MiB 上限改为按 scope、key、value 的合计字节数计算,不再按物理文件大小计算。空闲页(free pages)是问题根因,标题准确指出了这一点。标题简短,能让团队成员快速理解主要变更。
Description check Passed 描述与变更内容直接相关。描述说明了问题现象(Invalid or oversized Desktop global state file)、根因(空闲页使数据库文件超过 32 MiB)、修复方式(按 scope、key、value 的字节合计做上限检查,并在读取事务内完成)、回归测试以及本地验证步骤。这些内容与 packages/desktop-control 中的读取逻辑和测试文件一致。
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 unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1e10973 and 7eb7c48.

Files selected for processing: 2

  • packages/desktop-control/src/desktop-global-state.ts
  • packages/desktop-control/test/desktop-global-state.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details

Context from checks skipped due to timeout: 8

  • GitHub Check: CodeRabbit
  • GitHub Check: Check macos-26
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Web Host tests
  • GitHub Check: Check windows-latest
  • GitHub Check: Vitest
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Static checks
Additional context used

Code guidelines: 1

AGENTS.md — auto-discovered
Path-based instructions: 1

Source excerpt: Use package public exports for cross-package dependencies.

CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/desktop-control/src/desktop-global-state.ts
  • packages/desktop-control/test/desktop-global-state.test.ts

@iruriQ
iruriQ merged commit 8b71044 into BytePioneer-AI:main Nov 27, 2026
6 of 8 checks passed
@iruriQ

iruriQ commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

感谢首次贡献!改动克制精准、真实 SQLite 回归测试扎实,已合入 main。

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