refactor: whole-project /code audit round 2 (fixes + comment tightening)#71
Merged
Conversation
Line-by-line audit of all 236 Go files against the /code rulebook, findings adversarially verified before fixing. Correctness-adjacent: - utils.ResolveRef prefix path could resolve a null index entry and panic downstream (exact/name paths already nil-checked); skip nil entries - types.VM Resolved* methods deref NetworkConfigs[0] unguarded; add nil-safe firstNIC() accessor - snapshot export --to-dir flag help was mangled by pflag backquote handling - cmd/vm/status watch loop and cmd/vm run cloneFromDir copy pointers unguarded - firecracker console-relay failure now logs the actual error - CNI conflist load errors are no longer silently dropped: stashed and surfaced through errNoConflist at the point of failure Consistency/modernisms: - hand-rolled loops -> slices.ContainsFunc/DeleteFunc/Clone/Concat, maps.Copy, utils.MapValues reuse - qcow2/gzip magic bytes deduped into utils/magic.go (3 copies -> 1) - dead network.ErrNotFound sentinel removed; metering const/var block order; progress exported-above ordering; cmd.vm.* log tag consistency; debug.go verb-less Printf -> Print/Println; BlobExt instead of ".qcow2" Comments: 131 tightened to 1-2 lines (net -138 lines project-wide), dropping restatement/narration while keeping constraint-bearing WHYs; two stale comments corrected against actual behavior (MountSpec renders verbatim, sparse fallback triggers on empty files).
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.
What
Round-2 whole-project
/codeaudit: all 236 Go source files reviewed line-by-line against the house rulebook, findings adversarially verified before fixing, then a project-wide comment-density pass. Net +212 / −338 across 75 files.Correctness-adjacent fixes
utils.ResolveRefprefix path could resolve anullindex entry and panic downstream (the exact-ID and name paths already nil-checked; the prefix path didn't). Skip nil entries — a corrupt/hand-editedvms.jsonnow yieldsErrNotFoundinstead of a crash.types.VMResolved*methods dereferencedNetworkConfigs[0]unguarded → added a nil-safefirstNIC()accessor shared by all three.snapshot export --to-dirhelp text was mangled by pflag's backquote handling (rendered the flag's value-type asvm clone --from-dir). Single-quoted.errNoConflistat the point of failure (a bad.conflistno longer masquerades as "no conflist found").cmd/vmwatch loop /cloneFromDirpointer copies guarded; firecracker console-relay failure now logs the actual error.Consistency / modernisms
slices.ContainsFunc/DeleteFunc/Clone/Concat,maps.Copy,utils.MapValuesreuse.utils/magic.go(was 3 copies).network.ErrNotFoundsentinel removed;meteringconst/var block order;progressexported-above ordering;cmd.vm.*log-tag consistency;debug.goverb-lessPrintf→Print/Println;BlobExtinstead of a hardcoded".qcow2".Comments
131 tightened to 1–2 lines (dropping restatement / PR-narration, keeping constraint-bearing WHYs). Two stale comments corrected against actual behavior (MountSpec renders verbatim; sparse fallback triggers on empty files).
Verification
make lint— 0 issues onGOOS=linuxanddarwin;make test(race + cover) green.network.ErrNotFound) or changed signatures.inspect/vm listfilter /debugoutput / ACPI stop / rm — all pass.🤖 Generated with Claude Code