Skip to content

Fix panic when devbox.lock contains null values - #3154

Open
RyoKusnadi wants to merge 2 commits into
jetify-com:mainfrom
RyoKusnadi:fix/lockfile-null-values
Open

RyoKusnadi wants to merge 2 commits into
jetify-com:mainfrom
RyoKusnadi:fix/lockfile-null-values

Conversation

@RyoKusnadi

@RyoKusnadi RyoKusnadi commented Nov 30, 2026 •

Copy link
Copy Markdown

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 @ 17f94bb, 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.

Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
@greptile-apps

greptile-apps Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5 · The PR appears safe to merge, with one non-blocking gap in the sync regression test.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches project commands that load lockfiles and multi-project lockfile sync.

The PR appears safe to merge, with one non-blocking gap in the sync regression test.

FindingsFix All in Claude CodeFindings

  1. P2 Test misses second panic path ▶
Fix with agent prompt
### Issue 1
internal/boxcli/multi/sync_test.go:78-79
Both fixtures set `hello` to `null`, so `latestPackages` drops that key before the update loop runs. This never exercises the new `pkg != nil` check in `SyncLockfiles`; removing that check would leave the test passing.

Add a valid, dated `hello` entry in one lockfile and keep `hello: null` in another. That would catch a regression in the second panic path this PR fixes.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR prevents panics when devbox.lock contains null package maps, package entries, or system entries.

  • Project commands load lockfiles with null entries as missing data.
  • Multi-project lockfile sync skips null package entries.

Reviews (1) · Last reviewed commit: "lock: treat null values in devbox.lock a..." · Reviewed by Greptile

Comment thread internal/boxcli/multi/sync_test.go Outdated
Comment on lines +78 to +79
oldLock := write(filepath.Join(root, "old"), `{"lockfile_version": "1", "packages": {"go@latest": {"last_modified": "2024-01-01T00:00:00Z"}, "hello": null}}`)
write(filepath.Join(root, "new"), `{"lockfile_version": "1", "packages": {"go@latest": {"last_modified": "2024-06-01T00:00:00Z"}, "hello": null}}`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test misses second panic path

Both fixtures set hello to null, so latestPackages drops that key before the update loop runs. This never exercises the new pkg != nil check in SyncLockfiles; removing that check would leave the test passing.

Add a valid, dated hello entry in one lockfile and keep hello: null in another. That would catch a regression in the second panic path this PR fixes.

Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/boxcli/multi/sync_test.go
Line: 78-79

Comment:
**Test misses second panic path**

Both fixtures set `hello` to `null`, so `latestPackages` drops that key before the update loop runs. This never exercises the new `pkg != nil` check in `SyncLockfiles`; removing that check would leave the test passing.

Add a valid, dated `hello` entry in one lockfile and keep `hello: null` in another. That would catch a regression in the second panic path this PR fixes.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, both fixtures had hello as null, so it never got past the latest-packages scan and the update loop check wasn't tested. Now the old lockfile has hello null and the new one has a valid hello, so it reaches the loop. It panics at sync.go:44 without the check. Fixed in 17f94bb.

Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

A devbox.lock with null values panics instead of returning an error

1 participant