The hub read request bodies with unbounded io.ReadAll / json.Decode and ran
http.ListenAndServe with zero timeouts — a single client could OOM it or hold
connections open (slowloris). Now:
- handleBlob caps the body at 256 MiB, decode() caps JSON at 8 MiB, both via
http.MaxBytesReader -> 413 when exceeded.
- serve uses an http.Server with ReadHeaderTimeout/ReadTimeout/IdleTimeout +
MaxHeaderBytes. WriteTimeout intentionally unset so the long-lived /v1/events
SSE stream isn't killed. [fanned-out subagent: harden-dos]
A power loss between rename and the data hitting disk could leave a truncated/
empty file despite the atomic rename — breaking 'never lose a byte'. Now both
atomic-write paths f.Sync() the temp file before rename and best-effort fsync
the parent dir after (so the rename entry is durable too):
- internal/syncer/pull.go atomicWrite (pulled file content)
- internal/hub/blobstore Disk.Put (stored blobs)
Dir fsync is best-effort (unsupported on Windows). [fanned-out subagent: harden-fsync]
- rescan tickers for all mounts started in lockstep, so every 60s they rebuilt
manifests simultaneously (self-synchronized load spike on big trees). Stagger
the first tick by a random offset.
- jittered() called rand.Int63n(int64(d/2)) which panics for sub-2ns durations
(d/2==0). Guard it. (Latent: a panic in a recover-less goroutine.)
- healthyStream was 2min — 4x larger than typical SSE recycle (~30-60s), so a
recycled-but-healthy stream never reset backoff and sat at the 30s ceiling.
Lowered to 20s. Regression test for the jitter panic.
Snapshots are content-addressed with a GLOBAL id, so two shares with identical
content collide on one snapshots row and the idempotent push skips the refcount
bump — a chunk two share heads both need ends up refcount=1. The old GC then
pruned the 'old' snapshot for one share and freed chunks/manifests the OTHER
share's live head still pointed at. Permanent cross-share data loss.
Rework runGC as mark-and-sweep from every share's live snapshots as roots:
nothing reachable from a kept snapshot is ever deleted, whatever the refcounts
say. Never prune a snapshot that is any share's head. Plus hardening:
- DeleteSnapshot floors refcount at 0 and only decrements if the row existed
(no negative counts from a double-delete).
- DeleteChunkRow is now conditional (WHERE refcount<=0) and reports if it
deleted, so a push that re-references a chunk mid-GC isn't corrupted.
Cross-share repro test + existing single-share GC test both green.
Deferred to v2 (documented): proper per-(share,id) refcount accounting — needs
a schema migration of the live hub; the ground-truth GC makes it safe meanwhile.
The pull merge compared the hub against 'ours' = a .devignore/secret-guard
FILTERED manifest. A file still on disk but excluded from 'ours' looked like a
local delete, so a hub edit to that path hit 'case tOK && !oOK' and overwrote
the on-disk bytes with NO conflict copy — silently destroying ignored configs
and the very .env/keys the guard exists to protect (a teammate pushing .env
could wipe your local secret).
Now: in that branch, stat the real file first; if it's actually present,
preserve it as a .conflict-<host>-<ts> copy before applying the hub version —
honoring the 'never lose a byte' promise. Regression test proves the local
bytes survive.
Two ways a buggy/malicious hub could corrupt the local tree:
- writeEntry/deleteFile joined hub-supplied Entry.Path into root with no
containment check, so '../../.ssh/authorized_keys' wrote/deleted OUTSIDE the
mount. New safeJoin() uses filepath.IsLocal to refuse absolute/.. /escaping
paths before any write or delete.
- GetBlob returned bytes with only an HTTP-status check. Blobs (chunks AND
manifests) are content-addressed, so now verify chunk.Hash(body)==hash —
a corrupt/truncated transfer or hostile hub can't write wrong content
undetected. (manifest ID == chunk.Hash(Marshal()), so the check holds there.)
Regression tests for both.
GET /v1/blob/{hash} and /v1/have passed the URL hash straight into filepath.Join
in the blob store. Go's ServeMux URL-decodes %2f/%2e in the wildcard, so
'..%2f..%2f..%2fetc%2fpasswd' (or a hash starting with '..') escaped the blob
root — any enrolled device could read arbitrary files incl. the hub token DB.
Defense in depth:
- hub: validHash() rejects non-(64 hex) keys at the HTTP boundary (404 on GET,
400 on /have) before any store call.
- blobstore: safeKey() rejects keys that aren't a bare, separator-free filename
in Has/Get/Put/Delete — the sink can't be escaped even if a caller forgets.
e2e + unit regression tests for both layers.
Audit found the guard silently uploads real credentials:
- patterns were case-sensitive: .ENV / KEY.PEM / ID_RSA / Server.Key all passed
through on macOS/Windows. New ignore.CompileFold compiles the guard deny-list
case-insensitively (.devignore stays case-sensitive, gitignore semantics).
- added *.env and .envrc (prod.env / config.env hold the same secrets as .env).
- .aws/credentials and .ssh/id_* were root-anchored — a nested copy leaked; now
**/ depth-matched.
Regression test covers all three.
The v1 daemon only re-syncs a mount on a watcher event or a hub event. If the
watcher can't start (inotify max_user_instances/max_user_watches exhausted on a
big Pi tree — PRD risk #1) the mount silently stops pushing local edits.
Add a 60s per-mount rescan ticker that nudges a sync regardless, so a mount
reconverges even with no working watcher. Watcher-start failure now logs the
fallback + points at 'devbox doctor' instead of going quiet.
Fleet-verified on linux/arm64: with fs.inotify.max_user_instances=0 (watcher
dead) a local edit still propagated to a peer via the rescan tick.
scripts/m7-fleet-verify.sh exercises the full M7 surface + this rescan path.
Code-review pass on M6.5+M7:
- pidfile: claim via O_CREATE|O_EXCL and arbitrate live-vs-stale, so two
`devbox start` invocations can't both win the guard and run concurrently
- hub: serialize publish (publishMu) so a case-clash check + create is atomic;
reject share names ending in '.' (Windows strips it → silent collision)
- daemon: reset SSE backoff only after a genuinely healthy stream (2m), not the
30s ceiling, so a hub that recycles connections doesn't pin a 30s event lag
- document that restore/deploy's delete pass is ignore/guard-filtered on purpose
(never delete a user's gitignored runtime files or local secrets)
- test: pidfile claim/refuse/stale-reclaim arbitration
- devbox doctor: checks identity/join, hub reachability + bearer acceptance,
bash for hooks, fsnotify watcher (catches inotify exhaustion), and each mount's
writability; exits non-zero on any failure
- devbox stop + pidfile: start writes ~/.config/devbox/daemon.pid and refuses a
second daemon; stop SIGTERMs it (liveness-checked, cleans stale pidfiles)
- devbox hook edit <share> <event>: scaffolds an executable, documented bash
sample then opens $EDITOR/$VISUAL; hook list shows installed vs available
- hooks: AllEvents/IsEvent/Dir/Sample helpers
- daemon: exponential backoff (1s→30s) + ±25% jitter on SSE reconnect so a fleet
that drops together doesn't reconnect in lockstep; a long-lived stream resets it
- hub: ValidateShareName rejects path separators, traversal, control/non-ASCII
chars, reserved Windows device names (CON/NUL/COM1…), and case-clashes with an
existing share (Foo vs foo would collide on case-insensitive filesystems)
- tests for both
deploy applies a snapshot's manifest to a mount's local dir WITHOUT pushing a
new head — blue/green for /var/www boxes. History stays untouched; the mount is
pinned (config.Mount.Pinned) so the daemon won't live-advance it back to head.
Re-mount clears the pin.
- syncer.Deploy + shared applySnapshot helper (Restore now reuses it)
- config.Mount.Pinned; daemon skips pinned mounts
- CLI: devbox deploy <share> <snapshot> (prefers the --ro mount); status shows pinned
- test: deploy applies v1 while hub head stays v2 (the no-push property)
- mount share/subpath into any local dir; Pull filters+strips the share manifest
to the subpath, Push splices the local subtree back into the full share head
(entries outside the subpath preserved) so a partial mount never drops the rest
- declares all full-manifest chunks for correct hub refcounts (hub chunks size 0)
- cmd: 'devbox mount projects/p22/backend /var/www'; daemon threads Subpath
- state keyed by share+subpath+local
- test: sub-path mount sees only its subtree (stripped); editing+pushing from it
preserves docs/ and root.txt elsewhere in the share
- pkg/proto + internal/hub/events.go: SSE /v1/events with a broker; hub broadcasts
on genuine head ADVANCE only (idempotent re-push doesn't broadcast -> no storm)
- transport.Client.Events: SSE consumer (timeout-less, ctx-cancelled)
- internal/daemon: per-mount loop funnels watcher + SSE triggers into a serialized
Sync; read-only mounts pull-only; base snapshot persisted in state.json
- cmd/devbox: 'mount <share> <dir> [--ro]' (clone+sync) and 'start' (foreground daemon)
- fix: serialize chunk.Split — jotfs/fastcdc-go mutates a package global in
NewChunker, racing under concurrent chunking (caught by -race)
- test: two live daemons, an edit on one reaches the other automatically (race-clean)
- internal/syncer Pull: fetch hub head manifest, 3-way merge vs base + local tree:
hub-only changes apply (write/delete), local-only stay, both-changed keeps hub
canonical + preserves the local edit as path.conflict-<host>-<ts>.ext
- delete-vs-edit always keeps the edit; identical concurrent edits don't conflict
- Sync: pull->merge->push with conflict-retry loop (converges under races)
- atomic file writes; chunk reassembly via GetBlob
- tests: two devices concurrent-edit -> conflict copy propagates to BOTH, zero data
loss; hub delete propagates to clones