Skip to content

fix(manifest): detect same-second writes and keep the home profile - #228

Merged
savvides merged 3 commits into
mainfrom
cursor/manifest-write-path-b703
Nov 24, 2026
Merged

savvides merged 3 commits into
mainfrom
cursor/manifest-write-path-b703

Conversation

@savvides

@savvides savvides commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

The manifest write path could drop a section, leave a file behind on a refused save, or write into the home profile.

  • updated now has microseconds, so a second merge in the same second changes the stamp. --expect-updated then exits 8 and the first section stays. Before, the stamp had a resolution of one second, so that second merge replaced the section.
  • --create with a stamp that does not match a missing manifest exits 8 and makes no file. Before, it wrote a seed and then exited 8.
  • A course .idstack that points at the home profile, and a manifest whose real path is that profile, exit 9 and write nothing.
  • The lock file is next to the real manifest, so a symlinked manifest and its target wait for each other.
  • idstack-migrate keeps an explicit 0 in red_team_audit.findings_summary when it moves an old summary. An absent findings_summary still takes the old counts.

Skill templates were not edited. needs-analysis and learning-objectives still omit --expect-updated on shared sections. That fix belongs in the templates: #226

idstack-migrate still prints a traceback when import_metadata is not an object. The file does not change: #227

No existing issue. VERSION is unchanged.

Tests

  • ./test/test-manifest-merge.sh (the suite for this path)
  • ./test/smoke-test.sh
  • ./test/integration-test.sh
  • scripts/idstack-gen-skills --dry-run is clean (if a template changed) — no template changed
  • Deferred findings have their own issue

Real result of ./test/test-manifest-merge.sh:

test-manifest-merge

  PASS: section replaced
  PASS: context preserved
  PASS: needs_analysis preserved
  PASS: project_name preserved
  PASS: created preserved
  PASS: version preserved
  PASS: updated timestamp bumped
  PASS: stdin payload accepted
  PASS: unknown section exits 3
  PASS: malformed payload exits 1
  PASS: malformed manifest exits 2
  PASS: missing manifest exits 4
  PASS: missing payload file exits 5
  PASS: manifest with list root exits 2
  PASS: manifest with string root exits 2
  PASS: --init creates a manifest
  PASS: --init manifest is at the latest schema version
  PASS: --init manifest carries every mergeable section
  PASS: merge into an --init manifest succeeds
  PASS: --init preserves an existing manifest
  PASS: plain migrate does not create a manifest
  PASS: migrate that cannot write exits non-zero, prints nothing and keeps the manifest
  PASS: migrate works at a path with a quote
  PASS: migrate keeps the file mode at a path with a quote
  PASS: migrate writes through a symlinked manifest
  PASS: migrate in a read-only folder exits 1 with a clear message and keeps the manifest

  PASS: payload with list root exits 1
  PASS: payload with string root exits 1
  PASS: --create makes a missing manifest
  PASS: --create manifest is canonical and carries the section
  PASS: --create keeps an existing manifest
  PASS: multi-section write replaces each section
  PASS: --set writes project_name
  PASS: bad second payload exits 1
  PASS: bad second payload leaves the manifest unchanged
  PASS: bad payload with --create makes no manifest
  PASS: --set with an unknown key exits 3
  PASS: a --section with no --payload is refused
  PASS: merge keeps the manifest mode 644
  PASS: merge writes through a symlinked manifest
  PASS: merge in a read-only folder exits 6 with no traceback
  PASS: merge refuses a manifest from a newer idstack (exit 7, unchanged)
  PASS: migrate prints NEWER_SCHEMA for a manifest from a newer idstack
  PASS: migrate fills a null section with its defaults
  PASS: migrate --init leaves one valid manifest and no tempfile
  PASS: a new manifest has mode 644 under umask 022, and a merge keeps it
  PASS: a merge keeps mode 640 of an existing manifest
  PASS: merge in the home folder exits 9 and writes nothing
  PASS: migrate --init in the home folder exits 9 and writes nothing
  PASS: a symlink to the home folder is also refused
  PASS: two concurrent merges lose no update
  PASS: a merge waits while another process holds the lock
  PASS: a stale --expect-updated exits 8 and leaves the manifest unchanged
  PASS: a matching --expect-updated writes
  PASS: a second merge with the first read time is stale
  PASS: the merge git-ignores .manifest.lock once and keeps old lines
  PASS: a .gitignore that cannot be written warns on stderr and the merge still writes
  PASS: non-ASCII text in a payload from a cp1252 stdin and from a file stays UTF-8
  PASS: the slug of a non-ASCII project name
  PASS: a second merge in the same second keeps the first section
  PASS: a same-microsecond stamp moves forward
  PASS: --create with a stale --expect-updated exits 8 and makes no manifest
  PASS: migrate keeps an explicit zero in findings_summary
  PASS: merge through a symlinked .idstack into the home profile exits 9 and writes nothing
  PASS: migrate --init through a symlinked .idstack into the home profile exits 9 and writes nothing
  PASS: a merge through a symlinked manifest waits for the lock on the real file

manifest-merge: 66/66 passed, 0 failed

The new checks failed on the old code first (7 failures: same-second overwrite, missing fresh_updated, exit 8 leaving a file, explicit zero replaced, home-profile symlink for merge and migrate, symlink lock not shared). They pass after the fix.

Open in Web Open in Cursor 

Note

Medium Risk
Changes core manifest persistence (timestamps, locking, home-path guards, and migration merge rules); incorrect behavior could drop sections or write to the wrong profile, though tests were added for the reported failure modes.

Reviewed by Cursor Bugbot for commit e60938b. Bugbot is set up for automated code reviews on this repo. Configure here.

cursoragent and others added 2 commits November 23, 2026 20:43
--expect-updated missed a second merge in the same second because updated
had a one-second resolution, and --create left a new manifest when that
check then failed. A symlinked .idstack could also write into the home
profile, and the lock sat beside the symlink rather than the real file.
Migration from 1.3 no longer replaces an explicit findings count of 0.

Co-authored-by: Philippos Savvides <savvides@users.noreply.github.com>
…dings_summary takes old counts

fresh_updated could go back to an earlier stamp on a coarse clock, so a
stale --expect-updated matched again. An all-zero findings_summary is the
v1.2 seed; the PR kept it and dropped the real counts in the old summary.
Also fix two stale lock-path lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@savvides

Copy link
Copy Markdown
Owner Author

Review (pushed 40de886, all CI green incl. windows and mutation):

Fixed:

  • fresh_updated could go back to an earlier stamp: with a coarse clock (Windows Python <3.13) or a clock set back, a third write in one tick returned the first write's stamp, so a stale --expect-updated matched again (ABA). The stamp now always moves forward (previous + 1µs when the clock has not passed it); an empty, legacy or bad updated falls back to now.
  • idstack-migrate dropped real red-team counts: an all-zero findings_summary (the v1.2 seed) beside an old summary kept 0/0/0. An all-zero summary now takes the old counts; a non-zero one keeps explicit zeros, as the PR intended.
  • Two stale lock-path lines (script header, cli-reference).
  • Tests for both (fail on the PR code, pass now); CHANGELOG updated.

Checked, fine: skills pass no --expect-updated when the stamp is empty (so the early --create exit 8 does not break standalone runs); nothing parses updated; mutation anchors still match.

Deferred: #235 (case-variant ~/.IDSTACK symlink on macOS passes the realpath compare; no test for a manifest file symlinked into the profile).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@savvides
savvides merged commit 62077a8 into main Nov 24, 2026
10 checks passed
@savvides
savvides deleted the cursor/manifest-write-path-b703 branch November 24, 2026 02:39
@cursor cursor Bot mentioned this pull request Nov 24, 2026
3 of 4 tasks
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.

2 participants