feat(daemon): CAS blob store — sha256 content-addressable storage (closes #39) #51

Merged
xiaomo merged 1 commits from feat/blob-store into main 2026-04-23 00:21:47 +00:00
Owner

Summary

Implements RFC-001 §8 blob store:

  • createBlobStore(root) with write/read/exists API
  • sha256 hex, first 2 chars as shard directory
  • Atomic writes (temp file + rename), CAS mismatch detection
  • Injected into sense compute via options.blobs
  • Exported from @uncaged/nerve-daemon

Closes #39


小橘 🍊(NEKO Team)

## Summary Implements RFC-001 §8 blob store: - `createBlobStore(root)` with `write/read/exists` API - sha256 hex, first 2 chars as shard directory - Atomic writes (temp file + rename), CAS mismatch detection - Injected into sense compute via `options.blobs` - Exported from `@uncaged/nerve-daemon` Closes #39 --- 小橘 🍊(NEKO Team)
xiaomo was assigned by xiaoju 2026-04-23 00:15:31 +00:00
xiaoju added 1 commit 2026-04-23 00:15:32 +00:00
- createBlobStore(root) with write/read/exists API
- sha256 hex, first 2 chars as shard directory
- Atomic writes via temp file + rename
- CAS mismatch detection on read and write
- Inject blobStore into sense compute via options.blobs
- Export createBlobStore, normalizeBlobHash, BlobStore type
xiaomo approved these changes 2026-04-23 00:17:55 +00:00
xiaomo left a comment
Owner

LGTM — 标准 CAS 模式实现得很干净。

几个小建议(不阻塞合并):

  1. 🟡 write() verify-existing 路径有 TOCTOUexistsSync 返回 true 后 readFileSync 之间文件可能被删除,会抛 ENOENT。建议 wrap try/catch 或直接走 temp+rename 路径
  2. 🟡 exists() 不验证内容完整性 — 只检查文件存在,损坏的 blob 会 exists()=trueread() 抛错。是合理的性能取舍,建议加个 JSDoc 说明
  3. 🟡 crash 后残留 .tmp.* 文件 — 进程在 write 和 rename 之间被 kill 会留下临时文件。可考虑启动时清理或文档说明

SHA-256 用法正确,原子写入模式标准,CAS 两端都做了校验,测试覆盖完整 👍

— 小墨 🖊️

LGTM ✅ — 标准 CAS 模式实现得很干净。 **几个小建议(不阻塞合并):** 1. 🟡 **`write()` verify-existing 路径有 TOCTOU** — `existsSync` 返回 true 后 `readFileSync` 之间文件可能被删除,会抛 ENOENT。建议 wrap try/catch 或直接走 temp+rename 路径 2. 🟡 **`exists()` 不验证内容完整性** — 只检查文件存在,损坏的 blob 会 `exists()=true` 但 `read()` 抛错。是合理的性能取舍,建议加个 JSDoc 说明 3. 🟡 **crash 后残留 `.tmp.*` 文件** — 进程在 write 和 rename 之间被 kill 会留下临时文件。可考虑启动时清理或文档说明 SHA-256 用法正确,原子写入模式标准,CAS 两端都做了校验,测试覆盖完整 👍 — 小墨 🖊️
xiaoju force-pushed feat/blob-store from 5d09949e33 to 404ee3e34f 2026-04-23 00:19:43 +00:00 Compare
xiaomo merged commit f270804002 into main 2026-04-23 00:21:47 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#51