Skip to content

[CTX-1479] feat(storage): add default-off storage component host - #2574

Merged
Xuepoo merged 8 commits into
mainfrom
ctx-2495/feat-storage-host
Oct 23, 2026
Merged

Xuepoo merged 8 commits into
mainfrom
ctx-2495/feat-storage-host

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Refs #2495 (does not close it: the component stays default-off until the enable/migration task lands).

Priority: P1 | Area: architecture | Labels: feat,P1,area:architecture | Milestone: v0.0.28 | RFC: OQ-N/A | Task: CTX-1479

Contract outcome

Adds the opt-in Core host client for the bitty-storage component behind the default-off storage-component feature. The linked StorageSessionBackend / StorageKvBackend adapters remain the only startup path; no CLI flag, config key, or first-run migration reaches the component.

  • Resolves the component through the shared two-tier install layout (resolve_search_for_protocol) with descriptor + executable digest verification before every spawn.
  • Enforces the injectable StorageComponentGate (preferred / safe mode / capability grant) before install resolution, root creation, or process creation.
  • Spawns with a cleared environment, its own process group, piped stdio, a 64 KiB stderr ring, a 16-frame bounded inbound queue, a handshake deadline, per-exchange deadlines, and a bounded clean shutdown (ShutdownAck, stdin close, exit grace, recorded-PG kill).
  • Speaks protocol v1: namespace open, paged snapshot read, commit batch, rollback, shutdown. Request ids and namespaces are checked on every response; pages, rows, values, batches, and totals are locally bounded.
  • Fails closed on malformed/oversized frames, truncated frames, EOF, crash, timeout, unknown tags, and unsolicited frames. A mutation error poisons the connection; submission is recorded before the frame is written, so a commit/rollback is never replayed.
  • Adds explicit confined root selection: <state>/bitty/storage-component/<profile>, created owner-only, canonicalized under the explicit base, with symlink/escape rejection. Only the fixed --root argument carries a path; wire values are namespaces, keys, and opaque bytes.
  • Adds an explicit, idempotent migration helper (migrate_linked_file) that reads the linked file capped, commits the same bytes, and leaves the linked path untouched.
  • Maps opaque objects into the existing persistence model with component-backed SessionFileBackend / KvCommitBackend adapters. Session encode/decode delegate to the linked codec, so parity tests compare byte-identical images; KV parity compares the same store image.
  • Adds a hermetic fixture that serves the pinned component server (plus fault modes) and extends the W-147 fence to the new storage naming points.

Pin state

bitty-storage PR #18 merged at 502c7f53. The optional dependency now pins the reachable merge commit:

bitty-storage-component = { package = "bitty-storage", git = "https://github.com/bitty-terminal/bitty-storage", rev = "502c7f5", optional = true }

The linked model pin remains 7bf5177. bash scripts/check-extension-pins.sh reports both pins ok (0 unreachable).

The merged contract keeps Internal = 10, adds Uncertain = 11, and treats unknown codes as non-retryable. The host table matches that contract; an Uncertain mutation response poisons the client, the caller must reconnect and reopen the namespace to match the merged cached-handle eviction contract, and no mutation is replayed. The component remains default-off: no startup wiring or user-facing enable is added here.

Security / performance

  • Safe mode, missing capability, and default-off deny before resolution. Install tampering fails closed through the shared digest check.
  • No path, key, value, or stderr content is echoed in errors. The component receives exactly one host-chosen --root.
  • Snapshots are paged (128 rows / 240 KiB per frame) and bounded at 4096 rows / 1 MiB; the reader blocks on a bounded queue instead of buffering unbounded output.
  • Whole-object commits are additionally limited to the v1 single-batch ceiling (240 KiB). A larger object fails closed with Bounds before any mutation and leaves the previous object intact; whole-object atomic commits above that ceiling need a transaction extension in the component protocol.
  • No hot-path IPC was added to the default build: the feature is empty by default, and the optional component pin is not linked unless requested.

Validation

  • bash scripts/check-extension-pins.sh (both storage pins ok, 0 unreachable)
  • cargo fmt -p bitty-terminal --check
  • cargo clippy -p bitty-terminal --features storage-component --all-targets -j2 -- -D warnings
  • cargo clippy -p bitty-terminal --all-targets -j2 -- -D warnings
  • cargo check -p bitty-terminal --features storage-component --locked -j2
  • cargo test -p bitty-terminal --features storage-component --test storage_component_host -j2 (8 passed; includes StaleRevision and Uncertain mutation-poison cases)
  • cargo test -p bitty-terminal --features storage-component --bin bitty storage_component_host:: -j2 (5 passed)
  • cargo test -p bitty-terminal --test verify_w147_small_core_graph -j2 (22 passed)
  • cargo test -p bitty-runtime --test session_backend_seam --test plugin_store -j2 (7 + 12 passed)
  • cargo test -p bitty-terminal --bin bitty storage_backends::tests -j2 (18 passed)
  • Default and feature builds checked with a scoped CARGO_TARGET_DIR and -j2.

Follow-ups

  • Run the storage#18 merged-contract parity/fail-closed suite again when the component is enabled by policy.
  • Wire the injectable gate, startup restore/save, and an explicit user-facing enable in a separate scoped task.
  • Add a component crash-recovery/live campaign once the component is enabled by policy.

@Xuepoo Xuepoo added this to the v0.0.28 milestone Oct 23, 2026
@Xuepoo Xuepoo added feat Feature P1 Priority: high area:architecture labels Oct 23, 2026
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 769063a2-d1c6-43aa-ac9a-c71bb92f97ae
📥 Commits

Reviewing files that changed from the base of the PR and between 92306d9 and 69126b7.

⛔ Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing: 7
  • crates/bitty-terminal/Cargo.toml
  • crates/bitty-terminal/src/lib.rs
  • crates/bitty-terminal/src/main.rs
  • crates/bitty-terminal/src/storage_component_host.rs
  • crates/bitty-terminal/tests/storage_component_fixture/mod.rs
  • crates/bitty-terminal/tests/storage_component_host.rs
  • crates/bitty-terminal/tests/verify_w147_small_core_graph.rs
  • 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

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

@Xuepoo

Xuepoo commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Guard tick forensics — NEEDS-FIX on two independent gates

1. Windows: Unix path assumptions in the new host tests (real defect)

Run 39999659187, Windows check and test (job 120572170154), head dfc42e8c:

storage_component_host::tests::component_config_defaults_off_with_standard_deadlines
  panicked at crates\bitty-terminal\src\storage_component_host.rs:2086:67: root: Confinement
storage_component_host::tests::root_selection_rejects_invalid_profiles_and_relative_bases
  panicked at crates\bitty-terminal\src\storage_component_host.rs:2078:9:
  assertion failed: StorageRootSelection::under("/tmp", "default").is_ok()

The tests hardcode the POSIX /tmp root, so on Windows the confinement check
rejects it and both tests fail. Per the workspace cross-platform rule (Unix
assumptions must never leak into host/platform layers; Windows is a first-class
gate), the fix is to derive the root from a temp dir rather than a literal
/tmp — not to relax the confinement check.

2. Extension pin drift: bitty-storage pin 5b5f19eb is behind an unmerged PR

##[error]bitty-storage: pin 5b5f19eb is not reachable from upstream main (5c8e634)

5b5f19eb is an ancestor of bitty-storage#18 (ctx-0008/feat-component-server,
4 commits ahead of main), so the pin only becomes reachable from upstream main
once that PR merges. Storage #18 is otherwise fully green (11 pass / 1 skip at
head 0af1ca74) and is blocked only on REVIEW_REQUIRED — an independent
security verdict on the 7.6k-line component-protocol diff.

Sequence to clear this PR: merge bitty-terminal/bitty-storage#18 (needs the
independent verdict first) → re-run Extension pin drift here. No change to
this branch is required for gate 2; gate 1 needs the test fix above.

@Xuepoo

Xuepoo commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Re-pinned to the merged storage#18 commit 502c7f5 (502c7f53d652); linked model stays 7bf5177.

  • bash scripts/check-extension-pins.sh: both pins ok, 0 unreachable (bitty-storage 502c7f5 ... ok; 7bf5177 ... ok).
  • cargo check -p bitty-terminal --features storage-component --locked: pass.
  • Feature clippy -D warnings: pass.
  • Storage integration tests 8/8 (now covers StaleRevision and merged Uncertain=11 mutation poisoning); unit tests 5/5.
  • Merged contract verified: Internal=10, Uncertain=11, unknown codes remain generic/non-retryable.
  • W-147/default-build checks unchanged.

The previous intentionally-unreachable pin note is obsolete and has been removed. No merge.

Final head 1df67759: CI is fully green, including Extension pin drift (both storage pins ok). CodeQL is green as well. Not merged.

@Xuepoo

Xuepoo commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

CodeRabbit guard-tick findings addressed:

  1. Windows /tmp assumptions: fixed in 5b89f1a7 by deriving test roots from std::env::temp_dir(); the Windows job passes on the latest head.
  2. Storage pin drift: re-pinned to the merged storage#18 commit 502c7f5 in 1df67759; scripts/check-extension-pins.sh reports 0 unreachable.

No merge.

Deliver the opt-in Core host client for the bitty-storage component
(bitty#2495) behind the default-off `storage-component` feature. The
linked StorageSessionBackend/StorageKvBackend adapters stay the default.

- Resolve the component through the shared two-tier install layout with
  descriptor/digest verification, spawn it with a cleared environment and
  its own process group, and keep stderr in a 64 KiB ring.
- Bound the Hello/HelloAck handshake, each exchange, the inbound frame
  queue, snapshot pages/bytes, values, and commit batches.
- Speak v1 namespace open, paged snapshot read, commit batch, rollback, and
  shutdown; validate every response against request/namespace and fail
  closed on malformed, oversized, truncated, EOF, crash, or timeout.
- Poison the client after any mutation error and never replay a commit or
  rollback; submission is recorded before the frame is written.
- Add explicit confined root selection (<state>/bitty/storage-component/
  <profile>) and an explicit, idempotent migration helper. No path travels
  on the wire beyond the fixed --root argument.
- Map opaque objects into the existing persistence model with component-
  backed SessionFileBackend/KvCommitBackend adapters and hermetic parity
  tests against the linked codec/adapters.
- Add a hermetic fixture that serves the pinned component server plus fault
  modes, and extend the W-147 fence to the new storage naming points.

Pin state: bitty-storage PR #18 is unmerged and under a protocol follow-up
(Uncertain = 11). The optional component dependency is pinned at its current
head 5b5f19eb; the linked model remains 7bf5177. Re-pin instructions and the
isolated error-code table are documented in the module.
Check every existing component of the selected storage root before
create_dir_all so a symlinked ancestor cannot make the host create the
root outside the explicit base. The canonical post-create check remains
as the backstop, and the fence comment no longer calls storage a seam
crate.
Assert the component-backed SessionFileBackend keeps default discovery
off so the linked XDG path stays the only startup path until the
explicit migration/enable task.
…ault tests

Require absolute user/system component roots before resolution, and make
the malformed/oversized fixture modes linger so the host observes the
fault instead of racing a child exit. Give the legal 4096-page loop a
10 s per-exchange bound under loaded CI.
The component's commit batch is capped at 240 KiB while a snapshot may
read up to 1 MiB. A whole-object commit above the batch ceiling therefore
fails closed with Bounds before any mutation, leaving the previous object
intact; test both the ceiling and the 1 MiB bound. Whole-object atomic
commits above the ceiling need a transaction extension.
The packaging source gate requires exactly one [[bin]] in the composition
root. Move the hermetic storage fixture into a harness-free test target:
the test binary itself serves protocol v1 when the host passes --root, and
the test runner strips a copy to stay below the component's 256 MiB
executable ceiling. No packaging recipe changes.
Use std::env::temp_dir() instead of a /tmp literal so the absolute-root
and config-default unit tests also pass on Windows.
Move bitty-storage-component from the unmerged PR-branch head 5b5f19eb
to the reachable merge commit 502c7f5 (storage#18); the linked model pin
stays at 7bf5177. The pin-drift gate now reports both pins ok.

Verify the merged error contract: Internal stays 10, Uncertain is 11, and
unknown codes remain generic component failures. Extend the fixture with
an Uncertain commit response and assert it poisons the client without a
retry. Update module/PR docs from the pre-merge pin state to the merged
state; the component remains default-off until the enable/migration task.
@Xuepoo
Xuepoo force-pushed the ctx-2495/feat-storage-host branch from 1df6775 to 69126b7 Compare October 23, 2026 21:56

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INDEPENDENT REVIEW (guard-tick, agent: guard-review-2574) - head 69126b7

Static review only (no workspace build). Reviewed the full diff, issue #2495, the touched files at 69126b7, and the pinned component contract at bitty-storage 502c7f5.

What I verified as correct

  • Default-off is structural, not conditional. connect checks gate.allows() first (storage_component_host.rs:616), before resolution, root creation, or Command. default = [] still holds, and the PR adds no call site: mod storage_component_host; in main.rs:257 is never referenced, and the W-147 fence keeps both storage identifiers confined to storage_backends.rs + storage_component_host.rs. With the feature off, the compiled stub (:1947) returns Denied unconditionally, so a future mis-wiring still cannot spawn without the feature.
  • No bind/listen surface exists. Zero occurrences of bind/listen/Tcp/Udp/UnixStream/socket across all three new files; IPC is stdin/stdout pipes. No hardcoded host, port, socket, or path: the child receives exactly one --root arg, the root derives from an injected absolute base + bitty_runtime::SESSION_APP_DIR_NAME + a fixed dir constant + a validated profile (:367-385), and the unit tests confirm no std::env::var read in library code. Hello advertises env!("CARGO_PKG_VERSION").
  • MSRV 1.85 is clean. No let-chains anywhere in the diff (if|while let ... &&: 0 hits); newest APIs are Option::is_none_or (1.82) and is_some_and (1.70); const _: () = assert!(...) (1.57); Command::process_group (1.64). clippy.toml sets msrv = "1.85", so let-chain suggestions are suppressed — no E0658 risk.
  • Contract match with the pin. The compile-time asserts at :523-529 match bitty-storage@502c7f5 exactly (MAX_ROWS 4096, MAX_SNAPSHOT_BYTES 1 MiB, MAX_VALUE_BYTES 128 KiB, MAX_NAMESPACE_NAME_BYTES 64, MAX_KEY_BYTES 128, MAX_BATCH_ROWS 128, MAX_BATCH_BYTES 240 KiB). ErrorKind keeps Internal = 10, adds Uncertain = 11, from_code(12) == None; the host maps unknown codes to Unknown (:217). Message variants/fields match field-for-field. 502c7f5 exists in bitty-storage and the required runtime APIs (resolve_search_for_protocol, StderrRing, stderr_log_tail, SESSION_APP_DIR_NAME, MAX_SESSION_FILE_BYTES, SessionFileBackend, KvCommitBackend, STORE_FILE_MAX_BYTES) all exist on main. Digest + protocol-range verification happens inside resolve_with_protocol before spawn, and the host adds a canonical-path containment check (:643-654).
  • Fail-closed paths are sound: unsolicited frame at exchange entry, empty non-final page, revision/total drift, duplicate keys, oversize/truncated frames, EOF, timeout, and connection-level errors all poison and reap; the submission bit is set before the frame is written (:1178-1180), so a mutation cannot be replayed. PR-body claims matched the code on every point I could check statically.

Findings

  1. crates/bitty-terminal/src/storage_component_host.rs:467,481 — minor — StorageComponentConfig::shutdown_timeout is dead configuration: nothing reads it, shutdown(&self, deadline) takes an ad-hoc argument instead (:1105), so a caller can ignore the documented 3 s bound. The unit test at :2102 only asserts the default value, which is why this is invisible. Wire config.shutdown_timeout into the client (store it beside deadline, :720) or delete the field.

  2. crates/bitty-terminal/src/storage_component_host.rs:1871-1875 (with :1202-1207, :1286-1293) — minor — stop_child calls killpg(pid) unconditionally, but the write-failure path already ran try_wait() and may have reaped the child, so the recorded pid/pgid can be recycled before the signal lands (spurious SIGKILL to an unrelated group). Also child.wait() at :1874 is unbounded, which is the one place the "bounded clean shutdown" claim does not hold (a child in uninterruptible sleep blocks Drop/shutdown forever). Guard the killpg with the exited flag and use a bounded reap.

  3. crates/bitty-terminal/src/storage_component_host.rs:838,953,1094 — minor — Message::Error is accepted without checking the request id in open_namespace, read_snapshot, and rollback; commit_batch does check (:1046). A mismatched-id error is misattributed to the in-flight call, and for non-mutation exchanges the connection stays open. Match Message::Error { request: got, kind, .. } if got == request and fail closed otherwise.

  4. crates/bitty-terminal/src/storage_component_host.rs:1216-1219 — minor — every mutation error poisons the connection, including StaleRevision, which is a routine CAS conflict under two concurrent writers. The merged contract only requires reopen/reread on Uncertain; poisoning on stale turns ordinary contention into a full connection death for all namespaces. Fail-closed and consistent with the test at tests/storage_component_host.rs:492, but narrower poisoning (or at least distinct accounting) will matter once the enable task lands.

  5. crates/bitty-terminal/src/storage_component_host.rs:1933-1974 — minor — the feature-off connect() stub is the strongest default-off guarantee and no test asserts it. The 8 integration tests are required-features-gated, so a default cargo test only runs the 5 module unit tests (gate defaults, grammar, root selection, config defaults, fault table). Add one default-feature assertion that StorageComponentClient::connect(&config).is_err() and that is_running()/commit_was_submitted() are false, so the disabled path is executable rather than merely structural.

  6. crates/bitty-terminal/tests/storage_component_host.rs:390-402 — minor — the tamper test appends to the installed executable, which install() hard-linked to the OnceLock fixture (:177), so it mutates the shared fixture inode for every later test in the same process; behaviour also differs where hard_link falls back to copy (cross-device), making the test environment-dependent. Tamper a copied file instead.

  7. crates/bitty-terminal/tests/storage_component_host.rs:31 — minor — const COMPONENT_VERSION = "0.0.1" duplicates the pinned crate's own COMPONENT_VERSION, which the fixture already imports (tests/storage_component_fixture/mod.rs:32). A pin bump then fails the suite with a version mismatch instead of following the crate; derive it from bitty_storage_component::component::COMPONENT_VERSION.

  8. crates/bitty-terminal/tests/storage_component_host.rs:61-66 — minor — the fixture shells out to strip from PATH (with a STRIP override) and depends on the binary staying under the component's 256 MiB ceiling. That is fine on Linux + binutils but makes the target non-portable to runners without it; a skip or objcopy-free fallback would be safer for the cross-platform CI matrix.

  9. crates/bitty-terminal/src/main.rs:257 and crates/bitty-terminal/src/storage_component_host.rs:64,1927 — minor — the module is compiled into the binary but never referenced, and the file-wide #![allow(dead_code)] plus #[allow(unused_imports)] suppress every dead-item signal. Harmless today (default builds link only consts and the stub) but it removes the only automated hint when the module later becomes reachable; prefer a narrower #[allow(dead_code)] on the feature-on items.

  10. crates/bitty-terminal/src/storage_component_host.rs:130-137 — minor — capability_granted and safe_mode are caller-set booleans, not the repository's grant/safe-mode state (bitty_runtime::component::grant, composition-root safe-mode selection). Correctly described as injectable and deferred, but today the gate is a caller assertion, so it carries no capability enforcement until the follow-up wires it.

  11. crates/bitty-terminal/tests/verify_w147_small_core_graph.rs:117-118 — nit — the SEAM_CRATES doc still says every EXTENSION_CRATES entry absent from the table must have no normal edge, while bitty-storage (absent) keeps a hand-written allowlist in allowed_consumers. Pre-existing, but this PR edits exactly that policy area and adds bitty-storage to SOURCE_SEAM_FILES, so the doc is now the only place the two mechanisms disagree.

Assessment

Nothing here blocks. Default-off is genuine and cannot be defeated without rebuilding with storage-component; there is no listening socket, no hardcoded endpoint or path, no let-chain, and the wire contract matches the pin. Findings 1-3 are small correctness/robustness items in code that is not yet reachable; 5-8 are test hygiene; the rest are documentation and reviewability. Findings 1 and 3 are worth fixing before the enable task, since they are the ones a future wiring change would depend on.

VERDICT: APPROVE

@Xuepoo
Xuepoo merged commit e9c27fe into main Oct 23, 2026
20 checks passed
@Xuepoo
Xuepoo deleted the ctx-2495/feat-storage-host branch October 23, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:architecture feat Feature P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant