Repository navigation
Conversation
…ad spec The document a PATCH writes back is built from a snapshot taken before the spec lock, so assigning its `resources` list whole dropped any URI a concurrent writer had added in between; only the URIs this patch itself named may move. A patch that names no resource change now leaves a malformed `resources` value untouched rather than normalising a key it never read.
|
👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review. When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically. |
First Principles Review (Fable 5, fork) —
|
Opus 4.8 Review (fork) —
|
Design Review (Fable 5, fork) —
|
GPT 5.6 Review (fork) —
|
|
Thank you for this fix, @rnoack1 — the element-wise resources-patch merge is a real lost-update fix and the reasoning is sound. Since the head branch is on a fork, the AI review lanes could not run to completion here, so I opened an in-repo replacement that carries your change (and credits you via Closing this one as superseded by #13624. Your branch is untouched. Thanks again! |
One unit of a split of #7105, which was 6.9x over the 1500 added-line cap. This unit stands
alone: it reads and writes plain dicts and needs nothing from the other units. 226 added lines.
Problem / Motivation
api_agent_detail's PATCH path builds its result document from a snapshot taken before thespec lock is held, then assigns that document's
resourceslist onto the freshly-read specwholesale. Any
resourcesURI a concurrent writer added between the snapshot and the lock issilently dropped — the losing write looks like it succeeded, and the URI is simply gone.
Two smaller defects sit in the same assignment:
resourceschange still rewrote the key, so a malformed value therequest never looked at came back normalised;
str, an unguardedcomprehension over a malformed
resourcesvalue would rewrite it as a per-character list.Why it matters
This is a lost update with no error surface: the request that loses returns success, and nothing
reports which URI vanished. Two sessions editing one agent is the ordinary case, not an exotic
one, and the window is exactly the read-modify-write gap the lock exists to close.
What changed (motivation → approach → change)
The write-back cannot assign a value derived from a stale snapshot, so it must move only what
the request itself named.
_merge_resources_deltacomputes the patch's delta — the URIs itremoved and the ones it added — and applies just that to the freshly-read document:
so a malformed value it never read survives untouched rather than normalised.
this merge has an opinion about, so it is carried through unread rather than dropped.
[], matching the mapping writer,because an empty list suppresses the shipped steering defaults.
_locked_overwritenow skipresources, so the merge is theonly thing that writes it.
Tests
Four tests in
test/test_agent_detail_model_managed.py, each pinning one behaviour:…keeps_a_uri_a_concurrent_writer_added…names_no_resource_change_leaves_a_malformed_value_alone…over_a_malformed_fresh_value_does_not_split_it…preserves_resource_entries_it_cannot_readMutation controls, all four killed, one test each: assigning
afterwhole; dropping theearly return; dropping the non-list guard; rebuilding the kept list from the string view. Each
mutation failed exactly one test, and a different one — so no test here is vacuous and none is
redundant. The tree was restored byte-identical afterwards and re-run green.
Gates on the touched files: flake8, isort
--check-only, black--check, mypy all clean.Regression sweep over every test file importing this handler (57 files, traversal
positive-controlled): 3179 passed, 0 failed.
Manual verification
N/A — the lost update is reproduced directly in the first test by simulating the concurrent
writer, so unit coverage reaches the actual failure mode.
Related Issues
Part of the split of #7105.
Pattern harvest
Rule candidate: review-prompt
Pattern: a write-back that assigns a value derived from a pre-lock snapshot discards whatever a
concurrent writer changed in the same key — under a lock, write back only the keys the request
itself named, as a delta, never the whole re-derived document.
Checklist