Read Linear ENT-1601 and ENT-1535 (the 2026-08-12/13 comments carry all
decisions) for context. Task: reconcile and clean the A1 branch
nodo/ent-1601-jsconsumer-retry-schedule now that the COR-1257 broker-
semantics suite has merged to main. Do NOT merge the branch — that's a
separate review step. A previous session worked this branch; it is retired,
work only from the git state.
Fetch; rebase the branch onto origin/main (main tip carries
internal/brokersemantics — 21 real-broker tests + a follow-up fix).
jsconsumer/jsconsumer.go: two ConsumerLimits doc blocks collide.
KEEP MAIN'S version (the suite's — it already folded the branch's one
distinct point); drop the branch-side 7-line duplicate note from
f4e160a.
README.md: ordinary textual merge, keep both sides' content coherent.
While rewriting history anyway, fix the broken-bisect pair: 6143624
("correct the docs...") accidentally contains a reviewer scratch file
(swept in by git add -A) and does not compile; e150438 only removes that
file. Squash e150438 INTO 6143624 so the result is the doc corrections
alone, compiling. Note: interactive rebase isn't supported here — script
it via GIT_SEQUENCE_EDITOR.
Verify EVERY commit on the rebased branch builds (e.g. rebase with
--exec 'go build ./... && go vet ./...', or replay-check per commit).
Bisect-safety is the point of this exercise.
Full gate on the final HEAD: gofmt -s, build, vet, go test ./... (this
now includes the real-broker suite), go test -race, golangci-lint,
git diff --check.
Force-push is authorized ONCE steps 4–5 are green (reviewers pinned old
SHAs — the rewrite is deliberate, decided by Andrea). Use
--force-with-lease.
Report: new HEAD, commit count (should be 8), how per-commit build
verification was done, gate results, and the two conflict resolutions
as diffs-in-words. Touch nothing else; no Linear writes.
Assistant
I'll start by reading the Linear issues and inspecting the git state in parallel.
Assistant
Now let me set up the local branch and check the toolchain.
Assistant
Now the fixup squash (step 3), scripted via GIT_SEQUENCE_EDITOR:
Assistant
Now the rebase onto origin/main, with per-commit build+vet verification built in:
Assistant
Rebase applied cleanly — no textual conflicts. But that means the duplicate note likely survived. Let me check:
Assistant
Git auto-merged both doc blocks, leaving the duplicate. Let me examine the README merge result too:
Assistant
README merged coherently (branch prose in ## Subpackages, main's testing section under ## Development, License last). Let me verify the merge was lossless, then apply the pre-agreed jsconsumer.go resolution:
Assistant
Now a per-commit verification loop over the final SHAs (in a detached worktree, so no SHAs are rewritten):
Assistant
Let me confirm that check is actually load-bearing — i.e. it would have caught the old broken commit:
Assistant
All 8 commits pass, and the check is provably load-bearing (old 6143624 fails vet on the scratch probe). Now the full gate on final HEAD:
Assistant
Gate is fully green. Final review of the two conflict resolutions before pushing:
Assistant
Let me verify the rebase preserved every branch-side change apart from the one intended drop:
Assistant
Everything else preserved byte-for-byte; the only delta is exactly the 7-line duplicate note. Cleaning up and force-pushing (authorized, gates green):
Assistant
Done. Branch reconciled, cleaned, verified, and pushed. Not merged.
beebcd1 jsconsumer: correct beliefs the broker-semantics suite measured differently
289f565 jsconsumer: report an unconfirmed final ack as uncertain, not stranded
edd6455 jsconsumer: stop the schedule check failing consumers that adopted nothing
71d7c13 jsconsumer: reject a breaker threshold the ladder can never reach
daa9424 jsconsumer: correct the docs left describing the removed Nak disposition ← squashed
55d42c8 jsconsumer: model AckWait as the ladder when BackOff is absent
927b2fb jsconsumer: serve the server ladder by not disposing; fix schedule blind spots
ac91c8a jsconsumer: one retry schedule, dead-letter capture, and floor telemetry
The bisect fix: e150438 was folded into 6143624 as a fixup via GIT_SEQUENCE_EDITOR='sed -i "" -e "s/^pick e150438/fixup e150438/"' git rebase -i 9f88ab6, run before the rebase onto main so it stayed conflict-free. Result daa9424 carries 6143624's message verbatim and never introduces zz_probe_test.go — the file no longer exists anywhere in branch history. Its stat drops from 5 files to 4.
Per-commit build verification
Two independent passes, because the first rewrites SHAs and the second doesn't:
The rebase itself ran git rebase origin/main --exec 'go build ./... && go vet ./...' — verifying each commit as it was written.
After amending HEAD for the doc resolution, I re-verified the final eight SHAs in a detached throwaway worktree (no SHA churn): go build ./... && go vet ./..., plus go test -run '^$' -count=1 ./... to force every test binary to compile too. All 8 pass both.
Assistant
Let me read the review verdict comment on ENT-1601.
Assistant
The comment is real and matches — authored by Andrea, verdict "merge after this one fix pass (ordinary push, history append)". Let me read the relevant files.
Assistant
Now the doc sweep locations. Reading them in bulk:
Assistant
Let me ground the doc rewrites in what the suite actually measured, rather than paraphrasing the review.
Assistant
Now let me check whether the JetStream library exports these header-name constants:
Assistant
Now implementing item 1 — the header filter:
Assistant
Now the regression test. I'll make the fake publisher actually enforce Nats-Expected-Stream, so "capture succeeds" is a real assertion rather than a vacuous one:
Assistant
Now the critical check — does the new test actually fail on the pre-fix code?
Assistant
Item 1 verified load-bearing — reproduces err_code=10060 on the pre-fix code. Committing:
Assistant
Now item 2 — the terminate-path context hardening:
Assistant
Now item 2 — the terminate-path hardening:
Assistant
Now a test that's actually load-bearing — the existing fakes ignore ctx, so I need ones that don't:
Assistant
Verifying this test is load-bearing too:
Assistant
Reproduces the exact failure mode — settle:stranded from a cancelled context. Committing:
Assistant
Now item 3 — the doc/comment sweep. Working through the list by content:
Assistant
Now the two "Term does not settle" comments:
Assistant
Now the remaining Nak-era comments:
Assistant
Now jsconsumer.go:26-28 — the package-doc overclaim:
Assistant
Now schedule.go — the disproved AckWait model plus the redelivery-count cosmetic:
Assistant
Now retry.go:527 — the misattributed "run NewRetry locally" advice:
Assistant
Now the one behavior-adjacent item — retry.go:600-02, the duplicated RecoverBy comparison. Let me find the shared check first:
Assistant
The cosmetic fix exposed a test asserting the old off-by-one. Updating it:
Assistant
"only 1 redeliveries" reads badly. Rewording so the count is accurate and grammatical:
Assistant
Now the last sweep item — the README restart trade-off:
Assistant
Now let me verify I've covered every item in the list before committing:
Assistant
Now the full gate on the final HEAD:
Assistant
Gate fully green and the push is a clean append. Pushing:
Assistant
Fix pass landed. Merge remains a separate step.
New HEAD
79427bc801428994423d38728a2e2ff207eb9205 — 11 commits ahead of origin/main, appended as 3 new commits on top of the reviewed beebcd1. Confirmed a fast-forward (beebcd1..79427bc): the SHAs reviewers pinned are all still ancestors, nothing rewritten.
code
79427bc jsconsumer: retire comments the broker-semantics suite superseded
51e7223 jsconsumer: settle the terminal path on a context shutdown cannot cancel
3129b67 natsmsg: strip publish-control headers from the dead-letter copy
beebcd1 ← reviewed tip, unchanged
Part 1 — header filter (3129b67)
StrippedNats-Expected-Stream, Nats-Expected-Last-Sequence, Nats-Expected-Last-Subject-Sequence, Nats-Expected-Last-Msg-Id, Nats-Rollup — via the jetstream.*Header constants rather than string literals, so a library rename can't silently un-strip one.
One beyond the list, flag for your call: I also strip Nats-Expected-Last-Subject-Sequence-Subject. It's inert once its partner sequence header is gone, so this is not a correctness need — but it is a broker directive in the same family, and leaving one behind makes the guarantee "we strip control headers, except this one". Trivial to drop from the slice if you'd rather match the list exactly.
Nats-Msg-Id kept, with its dedupe role written down on dlqStrippedHeaders: it's a dedupe key rather than a stream assertion, and it's what makes the deliberate re-capture after a failed Ack (settle:dlq_ack_failed, which prefers a DLQ duplicate over a pinned floor) collapse inside the DLQ's duplicate window instead of leaving a replay tool two copies.
Regression test is load-bearing, which took one extra step: the existing fakeDLQPublisher ignored ctx and headers, so the obvious test would have passed on the broken code. It now checks Nats-Expected-Stream against the stream it stands in for and refuses a mismatch with err 10060. Against the pre-fix deadletter.go the test fails with err_code=10060 description=expected stream does not match (repo_ops_v1) — your reproduction, verbatim. Also asserts the original isn't mutated.
User
[Request interrupted by user]
User
[P1] Non-advancing AckFloor is still treated as proof of stranding. jsconsumer/retry.go:103 directs operators to follow the destructive runbook when the floor has not advanced. AckFloor is a contiguous watermark: an older pending
message can pin it even when this target’s ack landed. Non-advancement must remain uncertain and require consumer-specific evidence before removal. The nearby Captured documentation has the same assumption.
[P1] Preserving the original Nats-Msg-Id can silently discard distinct DLQ records. natsmsg/deadletter.go:44 intentionally carries the source ID into another stream, but NATS deduplicates stream-wide by ID alone. Two different
source messages sharing an ID can enter one DLQ stream; the second publish returns a successful duplicate PubAck, then this code acks the original without creating its DLQ record. Strip the ID or replace it with a DLQ-scoped
identity derived from origin stream and sequence.
[P1] Publish-control stripping omits Nats-TTL. natsmsg/deadletter.go:52 excludes expectations and rollup but not jetstream.MsgTTLHeader. Against NATS 2.14.3, the copied header either rejects capture when the DLQ disallows per-
message TTL or makes the captured record expire when it allows TTL. The original is then acked despite the DLQ record inheriting source retention semantics. Other current broker directives should be audited similarly.
Assistant
Let me verify each of these against the actual code rather than take them on report.
Assistant
All three confirmed. Let me check the Captured doc and what metadata is available for a DLQ-scoped identity:
Assistant
All three findings verified. Let me fix them — starting with the Nats-Msg-Id collision and the header audit:
Assistant
Now the tests — including a fake that dedupes stream-wide the way the broker does, so the collision is actually demonstrated:
Assistant
Two assertions I wrote last pass encoded the now-unsafe behaviour. Updating them, and extending the strip check to the newly-audited headers:
Assistant
Now verifying the collision test is load-bearing — it must fail on the pre-fix code:
Assistant
Confirmed load-bearing — two distinct messages collapse to one DLQ record on the old behaviour. Now finding 1, the operator guidance:
Assistant
Now the log line an on-call actually reads first:
Assistant
Committing the two code fixes and the doc fix separately:
Assistant
All three confirmed against the code, all three fixed. Committed locally, gate green — not pushed: the previous authorization was scoped to that fix pass, so say the word and I'll push.
code
d2d7515 jsconsumer: stop telling responders a stationary ack floor proves a strand
cd8a1b2 natsmsg: scope the DLQ copy's dedupe key, and strip the TTL and schedule directives
79427bc ← currently on the remote
1. Non-advancing AckFloor treated as proof of stranding — confirmed, fixed.OutcomeUncertain literally ended "if it has not, treat it as stranded and follow that runbook". Worth noting how self-contradictory this was: the package measures this property in TestAckFloorStaysStationaryWhileLaterMessagesAck, and shouldQuarantine rejects floor+1 as an identification rule for exactly the same reason — the docs were contradicting the branch's own findings on the one path where a responder acts destructively. Now: advancement past the sequence proves the ack landed (sound direction, kept); non-advancement proves nothing, and to implicate this message the floor must be pinned at it rather than below it because something older is unsettled. Fixed in the Captured doc too, and in the log line an on-call reads first. I also checked NumAckPending as a substitute — it isn't one, since TestExhaustedDeliveryPinsFloorWithNoAckPending shows an exhausted message pins the floor with it at zero, so that's called out explicitly.
2. Nats-Msg-Id collision — confirmed, and it was my 3129b67 that made it deliberate. The mechanism holds end to end: dedupe matches on the ID alone stream-wide, the duplicate publish returns a successfulPubAck{Duplicate:true}, DeadLetter discards the PubAck entirely, capture returns nil, terminate sets Captured = true and DoubleAcks. Message gone, no DLQ record. The copy now keys on origin stream + sequence, which serves the verdict's stated intent (dedupe the re-capture after a failed Ack) better than the raw ID did, since the same original re-presents the same key while distinct originals can never collide — and it makes ignoring PubAck.Duplicate safe rather than unsafe. The publisher's key is relocated to Nats-Dlq-Origin-Msg-Id for replay. Flagging for Andrea: this reverses the "keep Nats-Msg-Id" line in the 2026-08-13 verdict comment. I judged the intent behind that line to be the re-capture dedupe, which is preserved.
User
• Request changes on local head d2d7515.
[P1] DLQ copies still retain counter and atomic-batch control headers. The denylist in natsmsg/deadletter.go:75 omits Nats-Incr, Nats-Counter-Sources, and Nats-Batch-{Id,Sequence,Commit}. With pinned NATS 2.14.3:
Nats-Incr is rejected by an ordinary non-counter DLQ (/Users/nodo/go/pkg/mod/github.com/nats-io/nats-server/v2@v2.14.3/server/stream.go:6310).
Nats-Batch-Id is rejected when atomic publishing is disabled (/Users/nodo/go/pkg/mod/github.com/nats-io/nats-server/v2@v2.14.3/server/jetstream_batching_test.go:63).
Consequently, terminal capture of such messages can repeatedly fail and strand the original. Strip the complete server-side directive set—including Nats-Schedule-Rollup—and add broker-backed regressions.
The previous AckFloor guidance and dedupe collision findings are fixed locally. TTL and exported schedule headers are now stripped, but that fix is incomplete as described above.
Validation passed:
Focused tests
Full go test -race ./...
golangci-lint
git diff --check
GitHub PR #14 still points to 79427bc; these two fix commits are local and unpushed. GitHub currently reports no checks.
Assistant
Let me verify these against the pinned server source before acting.
Assistant
All six confirmed present in the pinned server, and none are exported by nats.go v1.52.0. Let me get the error codes and check how the server groups directives:
Assistant
Prefix matching only works if I know how nats.Header handles key casing. Checking:
Assistant
readMIMEHeader preserves original case and Get/Set are case-sensitive. That matters — let me check whether the server's lookup is case-sensitive:
Assistant
bytes.Index — the server matches header keys case-sensitively, so only canonical spellings are honoured. Now implementing the allow-list inversion:
Assistant
Now replacing the denylist with the namespace filter:
Assistant
Now the unit tests for the namespace rule, then the broker-backed regressions:
Assistant
My own belt-and-braces check caught the one reserved header we deliberately author. Making that explicit rather than weakening the check:
Assistant
Now the broker-backed regressions the reviewer asked for. Let me check the harness first:
Assistant
Now writing the broker-backed regressions:
Assistant
Let me clean up two rough spots in that test, then verify it fails on the previous denylist:
Assistant
Proven — the previous denylist fails the capture with err_code=10174 atomic publish is disabled, the reviewer's finding measured against the real broker. Full gate:
Assistant
Confirmed and fixed. New local head a7f9139 — still unpushed, as are d2d7515 and cd8a1b2.
The finding, verified
All six headers exist in the pinned server (server/stream.go:639-655), and none is exported by nats.go v1.52.0 — which is the root of why two passes of name-enumeration kept coming up short. I measured the rejections rather than taking them on report, on a DLQ declared the way adopters declare one:
Directive
Result on an ordinary DLQ
Nats-TTL
rejected, err_code=10166 "per-message TTL is disabled"
Nats-Incr
rejected, err_code=10168 "message counters is disabled"
Nats-Batch-Id
rejected, err_code=10174 "atomic publish is disabled"
Nats-Expected-Stream
rejected, err_code=10060
Permanent refusals — retrying doesn't change the stream's config — so a capture carrying one fails every delivery and strands the original, breaker included. Nats-Schedule-Rollup confirmed at stream.go:652.
What I did instead of extending the list
Third pass, third missing directive, so I changed the design: the filter is now a namespace boundary, not a name list.Nats- is NATS's reserved space — everything the broker interprets is in it, and an application has no business writing there. A captured copy keeps every header outside it verbatim (tracing, app metadata), and nothing inside it except this package's own Nats-Dlq- provenance plus the Nats-Msg-Id it authors. Filtering happens on the way in, so a copy never transiently holds a directive. A directive NATS ships next release is dropped before anyone here has heard of it.
This is the inversion I flagged as a follow-up two turns ago; the third instance of the same class made it the fix rather than a suggestion. Flagging it as a design change, not just a list extension, in case you want it scoped differently.
Two sub-findings worth your attention:
Case sensitivity is not a live bug. The server's lookup is bytes.Index (server/getHeaderKeyIndex) and nats.Header preserves original case with case-sensitive Get/Set — so is inert. I made the namespace match case-insensitive anyway: costs nothing, holds if that ever changes.
User
/effort
effort
User
• Still request changes on local head a7f9139.
[P1] The new dedupe key can still silently collapse distinct originals. natsmsg/deadletter.go:98 uses only /. Stream sequence numbers reset when a source stream is deleted and recreated, and MsgMetadata.Domain is
ignored. If the DLQ survives, two distinct messages can therefore produce the same ID within its duplicate window; the second publish succeeds as Duplicate, the original is acknowledged, and no second DLQ record exists. Include a
stable stream-incarnation component—such as domain plus original timestamp—and add a broker regression covering source recreation.
[P2] Re-capture does not preserve the provenance chain claimed by the new policy. Although natsmsg/deadletter.go:85 retains prior Nats-Dlq-* headers, natsmsg/deadletter.go:187 overwrites the original publisher ID with the previous
DLQ copy’s synthesized ID; the other fixed provenance fields are similarly overwritten. The first-hop publisher identity needed for replay is therefore lost. The broad prefix allowance can also retain producer-supplied provenance.
Use an explicit hop-chain representation or only retain provenance whose authorship is known.
The previous counter/atomic-batch header finding is fixed: the namespace filter works, and its new real-broker tests pass.
Validation passed:
Focused natsmsg and broker-semantics tests
Full go test -race ./...
golangci-lint
git diff --check
GitHub PR #14 still points to 79427bc; the local branch is three commits ahead and GitHub has no checks.
Assistant
Let me verify both findings before acting — starting with what's actually in the message metadata.
Assistant
Stream and domain arrive as single tokens of the dot-delimited ack subject, so neither can contain a .. Let me confirm the no-domain value:
Assistant
Both findings confirmed. Implementing — first the dedupe key:
Assistant
Now the provenance-authorship fix — no inbound Nats- header survives at all:
Assistant
Now the DeadLetter doc must state the per-hop reality rather than the chain claim I got wrong:
Assistant
Two things to fix: the zero-Timestamp fixtures produce a garbage negative number, so let me guard that, then update the assertions:
Assistant
Now the storedAt/wantKey helpers, plus tests for the two new properties:
Assistant
Now the broker regression the reviewer asked for — source stream deleted and recreated:
Assistant
Now let me confirm this new test fails on the previous two-part key:
Assistant
The recreation regression is confirmed — 1 record for 2 distinct messages on the old key. Now let me see what else the new key broke:
Assistant
Full gate green. Let me run -race and check the jsconsumer side isn't affected, then commit:
Assistant
Both findings confirmed and fixed. New local head e9597d8 — four commits ahead of the PR, still unpushed.
P1 — the dedupe key could still collapse distinct messages
Correct, and my dlqMsgID comment claiming it "names it uniquely across every stream in the deployment" was straightforwardly false. Both gaps verified:
Sequence reuse. Delete and recreate a stream, numbering restarts at 1. Measured against a really recreated stream: the DLQ ends up holding one record for two unrelated messages, second publish returning success-with-Duplicate, original acked with no copy stored.
Domain ignored.MsgMetadata.Domain exists and is parsed from the ack subject (jetstream/message.go:319); I wasn't using it, so same-named streams in different domains collided too.
Key is now <domain>.<stream>.<sequence>.<store-timestamp-ns>, and I've written the two required properties as arguments from the components rather than assertions:
Stable for one stored message — every part is fixed at store time, so identical on delivery 1 and delivery 6. NumDelivered is deliberately excluded; including it would give each redelivery a different key and turn the intended collapse into a pile of near-duplicates. Pinned by a test.
Two details worth flagging since they're judgment calls rather than transcription of your remedy:
The separator is provably unambiguous, not just conventional. Domain and stream arrive as single tokens of the dot-delimited $JS.ACK reply subject, so neither can contain a .; the other two components are decimal digits. That was worth establishing — isValidName permits /, so my previous / separator was the weaker choice.
A zero store time writes 0.UnixNano() on the zero Time returns -6795364578871345152, which reads like a real timestamp. Only reachable from fakes, but it was showing up in test output.
P2 — provenance didn't keep the chain it claimed
Also correct, and worse than "incomplete": the retention preserved nothing. Every Nats-Dlq-* field is overwritten for the current hop — Origin-Msg-Id included, which on a re-capture took the previous copy's synthesized DLQ key and buried the first publisher's. So the doc I wrote ("accumulates its chain of provenance") was false in the same commit that introduced it. Meanwhile the prefix allowance let any producer hand a replay tool forged provenance carrying this library's apparent authority.
Assistant
Before surgery — the conflicts I can see, and one genuine tension inside instruction 2.
Assistant
Now rewriting the header/provenance policy. Constants first:
Assistant
Now replacing dlqMsgID with the documented no-dedupe decision:
Assistant
Now the DeadLetter body and its doc:
Assistant
Now the tests. Let me see exactly what fights the simplification:
Assistant
Rewriting the test suite around the new contract:
Assistant
Now the broker-side tests — including the two new invariants asked for:
Assistant
All green. Now verifying both new invariants are load-bearing:
Assistant
Both load-bearing — though note (B): the broker re-capture test passed even with overwrite, because re-capturing the same original derives identical values. Let me add the hop that actually discriminates:
Assistant
Now the full gate:
Assistant
Now the PR hygiene item — pushing all five so the PR head matches local:
Assistant
Done. PR #14 head is now b9d7500 and matches local — the desync is closed.
Flags — what fought the simplification
You asked for these before surgery rather than after. I hit three, one of them a genuine tension inside instruction 2 rather than just a test to rewrite:
1. Instruction 2's two halves can't both be satisfied literally. "Set ONLY if absent — never overwritten" requires retaining inbound Nats-Dlq-*; "retain only provenance the library itself authored" forbids it. No header-level rule can distinguish a header written by an earlier DeadLetter hop from one a producer set on publish — that impossibility is what drove the previous round's design. I read the forced resolution as: retain a closed list of the origin keys this package defines (so an invented Nats-Dlq-Whatever never rides through) and state plainly in the docs that origin values are what the capture chain reported, not something the library vouches for. What is guaranteed is the shape: only these keys exist, per-hop fields are always freshly authored. If you meant the stricter reading, the fallback is retain-nothing — but that gives up write-once, so I don't think you did.
2. Tests that asserted dedupe. Four, all inverted rather than deleted: TestDeadLetterScopesTheDedupeKeyToTheCopy → TestDeadLetterNeverSuppressesACapture; the "stable across redeliveries → 1 record" subtest → 3 captures leave 3 records; TestDeadLetterKeyDistinguishesARecreatedSourceStream → TestEveryCaptureLeavesItsOwnDLQRecord; and TestDeadLetterDoesNotInheritProvenanceItDidNotWrite, which asserted the exact opposite of write-once and became TestDeadLetterWritesOriginProvenanceOnce.
3. The key was carrying information nothing else recorded. Dropping it would have lost origin domain and store time entirely — the two fields replay-side dedupe needs to tell incarnations of a recreated stream apart. Added as Nats-Dlq-Origin-Domain and Nats-Dlq-Origin-Timestamp (RFC3339Nano) so the identity is legible in the record where dedupe now happens.
What landed
No capture-time dedupe. No Nats-Msg-Id on the copy; dlqMsgID deleted. Documented where the retention rationale used to live, framed as the same safe-error-direction choice as the breaker clock: duplicate, never suppressed.
Write-once origin (setOrigin fills only what's absent) vs fresh per-hop (reason, delivered) plus .
User
Still request changes on live/local head b9d7500, now down to one correctness issue.
[P2] “Write-once” provenance cannot preserve legitimate empty values. natsmsg/deadletter.go:300 treats an empty header as uninitialized, while natsmsg/deadletter.go:316 is legitimately empty outside a JetStream domain. If that DLQ
record is later captured from a domain, the later hop’s domain is written as the original domain. Synthetic/no-metadata captures have the same problem for other absent fields. Use an explicit origin-initialized marker or stable empty
sentinel, and add a cross-domain recapture regression.
The previous findings are fixed:
Capture no longer uses Nats-Msg-Id, eliminating silent dedupe collisions.
Provenance uses an explicit carried-field allowlist.
Counter, batch, TTL, schedule, and future reserved directives remain filtered.
Validation passed: focused tests, full go test -race ./..., lint, build, and git diff --check. PR #14 is clean/mergeable, but GitHub still reports no checks.
Assistant
Verifying the finding first — the two conflation points:
Assistant
Confirmed — field-level absence is doing double duty as "not recorded". Implementing an explicit marker:
Assistant
The existing hop-2 fixture predates the marker. Fixing it, and adding the two absence cases:
Assistant
Now the cross-domain broker regression. Let me check the harness supports a domain-enabled server:
Assistant
The guard caught that the test wasn't actually testing what it claimed — o.JetStreamDomain alone doesn't put a domain in the ack subject. Let me find what does:
Assistant
Found it — the domain-bearing ack subject is behind a server feature flag; without it MsgMetadata.Domain is always empty on 2.14.3:
Assistant
Adding a measurement for that semantic, since Origin-Domain now depends on it:
Assistant
Now verifying the cross-domain regression is load-bearing against the previous field-absence logic:
Assistant
Both reproduce the finding exactly, including the DLQ-as-origin variant. Full gate:
Assistant
Confirmed and fixed. PR #14 head is now fbeee11, pushed in sync with this round.
The finding
Correct on both counts. setOrigin decided "already recorded" field by field from hdr.Get(h) == "", and two origin fields are legitimately absent:
Origin domain — a message captured outside a JetStream domain has none.
Origin stream / sequence / timestamp — a capture with no metadata has none.
Reading those absences as "not yet recorded" let a later hop answer for the first one. Both variants reproduce under the old logic:
code
Nats-Dlq-Origin-Domain = "hub" after re-capture inside domain "hub", want it still absent
Nats-Dlq-Origin-Stream = "repo_ops_dlq_v1", want it still absent
Nats-Dlq-Stream-Seq = "12", want it still absent
That second one is the sharper of the two — the record ends up naming the DLQ itself, at the DLQ's own sequence, as where the message came from. Silently wrong provenance, which is the same class as the overwrite that write-once was introduced to prevent.
Took the marker option: Nats-Dlq-Origin-Recorded gates the whole block. When present, every origin field is carried as-is and none is derived — absences included, because an absent field is now an answer ("the recording hop had nothing for it"), not a gap. I chose the marker over a sentinel because a sentinel needs one per field and there's no non-ugly sentinel for a sequence number; the marker also survives fields being added later.
A finding inside the finding
Measuring the cross-domain case turned up something worth having on the record: MsgMetadata.Domain is empty by default on 2.14.3 regardless of JetStreamDomain. The domain reaches a client only as a token of the $JS.ACK reply subject, and the domain-bearing V2 form is behind the js_ack_fc_v2 feature flag — FeatureFlagJsAckFormatV2, default off (server/consumer.go:1386, server/feature_flags.go:35). The v1 subject has no domain token at all.
Two consequences: an absent Nats-Dlq-Origin-Domain is the normal case rather than a defect, and if that flag is ever turned on, a later hop must not start claiming its domain as an older record's origin — which is exactly what the regression pins. Now measured in .
User
can you commit push and create a trail
Assistant
Everything is already committed and pushed — let me confirm, then look up the trail command.
Assistant
A trail already exists for this branch — #13 — and its description is badly stale (it still says "Retry plain-Naks into it", "A failed capture Naks instead", and nothing about the natsmsg capture work). Creating a second trail for the same branch would duplicate it. Let me check the update path:
Assistant
Updating #13's body rather than duplicating it. Writing the new description:
Assistant
Done — with one deviation worth flagging.
Commit and push: nothing to do. The working tree was already clean and fbeee11 was already on the remote from the last round; local and remote match, 17 commits ahead of main.
Trail: updated #13 rather than created a new one. A trail already existed for this branch — created 2026-08-12, before any of the review rounds. Creating a second one for the same branch would have split the review context and left reviewers with two places to look, so I updated it instead. Say the word if you actually wanted a separate trail.
The old description had gone materially stale — it was still describing behaviour the branch has since corrected, which is worse than being merely out of date:
"Retry plain-Naks into it" and "A failed capture Naks instead" — the retry path stopped disposing of messages entirely; it leaves the delivery for the ack timeout, because a plain Nak skips the ladder.
"a Nak at the broker's cap is dropped" — the actual reason nothing retries past the cap is that nothing redelivers at all.
"never a bare Term (ENT-1492)" implying Term doesn't settle — the suite measured that it settles cleanly; the objection is the missing record.
No mention of the natsmsg capture path, which is where four review rounds went.
The new body carries those corrections plus a section on the capture path as its own unit (namespace header filter, no capture-time dedupe, write-once origin provenance with the Nats-Dlq-Origin-Recorded marker, closed-key retention), the AckFloor-is-not-evidence correction, and a verification section noting the MsgMetadata.Domain / js_ack_fc_v2 finding.
Two things I left alone deliberately:
Title unchanged. It's what reviewers have been referring to across rounds, and the branch's headline is still accurate. It does undersell the natsmsg work now — happy to extend it if you'd rather.
Status and phase unchanged (open, building). The last review round was "request changes" and I've since fixed that finding, but moving it to review-ready is a judgment about whether the reviewer agrees, not mine to assert.
Still outstanding from my side: no CI runs on push (there's no .github/workflows in the tree), so the PR shows no checks despite the gate being green locally. That's the one gap between "green here" and "green where reviewers can see it".
User
P1 — the retention safety check fails open. jsconsumer/jsconsumer.go:340 silently returns success for every StreamInfo error, including authorization and transport failures. StreamInfo and consumer creation use separate JetStream API
subjects, so a credential can create the consumer without being able to read maxAge. An invalid ladder can then start and let the source expire before DLQ capture—the exact loss this check promises to prevent. Run already treats
ErrStreamNotFound as retryable, so the probe can return its error rather than swallowing it. The current entire-search grant includes $JS.API.>, so the immediate target is not exposed, but the reusable library contract is.
Assistant
Let me verify against the code.
Assistant
Confirmed — both paths return nil unconditionally. Let me check the claim that Run already handles the legitimate case:
Assistant
Finding confirmed on all three points. Let me check two details before fixing — how a permissions failure actually surfaces, and whether the second round-trip is even needed:
Assistant
A publish-permission denial surfaces as a timeout (async handler + no reply), so Run retries loudly rather than starting — fail-closed. Let me confirm js.Stream populates cached info so I can drop the redundant RPC:
Assistant
Confirmed: js.Stream already fetches the info, so the second Info() RPC is redundant. Fixing:
Assistant
Now a regression test. Let me look at the existing real-broker max-age test and the permissions pattern:
Assistant
Now the regression test — the exact scenario: STREAM.INFO denied, consumer creation permitted, ladder invalid against retention:
Assistant
That first test came out muddled — let me rewrite it cleanly with a proper two-user setup:
Assistant
Now confirming both tests are load-bearing against the fail-open version:
Assistant
That's revealing — the test caught the regression, but for the wrong reason: the credential couldn't create the consumer either (create consumer ... deadline exceeded), so it wasn't demonstrating the reviewer's scenario. Let me find the minimal grant that really can create:
Assistant
Definitive: with that grant CreateOrUpdateConsumersucceeds while $JS.API.STREAM.INFO.short_v1 is denied — the reviewer's scenario exactly. My 3s context was the problem: the denied probe ate the whole budget, so the create timed out instead. Fixing so the test discriminates on the real hazard:
Assistant
That's the real hazard demonstrated: pre-fix, Start succeeds with an unchecked ladder. Full gate:
I also confirmed the check is load-bearing rather than vacuous: checking out the old 6143624 in that worktree fails with vet: jsconsumer/zz_probe_test.go:15:58: undefined: stubPublisher. go build alone would have missed it — the breakage is test-file-only, so vet/test-compile is what catches it.
Gate on final HEAD — all green
Gate
Result
gofmt -s -l .
clean
go build ./...
OK
go vet ./...
OK
go test -count=1 ./...
ok — all 6 packages, incl. internal/brokersemantics (3.8s)
go test -race -count=1 ./...
ok — all 6 packages
golangci-lint run ./...
0 issues
git diff --check origin/main HEAD
clean
312 Test* functions run on HEAD. The embedded suite needs no external nats-server — it links nats-io/nats-server/v2/server in-process, and no go.mod change was involved in the rebase.
The two conflict resolutions
jsconsumer/jsconsumer.go — ConsumerLimits. Worth flagging: git did not raise a textual conflict here. The two blocks were adjacent but not overlapping, so it silently accepted both and produced a duplicate — the semantic conflict you predicted, arriving as a clean merge. Resolved as pre-agreed: main's version kept whole (the UNLESS the stream sets ConsumerLimits.InactiveThreshold qualifier on InactiveThreshold, the or the stream's ConsumerLimits.MaxAckPending qualifier on MaxAckPending, and the # Stream ConsumerLimits fill in both zeros section with the replay-cost consequence, the set-both-explicitly guidance, the pedantic-mode/NACK-reconcile note, and the TestStreamConsumerLimitsAreInheritedBySilentConsumers citation). The branch's 7-line note above InactiveThreshold from f4e160a was deleted — all four of its points (zero isn't always "never"; the stream fills unset InactiveThreshold and MaxAckPending; an unasked-for deletion timer; read the stored config) are already in main's block, stated more fully. f4e160a's otherjsconsumer.go change survives untouched: the Process comment reworded to "a bare Term settles the message perfectly well, it just leaves no trace of what was discarded".
One judgment call, since I was rewriting that commit anyway: its message claimed the ConsumerLimits confirmation was "noted on the field", which the resolution makes false. I rewrote that one clause to say the point was written on the field by the suite's own doc pass (f6f999f) more fully, so the note is dropped rather than duplicated. Nothing else in the message changed; all trailers preserved.
README.md — also merged without a textual conflict, and the result is coherent as-is. The branch's ~113 lines of jsconsumer.Retry/FloorMonitor prose sit in ## Subpackages; main's new ### Testing: the fake vs the real broker sits under ## Development; ## License stays last. No duplicated claims — the branch discusses the retry schedule and breaker, main's section discusses fake-vs-real test split. I verified losslessness mechanically rather than by eye: the set of added/removed README lines in origin/main..HEAD is identical to that in merge-base..pre-rebase-branch. Same check over doc.go, floor.go, retry.go, retry_test.go, schedule.go, schedule_test.go and fakemsg.go — all byte-identical branch-side changes. jsconsumer.go is the only file that differs, by exactly the 7 intended lines.
Force-pushed with --force-with-lease=…:f4e160a… (explicit expected old value); remote confirms + f4e160a...beebcd1 (forced update). The pre-rebase tip is kept locally as tag backup/ent-1601-prerebase → f4e160a if you want the old SHAs for comparison during review. No Linear writes; nothing else touched.
Part 2 — terminate-path hardening (51e7223)
terminate derives settleCtx := context.WithoutCancel(ctx), used for both the capture and the DoubleAck. The 15s bounds are untouched and are what keep it safe — worth noting explicitly because WithoutCancel drops the parent's deadline too, so those explicit dlqPublishTimeout/dlqAckTimeout bounds are now the only thing bounding the path. Values are preserved, so the handler's span/trace context still flows into the capture.
Scoped honestly in the comment: this narrows the window, it doesn't close it. A terminate outlasting nuts.DefaultJoinTimeout (10s) still gets its connection drained out from under it. What's gone is the case that failed immediately and by construction.
Test was practical, but needed new doubles — both existing fakes discard the context (FakeMsg.DoubleAck(context.Context), fakeDLQ.PublishMsg(_ context.Context, …)), so a cancellation test written against them passes on the unfixed code. Added a ctx-respecting publisher and a ctx-recording message, local to retry_test.go. On the unfixed path the test fails with settle:stranded: … context canceled — the production symptom.
Part 3 — doc/comment sweep, item by item
Review item
Done
retry_test.go:321, 1015-17 "Term does not settle"
Both rewritten: Term settles cleanly; the objection is the missing record
Figures removed, points at shouldQuarantine for the mechanism
retry_test.go:263 Nak-era
"naks with the ladder delay" → disposes of nothing, left for AckWait expiry
retry_test.go:823-25 Nak-era
"original is Nak'd instead" → left untouched for the ladder
retry_test.go:849-51 + 871 Nak-era
"a Nak is dropped" / "a dropped Nak is not a retry" → nothing redelivers past the cap
retry_test.go:882-84 Nak-era
"Delivery 4 … Naks with deliveries in hand" → left for the ladder with the reserve in hand (also drops the wrong delivery number)
jsconsumer.go:26-28 blocker overclaim
Now states the breaker does not identify the blocker; aligned with Settle's disclaimer incl. the one-per-window bound
schedule.go:203-05 disproved model
Rewritten: the server rewrites stored AckWait to BackOff[0]; check kept for the two surviving reasons (declared value never runs; pedantic create rejects rather than normalizes), citing REDACTED
schedule_test.go:30-31 superseded
Reframed as coverage of the NakDelay modelling path, explicitly not the adopted shape
retry.go:527 misattributed advice
"run NewRetry locally" → run Schedule.Validate, the same call fleet CI makes
retry.go:600-02 duplicated RecoverBy
Now calls Schedule.Validate and surfaces only RecoverBy violations; same rejections, one copy of the rule
README restart trade-off
Added to the Non-goal section, "late, never early"
Cosmetic: schedule.go:199 count
Fixed to MaxDeliver-1
Cosmetic: retry_test.go:223/227 wrong name
Comment now names TestNewRetryDefaults and describes what the test actually covers
Two things worth your attention in part 3. The rung-count fix had a test pinning the off-by-one ("only 2 redeliveries" with MaxDeliver: 2), so that assertion moved with it. And the corrected count made the message read "only 1 redeliveries", so I reworded it to "has %d rungs but MaxDeliver %d schedules at most %d of them: %d deliveries leave %d redeliveries" — accurate and grammatical at every count.
Gate on 79427bc — all green
gofmt -s clean · go build OK · go vet OK · go test ./... ok (6 pkgs, incl. internal/brokersemantics) · go test -race ok · golangci-lint 0 issues · git diff --check clean.
golangci-lint initially flagged two embeddedstructfieldcheck findings on the new test doubles; fixed and amended into 79427bc, then the whole gate re-run from scratch.
No Linear writes. One suggestion I did not act on, since it's beyond the fix pass: this module's own rule is that a doc comment stating a JetStream behaviour gets measured in internal/brokersemantics, and the part-1 fix now rests on such a claim (control headers are evaluated against the stream published to). My regression test encodes that in a fake. A brokersemantics test measuring the real 10060 would close the loop properly — worth a line on the post-merge follow-up list.
3. Nats-TTL omitted — confirmed, and the audit found more than TTL.jetstream.MsgTTLHeader exists in the pinned v1.52.0 and I'd missed it. Auditing the rest of the current set turned up the whole Nats-Schedule family — Nats-Schedule, -Target, -Source, -TTL, -Time-Zone. Those are worse than TTL: a copied schedule expression makes the captured record a scheduled publish, and Nats-Schedule-Target delivers it somewhere else entirely. All stripped. I deliberately left the server-set republish/direct-get headers (Nats-Stream, Nats-Sequence, …) alone — provenance, not directives, and a republished message carries real information there. Say if you'd rather those go too.
Both code fixes have tests verified to fail on the prior behaviour: the collision test stores 1 record for 2 distinct messages pre-fix, and it needed the fake publisher taught to dedupe the way the broker does (ID-only, stream-wide, success-with-Duplicate, storing nothing) — otherwise it couldn't distinguish deduping one message twice from collapsing two. Two assertions from 3129b67 pinned the old behaviour and moved with the fix.
Gate on d2d7515: gofmt -s clean · build · vet · go test ./... ok (incl. real-broker suite) · -race ok · golangci-lint 0 issues · git diff --check clean.
One thing these three findings together suggest, worth a follow-up rather than more patching: the DLQ copy's header handling is now a deny-list against a set the client library keeps growing, and this is the second pass to extend it. An allow-list — provenance plus tracing plus explicitly-approved application headers — would fail closed when NATS adds the next directive, instead of failing open as it did twice here. That's a design change beyond this review, so I've left it; happy to scope it if useful.
nats-incr
One reserved header does survive, by design — the Nats-Msg-Id we author for the copy's dedupe. My own belt-and-braces assertion caught it, and I made the exemption explicit rather than loosening the check. It's safe where the others weren't: dedupe is always available on a stream, so it can never fail a capture.
Reversal to flag: I'd argued last turn for keeping the server-set republish/direct-get provenance (Nats-Stream, Nats-Sequence, Nats-Time-Stamp, Nats-Subject). Under an allow-list, keeping them means asserting they're safe for a client to publish — which nats.go explicitly says they are not. They're dropped; the facts that matter are re-stated in Nats-Dlq-Origin-* where the authorship is known. Say if you'd rather they were preserved under a Nats-Dlq-Republish-* name; that's the natural follow-up and I left it out deliberately.
Broker-backed regressions
New internal/brokersemantics/publishdirectives_test.go, per the module's rule that a JetStream claim gets measured:
TestOrdinaryStreamRejectsPublishDirectivesItDoesNotEnable — the four rejections above.
TestDeadLetterCarriesNoPublishDirectiveOntoTheDLQ — end-to-end: consume a message carrying every directive the pinned server knows, capture into a plain DLQ, assert the capture succeeds, the stored copy carries none, app headers survive, and the dedupe key is events/1.
The directive table references natsserver.JS* constants, so a rename on the next server bump breaks compilation rather than silently un-stripping. Against the previous denylist the end-to-end test fails with err_code=10174 atomic publish is disabled — the finding, reproduced.
Unit side also extended: TestDeadLetterKeepsOnlyApplicationHeaders pins the boundary itself using invented future-directive names and mixed casing, so it tests the rule rather than today's list.
Gate on a7f9139: gofmt -s clean · build · vet · go test ./... ok · -race ok · golangci-lint 0 issues · git diff --check clean. (golangci-lint flagged one tparallel issue on the new subtests; fixed before commit.)
On your note that PR #14 points at 79427bc with no checks: the three fix commits are local and I've held off pushing, since the push authorization was scoped to the previous pass. Say the word and I'll push all three — that'll move the PR to a7f9139 and give CI something to run.
DLQHeaderPrefix
One cause, one fix — I took your second option: nothing inbound in the reserved namespace survives, this package's own prefix included. Every Nats-Dlq-* on a copy was written by the capture that produced it. keepsHeaderOnCapture collapses to a single namespace test.
The reason I didn't build a hop-chain representation: the authorship problem is unfixable by header content, since nothing distinguishes "written by a previous hop" from "written by the producer". So instead the chain is walkable as a chain of records — origin stream + sequence name the exact stored message, so the previous hop is one GetMsg away. I've stated the cost rather than hidden it: the walk needs each intermediate record to still exist, so a link can dangle where a replay tool acks records off a work-queue DLQ, and callers needing first-publisher identity across arbitrary hops should carry it in their own header outside the reserved namespace. Origin-Msg-Id now documents only what it claims — the Nats-Msg-Id the captured message carried, producer's on a first hop, previous copy's on a re-capture, message-reported either way.
Regressions
Broker: TestDeadLetterKeyDistinguishesARecreatedSourceStream — real delete/recreate, both messages at sequence 1, asserts two records and distinct keys. Fails on the previous key with 1 record.
Unit: key stability across redeliveries of one message; distinctness across incarnations and across domains; forged inbound Nats-Dlq-* (including an invented field) dropped and replaced with this hop's truth.
One stale expectation moved with the change: the namespace test previously asserted a prior hop's Nats-Dlq-Reason was kept. It's now asserted dropped.
Gate on e9597d8: gofmt -s clean · build · vet · go test ./... ok · -race ok · golangci-lint 0 issues · git diff --check clean.
Worth naming plainly: this is the third consecutive round where a fix to the capture path introduced or left a silent-loss path, and twice the defect was in a doc claim I wrote in the same commit as the fix. The namespace inversion removed the recurring directive class; this round removed the key and authorship classes. If you want more assurance before merge than review-round convergence, the honest next step is a property test over DeadLetter — random header sets and metadata, asserting no reserved header survives, the key is injective over distinct metadata and constant over redeliveries. I haven't written it; say if you want it in this pass.
PR #14 still points at 79427bc. Four commits are local and unpushed — cd8a1b2, d2d7515, a7f9139, e9597d8. Say the word and I'll push so CI has something to run.
Nats-Dlq-Hops
Retention is a closed key list, not the prefix.
Broker regressions — all three, verified load-bearing
(a)+(b) TestEveryCaptureLeavesItsOwnDLQRecord: source stream deleted/recreated so the second message stores at sequence 1 like the first, then two re-captures of one message — four captures, four records, on a DLQ with a 1-minute duplicate window so any identity would have collapsed them. Reintroducing a <stream>/<seq> key: 1 record for 4 captures.
(c) TestReCaptureKeepsTheFirstHopProvenance. Worth your attention: (c) as specified doesn't discriminate — re-capturing an original derives identical values whether the code is write-once or overwrite, so it passed under both. I added the hop that does discriminate: capturing a DLQ record, where this hop's stream/sequence/subject all differ. Under overwrite that fails with Origin-Stream = "events_dlq_recapture", want "events".
The fake publisher keeps modelling JetStream's dedupe even though copies carry no ID — it's now the guard that makes no-dedupe testable. Reintroduce an identity and the exactly-N tests fail.
Gate on b9d7500: gofmt -s clean · build · vet · go test ./... ok · -race ok · golangci-lint 0 issues · git diff --check clean. (goconst flagged a thrice-repeated traceparent literal; extracted before commit.)
One residual I'd rather name than leave implicit: Nats-Dlq-Hops is incremented from an inbound value, so it's reported like the origin fields, not derived from anything trustworthy — a producer can seed it. It's documented that way. If you'd rather not ship a forgeable counter at all, dropping it is a two-line change and the write-once contract doesn't depend on it.
TestMsgMetadataDomainNeedsTheV2AckSubject
This is also what caught my own first draft: I wrote the cross-domain test with o.JetStreamDomain = "hub" and a guard asserting hop 2 really ran in a domain. The guard failed — hop 2 ran in domain "", want hub — so the test would have passed while testing nothing. Adding jetstream.NewWithDomain didn't fix it either; the server flag was the missing piece.
Regressions
TestReCaptureAcrossDomainsKeepsTheDomainlessOrigin — two real brokers, because the case needs two: hop 1 in a domainless deployment, its record moved into a domained one, hop 2 there. Guards assert hop 1 really had no domain and hop 2 really had one, so it can't silently degrade into a no-op again.
TestDeadLetterDoesNotBackfillAnOriginThatWasRecordedAsAbsent — the domain case and the metadata-less case as unit tests.
One existing fixture needed the marker added, since a hop-1 record now carries it.
Gate on fbeee11: gofmt -s clean · build · vet · go test ./... ok · -race ok · golangci-lint 0 issues · git diff --check clean. Two lint findings fixed pre-commit (goconst on a repeated "hub", then a govet format-arg slip in the constant I extracted).
On CI showing no checks: that's a repo-side workflow question rather than something in the branch — there's no .github/workflows in this tree, so nothing runs on push. Worth someone wiring the gate up, since the whole value of internal/brokersemantics running untagged in go test ./... is that it gates merges. Happy to add a workflow if you want it in scope; I've left it out as it's outside this fix pass.