Repository navigation
docs(claude): record the immutable-id-over-list-position rule - #3702
Merged
Merged
Conversation
The autostash restore bug came from holding `stash@{0}` across a mutation
window, and nothing in the guidance said not to. Write the rule down next to
the structured-output rule it belongs with — both are about picking a robust
handle over a fragile one.
Scoped deliberately: the rule is about namespaces other processes can mutate,
not about indices generally. Stated loosely it would invite "fixing"
`relocate.rs`, whose indices point into a Vec wt builds once and only reads.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Aug 2, 2026
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.
Follows #3693. That PR fixed the autostash restore; this records the rule it was an instance of, so the next one doesn't have to be found the hard way.
Why
The bug was holding
stash@{0}— a position in a list any process can reorder — across agit push, then acting on it. Nothing in the guidance said not to.CLAUDE.mdalready has a rule for picking a robust handle over a fragile one (Structured Output Over Error-Message Parsing), so this sits next to it as a sibling.Scope of the rule
I swept the codebase for other instances before writing it. There are none, and the three places that look like the bug shape are why the rule is worded narrowly:
create_safety_backup(working_tree.rs) already does it right —git stash createreturns a SHA that never enters the stash list, stored under a namedrefs/wt-backup/<branch>ref.orphan_branch_age(step/prune.rs) readsreflog showfor a named ref and takes the oldest line as a creation timestamp. Single-shot, no mutation window; a pruned reflog makes a branch read younger, which skips it from pruning and so fails safe.relocate.rsholdsidxintopendingacross cycle-breaking moves. Not the bug shape:pendingis built once, only ever read, and owned bywt.So the rule is about namespaces other processes can mutate, not about indices generally. Stated loosely it would invite "fixing"
relocate.rsand making it worse — hence the closing sentence drawing that line explicitly.The one surviving positional selector, inside
StashData::locate_by_message, is cited in the rule as the correct pattern: re-derive the selector from something stable immediately before the operation that needs it.Testing
Docs-only.
cargo run -- hook pre-merge --yesgreen.