Repository navigation
fix(pm): post-stamped's unread-knock check never narrows on a stamp that names no instant - #18294
Conversation
…hat names no instant
The `--body` refresh derives "the body's last write" from the newest protocol
stamp in the stored body, and the file's header promises that derivation is a
LOWER bound: more comments count as newer, never fewer. It was not. The newest
stamp went through `Date.parse` alone, which rolls an impossible date FORWARD
and returns an ordinary number — a stored `2026-04-31T00:00Z` read back as
1 May, so a knock at `2026-04-30T12:00:00Z` fell outside the window, the check
answered `none-newer`, and the refresh voided the knock.
`lastWriteStamp` now judges every stamp with `stampRealInstant`, the same round
trip the write side refuses a quoted stamp with — one predicate, never two. A
stamp that names no instant (NaN or rolled over) is not read as the last write
at all; the derivation falls back to the newest REAL stamp, which is earlier, so
the window only widens, and a body whose stamps are all unreal lands on the
existing no-stamp rule and counts every comment. Nothing else moves: a card with
nothing newer is still written, so the acceptance control the header states
("no unread knock ⇒ the refresh is not affected") holds unchanged.
The derivation always answers an object now, carrying the stamps it refused to
read, so the refusal, the transcript line and the `--json` transcript can name a
window that is wider than the body looks instead of claiming the body carries no
stamp at all.
Self-test: 186 → 204 cases; the unread-knock battery floor 23 → 41.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HZfg2AwVX191qCizp88gQr
Contract reviewServed-tier: Reviewing seat: ① Derived judgments
② Semver levelNot applicable — nothing published moves; ③ Boundary flags
Implemented-by: VERDICT: PASS Generated by Claude Code |
|
Landing provenance — skills seat, session Generated by Claude Code |
… acknowledged one (objectstack-ai#18297) Fixes objectstack-ai#18295 ## The defect `unreadComments` in `scripts/pm/post-stamped.mjs` picked `newest` as the last element of a list sorted by `created_at` **with an `id` tiebreak**, but derived `after` — the comments that landed after the acknowledged one — from a strictly-later comparison on `created_at` **alone**. Two comments written inside one second (a batch, a bot) with `--ack-through` naming the lower id: the refresh was rightly refused as `ack-not-newest` and the remedy line named the right id, but the refusal's head read `0 comment(s) landed after it` and listed nothing — a count contradicting the refusal it sits in. Two orderings answering one question is the whole defect, so the fix is one ordering, not a second comparison bolted onto the filter. ## The fix One comparator, `byCommentOrder` (`created_at`, then `id`), declared once beside `commentCreatedMs` and read by **both** the newest pick and the "landed after" set. `id` breaks only an exact tie, so it never outranks the clock; comments whose `created_at` is unreadable share one instant and are ordered by id — the same tie the sort already resolved that way. The window filter keeps reading the instant alone, because it compares a comment against a stamp, not against another comment. Which refusal fires on which input is unchanged; only the count and the listing move. ## Reverse verification — ablation from the committed state, hash-proved Blobs: HEAD `0e6d55abf5a895c285bdb20879fb2024915543cb`, pre-fix `48275456ba4f55f10422aa25c76cba7e45015e73`. **Leg A — the unpatched derivation** (pre-fix blob restored on disk; on-disk hash re-read and matched, `byCommentOrder` occurrences 0). The reproducer, called on the pure core: ``` REPRO kind=ack-not-newest after.length=0 after.ids=[] newest.id=101 REPRO head: post-stamped: REFUSED — --ack-through=100 is not the newest comment on objectstack-ai#18295: 0 comment(s) landed after it. Nothing was written. ``` Restored with `git checkout HEAD --`; on-disk hash back to `0e6d55ab`, `git diff HEAD` and `git status --porcelain` both empty. After the restore: ``` REPRO kind=ack-not-newest after.length=1 after.ids=[101] newest.id=101 REPRO head: post-stamped: REFUSED — --ack-through=100 is not the newest comment on objectstack-ai#18295: 1 comment(s) landed after it. Nothing was written. REPRO listing-names-101: true ``` **Leg A says nothing about the new self-test cases** — a whole-file revert takes them with it, so its `--self-test` is green at 204 cases. Recorded as observed, not as a pass. **Leg B — the derivation alone reverted, the new cases kept** (mutation on top of HEAD; mutated blob `a577b24bb6afa543d4db105f44cc8c9121e4e956`, proved different from the HEAD blob and proved on disk by occurrence counts: new form 0, old form 1). `--self-test` exits **1**, `4 of 212 case(s) failed`: ``` ✗ …and the later id COUNTS as after it — the count no longer contradicts the refusal it sits in (after=[]) ✗ …so the refusal head reads 1, not 0 ✗ …and lists that comment, so the seat reads it rather than a count ✗ …the newest pick and the after set read ONE order: whoever is newest is in the set the refusal lists ``` The fifth new refusal case stays green there on purpose: the refusal itself was always right, only its count was not. Restore: on-disk hash back to `0e6d55ab`, `git diff HEAD` and `git status --porcelain` empty, `--self-test` back to 212 passing. Both legs run a `trap … EXIT INT TERM` restore against an absolute path; neither leaves a temporary file in the tree. ## Self-test 204 → **212** cases across 10 batteries; the unread-knock battery's floor 41 → **49**, the measured count. Added: the filed reproducer (after = `[101]`, the head reads 1, the listing names 101), the newest/after agreement invariant, the ordinary later-second control restated as unchanged, the same-second pair with the ack naming the **higher** id still cleared, and the ordinary ack-the-newest case still cleared. ## Gates `node scripts/pm/dispatch-gates.mjs --commands scripts/pm/post-stamped.mjs` derived **32** commands; all 32 ran, all exit 0. Reconciliation on the same tree: ``` ✓ dispatch-gates --ran: 32 derived famil(ies) accounted for — 32 run, 0 NOT-MEASURED ``` Among them `pnpm check:pm-dispatch-gates` (the gate source's own battery, run detached: 1730 cases, exit 0, 439.0s on this box), `pnpm check:pm-post-stamped`, `pnpm check:nul-bytes`, `node scripts/check-self-test-wired.mjs`. Plus, outside the derivation: `node --stack-size=4000 node_modules/eslint/bin/eslint.js scripts/pm/post-stamped.mjs` — clean; and a control-character self-scan over the file — no hit. ## Acceptance notes - `skip-changeset`: `scripts/pm/**` is tooling, shipped by no package's `files[]` — nothing published moves. - Landing: non-governed surface, so the skills seat lands it in-seat after review. Left **draft**, no reviewers requested, no auto-merge, no queue. - Serial with PR objectstack-ai#18294 (landed), which touched the same function; the sibling card objectstack-ai#18296 names a different defect shape in this file and is not addressed here. - No out-of-scope findings to file: `commentCreatedMs` has exactly three call sites, and the third (the read-window filter) compares a comment against a stamp instant rather than against another comment, so it is not a second ordering. --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01HZfg2AwVX191qCizp88gQr --- _Generated by [Claude Code](https://claude.ai/code/session_01HZfg2AwVX191qCizp88gQr)_ Co-authored-by: claude[bot] <claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
Fixes #18293
The
--bodyrefresh's unread-knock check derives "the body's last write" from the newest protocol stamp in the stored body, and the file's own header promises that derivation is a LOWER bound: "MORE comments count as newer, never fewer — the check may ask for an acknowledgement it did not strictly need, and cannot skip one it did". It was not a lower bound.lastWriteStampread the newest stamp throughDate.parsealone, which rolls an impossible date FORWARD and hands back an ordinary number, so a stored2026-04-31T00:00Zread as2026-05-01T00:00:00.000Z— later than its own digits — and a knock at2026-04-30T12:00:00Zfell outside the window. The check answerednone-newer, the refresh proceeded, and the knock was voided with no signal to the knocker.PR #18292 refuses such a stamp on the WRITE side. A stored body can still carry one: hand-written, edited through the platform's own editor, or written before this tool existed.
What changed
One rule decides what the last write instant is.
lastWriteStampnow judges every stamp withstampRealInstant— the same round trip the write side refuses a quoted stamp with, one predicate and never two — and a stamp that names no instant the calendar has is not read as the last write at all. The derivation falls back to the newest REAL stamp in the body, which is earlier, so the window only widens; a body whose stamps are all unreal lands on the existing no-stamp rule and counts every comment.lastWriteStampalways answers an object now:stamp/fromare null when nothing readable is there, andunrealcarries the stamps it refused with the date each one rolls over to (null for the half that does not parse at all). The refusal, the transcript pass line and the--jsontranscript name those stamps, so a window wider than the body looks is something the transcript can say, instead of claiming the body carries no stamp at all.Nothing else moves. A card with nothing newer is still written, so the acceptance control the header states — "no comment newer than the last write ⇒ no flag, no refusal, and the write is what it was before this check existed" — holds unchanged.
Why this fallback and not "refuse and require --ack-through"
The card offered two honest fallbacks: treat the last write instant as UNKNOWN and refuse the refresh until
--ack-throughnames the newest comment, or fall back to the newest real stamp. The header's own rule picks the second.--ack-throughhas no legal value and the seat post can never be refreshed again — the one dead end this tool must not build. That also breaks the acceptance control quoted above, which the header states as a promise.--ack-throughnaming the newest clears it. It is the same protection without the dead end.quotedRouteClosed, that two spellings of one question is how a remedy comes to prescribe a refusal.This is a contract tightening at the derivation, not a tolerant fallback at a consumer: the unreal stamp is refused as a reading of anything (the write side already refuses to write one), so no caller can obtain a narrower window by storing a bogus date.
Reverse verification (ablation from the committed state, hash-proved)
Base blob
6cd7b9074ac019c85d16e140b1a335bee6fe5b54restored overscripts/pm/post-stamped.mjs, reading taken, HEAD blob48275456ba4f55f10422aa25c76cba7e45015e73restored,git diff HEADempty. The on-disk hash was compared to the expected blob on both legs before any reading was taken.Measured scenario — stored body whose newest stamp is
2026-04-31T00:00Z, one knock at2026-04-30T12:00:00Z:Same body plus an older real stamp
2026-04-29T09:00Zbeside the impossible one: before,sincewas the rolled2026-04-31T00:00Zand the reading wasnone-newer; after,sinceis2026-04-29T09:00Zand the reading isunacknowledged— the window measured from earlier, which is the "never fewer" direction. Control legs: a card with no comments is still written (none-newer, both before and after), and--ack-throughnaming the newest comment clears (acknowledgedafter; the base tool never reached that path because it had already answerednone-newer).A second leg mutates only the guard on the committed tree (the unreal stamp recorded but still read as the last write) and leaves the new cases in place:
--self-testgoes RED, 8 of 204 cases failing, then restores to the HEAD blob withgit diff HEADempty and 204/204 green. Two of the added cases stay green under that mutation, on purpose — see the acceptance note below.Gates
node scripts/pm/dispatch-gates.mjs --commandsderived 32 families for this change set; all 32 ran and all 32 exited 0.node scripts/pm/dispatch-gates.mjs --ranverdict: "32 derived famil(ies) accounted for — 32 run, 0 NOT-MEASURED (a DERIVED zero — all 32 recorded an exit code and none of them is 3)". The gate-source batterypnpm check:pm-dispatch-gatesran detached: exit 0, 447.5s on this box, 1730 self-test cases. Plus the tool's own--self-test(186 cases before, 204 after; the unread-knock battery floor 23 raised to 41), ESLint on the file (exit 0, no findings),node scripts/check-self-test-wired.mjs(exit 0), and a control-character self-scan over the file (no hits).No changeset: nothing published moves.
scripts/pm/**is not on any package'sfiles[].Acceptance notes
2026-13-45T99:99Z) reach the same outcome as the rollover. Measured on the base tool, it ALREADY did —stampSpanreturns null for it and the old loop skipped it — so that half was correct by accident, through a different code path, and unpinned. It is pinned now and comes from the same predicate as the rollover half. The mutation leg leaves those two cases green for exactly that reason.unreadPassTextgrew a clause and stays a single line, so "the one line a transcript carries" still holds. Successor: the next author of this file.unreadCommentscomputesafterfor theack-not-newestrefusal with a strictly-later comparison oncreated_atonly, while the newest is chosen with an id tiebreak. Two comments sharing onecreated_at, acknowledging the lower id, refuses with a head reading "0 comment(s) landed after it" and lists nothing — a count that contradicts its own refusal. The remedy line still names the right id, so nothing is lost; the text is simply false. Reproducer:unreadComments({ storedBody: 'seat 2026-09-12T10:00Z', comments: [{id:100,created_at:'2026-09-12T11:00:00Z'},{id:101,created_at:'2026-09-12T11:00:00Z'}], ackThrough: 100 }). Dedupe words: post-stamped, ack-not-newest, after, created_at tiebreak, same-second comments. Pre-existing, untouched by this PR.Draft on purpose:
scripts/pm/**is not a governed surface, and the dispatching seat lands this in-seat after review. No reviewers requested, no auto-merge armed.Generated by Claude Code