Skip to content

test(gateway): pin that a pull over /nats keeps the stream subject - #93

Merged
bketelsen merged 2 commits into
mainfrom
irulan/t1947-nats-ws-guard
Nov 16, 2026
Merged

bketelsen merged 2 commits into
mainfrom
irulan/t1947-nats-ws-guard

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A guard test and a spec rule for clients of the broker's /nats door: a message that a pull delivers keeps its stream subject.

  • internal/gateway/broker_pull_test.go: TestNatsPullKeepsTheStreamSubject runs the real broker behind the gateway's /nats handler. It speaks the NATS protocol's own lines over the WebSocket, so no client library hides what arrives. A client subscribes a request mux (_INBOX.chani.mux.*, as nats.js does) and asserts 3 things:
    1. A pull that expires with no event answers a 408 status, whose subject is the pull's inbox.
    2. After the app publishes 1 event (with a message ID, as frostmarks does), the pull delivers it on the mux's subscription, with the stream subject (marks.bookmark.created.folder.pilot), not the inbox, and with a $JS.ACK.app_marks.<consumer>.… reply.
    3. +ACK on that reply moves the consumer's ack floor.
  • docs/specs/lodge-http.md, The broker: "A pulled message keeps its stream subject". A client reads a pull on a subscription of its own and never finds its request by the subject. A request mux that does (nats.js request() without noMux) drops every event and sees only the status replies.
  • .memory/corrections/2026-11-16-pr-93-pull-keeps-stream-subject.json: the broker's client tests used only nats.go. nats.go's request mux gives a message with an unknown subject to its single open request, so no test showed the subject.

Why

The pilot run of docs/runbook-pilot.md failed at line L2: a saved bookmark did not reach the agent's events bridge.

  • On lodge's host, the broker delivered the event 17 times, and no ack came.
  • A reproduction with the bridge's client (@nats-io/nats-core 3.4.0 over a WebSocket door, in the nsl machine) showed the cause. Each request() pull timed out. The protocol trace showed MSG marks.a 1 $JS.ACK…: the message came on the mux's subscription, with the stream subject, and the mux dropped it.
  • The same pull with noMux: true returned the message in 2 ms.

The fix is in the bridge, not in lodge: lodge behaves as JetStream does. This PR records the contract and guards lodge's side of it.

Verification

  • make ci passed before the first push. It includes make race, make cross and the nsl checks.
  • Revert test. In a scratch worktree, I removed the client's ack import in internal/broker/broker.go (addImports). Then go test ./internal/gateway -run TestNatsPullKeepsTheStreamSubject failed: the ack floor is 0 after the ack, want 1. The test checks lodge's own pull and ack path, so it can fail. The stream subject is JetStream's behavior, which lodge cannot change. The test pins that behavior for clients.

Risk tier

Risk tier: 1 — tests and docs only (level L3). The PR changes only a test, the spec and a correction record. It matches no path in .github/risk-paths.json (internal/gateway/broker.go is listed; broker_pull_test.go is not).

Docs housekeeping

  • Spec changed alongside its code (the test); no new doc, so no index line
  • Conformance aliases and canonical symlinks are unchanged

Cross-review

Coder: anthropic/claude-opus-5-5. Reviewer: openai/gpt-6.1-sol.

  • Initial review at 22962d19a0ff3f5047dd0bfc033ecabd5d2c5422 (base 49b1616ab67b8d91bb7586d06e531abc6fbddd78): Ready, Blocking: none. It had 1 low finding: the event pull reused the 300 ms expiry, so a slow delivery could give a 408.
  • The fix at 23ecc044bd2ddc57c5f6b4cbf04e32aeda1728d7: the event pull now has a 5 s expiry. Re-review 1 at that head: Ready, Blocking: none, no findings.

A message that a pull delivers comes on the pull's inbox subscription,
but with the event's own subject and the ack subject as its reply; only
a status reply carries the inbox as its subject. A client whose request
mux finds the request by the subject's last token (nats.js request()
without noMux) drops every event. nats.go's mux hides this, because it
gives a message of an unknown subject to its single request, so the
broker's tests could not see it.

TestNatsPullKeepsTheStreamSubject drives the protocol's own lines over
/nats with the real broker: the expired pull's 408 on the inbox subject,
the event on the mux's subscription with the stream subject, and the ack
that moves the ack floor. The spec's broker section tells clients to read
a pull on a subscription of their own.
@github-actions github-actions Bot added the level:L3 Skim label Nov 16, 2026
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 16, 2026
@bketelsen
bketelsen merged commit 789ed5d into main Nov 16, 2026
11 checks passed
@bketelsen
bketelsen deleted the irulan/t1947-nats-ws-guard branch November 16, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L3 Skim ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants