refactor(subscriber): give lease-lost telemetry one home#110
Merged
Conversation
_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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_flush_terminaland_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 inphase("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
OutboxSubscriber._emit_lease_lost(row, *, phase)— the log +lease_lostrecorder emit.if not landed: self._emit_lease_lost(...); return Falsebranch, so the rowcount-0 → redeliver decision stays visible.Why the minimal form (B and C rejected)
Leasevalue object(message_id, token)through the client interface — rejected: the pair is passed at only two sites, and it would ripple throughAbstractOutboxClient+ both adapters + the just-landedtests/test_client_contract.pyfor modest gain.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_tokenfield, the<table>_lease_ckCHECK) is already single-sourced or intrinsically SQL and stays put.Verification
_flush_terminal/_flush_retrydirectly, 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