Repository navigation
feat(purchase): recheck ladder switches before any provider call (#118 PR4r) - #848
Conversation
…PR4r) Ladder executions can wait approved or scheduled for hours. Re-read the global ladder flags, the ladder config (enabled, auto_approve) and the run (not canceled) in executeAndFinalize, so every executor entry (approve, fire, claimAndExecute/SQS, re-drive) is covered. The tranche is found by comparing the idempotency key to ladder_tranches.id as text; other key shapes are not ladder executions. A lookup error refuses. A refusal is a beforeSubmission error, so the row ends failed with no_submission and the reconciler can release netting. Inert: nothing creates ladder executions yet. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Gate verdict: APPROVE (money path, independent adversarial review)Reviewed SHA: Paths traced (source): the only provider call ( Lookup: Refusal class: wrapped as beforeSubmission, so the row ends failed with no_submission. Local evidence (git archive at exact head, GOTOOLCHAIN=go1.26.9, throwaway PG17 17.11 cluster, no Docker, under the suite lock):
Follow-ups (non-blocking):
|
Refs #118. Inert: nothing creates ladder executions yet (no schema, no task wiring), so this changes behavior only for rows whose idempotency key is a ladder tranche id.
What
executeAndFinalizenow rechecks, before any provider call, that an execution belonging to a ladder tranche is still allowed to buy:LadderingEnabledandLadderExecutionEnabledare on, the ladder config is enabled with modeauto_approve, and its run is not canceled. The check sits inpreExecutionRefusalbeside the armed re-drive and stale Azure pricing refusals, so every executor entry is covered (approve, scheduler fire, claimAndExecute for SQS and the cron sweep, stranded re-drive).Details
idempotency_keycompared toladder_tranches.idas TEXT (GetLadderExecutionGate, one query joining config and run). Non-UUID keys (<root>:<acct>multi-account, legacy ExecutionIDs, empty) match nothing and are not ladder executions. Only a real DB error refuses (fail closed). A deleted config or run (FK is ON DELETE SET NULL) also refuses.beforeSubmissionerror: the row endsfailedwithno_submissionstamped. The ladder reconciler reads that proof (decideFiredTranche) to fail the tranche and release netting.Verification
failed+no_submission; all-on buys once; multi-account, legacy and empty keys are unaffected with flags off; each of the four entries refuses.t.id = $1::uuidcompare (integration test fails with 22P02).golangci-lint(go1.26.9) 0 issues, gocyclo ok, git-secrets clean,go vet -tags=integrationok.🤖 Generated with Claude Code
Summary by CodeRabbit