Repository navigation
fix(ci): deterministic snapshot ordering and release workflow permissions - #59
Merged
Merged
Conversation
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.
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.
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" contractThis surfaced as an intermittent CI failure, not a hard one:
listSnapshots()sorts onmanifest.timestamp, butnew Date().toISOString()only resolves to whole milliseconds. Two snapshots created in quick succession therefore share a timestamp,localeComparereturns0, and the stable sort falls back tofs.readdirSync()order — which is arbitrary.Probing 300 back-to-back
createSnapshot()calls:listSnapshots()[0]was not the newestThe 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, withDate.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 Releasecould not push its own tagOnce #58 unblocked the test step,
Auto Releasegot further than ever before and then failed atGit push:The job had no
permissionsblock, so it inherited the repository's default read-onlyGITHUB_TOKEN.release-itbumped 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: writeto the release job, which is what it needs for the version-bump push, thev${version}tag, and the GitHub Release it creates. npm publishing is already disabled via"npm.publish": falsein.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 hooktest/unit/rollback.test.js— 0 failures / 20 consecutive runscreatedAtstill list newest-first (backwards-compat check)Note
The commit for the workflow change deliberately mentions "Release", but GitHub Actions
contains()is case-insensitive and theAuto Releasejob skips on that substring. The branch name isfix/ci-flakes(not...-release) so the merge commit message onmaindoes not contain the substring and the workflow actually runs — otherwise this fix could never be verified.