Repository navigation
docs: rule the session accessors and record phase 2 as proved - #411
Merged
Merged
Conversation
Phase 2b of the native-Windows-permissions plan (#405) needed two design questions answered before its 82-site mechanical pass could start. Both are now ruled, with the reasoning and the rejected alternatives recorded so neither gets relitigated. Root: HasRoot() bool plus a Root() that panics when it is false, modeled on reflect.Value.IsValid -- whose doc states the rule once, whose panic is typed rather than a string, and whose discipline puts the burden on the producer to advertise. The case is real: cmd/lore/lore/builder.go builds a rootless session in production, and seven call sites nil-check the field today. Comma-ok was rejected on call-site distribution (75 of 82 sites structurally have a root); a bare nil was rejected because fsroot.Root is an interface, so nil relocates the panic into fsroot internals rather than preventing it. Scratch: no HasScratch -- root's absence is configured, scratch's is not configurable at all, so the predicate could only ever return true. Scratch() is an accessor to a per-session directory INSIDE the OS temp directory, never a root over the temp directory itself: OpenScratch's Close contract would delete the shared tree, confinement to a directory every process writes to isolates nothing, and only a directory of our own can be created 0700 and pick up phase 2's DACL protection -- which matters, because scratch holds the most sensitive transient data. os.TempDir() accessibility is preflighted at environment build like the root's anchor, and that decides the signature: preflighting supplies the validated premise, so a later MkdirTemp failure is a failure AFTER verification, which is an assert. Scratch() fsroot.Dir returns the directory alone, symmetric with Root(). fsroot.Dir gains CreateTemp and MkdirTemp, landing in 2b.2 alongside the accessors. A shared per-session directory needs unique names within it and gather dispatches bodies concurrently by design; os.CreateTemp gives that free today and Dir.Create does not. Both trees carry the methods, and the rule for choosing goes in both doc comments: use Scratch() unless the bytes must end up in the root's tree atomically, because a rename out of scratch can cross a device boundary. Phase 2 is marked complete. Its CI exit gate was met and never recorded: pkg/fsroot reports ok on test (windows-latest), so all six TestApplyMode DACL tests pass on a real runner and none appear in that leg's 28 known failures. Call sites are cleared to migrate. Also: PR 2b.1 split into 2b.1a (merged, #410) and 2b.1b (next), with a branch plan for the remaining 13 files and 26 sites naming both traps -- starcode's Root: lines are only half environment fields, and file/provider_test.go sets a BackupSuffix the constructor never defaults. The current-state table now separates Windows enforcement through fsroot, which works, from everywhere else, which does not. Recorded from the 2b.1a round-trip: make lint-all is the gate to run before handing off Go changes, not gofmt, which never reorders import groups. This repository runs no pre-commit hooks by decision. Assisted-by: Claude Signed-off-by: David Noble <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2b of
windows-native-permissions.md(#405) was blocked on two design questions.
Both are ruled here, with rejected alternatives recorded so they are not relitigated.
The rulings
Root—HasRoot() boolplus aRoot()that panics when it is false, modeled onreflect.Value.IsValid: the rule stated once in the predicate's doc, a typed panic rather than astring, and the producer advertising which constructors can yield a rootless session. The case is
real —
cmd/lore/lore/builder.go:108builds one in production, and seven call sites nil-check thefield today.
Rejected: comma-ok (
context.Deadline's shape) on call-site distribution — 75 of 82 sitesstructurally have a root, which is exactly why
reflect.Valuepairs a predicate with panickinggetters; and a bare
nil, becausefsroot.Rootis an interface, so nil does not avoid thepanic, it relocates it into
fsrootinternals with a stack that never names the mistake.Scratch— noHasScratch(root's absence is configured, scratch's is not configurable atall, so the predicate could only ever return
true), andScratch()is an accessor to aper-session directory inside the OS temp directory — never a root over the temp directory itself.
That anchoring fails three ways:
OpenScratch'sClosecontract would delete the shared systemtemp directory; confinement to a directory every process writes to isolates nothing and collides by
name; and only a directory of our own can be created
0700and inherit phase 2's DACL protection —which matters, because scratch holds the most sensitive transient data in the system.
os.TempDir()accessibility is preflighted at environment build like the root's anchor, andthat settles the signature: preflighting supplies the validated premise, so a later
MkdirTempfailure is a failure after verification — an assert.
Scratch() fsroot.Dirreturns thedirectory alone, symmetric with
Root().fsroot.DirgainsCreateTempandMkdirTemp, landing in 2b.2 alongside the accessors. Ashared per-session directory needs unique names within it, and
gatherdispatches bodiesconcurrently by design —
os.CreateTempsupplies that free today,Dir.Createdoes not. Both treescarry the methods; the rule for choosing goes verbatim in both doc comments: use
Scratch()unless the bytes must end up in the root's tree atomically, since a rename out of scratch can
cross a device boundary and degrade to a copy.
Phase 2 is complete
Its CI exit gate was met and never recorded:
pkg/fsrootreportsokontest (windows-latest), so all sixTestApplyMode_*DACL tests pass on a real Windows runner andnone appear in that leg's 28 known failures. Call sites are cleared to migrate, which was the
condition phases 3 and 4 were waiting on.
Also
remaining 13 files / 26 sites naming both traps:
starcode'sRoot:lines are only halfenvironment fields, and
file/provider_test.gosets aBackupSuffixthe constructor neverdefaults.
fsroot(works) fromeverywhere else (does not).
make lint-allis the gate, notgofmt, which neverreorders import groups. This repository runs no pre-commit hooks, by decision.
Documentation only — no code changes.
Assisted-by: Claude