Add retrying-agent-decisions-under-contention skill (Application Development) - #26
Open
rajj28 wants to merge 1 commit into
Conversation
Guides developers whose writes are chosen by a language model rather than computed by deterministic code, through what to do when a serialization failure invalidates a decision the model has already made. This exists because reading designing-application-transactions first showed that two pieces of its guidance are individually correct and, composed for an agent, produce a silent bug: step 14 says keep RPC calls outside the transaction (right), step 3 says retry the unit of work (right), and together they mean the retry re-executes the write with the decision the model made against the state the previous attempt read. Nothing catches it. The transaction is properly serializable, state was read correctly on every attempt, and the committed value is one the model really did choose. Only an instrument on the reasoning step tells the two apart. The skill covers: checking first whether the constraint belongs in SQL instead; keeping model calls outside the transaction without replaying a stale decision; re-deriving rather than replaying on retry; refreshing retrieved context as well as rows, and where retrieval must sit relative to BEGIN/ROLLBACK; instrumenting reasoning invocations so a retry that failed to re-decide is detectable; bounding and validating the model's action space; and what to record per attempt. It links to designing-application-transactions for transaction scoping, retry and backoff, and connection pooling rather than restating them.
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.
What does this PR do?
Adds
retrying-agent-decisions-under-contentionto Application Development.It covers what to do when a serialization failure invalidates a decision a model has already made. Under SERIALIZABLE an agent's write hits
40001like any other, but the standard remedy — retry the transaction — behaves differently when the value being written was chosen by a model call that cannot be replayed inside the retry. The retry re-reads state and then writes the decision computed against the previous read.The motivation came from this repository. Reading
designing-application-transactionsfirst showed that two pieces of its guidance are individually correct and, composed for an agent, produce a silent bug:Together, for an agent, they mean the retry re-executes the write with a stale decision. Nothing catches it: the transaction is properly serializable, state was read correctly on every attempt, and the committed value is one the model genuinely produced. Only an instrument on the reasoning step distinguishes "re-decided" from "replayed".
The skill links to
designing-application-transactionsfor transaction scoping, retry/backoff and pooling rather than restating any of it.Its seven sections:
BEGIN/ROLLBACK, since retrieval inside the racing transaction joins its refresh spanenumis guidance, not a contractEvidence behind the guidance
Measured on a live CockroachDB Cloud cluster: 250 runs, 5,000 agent decisions, five arms differing by one flag. Runs breaking a
SUM(...) <= limitinvariant went 47/50 → 0/50 when each attempt re-derived its decision instead of replaying it, with no other change. Repository, methodology log and the two predictions we falsified: https://github.com/rajj28/racelabRelated Issue
Closes #25
Type of Change
Skill Compliance Checklist
name,description)scripts/,references/,assets/subdirs)python scripts/validate-spec.py skills/One validator warning, and why it is a false positive
The name is already gerund — it begins with retrying. The heuristic inspects the trailing word, so its suggestion is
...contentioning. The same warning fires on several already-merged skills (enabling-cmek-encryption,managing-tls-certificates,hardening-user-privileges, …), so this looks like a known rough edge rather than something to fix in the name. Happy to rename if maintainers prefer.python scripts/validate-spec.py skills/reports 0 errors across the whole tree with this skill added.Documentation Updates
No index file lists skills individually, so nothing else needed updating. Say the word if I have missed one.
Testing
Manual testing:
Automated testing:
python scripts/validate-spec.py skills/Notes for reviewers
Two things I would especially value a maintainer's view on:
designing-application-transactions. I have deliberately kept this skill narrow and linked out rather than duplicating. If you would rather this be a section in that skill than a sibling to it, I am glad to reshape it.