Repository navigation
Bound deadline-close child cascades and back off failing closes - #1292
Conversation
A bounded deadline close (#1116) counted every item as one history event and five rows. A child's termination runs that child's whole close in the parent's transaction, and a failed accepted update writes two events and eleven rows, so one close transaction could write about twice the event limit and up to a thousand child terminates. Each transaction now has a DeadlineCloseBudget of the limit's events and rows, and every kind of work is charged what it writes with its projections: a child is charged its own open work, accepted updates and the children its own policy closes. Work is taken while it fits; a batch or settlement pass takes at least its first item, and a run with no open work left always closes. A failing ordinary close records its error, attempt and the settlement's backoff on the run's workflow task, and the watchdog skips the run until it is due, so failing closes no longer starve other expired runs. A run projection keeps a stored JSON value that differs only in key order. MySQL reorders JSON keys, so every projection rewrote each lineage row and a pass wrote one more row per child link. There is deliberately no operator release for a held settlement; the completion budget guide records why. Fixes #1290 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A terminate-policy child under a 20-row limit is terminated by the settlement, not by the close transaction, and the parent keeps the single close's history. On the base revision the close terminates it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A long-poll wake signal lands in Laravel's cache tables only when the application uses the database cache store on the same connection, so the statement budget tests leave those tables out. The child-cost fixture projects its runs first, as a real run is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A timed-out child's close still resumes its live parent in the same transaction; the changelog and guide no longer claim every close stays within the limits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent review: PASS at The reviewer worked in a fresh context and reviewed this PR's own changes against main, not my reasoning. PASS at
Should-fix #1 is resolved. The reviewer found that a timed-out child's close also resumes its live parent in the same transaction, and those writes are not charged. The behaviour predates this PR, but the CHANGELOG claimed every close stays within the limits. The docs-only delta Nits left for follow-up:
🤖 Generated with Claude Code |
|



Fixes #1290 (items 1–4; item 5 is unchanged, see below).
Why
The bounded deadline close (#1116) counted every item as one history event and five rows. That undercounted in two ways:
Separately, a failing ordinary close was retried with no backoff and stayed at the front of the oldest-deadline scan, so 25 of them starved every other expired run in scope (item 2).
What changes
Charged by what it writes (items 1 and 3). Each close, batch and settlement transaction now has a
DeadlineCloseBudget: the limit's events (history_transaction_size) and rows (completion_rows). Every kind of work is charged the events and rows it writes, including projections:terminate/request_cancel, before its own workrequest_cancellation)A terminated child is charged its own open activities, timers and tasks, its accepted updates, and recursively the children its own policy closes. The child's counts come from one
withCountquery. Counting stops once the total no longer fits.Backoff for a failing ordinary close (item 2). When the watchdog's close of an ordinary expired run fails, the close rolls back. In its own transaction the watchdog then updates the workflow task it closed with:
last_errorholds the error;attempt_countgoes up by one;deadline_close_failuresgoes up by one;available_atmoves out by the settlement's backoff (10 s, doubling, capped at 1 h).The deadline scan skips the run until the task is due. A task held for a settlement or under a live lease is never touched.
MySQL projection rewrite. On MySQL every run projection rewrote each of the run's lineage rows, so every pass wrote one more row per child link. Cause: MySQL reorders JSON keys, and Eloquent compares decoded arrays with
===.IdempotentProjectionUpsertnow keeps a stored JSON value that differs only in object key order. List order still counts as a change.No operator release (item 4). This is a documented decision, not a command (see
docs/architecture/completion-budget.md). Releasing a held settlement would leave accepted updates waiting forever and leave children running that the policy closes. A failing pass is retried with backoff and stays visible in metrics, queue visibility and describe.WorkflowExecutor::deadlineCloseBatchSize()is removed. Nothing in the org calls it, and the budget replaces it.Decisions for review
Tests
tests/Unit/V2/CompletionWriteFamilyBudgetTest.php. All performance assertions are statement budgets measured from the SQL itself. None are wall-clock limits.testEachDeadlineCloseItemIsChargedWhatItWrites(11 kinds): each kind writes no more than its charge, both in the close and in a pass that takes it alone. The charge is also within one row of what the item writes in the close.testEveryTransactionOfABoundedCloseStaysWithinTheLimits(event limit, row limit, both): a parent with every kind of work. Every transaction stays within the limits, and the history equals the single close.testAChildIsChargedItsWholeTerminate: four children with five activities each take two transactions, where they all used to land in the close.testABoundedCloseSettlesUpdatesAndChildrenAcrossPassesWithTheSingleCloseHistory: reworked to a 201-event limit. The close fails 100 updates, then the passes go 100, 100 updates and then 67, 67, 66 children.testAFailingOrdinaryCloseBacksOffAndCannotStarveOtherCloses: covers the backoff, the doubling and the eventual close.IdempotentProjectionUpsertTest::testPrefetchedRowKeepsAPayloadThatDiffersOnlyInKeyOrder.V2EmbeddedReplayRegressionCorpusTest::testDeadlineCloseCorpusChargesAChildItsTerminateuses the new replay evidencedeadline-close-child-charged-its-terminate.json. A terminate-policy child under a 20-row limit is terminated in a later transaction thanWorkflowTimedOut, by the settlement. I checked locally that this test fails on the base revision, where the close terminates the child in its own transaction.The statement measurement leaves out writes to Laravel's
cacheandcache_lockstables. Long-poll wake signals land there only when an application uses the database cache store on the same connection. Run fixtures are projected first, as a real run would be.CI adds a MySQL step to
pr-feature-mysqlfor these cases. It took 52 s on the first run.Local runs, in Docker with PHP 8.3:
test-build-routing.py,verify-feature-shards.php,validate-regression-corpus.py --skip-counterfactual,test-regression-corpus-policy.pyandcheck-public-boundary.sh: pass.CompletionWriteFamilyBudgetTestandIdempotentProjectionUpsertTest: pass on SQLite and PostgreSQL 16 (62 tests). The 20 deadline-close cases pass on MySQL 8.0.🤖 Generated with Claude Code