Commit graph

16 commits

Author SHA1 Message Date
efc8bcc24b
fix: merge advanced hub head after sync push conflict 2026-11-28 00:17:41 -06:00
f1a6ac226f fix(syncer): stop pull from clobbering an edit made during the pull window
manifest.Build snapshots `ours` once before Pull applies any writes. A local
edit landing after that snapshot but before writeEntry looked unchanged
(oursCh false) and got overwritten with the hub version verbatim, with no
conflict copy — the edit's bytes ended up in no file and no snapshot.

Re-stat/re-hash the on-disk file right before a hub-only write would apply
and compare it against the entry manifest.Build captured. A mismatch routes
through the existing preserve-as-conflict path instead of clobbering. Only
checked when hub is about to write over a path `ours` already knew about —
a pure hub-only add has nothing on disk yet to race with.

This narrows the window, it doesn't close it: a rename at pull.go:424-451
still isn't atomic with this check. A real fix needs a filesystem-level
lock or lease around the whole pull, tracked separately.

Includes the untracked repro (zz_repro_stale_ours_test.go) that found this.
2026-08-05 02:35:12 -05:00
4727d3d7f3 round9-client: log swallowed hook failures, doctor free-disk check, validate devbox ignore pattern 🩺⚠️🙈
Some checks are pending
CI / vet-build-test (push) Waiting to run
2026-06-30 18:07:53 -05:00
963ece58b0 feat(transfer): harden the WAN sync path — timeouts, retry, parallel I/O, download gzip 🌐⚡
Now the hub is WAN-reachable, the transfer path needed real hardening:

- ⏱️  request timeout fix: replaced the 30s TOTAL http.Client.Timeout (which
  killed a 256MiB blob mid-transfer over a slow link) with granular dial / TLS /
  response-header timeouts + TCP keepalive. Body transfer is no longer wall-clocked.
- 🔁 retry + exponential backoff on transient blob transfers (network / 5xx),
  3 attempts; 4xx fails fast. Blob GET/PUT are content-addressed (idempotent),
  so retry is safe; control calls are left alone.
- 🚀 parallel blob uploads (push) and parallel chunk downloads (pull reassembly),
  bounded pools (8), sharing the existing rate limiter. WAN is RTT-bound — this
  keeps the pipe full instead of one-blob-at-a-time.
- 🗜️ download (response) gzip: round 1 compressed only uploads, but a clone is
  download-heavy. Client negotiates gzip explicitly (so the rate limiter counts
  wire bytes), hub streams the response through gzip, client decompresses
  bomb-safely. Gated by the same settings.transfer.compress flag.

Tests: retry transient-then-success + 4xx-no-retry, gzip download round-trip.
All existing push/pull round-trips green under -race (refactors behavior-preserving).
2026-06-30 13:15:17 -05:00
03469958d3 chore: prep for public release — MIT license + github.com module path 🌍⚖️
Some checks are pending
CI / vet-build-test (push) Waiting to run
- LICENSE: MIT (enables the adoption push; public repo was all-rights-reserved).
- go.mod + all imports: git.shoemoney.ai/shoemoney/devbox -> github.com/shoemoney/devbox,
  so outsiders can 'go install github.com/shoemoney/devbox/cmd/devbox@latest'. Forgejo
  stays the self-hosted home; the registry (devbox-hub) + public dist (devbox-dist) are
  unchanged. vet + build + go test -race all green after the rename.
- README: document the go install path.

Security: full git-history scan (manual blob sweep + gitleaks, 84 commits) found
ZERO secrets — Forgejo token never committed, no keys/passwords/private keys.
2026-06-23 19:19:09 -05:00
abab3b5ff9 feat(M8): restore preserves uncommitted edits (never lose a byte) 🛟
Closes the audit's deferred #18 — the right way this time. An explicit
'devbox restore' no longer silently clobbers UNCOMMITTED local edits:

- captureUncommitted reads the bytes of any local file that differs from
  BOTH the snapshot being restored AND the current hub head (== an edit
  that was never pushed) BEFORE the restore overwrites/deletes it.
- After applySnapshot runs, those bytes are written back as .conflict-
  <host>-<ts> copies (discoverable via 'devbox conflicts', and they
  propagate like any conflict copy).

The head comparison is the key: a CLEAN restore (no uncommitted edits)
captures nothing and reproduces the snapshot exactly — TestRestoreWholeTree
still passes. Capture-before / write-after ordering means applySnapshot's
delete pass never eats the copy. Refactored the conflict-name probe into a
shared freeConflictName. Deploy stays as-is (read-only/pinned mounts have
no uncommitted edits to lose). New test: an uncommitted v3 survives a
revert to v1 as a conflict copy. 18 pkgs -race green; windows builds.
2026-06-23 11:44:45 -05:00
4b6a4b97b2 harden(durability): fsync atomic writes before publishing the rename 💽
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]
2026-06-23 02:59:26 -05:00
57ebed35b5 fix(dataloss): don't clobber a .devignore'd/guarded local file on pull 🩸🛟
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.
2026-06-23 02:28:51 -05:00
c864461fa1 fix(sec): contain manifest paths + verify blob integrity on download 🛡️🧊
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.
2026-06-23 02:24:32 -05:00
5bfccdb297 fix(M7): review fixes — pidfile O_EXCL, publish race, backoff reset 🐛
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
2026-06-23 01:37:58 -05:00
2c6dba2dd2 feat(M6.5): devbox deploy — pin a mount to a snapshot (no push) 🚀
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)
2026-06-23 01:17:20 -05:00
6d0453d8e3 feat(M6): versioning — log, restore, hub gc 🕰️
- devbox log <share>: hub GET /v1/log (meta.SnapshotLog newest-first), client.Log
- devbox restore <share> <snapshot> [path]: snapshot id == manifest blob hash, so
  syncer.Restore fetches the old manifest, rewrites the file(s) (+deletes extras for
  a whole-tree restore), and pushes -> itself a new reversible snapshot
- devbox-hub gc [--keep N]: prune snapshots beyond the newest N (never the head),
  decrement chunk refcounts, sweep refcount<=0 chunks + manifest blobs from the store
- meta: SnapshotLog, ShareNames, DeletableSnapshots (rowid tiebreaker), DeleteSnapshot
  (tx + refcount--), UnreferencedChunks, DeleteChunkRow
- tests: log order/limit, deletable keeps head+newest, refcount decrement, whole-tree
  + single-path restore, gc end-to-end (old unique chunks freed, head intact)
2026-06-23 01:01:54 -05:00
613de19818 feat(M5): lifecycle hooks 🪝
- internal/hooks: Runner finds <mount>/.devbox/hooks/<event>, runs via bash (or
  .ps1->pwsh), injects DEVBOX_EVENT/MOUNT/SHARE/HOST/REMOTE/SNAPSHOT/CHANGED_FILES,
  60s timeout (WaitDelay bounds post-kill cleanup), pre-* non-zero exit = veto
- syncer fires pre-push/post-push (in Push) + pre-pull/post-pull/on-conflict (in
  Pull); pre-* veto -> PullResult/Result.Vetoed -> Sync skips, waits for next nudge
- daemon builds a Runner per mount; cmd mount/publish pass nil (daemon drives hooks)
- tests: env+changed-files injection, absent=no-op, pre-* veto, 60s timeout kill,
  post-pull fires with changed list, pre-push vetoes (head not advanced)
2026-06-23 00:48:16 -05:00
512e7f8b73 feat(M4): sub-path mounts 🎯
- 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
2026-06-23 00:36:11 -05:00
6532c510f5 feat(M4) + harden: bandwidth cap + M3 review fixes 🔒🛡️
Bandwidth cap (M4):
- transport rate-limited blob up/download (golang.org/x/time/rate); config.toml
  [transfer].max_kbps; daemon applies it per mount; [secrets].extra_patterns too

M3 ponytail review fixes (data-loss + resilience):
- C1: conflict-copy names use nanoseconds + collision probe — second-granularity
  timestamps could collide and os.Rename would overwrite a copy (lost edit)
- C3: pull resilience — a filesystem clash (file<->dir) skips that path instead of
  aborting the whole batch; network errors still abort+retry. PullResult.Skipped
- C2(partial): manifest skips .devbox-tmp-* (atomic-write temp files never sync).
  Kept conflict-copy propagation (design + Dropbox: losing edit survives device death)
- dedup: manifest.SameContent shared (was duplicated in pull)
- tests: file<->dir clash skips one path not the mount; rate-limit throttles
2026-06-23 00:29:50 -05:00
a951d4ab2f feat(M3): pull + 3-way merge engine — converge without losing a byte 🔱
- 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
2026-06-23 00:01:06 -05:00