Repository navigation
[CTX-1479] feat(storage): add default-off storage component host - #2574
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. Comment |
Guard tick forensics — NEEDS-FIX on two independent gates1. Windows: Unix path assumptions in the new host tests (real defect)Run 39999659187, The tests hardcode the POSIX 2.
|
|
Re-pinned to the merged storage#18 commit
The previous intentionally-unreachable pin note is obsolete and has been removed. No merge. Final head |
|
CodeRabbit guard-tick findings addressed:
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.
1df6775 to
69126b7
Compare
Xuepoo
left a comment
There was a problem hiding this comment.
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.
connectchecksgate.allows()first (storage_component_host.rs:616), before resolution, root creation, orCommand.default = []still holds, and the PR adds no call site:mod storage_component_host;inmain.rs:257is never referenced, and the W-147 fence keeps both storage identifiers confined tostorage_backends.rs+storage_component_host.rs. With the feature off, the compiled stub (:1947) returnsDeniedunconditionally, 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
--rootarg, 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 nostd::env::varread in library code.Helloadvertisesenv!("CARGO_PKG_VERSION"). - MSRV 1.85 is clean. No let-chains anywhere in the diff (
if|while let ... &&: 0 hits); newest APIs areOption::is_none_or(1.82) andis_some_and(1.70);const _: () = assert!(...)(1.57);Command::process_group(1.64).clippy.tomlsetsmsrv = "1.85", so let-chain suggestions are suppressed — no E0658 risk. - Contract match with the pin. The compile-time asserts at
:523-529matchbitty-storage@502c7f5exactly (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).ErrorKindkeepsInternal = 10, addsUncertain = 11,from_code(12) == None; the host maps unknown codes toUnknown(:217).Messagevariants/fields match field-for-field.502c7f5exists inbitty-storageand 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 onmain. Digest + protocol-range verification happens insideresolve_with_protocolbefore 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
-
crates/bitty-terminal/src/storage_component_host.rs:467,481— minor —StorageComponentConfig::shutdown_timeoutis 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:2102only asserts the default value, which is why this is invisible. Wireconfig.shutdown_timeoutinto the client (store it besidedeadline,:720) or delete the field. -
crates/bitty-terminal/src/storage_component_host.rs:1871-1875(with:1202-1207,:1286-1293) — minor —stop_childcallskillpg(pid)unconditionally, but the write-failure path already rantry_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). Alsochild.wait()at:1874is unbounded, which is the one place the "bounded clean shutdown" claim does not hold (a child in uninterruptible sleep blocksDrop/shutdownforever). Guard the killpg with theexitedflag and use a bounded reap. -
crates/bitty-terminal/src/storage_component_host.rs:838,953,1094— minor —Message::Erroris accepted without checking the request id inopen_namespace,read_snapshot, androllback;commit_batchdoes check (:1046). A mismatched-id error is misattributed to the in-flight call, and for non-mutation exchanges the connection stays open. MatchMessage::Error { request: got, kind, .. } if got == requestand fail closed otherwise. -
crates/bitty-terminal/src/storage_component_host.rs:1216-1219— minor — every mutation error poisons the connection, includingStaleRevision, which is a routine CAS conflict under two concurrent writers. The merged contract only requires reopen/reread onUncertain; poisoning on stale turns ordinary contention into a full connection death for all namespaces. Fail-closed and consistent with the test attests/storage_component_host.rs:492, but narrower poisoning (or at least distinct accounting) will matter once the enable task lands. -
crates/bitty-terminal/src/storage_component_host.rs:1933-1974— minor — the feature-offconnect()stub is the strongest default-off guarantee and no test asserts it. The 8 integration tests arerequired-features-gated, so a defaultcargo testonly runs the 5 module unit tests (gate defaults, grammar, root selection, config defaults, fault table). Add one default-feature assertion thatStorageComponentClient::connect(&config).is_err()and thatis_running()/commit_was_submitted()are false, so the disabled path is executable rather than merely structural. -
crates/bitty-terminal/tests/storage_component_host.rs:390-402— minor — the tamper test appends to the installed executable, whichinstall()hard-linked to theOnceLockfixture (:177), so it mutates the shared fixture inode for every later test in the same process; behaviour also differs wherehard_linkfalls back tocopy(cross-device), making the test environment-dependent. Tamper a copied file instead. -
crates/bitty-terminal/tests/storage_component_host.rs:31— minor —const COMPONENT_VERSION = "0.0.1"duplicates the pinned crate's ownCOMPONENT_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 frombitty_storage_component::component::COMPONENT_VERSION. -
crates/bitty-terminal/tests/storage_component_host.rs:61-66— minor — the fixture shells out tostripfromPATH(with aSTRIPoverride) 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 orobjcopy-free fallback would be safer for the cross-platform CI matrix. -
crates/bitty-terminal/src/main.rs:257andcrates/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. -
crates/bitty-terminal/src/storage_component_host.rs:130-137— minor —capability_grantedandsafe_modeare 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. -
crates/bitty-terminal/tests/verify_w147_small_core_graph.rs:117-118— nit — theSEAM_CRATESdoc still says everyEXTENSION_CRATESentry absent from the table must have no normal edge, whilebitty-storage(absent) keeps a hand-written allowlist inallowed_consumers. Pre-existing, but this PR edits exactly that policy area and addsbitty-storagetoSOURCE_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
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-storagecomponent behind the default-offstorage-componentfeature. The linkedStorageSessionBackend/StorageKvBackendadapters remain the only startup path; no CLI flag, config key, or first-run migration reaches the component.resolve_search_for_protocol) with descriptor + executable digest verification before every spawn.StorageComponentGate(preferred / safe mode / capability grant) before install resolution, root creation, or process creation.ShutdownAck, stdin close, exit grace, recorded-PG kill).<state>/bitty/storage-component/<profile>, created owner-only, canonicalized under the explicit base, with symlink/escape rejection. Only the fixed--rootargument carries a path; wire values are namespaces, keys, and opaque bytes.migrate_linked_file) that reads the linked file capped, commits the same bytes, and leaves the linked path untouched.SessionFileBackend/KvCommitBackendadapters. Session encode/decode delegate to the linked codec, so parity tests compare byte-identical images; KV parity compares the same store image.Pin state
bitty-storagePR #18 merged at502c7f53. The optional dependency now pins the reachable merge commit:The linked model pin remains
7bf5177.bash scripts/check-extension-pins.shreports both pinsok(0 unreachable).The merged contract keeps
Internal = 10, addsUncertain = 11, and treats unknown codes as non-retryable. The host table matches that contract; anUncertainmutation 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
--root.Boundsbefore any mutation and leaves the previous object intact; whole-object atomic commits above that ceiling need a transaction extension in the component protocol.Validation
bash scripts/check-extension-pins.sh(both storage pinsok, 0 unreachable)cargo fmt -p bitty-terminal --checkcargo clippy -p bitty-terminal --features storage-component --all-targets -j2 -- -D warningscargo clippy -p bitty-terminal --all-targets -j2 -- -D warningscargo check -p bitty-terminal --features storage-component --locked -j2cargo test -p bitty-terminal --features storage-component --test storage_component_host -j2(8 passed; includesStaleRevisionandUncertainmutation-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)CARGO_TARGET_DIRand-j2.Follow-ups