Shared-store adapter plan (FLT-313, v2)¶
Author: Clahadore. v1 was reviewed by Jenny, Gronktayvius (Red Team) and Susie Franny. All three said REVISE, and v2 folds in their findings. The Cedric seat saw an empty diff, so it is re-run against this file.
Problem¶
Peer resource samples travel through one sync folder, set by ResourceFiles.ShareDir() at src/UsageGovernor.Core/ResourceFiles.cs:19. On 2026-11-05 OneDrive stopped uploading:
- the local tree holds 85 GB against a 5 GB free tier;
- Andrew says the subscription is inactive.
Peers stopped receiving samples about 11/03. Greatroom then showed "no peer has room" with no warning.
Goal¶
- Losing any one transport (quota, sign-out, a client crash, an uninstall) does not blind peers.
- When a transport stops, the hook line says so.
- A hook never blocks on cloud or network I/O.
Decisions¶
- The hook reads only a local cache. The watcher owns all discovery, cloud and network I/O, and publishing. It writes the merged peer view to
~/.claude/usage-governor/peers.json.ReadForPreTool(ResourceFiles.cs:107) reads only that file, so the hook touches no store. - Transports are behind
ISharedStore. It has: Name(a closed enum:OneDrive | GoogleDrive | Dropbox | ICloud | Tailnet | Override);Publish;ReadPeers.
Discovery returns a list of stores.
- Folder stores use personal roots only. No team, shared or business folders, since those could expose machine data to an organisation. Discovery sources:
- OneDrive: %OneDriveConsumer%, then %OneDrive%, deduplicated. Never %OneDriveCommercial%.
- Google Drive for desktop: the DriveFS registry mount, or the My Drive folder (the name can be localized). In stream mode it is a placeholder filesystem; in mirror mode it is a plain folder. No DriveInfo label probing on any hook path.
- Dropbox: personal.path from %APPDATA% or %LOCALAPPDATA% Dropbox\info.json, with the file capped at 64 KB.
- iCloud: %USERPROFILE%\iCloudDrive, or a discovered relocation. On macOS, ~/Library/Mobile Documents/com~apple~CloudDocs, which can raise a TCC prompt. The watcher must not trigger that prompt unattended, so iCloud is skipped on macOS unless access is already granted.
Exact paths are confirmed against live docs and captured fixtures before code is merged, never taken from memory.
- Root validation, applied to every root source, including UG_SHARE_ROOTS and UG_RESOURCE_SHARE:
- Canonicalize the path.
- Reject UNC, \\?\ and \\.\ paths, relative paths, non-fixed drives, and any reparse point that escapes the root.
- The subfolder is fixed as _shared/usage-governor/resources.
- Config precedence:
- UG_SHARE_ROOTS (;-separated, absolute paths only) replaces discovery.
- Otherwise UG_RESOURCE_SHARE adds one Override store alongside discovery.
- Bad entries are dropped and logged.
- Peer input is untrusted.
- The filename must match ^[A-Za-z0-9-]{1,32}\.json$ and equal payload.machine (case-insensitive).
- Files are capped at 16 KB, with a limited JSON depth.
- sampledAt must be UTC ISO-8601 and lie within [now - 1h, now + 2m]; otherwise the sample is dropped.
- *.tmp files and conflict copies are ignored.
- Placeholder or offline files (recall-on-open or recall-on-data-access attributes) are skipped, so there is no hydration.
- Merge order: filter by filename, then validate, then reduce to one sample per machine (newest sampledAt; ties go to the lexically first store name), then cap at 16 machines.
- Writes:
- The sample goes to a temp file, which is renamed, with retry on a sharing violation.
- Each store write runs isolated with a 5 s timeout, so one failure never blocks the others.
- A store whose write hangs is skipped for the rest of the tick.
- Liveness:
- Liveness is computed per store, before the merge, and ignores the local machine.
- A store is not syncing when some peer M has a fresh sample (under 30 min old) in another store, while this store holds an older sample from M (older than 30 min). That older sample proves M publishes here.
- A missing sample proves nothing, so it never marks a store as not syncing.
- Liveness metadata is kept apart from routable samples (Cedric, plan review). A sample older than the 1 h routing window is dropped from routing but kept as validated evidence: the machine, sampledAt and the store. That way a stall lasting days still reports the stalled store, instead of the warning vanishing after an hour. Test: a stalled sample 3 days old on store A, with a fresh one on B, still names A.
- When every store is stale and no peer is fresh anywhere, the line says share: no fresh peers. It is no longer silent.
- Hook line: shows provider enum names only, never free text from a path or a payload. For example: share: OneDrive not syncing. If nothing is wrong, nothing is shown.
- TailnetStore gets its own step and its own Red Team pass. Folder stores alone do not restore greatroom, which has only OneDrive installed. Until TailnetStore ships, the ticket stays open and must not be reported as fixed.
- Transport: existing Tailscale SSH only, with BatchMode=yes, ConnectTimeout=3 and StrictHostKeyChecking=yes against existing known_hosts. No new keys or credentials.
- Targets: a static node allowlist from config; addresses only in 100.64.0.0/10 or the tailnet IPv6 range.
- Remote side: one fixed path read with scp or sftp, no remote shell command.
- Runs: single-flight, every 5 min, with a hard 10 s timeout per peer.
- Pulled files go through the same untrusted-input checks.
- If SSH is not already configured between PCs, the step stops and reports. It does not set SSH up.
Steps, each with an executable check¶
ISharedStore,SyncFolderStore, discovery and root validation. Check: unit tests for each provider, using captured or verbatim fixture shapes, each commented with its source. Negative tests: missing client, UNC root,..escape, oversizedinfo.json, commercial OneDrive ignored.MultiStore(merge and write isolation). Check:- a newer
sampledAtwins even with an older mtime; - a future
sampledAtis dropped; - a filename that doesn't match the machine is dropped;
- 40 junk files do not hide a real peer;
- one store throwing or hanging still publishes to the other.
- Liveness. Check: replay fixtures for
- quota stall: the old sample sits on store A and a fresh one on B, so the line names A;
- asymmetric publishers: no false claim;
- local-only fresh: not treated as live;
- all stale:
no fresh peers. - Watcher writes
peers.json; the hook reads only it. Check: - existing
LowResourceProgramTestsandLowResourceFix1Testspass with no edits to those files; - a hook latency test with a deliberately hanging store, where PreToolUse returns in under 200 ms;
- a pinned hook-line test.
- Mutation gate.
Check: Stryker.NET on the new files, with
breakset above 0, so it can fail CI. - TailnetStore (separate commit, separate Red Team seat). Check: tests for the allowlist, CIDR rejection, the timeout and single-flight. A dry run on bedroom pulls greatroom's sample.
- Deploy. Build and run the full suite on bedroom, never greatroom. Swap the publish exe, keeping a rollback copy, and restart each watcher by exact path. Check:
- every PC has a fresh
peers.jsonlisting at least one peer; - greatroom's hook line names a peer when one has room;
- rollback was tested once on bedroom.
Workers¶
- Writer: Jenny (
gemini-4-argon-high), with Susie as fallback. - Router and verifier: Clahadore.
- Review: the council-seat gate before landing. TailnetStore also needs the Gronktayvius Red Team seat.
Out of scope (follow-ups)¶
- Fleet backups (claude-mem, Vikunja) write only to OneDrive, so they have the same single point of failure. They will reuse this adapter.
- The OneDrive subscription itself is Andrew's call.