Skip to content

Fresh access tokens can introspect inactive due to rounded PostgreSQL nbf defaults #342

Closed

Description

@voidvec

Problem

Fresh access tokens can be rejected as inactive immediately after successful issuance when the Redis token cache is enabled. This blocks the real-stack smoke prerequisite for S07; delaying requests or retrying failed introspections would conceal the behavior.

Evidence

Verified on product commit d616a7b424d934a4c93713ae92744b014e546d04, native Linux, PostgreSQL 16.15 + Redis 7, Release without instrumentation. The default-profile nine-scenario smoke passed; the tuned profile failed while preparing a freshly issued client-credentials token.

A separate bounded diagnostic retained the first failure after nine successful issuances:

  • client observation: 1794634005.5386012;
  • stored not_before=1794634006, issued_at=1794634006, expires_at=1794637605, revoked=false;
  • PostgreSQL clock_timestamp() epoch: 1794634005.583454;
  • immediate introspection: HTTP 200, active=false.

apps/server/migrations/V002__oauth2_core.sql:46-49 defaults issuance/not-before timestamps using EXTRACT(EPOCH FROM CURRENT_TIMESTAMP)::BIGINT, which rounds fractional seconds. PostgresTokenRepository::saveAccessToken persists expiry/issuer but does not explicitly persist issuance/not-before. RedisCachedTokenRepository::introspectToken rejects a fresh snapshot with nbf > std::time(nullptr). The database-backed introspection path currently does not apply the same nbf test.

The diagnostic above is published with the repository owner's approval. Full raw runs remain local; the tools PR contains no runtime archive. These are functional failure evidence, not capacity results.

Suggested fix

Persist the issuance-defined timestamps with consistent whole-second semantics rather than relying on the rounding SQL defaults. Review authorization-code, client-credentials and refresh issuance paths. Preserve cache nbf enforcement; do not add sleeps, weaken validation, edit generated ORM models or rewrite a baselined migration as a workaround. Follow the repository's async Mapper/callback error-handling rules.

Acceptance criteria

  • Deterministic regression covers fractional-second issuance on both sides of the rounding boundary, without sleep-based success.
  • Stored iat/nbf/expiry reflect the intended issuance semantics across the affected grants.
  • Newly issued valid tokens introspect as active immediately on both cached and uncached paths; an intentionally future nbf remains inactive.
  • Cache hit/miss, revocation and expiration behavior remain correct; existing relevant tests pass.
  • Rerun the real S07 paired protocol smoke and retain every attempt; no retries erase the original failures.

Out of scope / follow-ups

S07 capacity claims, persistent-space provisioning, the known #300 shutdown issue and macOS runner changes. The S07 tools PR does not fix this product behavior or close this issue.

Activity

  1. added
    tracking
    on Nov 14, 2026
  2. added a commit that references this issue on Nov 18, 2026
    e9b1015
  3. added 2 commits that reference this issue on Nov 19, 2026
    edbcfbd
    7884511
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tracking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions