feat/jumping-usb-hw-stamp-and-status #82

Merged
clawdie merged 19 commits from feat/jumping-usb-hw-stamp-and-status into main 2026-11-19 21:19:55 +01:00
Owner
No description provided.
Extend clawdie-max2-state with three read-only boot-fact lines so the
operator can see the persisted boot preference, the hardware envelope,
and declared rc enable state before deciding anything at onboarding.

Scope (deliberately narrow, Increment 1 only):
- BOOT: the persisted preference written by clawdie-firstboot-confirm
  (standalone -> A zot/pi-only, max2-onboard -> B operator+agent).
  A preference is not proof of the current choice and says nothing
  about which daemons run.
- HW: a decoded hw-harvest hardware-facts sample (ram_gb, cpu_cores,
  boot_type, colibri_running, optional headroom metrics) plus a
  boot-epoch comparison labelled same-boot / stale-boot / missing and
  the sample file's own age. same-boot is not a freshness claim, and
  stale samples are never used to gate anything.
- RC: declared enable state (enabled / enabled-no-binary / disabled /
  disabled-by-default / not-declared / unrecognized / unknown) read
  from rc.conf, rc.conf.local, rc.conf.d/<service> and defaults, last
  assignment wins. This is not effective rc resolution: rc.subr sources
  shell code and other startup scripts can set the same variable, so an
  unreadable candidate renders unknown and a missing key renders
  not-declared, never disabled. "enabled" never means running, healthy,
  or admitted.

Limits and safety:
- No rc.conf writes, no service start/stop, no probing, no host diffing,
  no key handling, no thresholds. The strip reports; it never decides.
- Structural JSON is decoded by python3 (json.load) with strict typing,
  so truncated, malformed, wrongly typed or duplicate-key input cannot
  fabricate values; absence of a parser is reported as no-parser.
- Paths that exist but are not readable regular files (symlinks,
  dangling symlinks, directories, unreadable files) are reported as
  unknown/unreadable rather than "none" or "missing".
- A future sample mtime is reported as file skew, never clamped to 0s.
- The pre-existing Jev badge path can still write jev-status.env when
  the real clawdie-jev-env helper is sourced; this change adds no writes
  of its own and the test stubs that helper to keep the check honest.

Tests: extend the existing status-pane suite (tests/status-pane-event-
and-base-update-test.sh) with 39 hermetic assertions covering the real
probe schema (pretty and compact), truncated/malformed/duplicate JSON,
boot-epoch and skew semantics, rc last-wins and rc.conf.d precedence,
unreadable candidates, absent parser, profile preference semantics, and
a non-vacuous fixture/producer schema drift guard with self-tests that
prove it fails when either side drifts.

Suite results: 90 passed, 0 failed (was 51 before this change).
Verified on Debian 13 and FreeBSD 15.1-RELEASE-p7.

Sam & Pi
Expand collect_platform_firmware() in clawdie-system-probe to collect
local BIOS, SMBIOS system/planar/chassis metadata and serials/UUIDs via
FreeBSD kenv(1) + sysctl (kern.hostuuid, kern.hostid) with a Linux
/sys/class/dmi/id fallback, emitting null for unavailable fields.

Keep outbound N-Quads (--emit-nquads) limited to non-identifying
firmware/board model metadata (biosVendor, biosVersion, systemMaker,
systemProduct, planarMaker, planarProduct), excluding raw UUIDs,
host_id, and serial numbers from unauthenticated Oxigraph projection.

Add hermetic kenv/sysctl, DMI fallback, and N-Quads filter tests to
tests/clawdie-system-probe-test.sh.
- Encode platform_firmware via python3 json.dumps(..., ensure_ascii=True)
  with raw-byte UTF-8 replacement (plus portable POSIX-sh fallback), so
  control characters and invalid UTF-8 bytes from OEM firmware never
  produce malformed JSON.
- Fix json_escape() to strip control characters portably on FreeBSD and
  GNU sed/awk.
- Record per-field platform_firmware.field_status (ok | empty | absent |
  permission_denied | read_error | unavailable) while preserving raw
  values verbatim (including OEM placeholders), so read failures or
  permission denials are never conflated with absent fields.
- Propagate non-zero exit status on --emit-nquads failure (missing
  python3 or JSON parse error) instead of exiting 0 with empty stdout,
  and escape control characters in N-Quad string literals.
- Add hermetic no-kenv DMI fallback, permission_denied vs absent, OEM
  placeholder, control-char/non-UTF8 firmware, and --emit-nquads failure
  tests to tests/clawdie-system-probe-test.sh.
- Invoke kenv without -q and classify kenv/sysctl non-zero exits from
  stderr: 'unable to get'/'unknown oid' -> absent, permission errors ->
  permission_denied, all other/silent failures -> read_error (never
  guessed absent).
- Flag invalid UTF-8 or ASCII control characters in firmware values with
  field_status='malformed' (never 'ok'), and when python3 is absent emit
  null + field_status='no_parser' instead of lossy shell tr-stripping.
- Fix Case 5 test PATH portability on FreeBSD (/usr/local/bin/python3)
  by symlinking real python3 into SMBIOS_BIN, and require rc==0 plus
  non-empty N-Quads before exclusion assertions so empty output cannot
  pass vacuously.
- Remove sova from clawdie_hw_harvest REQUIRE (keeping REQUIRE:
  clawdie_lineage and BEFORE: colibri_daemon) so hardware facts land
  before optional services and work cleanly offline.
- Rotate hardware-facts.json -> hardware-facts.prev.json atomically ONLY
  when petelin_provenance.boot_epoch changes (same-boot re-runs never
  clobber the prior boot's stamp).
- Emit deterministic, privacy-minimized hw-diff.json (clawdie.hw-diff.v1):
  classifies first_boot | same_host | hw_changed | new_host | unknown,
  deduplicates equal system/host UUIDs and system/chassis serials, treats
  OEM placeholders ('None', all-zero UUID, etc.) and absent planar fields
  as 'unknown' rather than fake changes, sets capacity_recheck_needed
  without inventing RAM thresholds, and never leaks raw UUIDs/serials.
- Update tests/rcorder-graph-test.sh and add tests/hw-harvest-diff-test.sh.
- Add --emit-nquads-from <json> to clawdie-system-probe so
  clawdie_hw_harvest probes hardware once and derives hardware-facts.nq
  from that exact snapshot (eliminating JSON<->NQ double-probe drift).
- Add replay / onereplay subcommand to clawdie_hw_harvest that projects
  the saved hardware-facts.nq with zero hardware resampling, replaces
  only owned hw-harvest/petelin named graphs via HTTP PUT (falling back
  to POST /store only on HTTP 405/501, never clearing unrelated graphs),
  and writes ingest-status.json atomically with payload_sha256,
  store_url, ingest_mode, and state (pending | ingested | failed).
- Require at least one matching non-placeholder hardware ID signal (and
  clean stamp rotation) before classifying same_host; identical-spec
  hosts with zero comparable IDs now classify unknown with
  capacity_recheck_needed=true.
- Document explicit operator Option B ACL (0644 hardware-facts.json) and
  latest-snapshot-only contract; expand tests/hw-harvest-diff-test.sh to
  16 assertions covering offline->start->replay, stale-triple
  replacement, store-reset recovery, and unknown-ID uncertainty.
Address ZOT-LANE-B-REVIEW-c3a4394 blockers:
1. Replace destructive prefix-based PUT graph replacement with strict
   validation + non-destructive POST /store projection
   (ingest_mode=non_destructive_post, projection_semantics=additive_non_destructive),
   preserving pre-existing triples in shared revision-keyed petelin and
   hostname-keyed hw-harvest graphs across independent writers.
2. Fail closed (0 HTTP calls, state=failed, non-zero on replay) on
   malformed N-Quads, empty snapshots, disallowed graph URIs, or HTTP
   4xx/5xx responses (no silent POST fallback on HTTP 405).
3. Require a valid non-placeholder unique serial/UUID (respecting
   platform_firmware.field_status=='ok' when present) AND known equal
   ram_gb/cpu_cores before classifying same_host; move planar_maker +
   planar_product to non-unique capabilities; set
   capacity_recheck_needed=true on first_boot and whenever core
   capabilities are unknown.
4. Stage hardware-facts.json and hardware-facts.nq together before
   committing either file (serializing concurrent start/replay via
   lockdir), invalidate ingest-status.json truthfully to failed on NQ
   conversion failure and to pending for the new payload_sha256 prior to
   Sova projection. Preserve approved 0644 Option B + latest-snapshot
   decisions and document that no automatic replay trigger exists yet.
Addresses ZOT-REVIEW-ea7eaf5 blockers on feat/jumping-usb-hw-stamp-and-status:
1. Enforce strict generated-subset N-Quads object grammar (IRI or typed/escaped
   literal only; rejects bare tokens like NOT_A_VALID_RDF_OBJECT with 0 HTTP calls).
2. Treat ram_gb<=0 / cpu_cores<=0 as unknown (capacity_recheck_needed=true); when
   platform_firmware.field_status is present, require a dict with key == 'ok'.
3. Check every mv -f and bind each generation via atomic snapshot-manifest.json
   (json_sha256, nq_sha256, diff_sha256); verify manifest parity before replay.
4. Replace shell mkdir/.harvest.lock with kernel-managed fcntl.flock(.harvest.flock)
   and reject both symlinks and non-regular files at every target path.
5. Label additive POST explicitly non-authoritative (ingest_mode:
   additive_post_non_authoritative, current_state_safe: false, stale_triples_possible: true).
6. Never mask status-write failures behind || true; fail non-zero when ingest-status.json
   or hardware-facts.nq cannot be written.
Addresses ZOT-REVIEW-4faf7b6 findings on feat/jumping-usb-hw-stamp-and-status:
1. Stage hardware-facts.prev.json in a temp file and only commit after
   ingest-status.json pending write succeeds; reject same-boot prev_epoch == curr_epoch
   as unknown + capacity_recheck_needed=true (never fake same_host).
2. Verify diff_sha256 and prev_sha256 in snapshot-manifest.json before replay
   and reject Unicode surrogate escapes (\uD800..\uDFFF) with 0 HTTP requests.
3. Remove forgeable CLAWDIE_HW_HARVEST_LOCKED=1 bypass: clawdie_hw_harvest_start
   and clawdie_hw_harvest_replay unconditionally acquire kernel fcntl.flock()
   before dispatching internal functions with SIGTERM/SIGINT forwarding.
4. Preserve hw-diff.json and snapshot-manifest.json in firstboot/retarget-be.sh
   and verify sibling snapshot-manifest.json in clawdie-max2-state when present.
Addresses ZOT-PR2-D579-REVIEW findings on feat/jumping-usb-hw-stamp-and-status:
1. firstboot/retarget-be.sh: acquire shared .harvest.flock when present, copy the
   complete hw-harvest bundle including hardware-facts.prev.json, verify full
   snapshot-manifest.json parity before publishing, scrub stale destination files
   absent from source, and exit non-zero on copy or parity failure.
2. clawdie-hw-harvest-rc (malformed prev): hash raw hardware-facts.prev.json bytes
   into prev_sha256 whenever present as a regular file and record prev_status
   (ok|malformed|missing) so evidence is preserved, hw-diff stays unknown, and
   start/replay parity succeeds cleanly until next distinct boot overwrites prev.
3. clawdie-hw-harvest-rc (process-group flock): spawn locked child in its own
   process group (start_new_session=True) inheriting the locked fd (pass_fds);
   SIGTERM/SIGINT kills the entire process group before closing fd, and SIGKILL
   of the wrapper keeps the kernel flock held by surviving descendants until exit.
4. clawdie-hw-harvest-rc (interrupted publish): verify existing hardware-facts.json
   against snapshot-manifest.json (json/nq/diff digests) before promoting it to
   hardware-facts.prev.json; refuse to promote uncommitted mixed generations and
   report classification=unknown + capacity_recheck_needed=true.
Addresses ZOT-PR2-PREV-PARITY on feat/jumping-usb-hw-stamp-and-status:
- Verify hardware-facts.prev.json presence and SHA-256 digest against
  snapshot-manifest.json prev_sha256 before any baseline comparison or rotation.
- Mark unverified/tampered/unexpected prev baselines with prev_status=unverified
  and classification=unknown + capacity_recheck_needed=true, and refuse to
  launder prev_status=unverified back into same_host on repeated same-boot harvests.
- Preserve matching malformed prev evidence (prev_status=malformed) while
  recovering cleanly on the next distinct boot.
- Add regression tests for tampered valid prev (100->50), repeated same-boot
  anti-laundering, missing prev, unexpected prev after prev-rename interruption,
  and matching malformed prev.
Addresses ZOT-PR2-RETARGET-PATH and ZOT-PR2-LINK-COHERENCE:
1. firstboot/retarget-be.sh: traverse and create MNT/var/db/clawdie/provenance/jumping-usb
   strictly via dir_fd + O_NOFOLLOW|O_DIRECTORY (never following symlinked parents,
   symlinked jumping-usb, or symlinked targets) and stage files with randomized
   O_CREAT|O_EXCL|O_NOFOLLOW temp files + descriptor-relative os.replace/os.unlink.
   Documents residual trust boundary ( mountpoint trust, checked per-file publication).
2. firstboot/retarget-be.sh: validate birth-record.json and derive parent-usb-link.json
   BEFORE touching ; remove broad except Exception: pass so malformed records or
   write errors fail closed non-zero without overwriting prior coherent files; scrub
   stale cert/link/hw artifacts absent from the new source bundle.
3. tests/retarget-be-test.sh: add Scenario 7 (symlinked jumping-usb, symlinked parent
   provenance, symlinked destination file; verifies non-zero exit + external dir/file
   untouched) and Scenario 8 (malformed birth-record fail-closed + stale cert/link scrub).
4. tests/hw-harvest-diff-test.sh: fix FreeBSD ps -o syntax (separate -o flags) and
   /bin/sh tail-call exec detection in _find_py_holder for SIGTERM/SIGKILL lock tests.
Addresses ZOT-PR2-UNVERIFIED-BIRTH-DECISION (Option B) on feat/jumping-usb-hw-stamp-and-status:
1. clawdie-birth-certificate (collect_usb_derivation): require regular non-symlink
   birth-record.json whose canonical self-hash (indent=2 + newline) matches declared
   64-hex record_sha256, verify birth-manifest.json schema/record_sha256 when present,
   and remove unverified parent-usb-link.json orphan fallback. Invalid/missing/orphan
   evidence degrades to None (no derivation claim, raw files preserved, optional boot
   never blocked). Self-hash is documented as internal record integrity, not auth.
2. firstboot/retarget-be.sh: verify canonical self-hash of birth-record.json (and
   birth-manifest.json parity when present) before touching MNT; fail closed non-zero
   on forged/mismatched explicit cert without altering prior coherent provenance, while
   keeping optional cert absence non-blocking.
3. tests/retarget-be-test.sh: use repository canonical self-hashes in Scenarios 5 & 8,
   add forged/tampered/manifest-mismatch retarget negatives, and add Scenario 9
   independently testing collect_usb_derivation on valid, forged, tampered, bad-manifest,
   orphan-link, malformed-with-link, and missing/empty fixtures.
Addresses ZOT-PR2-LOCK-TEST on feat/jumping-usb-hw-stamp-and-status:
- Replace fixed-sleep + kill -0 SIGKILL check with a gate-file-controlled first
  probe and direct fcntl.flock(LOCK_EX|LOCK_NB) checks (portable across Linux
  errno 11 and FreeBSD errno 35) proving HELD before and after SIGKILL of the
  real Python lock holder while the grandchild lives.
- Verify a second real harvest's probe entry marker stays absent while gated,
  then appears and completes once released, with flock returning to FREE.
Addresses ZOT-PR2-LOCK-CLEANUP on feat/jumping-usb-hw-stamp-and-status:
- Remove late kill -TERM on _gc_kpid after gate release / FREE (avoids signaling
  an unrelated reused PID); release gate.release in cleanup() trap instead.
- Bound waiting for _second_pid with an explicit deadline checking ps stat (distinguishing
  zombie Z* from live) and only signaling our unreaped direct child on timeout.
Addresses ZOT-PR2-PRIVACY-DECISION and ZOT-PR2-URL-ERROR on feat/jumping-usb-hw-stamp-and-status:
1. clawdie-hw-harvest-rc: enforce literal http://127.0.0.1 or http://[::1] only before
   any network call on both boot and replay; reject localhost DNS/hosts, userinfo,
   malformed URLs (catching urlsplit ValueError), invalid/out-of-range ports, HTTP
   redirects, and proxy environment variables with 0 off-target HTTP requests while
   preserving the local snapshot and recording state=failed (projection_scope:
   local_loopback_only) without leaking URL userinfo/credentials into ingest-status.json.
2. clawdie-hw-harvest-rc & clawdie-system-probe: document truthfully that N-Quads omit
   known raw ID keys but still carry hostname (node_slug) and free-form SMBIOS/model
   strings (potentially identifying, NOT anonymized; pure emit has no network gate).
3. firstboot/retarget-be.sh & clawdie-birth-certificate: reject non-finite JSON
   constants (NaN/Infinity/-Infinity) via parse_constant and allow_nan=False.
4. tests/hw-harvest-diff-test.sh & tests/retarget-be-test.sh: cover non-loopback,
   localhost DNS, redacted userinfo, malformed IPv6 bracket, invalid/out-of-range ports,
   local 302 redirect non-follow, ignored HTTP_PROXY/ALL_PROXY, literal IPv6 [::1], and
   NaN birth-record rejection.
Addresses ZOT-PR2-URL-QUERY-SECRET on feat/jumping-usb-hw-stamp-and-status:
- Restrict CLAWDIE_OXIGRAPH_STORE_URL to exact http://127.0.0.1[:port]/store or
  http://[::1][:port]/store with zero query, fragment, userinfo, or extra path segments.
- Canonicalize valid loopback URLs and replace any rejected URL with
  <redacted-disallowed-url> in 0644 ingest-status.json; use static error strings
  without echoing raw hostnames, queries, paths, or HTTP redirect Location headers.
- Add synthetic canary tests covering query, path, fragment, userinfo, disallowed host,
  and redirect Location across boot/replay/redirect states.
Addresses ZOT-PR2-TEST-PRIVACY-LABEL on feat/jumping-usb-hw-stamp-and-status:
Relabel the synthetic SERIAL_DO_NOT_LEAK / MAC regex check in
tests/server-matrix-and-oxigraph-harvest-test.sh so it accurately describes
the synthetic fixture check rather than claiming universal absence of UUIDs
or raw identifiers.
Merge remote-tracking branch 'origin/main' into feat/jumping-usb-hw-stamp-and-status
All checks were successful
format-check / gates (pull_request) Successful in 2m17s
91ab01143b
clawdie deleted branch feat/jumping-usb-hw-stamp-and-status 2026-11-19 21:19:55 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
clawdie/clawdie-iso!82
No description provided.