Bound workspace doctor file reads with size cap#110592
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 7:54 AM ET / 11:54 UTC. Summary PR surface: Source +27. Total +27 across 1 file. Reproducibility: no. high-confidence current-main reproduction was executed in this read-only review, but the pre-fix unbounded-read path and the proposed capped failure path are directly identifiable from source and the PR includes after-fix terminal scenarios. Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Rebase onto current Do we have a high-confidence way to reproduce the issue? No high-confidence current-main reproduction was executed in this read-only review, but the pre-fix unbounded-read path and the proposed capped failure path are directly identifiable from source and the PR includes after-fix terminal scenarios. Is this the best way to solve the issue? Yes. Reusing the established shared bounded-reader primitive and preflighting both memory inputs before archival is the narrowest maintainable fix for the stated allocation and recoverability problems. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 39ddf710f0f3. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +27. Total +27 across 1 file. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (5 earlier review cycles)
|
Behavior Proof — Bounded Workspace Doctor File ReadTest Coverage运行 Live Bounded-Read Validation直接验证 两种场景全部通过:
CI Gate
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
PR body updated with behavioral proof and compatibility contract. @clawsweeper re-review |
|
PR body updated with full migration-path proof (read-before-archive scenarios A and B, 15 MB oversized rejected with legacy preserved). @clawsweeper re-review |
|
Thanks for pushing this bounded-read direction. This is now fixed on The landed version covers the same |
What Problem This Solves
shouldSuggestMemorySystemandmigrateLegacyRootMemoryFilein the doctor workspace path callfs.promises.readFileon AGENTS.md and MEMORY.md files with no size limit. A corrupted or enormous workspace file can OOM the doctor path.Why This Change Was Made
PR #101472 established the bounded-read pattern. The doctor workspace path reads user-authored workspace files (AGENTS.md, canonical MEMORY.md, legacy MEMORY.md) — the same unbounded-read vulnerability class. This change replaces all three
fs.promises.readFilecalls withreadRegularFileusing a 10 MB cap, which covers even very large memory files.Additionally,
migrateLegacyRootMemoryFileoriginally archived the legacy file before attempting the bounded read, meaning an oversized file would leave the legacy file already archived with no recovery path. The read is now performed before archival, so oversized files cleanly abort with no side effects.User Impact
No change for normal workspace files under 10 MB. Files exceeding the cap result in graceful fallback (treated as unreadable) rather than process crash. The legacy migration path is safe: if either the canonical or legacy MEMORY.md exceeds 10 MB, the function returns without archiving the legacy file, preserving both files in place.
Evidence
Code changes
src/commands/doctor-workspace.ts:44:shouldSuggestMemorySystemusesreadRegularFilewith 10 MB capsrc/commands/doctor-workspace.ts:220-228:migrateLegacyRootMemoryFilereads both canonical and legacy MEMORY.md before callingmoveLegacyRootMemoryFileToArchive— oversized files abort cleanly with legacy file intactWORKSPACE_DOCTOR_MAX_BYTES = 10 * 1024 * 1024constantreadRegularFileimport from../infra/regular-file.jsreadRegularFileresults use.buffer.toString("utf-8")for string conversionBehavioral proof — read-before-archive migration path
Scenario A: Normal files (under 10 MB cap)
Both canonical and legacy files read successfully — migration proceeds.
Scenario B: 15 MB canonical MEMORY.md (exceeds 10 MB cap)
Read happens BEFORE archive. Oversized file is rejected cleanly, legacy file remains intact.
The critical difference from the before state:
Unit tests
src/commands/doctor-workspace.test.ts: 3 tests passed (under|commands|Vitest shard)Proof commands
node scripts/run-vitest.mjs "src/commands/doctor-workspace.test.ts" node scripts/proof-doctor-migration.mjsRelated
readRegularFilebounded-read pattern insrc/cron/store.ts)