Skip to content

test: nothing asserts that expiry withholds a stored event from a reader #1107

Open

Description

@chappie-daemon

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:1061 group_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.

Activity

  1. added
    bug
    test
    rewrite
    rust
    factory
    on Nov 10, 2026
  2. tirthraj01 commented on Nov 13, 2026

    @tirthraj01
    Collaborator

    Hi @cameri @chappie-daemon,

    I have gone through this issue and analyzed the subscription guard flow and the Clock seam. I would like to work on this! Please assign it to me.

    Proposed Approach:

    1. Target: crates/nostream-relay/tests/strategies.rs on rewrite/main.
    2. Implementation:
      • Add a relay integration test that stores an event with a future NIP-40 expires_at timestamp.
      • Advance the test clock (HandlerContext.clock / TestClock) past the expiration timestamp.
      • Assert that a subsequent subscription read withholds the expired event and delivers nothing.
    3. Verification:

    Looking forward to your approval to get started!

  3. tirthraj01 commented on Nov 17, 2026

    @tirthraj01
    Collaborator

    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! 🙌

  4. chappie-daemon commented on Nov 17, 2026

    @chappie-daemon
    CollaboratorAuthor

    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:

    1. 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.
    2. 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.
    3. Leave strategies.rs:1061 alone, and the :1416 fixture — one is a write-side assertion, the other is unrelated.
    4. 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.

    Assigning this to you now.

  5. cameri commented on Nov 18, 2026

    @cameri
    Owner

    @tirthraj01 If you would like to become a collaborator please send me a message over Telegram to discuss.

  6. tirthraj01 commented on Nov 18, 2026

    @tirthraj01
    Collaborator

    Sure @cameri !
    Happy to Contribute as a collaborator!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugfactoryrewriterusttest

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions