Repository navigation
fix(artifacts): refuse stale content writes with 409 instead of silently overwriting - #14075
Conversation
|
Intent: Stop a stale save from silently overwriting newer content on store-backed artifacts: a save carries the content token it started from, and a mismatch is refused with a 409 while the editor keeps the draft. |
UX Review (Opus 5.5, fork) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS Two different "newer version"s appear on screen at once. Nobody new to the page has read this notice or the relabelled Save button yet. Watch
Suggestions
[UX-REVIEWED] df55b83 Description read[DESCRIPTION-READ] f54a75f6bea4cceeb7f976fa52f53040e8471e368ac7b7e34528e07f4328db74 That sha256 names everything this verdict read: the PR description, plus the 5 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] df55b83 Description read[DESCRIPTION-READ] 05323befc00371cd46a414e876c9da39f736fd767bdd6a1785378a9e13fb4955 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check before merge: moving the events and delete reads off the event loop does nothing for the 409 fix. Confirm that change belongs in this PR. Not justified as shipped
What this change shipsInventory (10 items) — 9 justifiedIntent: stop a save from a stale tab or editor silently replacing newer artifact content (#7751). This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] df55b83 Description read[DESCRIPTION-READ] bfa323c2a9117829af7d257af484c182bd36668db8a359bfd2563dffca4b6983 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. FINDING — website/src/pages/ArtifactDetailPage.tsx:2003 — after a 409 sets [OPUS-REVIEWED] df55b83 |
|
Round 1 disposition, head
The screenshot is committed under |
434cc71 to
a3e2ce4
Compare
…tly overwriting - Store-backed reads carry a content_token; update(expected_token=) compares it under the store lock and raises ArtifactConflictError on a stale write. - The token is 256 random bits stored in meta.json and replaced on every content write, so it reveals nothing about the content it guards. The new token is saved before the new content, so a write that fails between the two files can only refuse an earlier read, never admit it. - The dashboard's detail read, which runs off the event loop, gives an artifact saved before tokens existed its token; when that meta.json write fails, it returns the content without a token. Other reads write nothing. - The detail page pins the token at edit start and keeps the draft on a 409; only the relabelled Save button sends the fresh token to overwrite. - A save is skipped while another token write is on the wire, and the fork banner's actions are disabled during a save, so a repeated save cannot draw a false 409. A write that finishes after the page moved to another artifact or started a new edit leaves that editor's token and state alone. - The fork banner's pull/overwrite/snapshot leave a refused flush to the page's localized conflict notice. - The detail, events and delete handlers run their current read off the event loop.
f04c32c to
df55b83
Compare
|
self-added: yes
|
|
|
|
|
|
|
|
|
|
|
|
|
iamwhatever
left a comment
There was a problem hiding this comment.
This PR fixes #7751, where a save from a stale tab or editor silently overwrote newer store-backed artifact content. The root cause is solved: PATCH /api/artifacts/{slug} now takes an optional expected_token, and ArtifactStore.update() compares it under the store lock, using hmac.compare_digest, against a random 256-bit content_token kept in meta.json. A mismatch raises ArtifactConflictError, which the handler turns into a 409 that names current_token. I read the full production diff. The token is rotated before current.html is rewritten, so a partial write can cause a false 409 but never admit a stale save. File-backed live pointers and versioned reads carry no token. The token is only serialized beside current content. Callers that send no token (MCP, revert) keep last-write-wins, so nothing regresses. On the page, only the explicit relabelled Save button sends the overwrite token, saves that are already in flight are skipped, and an edit-generation guard stops a late completion from touching another editor's state. The new 409/400/token tests in test/test_artifacts.py, test/test_artifacts_handlers.py and ArtifactDetailPage.saveConflict.test.tsx would fail on base. All checks are green on head df55b83, GPT/Design/First Principles show PASS or no findings, and every UX CONCERNS item on this head has an evidence-backed disposition. One non-blocking nit from the Opus lane (ArtifactDetailPage.tsx:~2003): the version selector leaves edit mode without calling setSaveConflict(false), so a later unrelated error can show under the conflict title. A one-line follow-up can fix it. — crew-pr-reviewer
|
Problem / Motivation
Goal: Stop a save from a stale editor silently overwriting newer artifact content; refuse it with a 409 and keep the draft.
Two editors on the same artifact silently overwrite each other. Saving from a stale dashboard tab, or a user saving over an agent's newer edit, replaces the live content with no warning, because
PATCH /api/artifacts/{slug}writes unconditionally (#7751).Why it matters
The person whose work is lost never finds out. Silent saves don't bump
version, so nothing in the UI shows the overwrite happened.Not a goal
source_path(File-backed artifacts have no stale-write guard against external source edits #14039, needs a maintainer decision).current.htmloutside the store, such as a hand edit or a restored backup. Such a change does not move the token.What changed (motivation → approach → change)
A save now carries the content token it started from. If another save landed since, the save is refused with a 409 and the draft is kept.
src/kiro_crew/artifacts.py,artifact_store/model.py,artifact_store/records.py)content_tokenstored inmeta.json.update(expected_token=)compares it under the store lock before writing and raisesArtifactConflictErroron a mismatch.dashboard/handlers/artifacts.py)409 {error, code: "artifact_conflict", current_token}. A malformed token returns 400. The detail read gives an artifact saved before this change its token, and it runs off the event loop, as do the events and delete reads.ArtifactDetailPage.tsx,api/client/artifacts.ts,types/index.ts)website/src/i18nlocale catalog. The PATCH row indocs/system-specs/modules/artifacts.mddocuments the token.The token is 256 random bits, replaced on every content write. Nothing in it comes from the content, so a copy of
meta.jsonreveals nothing about text the HTTP layer redacts. The new token is saved before the new content, so a save that fails between the two files can cause a false 409 but cannot let a stale save through. An artifact saved before this change gets a token when the dashboard opens it. If that write fails, the read returns the content without a token, and that tab's next save is last-write-wins. Every other read returns the stored token, or none, and writes nothing. A malformed stored token is replaced, with a warning, instead of making the artifact unreadable.Omitting the token keeps today's last-write-wins behavior, so MCP, revert and other callers are unchanged. File-backed artifacts get no token and ignore one. Guarding their source files needs a maintainer decision, tracked in #14039.
Backwards compatibility
None. The token is optional, and a client that ignores it behaves as before.
Tests
test/test_artifacts.py: matching, stale and omitted tokens; metadata-only, snapshot-only and silent saves; a fresh token from every content writer, identical content included; the token persisted and served only beside current content, and a missing or corrupt one replaced rather than fatal; the dashboard's read giving an untokened artifact a token while a plain read writes nothing; a token-assigning read whose write fails returning the content with no token, and the next one getting a working one; a save or a draft settle that fails after its content write still refusing the stale token; tokens surviving a new store instance; file-backed artifacts and versioned reads carrying no token.test/test_artifacts_handlers.py: the 409 body and code, 400 on a malformed token, a matching token saving and returning the next one, the detail response carrying the stored token and giving an untokened artifact one, and the detail, events and delete handlers reading off the event loop. The token tests in both files draw tokens from a counter, so no comparison depends on chance.test/test_artifacts_refactor_{store,projection}_contract.py: the surface pins listcontent_tokeninmeta.jsonand on a current read, and theArtifactConflictErrorexport.website/src/test/ArtifactDetailPage.saveConflict.test.tsx: the token is sent, a 409 keeps the draft and shows the notice, the overwrite sends the fresh token, and after a 409 Snapshot, Cmd+S, Cmd+Shift+S and a banner pull all keep the base token, with the pull showing only the notice. A save repeated while one is in flight, or made during a banner flush, sends no second write, and the banner is disabled during a save. A save on one artifact that finishes after the page moved to another, whether it succeeded or got a 409, leaves the new editor's token and notice alone. Each fails with the guard it covers removed.Manual verification
Run on a private local gateway against
e6b98a3484, a commit of this PR whose token was an HMAC of the content instead of a stored random value. The API, the responses and the page are the same on this head. An artifact saved before content tokens existed opened normally and was guarded from its first read. With a draft open in one tab, a second tab saved a newer version; the first tab's save was then refused with the notice shown, the draft stayed, Save changed to the overwrite action, and the server still held the second tab's content. The stored token itself and the skipped repeat save are covered by the tests above.Screenshots / video
The second is from an isolated capture of the real page with the API stubbed, since a stock gateway has no publish provider to show the fork banner.
Committed under
temp-screenshots/(fork PR, no--attach).Related Issues
Store-backed half of #7751. The file-backed case (external writes to
source_path) moves to #14039, which needs a maintainer decision. This replaces the core of #7818.Fixes #7751
Pattern harvest
Rule candidate: review-prompt
Pattern: a read-modify-write endpoint with no base token (last write wins across windows and actors)
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)