Skip to content

feat(commitments): improve settlement receipts with bounded polling and telemetry - #1406

Open
DevALVIN-24 wants to merge 1 commit into
StellarLend:mainfrom
DevALVIN-24:fix/settlement-receipts-recovery-bounded
Open

DevALVIN-24 wants to merge 1 commit into
StellarLend:mainfrom
DevALVIN-24:fix/settlement-receipts-recovery-bounded

Conversation

@DevALVIN-24

Copy link
Copy Markdown
Contributor

closes #1366

Description
This PR addresses the production-quality risks in the settlement receipts implementation by introducing rigorous invariants, bounded performance, and operational visibility for the SettlementReceipt component and its integration within src/app/commitments/[id]/page.tsx.

Acceptance Criteria Addressed:
Establish the feature's explicit state, data, authorization, and failure invariants:
The SettlementReceipt leverages CommitmentDetailResponse and enforces data bounds on successful fetch results. State machines map gracefully into success, error, and loading UI states, rejecting malformed API schemas.
Set explicit bounds for pagination, polling, chart points, upload sizes, and concurrent requests where applicable:
Polling now strictly utilizes an exponential backoff strategy, bounded by explicit limits (POLLING_MAX_RETRIES, POLLING_MAX_INTERVAL_MS). This bounds the total network bandwidth and CPU cycles per user session.
Avoid redundant fetches and state updates during route changes, reconnects, or rapid user interaction:
The hook-based polling implementation manages an AbortController in a useRef. Whenever a route changes, unmounts, or rapidly refetches, any previous in-flight fetch requests and timers are eagerly aborted and cleared, preventing memory leaks and state thrashing.
Expose actionable client telemetry or structured diagnostics for latency, failure, and recovery paths without leaking secrets:
Uses the existing telemetry pattern (onTelemetry) to log latency (api_latency), poll lifecycle events (polling_started, polling_stopped), and failures (polling_error). All failure telemetry uses sanitization regex to mask potential secret leaks from crash errors.
Keep the change focused on this feature and preserve unrelated public behavior:
Implementation strictly anchors at components/settlement/SettlementReceipt.tsx and minimally integrates alongside CommitmentDetailActions in src/app/commitments/[id]/page.tsx, untouched and decoupled from unrelated dashboard features.
Automated tests cover success, failure, boundary, retry, and permission behavior:
Implemented rigorous test coverage in SettlementReceipt.test.tsx employing Vitest fake timers to exhaustively evaluate the bounded exponential polling behaviors and error states.
Validation Results
Verified network-layer cancellation upon component unmount.
Verified telemetry pipeline emits expected metrics without logging sensitive tx-hashes.
Verified exponential backoff successfully halts when MAX_RETRIES bounds are exceeded.
Known Limitations & Pre-existing CI Failures
The codebase's Vitest configuration uses strict workspace globs. Running npx vitest run components/settlement/SettlementReceipt.test.tsx standalone requires either modifying the accessibility workspace glob configuration to include components/settlement/* or running the tests globally outside of the constrained workspaces.

This branch has not been deployed

No deployments
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.

[Quality][Medium] Improve settlement receipts and transaction history: bounded performance and operational visibility

1 participant