← Back to Pull requests

Fix panic when devbox.lock contains null values #3154

Open
unknown opened this pull request with 367 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 30, 2026 14:12 UTC
Author

Summary

Problem: devbox panics (nil pointer or "assignment to entry in nil map") when devbox.lock has a JSON null where an object is expected. Fixes #3101.

How it happens: devbox never writes these nulls itself. They come from a hand edit, a merge conflict fixed by hand, or a script that rewrites the lockfile (a Go program that marshals a nil map writes null). Once the file has one, any command that loads the project hits it.

Steps to reproduce: put {"lockfile_version": "1", "packages": null} (or "packages": {"hello@latest": null}, or "systems": {"x86_64-linux": null}) in devbox.lock, then run devbox add hello.
Expected: the null is treated like a missing entry.
Actual: panic.

Cause: lock.GetFile decodes straight into File, so null leaves Packages nil (Resolve then writes to a nil map) and leaves nil Package / SystemInfo entries that ensurePackagesHaveOutputs, resolvedEntry and HasAllowInsecurePackages dereference.

Fix: GetFile now normalizes right after parsing: nil Packages becomes an empty map, and null package and system entries are dropped. A dropped package is resolved again on the next use, the same as one missing from the file. The issue title says "returning an error"; I chose to recover because the file has no real data for those entries, so there is nothing to refuse.

Scope: internal/boxcli/multi/sync.go (devbox update across several projects) reads lockfiles without GetFile and had the same nil dereference on a null package entry, so it now skips nulls. Other lock.File users go through GetFile.

How was it tested?

New tests: TestGetFileNullValues (4 cases) and TestSyncLockfilesNullPackage. The sync test has one lockfile where hello is null and another where it is valid, so the null entry reaches the update loop in SyncLockfiles; a third key is null everywhere to cover the latest-packages scan. Before the fix, TestGetFileNullValues fails with Packages is nil, want an empty map, and the sync test panics with a nil pointer dereference in SyncLockfiles (sync.go:44 with the update-loop check removed, sync.go:90 with the scan check removed). After: pass.

Commands: GOTOOLCHAIN=local go vet, go test ./internal/lock/ ./internal/boxcli/multi/, gofmt -l, golangci-lint run on both packages (0 issues).

Environment: fix branch @ 17f94bbd, go1.27.4, darwin/arm64

Community Contribution License

All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.

By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.

Diff: 367 lines (+275 / -92) across 4 files Reviewer: greptile-apps[bot] Review duration: 12m
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 367 lines diff across 4 files
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.353
Shallow Review Depth shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3154"
general weight: 0.35
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 42.7% (MEDIUM) · Higher = larger blast radius
42.7%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 22.8% · Safe to merge
22.8%