Skip to content

refactor(subscriber): give lease-lost telemetry one home#110

Merged
lesnik512 merged 2 commits into
mainfrom
refactor/consolidate-lease-lost
Jun 23, 2026
Merged

refactor(subscriber): give lease-lost telemetry one home#110
lesnik512 merged 2 commits into
mainfrom
refactor/consolidate-lease-lost

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

_flush_terminal and _flush_retry (subscriber/usecase.py) each carried a byte-identical ~17-line tail — the lease-lost WARNING log (extra={event, phase, row_id, queue, deliveries_count}) plus _emit_metric("lease_lost", …) — differing only in phase ("terminal"/"retry"). This consolidates that into one _emit_lease_lost(row, *, phase) helper, so lease-lost telemetry has a single home and a future change can't diverge between the two paths.

This is candidate #2 ("give the lease a home") from the 2026-06-23 architecture review, scoped to its only genuinely-duplicated, in-process piece.

Change record: planning/changes/2026-06-23.02-consolidate-lease-lost/change.md.

What changed

  • Add OutboxSubscriber._emit_lease_lost(row, *, phase) — the log + lease_lost recorder emit.
  • Both flush methods keep their explicit if not landed: self._emit_lease_lost(...); return False branch, so the rowcount-0 → redeliver decision stays visible.
  • ~36 duplicated lines removed.

Why the minimal form (B and C rejected)

  • (B) a Lease value object (message_id, token) through the client interface — rejected: the pair is passed at only two sites, and it would ripple through AbstractOutboxClient + both adapters + the just-landed tests/test_client_contract.py for modest gain.
  • (C) a full "Lease module" owning issue/guard/cutoff — rejected for the same reason refactor: dedupe outbox rules between real and fake clients #109 left eligibility/lease/retry-timing as two implementations: the real client runs the guard in SQL (WHERE acquired_token = :token), so a pure Lease module would have one Python consumer — a hypothetical seam, i.e. indirection.

The rest of the lease lifecycle (issue/guard/expiry in SQL, the acquired_token field, the <table>_lease_ck CHECK) is already single-sourced or intrinsically SQL and stays put.

Verification

  • Existing lease-lost unit tests invoke _flush_terminal/_flush_retry directly, so the extraction is transparent to them — they served as the regression guard unchanged.
  • just test: 543 passed, 100% coverage. just lint-ci: clean.

🤖 Generated with Claude Code

lesnik512 and others added 2 commits June 23, 2026 17:28
_flush_terminal and _flush_retry carried a byte-identical detect->log->emit tail
differing only in phase. Extract _emit_lease_lost(row, *, phase); each flush
method keeps its explicit rowcount-0 branch. Minimal (A) form — the Lease value
object (B) and Lease module (C) were rejected (lease guard is intrinsically SQL).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 7be8da8 into main Jun 23, 2026
3 checks passed
@lesnik512 lesnik512 deleted the refactor/consolidate-lease-lost branch June 23, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant