Repository navigation
fix(events): refilter before /nats admits a client, and resync a gap that a pull passed - #96
Merged
Merged
Conversation
…that a pull passed A grant change commits in the store before its hook refilters the consumers, so a stop between the 2 left a restored consumer with a filter wider than the grant, and /nats admitted clients a minute before the first sweep. The events service now runs Restore when it starts: it refilters every restored subscription from the grant store, revokes a client it cannot read (fail closed), and the token check of /nats waits for it. The resync check saw a gap only while the consumer's own position was before the stream's first message, and a pull on an open connection moves that position past the gap. The broker now records each consumer's last known position (at its birth, at a restore and at each check) and sends the resync event when the stream's first message is past that record. ADR-0022, the HTTP spec, the overview and the configure guide say both.
…only on a live start A cancelled start revokes nothing and admits no client. The position record moves only after the resync event is stored, an update never raises it, the birth record comes from the create's answer, and the records live in the hub-only key-value bucket lodge_positions, so a start keeps them; a consumer with no record is at 0. Position cleanup takes its own lock, not the resync check's.
…y when a position record moves
bketelsen
approved these changes
Nov 17, 2026
This was referenced Nov 17, 2026
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.
Summary
2 fixes in lodge's event broker, each with a guard test and a correction record.
/natsadmits a client. A grant change commits in the grant store and then runs its hook, which refilters the consumers. A stop between the 2 left a restored consumer with a filter wider than the grant, and/natsadmitted clients a minute before the first sweep, so a client could read events outside its grant.events.Service.Runnow runsRestorefirst: it refilters every restored subscription from the grant store, and revokes a client that it cannot read, that has no principal or no scopeevents(fail closed). The token check of/nats(Service.Tokens) waits forRestore, at most 5 s, and refuses a client before it.ADR-0022 (Proposed),
docs/specs/lodge-http.md,docs/design/overview.mdandsite/content/guides/configure.mdsay both.Risk tier
Risk tier: 3 —
risk:high. Matched paths:internal/events/**(the grant-driven event policy): the change only narrows what a client gets. Before a start has refiltered every restored consumer from the grant store, no client is admitted. A client whose OAuth client cannot be read is revoked, not admitted with its stored filter. A cancelled start admits no client at all.internal/broker/**(the broker's doors and consumers): no permission, account, import or door changes. The new code is an in-memory map of consumer positions under the existingresyncMu, and a second condition that can only add a resync event. No path removes or delays an event.Docs housekeeping
make check,internal/repocheck)Verification
make checkgreen (host)make raceandmake crossgreen (make ciran verify, race and cross green; its nsl stepsclient-check,ui-checkandshell-checkcould not start, because the nsl machine does not start on the host now. This PR changes nothing underclient/,ui/orshell/; CI runs them.)git worktree add), ata0d5c6a:internal/broker/broker.goandresync.goatc3fe29e, thengo test ./internal/broker/ -run 'TestResyncAfterAPullPassesTheGap|TestResyncFindsTheGapOfAConsumerBornBeforeIt|TestResyncSkipsAConsumerThatKeptUp': the first 2 fail on their resync assertions.Restorereduced tomarkReadyand the wait inTokensremoved, thengo test ./internal/events/ -run 'TestRestartRefiltersBeforeAdmission|TestRestartRevokesAClientItCannotRead': both fail ("the tokens check named a client before Restore"; "the broker keeps the subscriptions"). With only the loop ofRestoreremoved,TestRestartRefiltersBeforeAdmissionfails on the filters.TestRestoreCancelledRevokesNothing(no parent check inrestoreFailure: the subscription is deleted),TestAResyncWhosePublishFailsKeepsTheRecord,TestARePutKeepsThePositionRecord,TestThePositionRecordSurvivesARestart,TestAConsumerWithNoRecordGetsTheResync,TestAConsumerThatKeptUpGetsNoResyncAfterARestart,TestTheBirthPositionIsRecorded,TestRevokeDoesNotWaitForAResyncCheckeach fail..memory/corrections/(2 for the findings that this PR fixes, 7 for the cross-review's blocking points below):2026-11-16-pr-96-restart-refilters-before-admission.json:TestRestartRefiltersBeforeAdmission,TestRestartRevokesAClientItCannotRead2026-11-16-pr-96-resync-after-a-pull-passes-the-gap.json:TestResyncAfterAPullPassesTheGap,TestResyncFindsTheGapOfAConsumerBornBeforeIt,TestResyncSkipsAConsumerThatKeptUpReview record
Coder:
deepseek/deepseek-flash(directed and reviewed byanthropic/claude-opus-5-5). Reviewer:openai/gpt-6.1-sol.a0d5c6aa72a307566329dMerge-base
c3fe29ec096486dc59d436dff694a77c06951ab5. Each round covered the diff since the head before it. Every changed path was reviewed; none was excluded.What else changed for the review: the position records live in the key-value bucket
lodge_positionsin lodge's own (hub) account. No client or app account imports its subjects (TestThePositionBucketIsOutOfReach). A consumer with no record after a start is taken as being at position 0, so the first start of this version can send each subscription 1 resync event, if its stream has ever dropped a message.