Skip to content

fix(ci): deterministic snapshot ordering and release workflow permissions - #59

Merged
sagar0163 merged 2 commits into
mainfrom
fix/ci-flakes
Sep 25, 2026
Merged

sagar0163 merged 2 commits into
mainfrom
fix/ci-flakes

Conversation

@sagar0163

Copy link
Copy Markdown
Owner

Follow-up to #58. While verifying that PR on main, two separate, pre-existing failures turned up that #58 could not address. Both are fixed here.

1. listSnapshots() violated its own "newest first" contract

This surfaced as an intermittent CI failure, not a hard one:

AssertionError: expected 'first' to be 'second'
 ❯ test/unit/rollback.test.js:53

listSnapshots() sorts on manifest.timestamp, but new Date().toISOString() only resolves to whole milliseconds. Two snapshots created in quick succession therefore share a timestamp, localeCompare returns 0, and the stable sort falls back to fs.readdirSync() order — which is arbitrary.

Probing 300 back-to-back createSnapshot() calls:

before after
identical-millisecond ties 80.7% 0%
listSnapshots()[0] was not the newest 41.0% 0%

The bug is timing- and filesystem-dependent, which is why it passed locally (real file I/O between the two calls pushes the timestamps apart) while failing on the faster CI runner.

Fix: store a high-resolution, monotonic createdAt (performance.timeOrigin + performance.now()) next to the ISO timestamp and sort on that, with Date.parse(timestamp) as fallback so snapshot directories written by older versions keep working, and the snapshot id as a final tie-break for full determinism. No behavioural change for the normal path, and the test's original expectation is now meaningful rather than racy.

2. Auto Release could not push its own tag

Once #58 unblocked the test step, Auto Release got further than ever before and then failed at Git push:

remote: Permission to sagar0163/Nebula_cli.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/sagar0163/Nebula_cli/': The requested URL returned error: 403

The job had no permissions block, so it inherited the repository's default read-only GITHUB_TOKEN. release-it bumped the version and built the commit and tag locally, then could not push either, and its tag-rollback attempt failed the same way.

Fix: add permissions: contents: write to the release job, which is what it needs for the version-bump push, the v${version} tag, and the GitHub Release it creates. npm publishing is already disabled via "npm.publish": false in .release-it.json, so no registry token is involved.

Verification

  • npm test — 19/19 files, 219/219 tests, run 3x consecutively plus once per commit via the pre-commit hook
  • test/unit/rollback.test.js — 0 failures / 20 consecutive runs
  • legacy manifests with no createdAt still list newest-first (backwards-compat check)

Note

The commit for the workflow change deliberately mentions "Release", but GitHub Actions contains() is case-insensitive and the Auto Release job skips on that substring. The branch name is fix/ci-flakes (not ...-release) so the merge commit message on main does not contain the substring and the workflow actually runs — otherwise this fix could never be verified.

listSnapshots() is documented as returning "newest first", but it sorted on
manifest.timestamp, which new Date().toISOString() only resolves to whole
milliseconds. Snapshots created in quick succession therefore share a
timestamp, localeCompare returns 0, and the stable sort falls back to
fs.readdirSync() order, which is arbitrary.

Measured over 300 back-to-back createSnapshot() calls: timestamps tied in
80.7% of runs and listSnapshots()[0] was not the newest in 41.0%, silently
breaking the documented contract. This surfaced in CI as an intermittent
failure of the "should list available snapshots" assertion in
test/unit/rollback.test.js (expected 'second', received 'first').

Store a high-resolution, monotonic createdAt alongside the ISO timestamp and
sort on that, falling back to Date.parse(timestamp) for manifests written by
older versions so existing snapshot directories keep working, with the
snapshot id as a final tie-break for full determinism.

After the fix the same 300-call probe reports 0 ties and 0 misorderings.
The Auto Release job had no permissions block, so it inherited the
repository's default read-only GITHUB_TOKEN. release-it bumped the version,
created the commit and tag locally, then failed to push them with
"Permission to sagar0163/Nebula_cli.git denied to github-actions[bot]"
(HTTP 403), which also left its tag-rollback attempt failing the same way.

The job needs contents:write for the version-bump push, the v${version} tag,
and the GitHub Release it creates. npm publishing is already disabled via
"npm.publish": false in .release-it.json, so no registry token is involved.
@sagar0163
sagar0163 merged commit 125d1ee into main Sep 25, 2026
1 check passed
@sagar0163
sagar0163 deleted the fix/ci-flakes branch September 25, 2026 17:18
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.

1 participant