Skip to content

ci(nix): refresh the vscode npmDepsHash automatically - #2284

Merged
robcohen merged 3 commits into
mainfrom
chore/automate-vscode-npm-deps-hash
Sep 8, 2026
Merged

robcohen merged 3 commits into
mainfrom
chore/automate-vscode-npm-deps-hash

Conversation

@robcohen

@robcohen robcohen commented Sep 8, 2026

Copy link
Copy Markdown
Member

flake.nix pins npmDepsHash over packages/vscode/package-lock.json, because buildNpmPackage hashes the vendored dependency tree. Dependabot updates the lockfile and has no way to know a Nix expression hashes it, so every npm bump to that package lands red:

error: hash mismatch in fixed-output derivation
         specified: sha256-Oc3yvMFep3AogJpFa5Ji4zIMXCIF/PGLJc7AM98mr7w=
            got:    sha256-RAG2KxhwVzCbaywKCclZHf5ySBdA/RBjbtd7NPAV+2c=

That is #2109, #2202, #2243, and both dependabot PRs open right now (#2269, #2272). build requires the VS Code Extension (Nix) job, so none of them can merge unattended.

There was no tooling for it. Nothing in .github/, scripts/, or the justfile mentioned prefetch-npm-deps. The repair was folklore, which is why it recurred rather than got handled.

What this adds

A workflow that recomputes the hash on any PR touching the lockfile and commits it to the branch.

It is deliberately separate from the VS Code Extension (Nix) job. That job verifies; this one repairs. A verifier that silently rewrites the thing it is checking is worse than one that fails.

It handles forks. It cannot push to a fork branch, so it always writes the correct value to the job summary regardless:

npmDepsHash is stale

packages/vscode/package-lock.json changed, so flake.nix needs:

npmDepsHash = "sha256-…";

A contributor whose PR it cannot fix still gets the exact line to change, instead of a bare Nix hash mismatch.

The push is self-terminating. It only commits when the computed hash differs, so the run that push triggers finds a match and stops. No loop.

A local recipe, just nix-refresh-vscode-hash, plus a CONTRIBUTING section explaining why the failure happens at all.

Verification

I verified the command before writing a workflow around it, and verified the recipe both ways rather than only the happy path:

on main (hash correct):     ✓ npmDepsHash is already correct (sha256-Oc3yvM…)
after corrupting flake.nix: ✓ npmDepsHash sha256-AAAA… -> sha256-Oc3yvM…
                            ✓ flake.nix restored byte-identically

A repair tool that only ever reports "already correct" would be indistinguishable from one that does nothing.

Note

This does not fix #2269 or #2272 themselves — they were opened before the workflow existed. Once this merges, closing and reopening them (or any rerun) will pick it up. Worth knowing that they interfere: each changes the lockfile, so whichever merges first invalidates the other's hash, and the second needs a fresh run.


Supersedes #2283, which used a ci/ branch prefix that the branch-name gate rejects (allowed: feat|feature|fix|docs|chore|refactor|release|hotfix|claude|dependabot|copilot|perf). Same commit, renamed branch.

`flake.nix` pins `npmDepsHash` over packages/vscode/package-lock.json,
because buildNpmPackage hashes the vendored dependency tree. Dependabot
updates the lockfile and has no way to know a Nix expression hashes it,
so every npm bump to that package landed red on a fixed-output mismatch
and sat there until somebody recomputed the hash by hand. That is #2109,
#2202 and #2243, and both currently open dependabot PRs (#2269, #2272).
`build` requires that job, so none of them could ever merge unattended.

There was no tooling for it: nothing in .github, scripts or the justfile
mentioned prefetch-npm-deps. The repair was folklore.

Adds a workflow that recomputes the hash on any pull request touching the
lockfile and commits it to the branch. It is deliberately separate from
the `VS Code Extension (Nix)` job: that job verifies, this one repairs,
and a verifier that silently rewrites what it is checking is worse than
one that fails.

It cannot push to a fork, so it always writes the correct value to the
job summary as well. A contributor whose PR it cannot fix still gets the
exact line to change instead of a bare Nix hash mismatch.

The push is self-terminating: it only commits when the computed hash
differs, so the run it triggers finds a match and stops.

Also adds `just nix-refresh-vscode-hash` for the same repair locally, and
documents both in CONTRIBUTING.

Verified rather than assumed: the recipe reports "already correct" on
main, and when flake.nix is corrupted it repairs the value and restores
the file byte-identically.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen
robcohen requested a review from a team as a code owner September 8, 2026 14:02
Copilot AI lite review requested due to automatic review settings September 8, 2026 14:02
@robcohen
robcohen enabled auto-merge (squash) September 8, 2026 14:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new workflow and local recipe drop stderr from prefetch-npm-deps (hurting debuggability), and the just recipe’s sed -i usage is not portable to macOS/BSD without adjustment.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds automation and contributor tooling to keep flake.nix’s VS Code npmDepsHash synchronized with packages/vscode/package-lock.json, preventing recurring fixed-output hash CI failures on dependency bumps.

Changes:

  • Introduces a dedicated GitHub Actions workflow that recomputes npmDepsHash on PRs touching the VS Code lockfile and (when possible) commits the fix back to the PR branch.
  • Adds a just nix-refresh-vscode-hash local repair recipe mirroring the CI recomputation.
  • Documents the failure mode and remediation path in CONTRIBUTING.md.
File summaries
File Description
justfile Adds a local just recipe to recompute and update npmDepsHash in flake.nix.
CONTRIBUTING.md Documents why the hash mismatch happens and how CI/local tooling repairs it.
.github/workflows/vscode-npm-deps-hash.yml New workflow to recompute and optionally push updated npmDepsHash for PRs updating the VS Code lockfile.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread justfile Resolved
Copilot review on #2284, both valid.

Discarding prefetch-npm-deps stderr meant any real failure — network,
auth, a lockfile it cannot parse — surfaced only as "produced no hash",
which says nothing about why. That is the same silent-failure shape this
whole change exists to remove, one level up. stderr is captured and
printed when no hash comes back.

The justfile used `sed -i` with no suffix, which is GNU-only: BSD and
macOS sed take a mandatory argument there, and no single spelling works
on both. Replaced with write-to-temp and move. The workflow's own sed
runs on ubuntu-latest so it was never affected, but the recipe is for
contributors, some of whom are on macOS.

Re-verified both directions after the change: the recipe repairs a
corrupted hash and restores flake.nix byte-identically, and reports
"already correct" when it is.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
CodeQL on #2284: unsafe checkout of untrusted code in a non-privileged
context. The finding is correct. The job held `contents: write`, checked
out pull-request head code, and ran a tool over a lockfile the pull
request controls. That is the shape of the problem, regardless of whether
this particular tool is exploitable.

Automating the commit safely needs the two-stage `workflow_run` split,
where the privileged half never checks out untrusted code. That is a lot
of machinery for a one-line repair, so the job now reports instead: it
fails with the exact value to set, in both the error annotation and the
job summary, and `just nix-refresh-vscode-hash` applies it in one
command.

That keeps what actually made this recur — nobody knew the command, and
nothing in the repo mentioned prefetch-npm-deps — while dropping the
write permission and the head-ref checkout entirely. The job now needs no
permissions beyond the read-only default and takes the ordinary
merge-commit checkout.

Worth revisiting with the workflow_run split if reporting proves to be a
nuisance rather than a fix.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@robcohen
robcohen merged commit 1c774c8 into main Sep 8, 2026
45 checks passed
@robcohen
robcohen deleted the chore/automate-vscode-npm-deps-hash branch September 8, 2026 14:26
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 99% (raw 93%, 169 masked)
Full AST Match 100%
Total Files 812
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants