Skip to main content

classify_token_consume

Function classify_token_consume 

Source
pub fn classify_token_consume(
    changed: usize,
    found: bool,
    already_consumed: bool,
    binding_ok: bool,
) -> TokenConsumeOutcome
Expand description

Classify a consume attempt from the atomic UPDATE and a follow-up SELECT.

changed is the affected-row count from:

UPDATE codlet_form_tokens
SET consumed_at = :now
WHERE lookup_key = :key
  AND purpose    = :purpose
  AND subject    = :subject         -- binding
  AND expires_at > :now
  AND consumed_at IS NULL

When changed == 0, the follow-up SELECT provides:

  • found — a row matching the lookup key + purpose + subject exists.
  • already_consumed— that row has consumed_at IS NOT NULL.
  • binding_ok — the row’s bound resource matches the caller’s.

The single rule that must never be violated (INV-6): changed == 0 never produces TokenConsumeOutcome::Proceed (RFC-007 §5, §13.5, acceptance checklist item “changed == 0 never proceeds”).