You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test: nothing asserts that expiry withholds a stored event from a reader #1107
bugSomething isn't workingfactoryBuilt by the software factoryrewritenostream 4.0 Rust/LMDB rewriterustRust implementation worktestUnit or integration test improvements
No test asserts that a stored event whose NIP-40 expires_at has passed is withheld from a subscriber, so the guard in handlers/subscribe.rs can regress silently. This is the reason #953 went unnoticed: the clock is captured once, at subscribe.rs:306, and consumed per event at :381, while the await that opens the window is stream.next() at :364 over lazily-read LMDB batches — an event expiring mid-stream is delivered — and nothing in the suite would have failed.
What exists today is not that assertion:
crates/nostream-relay/tests/strategies.rs:1061group_accepts_an_expiration_tag_alongside_the_h_tag checks a write, not a withheld read;
the only other expires_at in that file, at :1416, is a fixture field set to None.
The Clock seam is what makes such a test possible (HandlerContext.clock, TestClock advancing between permits); #1106 is the storage side of the same gap, where two LMDB query entries read Utc::now() and so cannot be driven by a test clock at all.
Acceptance: a relay test that stores a far-future expires_at, advances the test clock past it between two fixture permits, and asserts the second read delivers nothing — red at 2c151f2a, green with #953's fix.
Hi @tirthraj01 — thank you for picking this up. I filed #1107 and its premise is wrong, so this is a correction rather than approval of the plan as written.
The assertion already exists.crates/nostream-relay/tests/connection.rs:625, an_event_that_expires_while_earlier_records_are_still_being_read_is_not_delivered, landed with the #953 fix in 5830e61 (2026-11-10). It is the acceptance criterion, already built: fixture.events.gate_reads_per_item(), the first event's expiration an hour ahead, the second at NOW_SECS + 5, one permit per record, clock.advance(EXPIRY_ADVANCE_MS) between them, and the second event must not appear in the frames. A companion at :735 pins the boundary (expiration <= now).
So step 2 of the plan would add a second copy, three hundred lines from the first, in strategies.rs. And step 3 cannot be honoured: the base 2c151f2a has neither the fix nor the test, so "red at base, green with the fix" proves nothing here — the red would be a test that never had a guard to exercise.
What is worth doing, and what this ticket becomes:
Prove the existing test actually guards the code. In handlers/subscribe.rs, hoist the clock read above the loop — capture context.now_secs() into a local before loop { and use that local at the expiry check, which is the pre-relay: event expiry is checked against a clock captured before the stream #953 shape. Run an_event_that_expires_while_earlier_records_are_still_being_read_is_not_delivered: it must fail. Restore, run again: it must pass. Put both outputs in the PR. A test added alongside its own fix has never been shown to catch the regression it is named for.
If it does not fail under that mutation, that is the real finding: say so, and propose the smallest change that makes it fail for the right reason. That is the whole ticket if it happens.
Leave strategies.rs:1061 alone, and the :1416 fixture — one is a write-side assertion, the other is unrelated.
A .changeset/*.md entry in the shape of the existing ones, even though the change is test-only.
Then take the gap that is still open: #1106. Sixty production sites read the system clock outside the Clock seam, two of them in LMDB query entries that no test clock can drive. That is the same defect class one layer down, and a test cannot pin what the clock cannot reach.
bugSomething isn't workingfactoryBuilt by the software factoryrewritenostream 4.0 Rust/LMDB rewriterustRust implementation worktestUnit or integration test improvements
Activity
tirthraj01 commentedon Nov 13, 2026
Hi @cameri @chappie-daemon,
I have gone through this issue and analyzed the subscription guard flow and the
Clockseam. I would like to work on this! Please assign it to me.Proposed Approach:
crates/nostream-relay/tests/strategies.rsonrewrite/main.expires_attimestamp.HandlerContext.clock/TestClock) past the expiration timestamp.2c151f2aand passes cleanly with the relay: event expiry is checked against a clock captured before the stream #953 fix).Looking forward to your approval to get started!
tirthraj01 commentedon Nov 17, 2026
Hey @chappie-daemon @cameri!
Just a gentle follow-up on this issue. I'm still interested in working on it and would appreciate your feedback or approval to proceed.
Thanks! 🙌
chappie-daemon commentedon Nov 17, 2026
Hi @tirthraj01 — thank you for picking this up. I filed #1107 and its premise is wrong, so this is a correction rather than approval of the plan as written.
The assertion already exists.
crates/nostream-relay/tests/connection.rs:625,an_event_that_expires_while_earlier_records_are_still_being_read_is_not_delivered, landed with the #953 fix in 5830e61 (2026-11-10). It is the acceptance criterion, already built:fixture.events.gate_reads_per_item(), the first event's expiration an hour ahead, the second atNOW_SECS + 5, one permit per record,clock.advance(EXPIRY_ADVANCE_MS)between them, and the second event must not appear in the frames. A companion at:735pins the boundary (expiration <= now).So step 2 of the plan would add a second copy, three hundred lines from the first, in
strategies.rs. And step 3 cannot be honoured: the base2c151f2ahas neither the fix nor the test, so "red at base, green with the fix" proves nothing here — the red would be a test that never had a guard to exercise.What is worth doing, and what this ticket becomes:
handlers/subscribe.rs, hoist the clock read above the loop — capturecontext.now_secs()into a local beforeloop {and use that local at the expiry check, which is the pre-relay: event expiry is checked against a clock captured before the stream #953 shape. Runan_event_that_expires_while_earlier_records_are_still_being_read_is_not_delivered: it must fail. Restore, run again: it must pass. Put both outputs in the PR. A test added alongside its own fix has never been shown to catch the regression it is named for.strategies.rs:1061alone, and the:1416fixture — one is a write-side assertion, the other is unrelated..changeset/*.mdentry in the shape of the existing ones, even though the change is test-only.Then take the gap that is still open: #1106. Sixty production sites read the system clock outside the
Clockseam, two of them in LMDB query entries that no test clock can drive. That is the same defect class one layer down, and a test cannot pin what the clock cannot reach.Assigning this to you now.
cameri commentedon Nov 18, 2026
@tirthraj01 If you would like to become a collaborator please send me a message over Telegram to discuss.
tirthraj01 commentedon Nov 18, 2026
Sure @cameri !
Happy to Contribute as a collaborator!