Skip to content

fix(artifacts): optimistic-concurrency token for content PATCH (409 on stale write) - #7818

Closed
peterhieuvu wants to merge 1 commit into
kirodotdev:mainfrom
peterhieuvu:fix/artifact-patch-conflict-token
Closed

peterhieuvu wants to merge 1 commit into
kirodotdev:mainfrom
peterhieuvu:fix/artifact-patch-conflict-token

Conversation

@peterhieuvu

@peterhieuvu peterhieuvu commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

PATCH /api/artifacts/{slug} has no stale-write protection: api_artifact_update passes body["content"] straight into ArtifactStore.update(), which writes unconditionally. Last write wins. Two dashboard windows open on the same artifact silently clobber each other today; a user's stale buffer silently overwrites an agent's iteration; and for file-backed artifacts, an external write to source_path is invisible to an editor holding a stale buffer. The frontend artifactEditGuard is page-local and does nothing across windows or surfaces.

Neither existing field can detect a stale base: version is not bumped by silent saves (snapshot: false, the dashboard default), so two different live states can share a version number; updated_at is bumped by metadata-only renames/retags, so it false-positives on non-content changes.

Why it matters

This is the same stale-snapshot-clobber class already recognized on the agent-config PUT surface (#7470, #7089) — the artifacts PATCH instance of it. The blast radius is user data: the overwritten content is someone's live edit. It gets worse as write frequency rises — any client implementing debounced autosave of live state multiplies the race windows. The store itself already treats this as a real problem for remote pushes (PublicationMetadata.last_pushed_sha256, sent as expectedCurrentSha256, is described in source as "the optimistic-concurrency guard"); local writes had no equivalent.

What changed (motivation → approach → change)

Symptom → root cause: unconditional content writes with no way for a caller to say "only if nothing changed since I read." Approach: opt-in optimistic concurrency mirroring the store's own remote-push design, with the compare inside the store lock (a handler-level compare would be TOCTOU-racy against concurrent store writers).

  • ArtifactStore.update() gains optional expected_token. When provided with content, live content is read exactly the way get() reads (source file for file-backed artifacts, current.html otherwise), digested, minted into the token and compared (constant-time) under self._lock before any mutation. Mismatch raises the new ArtifactConflictError, which carries current_token + version.
  • The wire token is opaque. content_token is HMAC-SHA256 over salt:digest under a 32-byte key the store loads at construction from <root>/.token_key (0600; creation serialized across processes by a lock file and published by rename, so racing processes share one whole key; a malformed key file is refused rather than silently replaced, since reissuing the key would invalidate every token in flight; the read is bounded to one byte past the key length before the exact-length check, so an oversized file planted at that path is refused without being read into memory at warm-up). The salt is a per-artifact random value (content_salt, persisted in meta.json, never sent to a client; on load it is accepted only as the empty legacy value or exactly 32 lowercase hex characters, anything else refused as a malformed meta.json rather than reaching the HMAC's ASCII encode as a 500) rotated on every store-mediated content write — without it the token would be a function of content alone, and a reader who can also write could mint a comparison token for a guessed secret by saving the guess somewhere; every save lands under a fresh salt instead, and no API mints under an old one. An external edit to a file-backed source rotates nothing and moves the digest, so the guard still trips on it; a snapshot re-reads the same content and keeps the salt, so it never 409s an editor holding a token against unchanged content. Historical reads (GET …?version=N) carry no token at all: a version is never an editing base, and minting one would let a writer snapshot a guess and compare its version token with the hidden version's under the same salt. Every store-mediated content write rotates the salt — create, a content update, settling a blank's draft, and image creation — and an artifact written before the field existed is minted under a domain derived from its slug, so two pre-upgrade artifacts never share one. The default store is built post-bind on a worker thread (_kick_artifact_store, the same shape as the other post-bind kicks — never an on_startup hook, which would put its filesystem work in front of the listener), and a coroutine that needs the store before that warm-up has finished goes through get_default_store_async: the cached instance is a plain attribute read (no I/O, no thread hop); an unbuilt one is constructed on a worker thread, never on the loop. Every get_default_store() call inside a coroutine anywhere in the package uses that accessor or resolves the store inside the worker callable (a package-wide source-scan test pins it; the deploy teardown handler was binding get_default_store().get on the loop before handing it to the thread), each module forwarding its own getter name so a test that substitutes it keeps the substitute. Auto Research constructs its store inside the worker thread it already writes from. The HTTP serializer redacts credentials out of content after the token is computed, and the codebase's own rule for redacted path labels (security/redaction.py, keyed HMAC) applies: an unkeyed hash beside redacted text would let a reader test low-entropy guesses for the redacted secret offline. The raw SHA-256 never leaves the store — it is used only where both sides are the store itself (the file compare-and-swap's base hash). The key is persisted rather than per-process so a token taken before a gateway restart still validates after it; losing the file costs one 409 per open editor and protects nothing at rest.
  • File-backed artifacts get a second layer: the store lock only excludes store-mediated writers, so an external process can rewrite source_path between the compare and the mirror. For guarded writes the source mirror is a descriptor-pinned compare-and-swap through the existing verified_replace_file_nolink primitive (base_hash= the raw digest the client's token was minted from, max_bytes=MAX_CONTENT_BYTES); conflict/too_large abort before current.html or metadata are touched. _try_write_source_path now returns the verdict string instead of a bool; all call sites updated. Unguarded writes keep today's last-write-wins + demotion-to-source_copy_only semantics exactly.
  • Inside that primitive, the pre-staging identity re-check (the validated inode is not what the name resolves to) now answers conflict to a verifying caller instead of refused. The predicate cannot tell a hostile ancestor swap from an editor's own atomic save (both install a new inode under the same name); for the verifying caller refused means "unwritable, no competing writer" and is answered by keeping the stale edit and demoting the link — so a swap in that window was reported as applied instead of 409ing. The post-staging twin of the check already made this split; the audit WARNING is unchanged for both. The prompts PUT handler shares this primitive and gains the same correction: a pre-staging swap now reaches it as its existing content_conflict 409 rather than "write refused".
  • The handler maps ArtifactConflictError → 409 with {error, current_token, version} so the client can refetch and re-base; a token that is not the 64-hex shape this store mints (non-string, wrong length, non-ASCII — which the constant-time compare would refuse by raising) is a 400 at the handler and a validation error at the store, never a 500 and never a phantom conflict.
  • Every Artifact the store hands out with content is stamped with content_token (get, create, update), and to_dict emits it whenever content is included — minted from the raw content before the HTTP serializer's redaction pass, because the guard digests the raw bytes on disk; a snapshot-only update that read its content off the source file stamps the raw bytes it read, as get does, so a source that is not valid UTF-8 hands back a token a later save can match. The list path serializes without content and pays nothing; meta.json never carries it.
  • ArtifactDetailPage adopts the token: handleSave sends expected_token from its last fetch, and so does the buffer flush that precedes the sync banner's Pull / Overwrite / Snapshot — a 409 there keeps the buffer, raises the same notice, and aborts the sync action instead of pushing the stale buffer over the newer content — and does not rebase the held token, so a retried sync action 409s and aborts again; only the labelled Save can overwrite. A 409 renders as a "changed since you loaded it" notice that preserves the buffer (editedContent untouched, editing stays true) and refetches so the next save carries the fresh token — a deliberate overwrite instead of a silent one. New i18n key in all 13 catalogs (en-XA regenerated).

Token omitted = today's behavior; zero existing callers change (MCP, revert, pull/publish, blank-settlement all send no token).

Review-round hardening:

  • The client token is captured at edit start and held for the edit session (a background refetch mid-edit can no longer authenticate a stale buffer); it moves only via a successful save's response or a 409's body.
  • For a live file-backed read the token is minted from the raw-byte digest of the source, and the guard, the mirror's compare-and-swap base and the 409 body all derive from that one digest. It equals the text digest wherever the bytes are valid UTF-8 (every store-written file), so a client that re-reads gets the same token either way — but an external edit confined to malformed UTF-8, invisible after the lossy decode, still moves the token and 409s, and a source with non-UTF-8 bytes saves cleanly instead of 409ing forever.
  • The 409 banner has its own title ("Save refused — content changed") and a "View the newer content" link that opens the live version in a popout without leaving the edit buffer.
  • While that banner is up, the Save button reads "Save — overwrite newer content" (title spells out why): the 409 armed a separate overwrite token that only this labelled Save consumes, so the same button now performs the overwrite, and a reflex second Cmd+S must read as the overwrite it is. The token the buffer was opened against is never rebased: the pre-sync flush and Snapshot keep sending it, so retrying Pull / Overwrite / Snapshot after the banner 409s again and aborts again rather than becoming an unlabelled overwrite. While the conflict is armed the Snapshot button is disabled (Cmd+Shift+S is a no-op) with a title saying only Save overwrites — otherwise each attempt would 409, drop and re-arm the same banner, an unexplained loop, and the notice's "saving again will overwrite" would be untrue of it. Only a distinct second action gets there: the shortcut ignores key-repeat (a held Cmd+S auto-repeats keydown, and the repeat would otherwise be the overwrite of content the user has not seen), and a save entering while one is in flight is dropped rather than run against whatever token the first one leaves behind. The conflict notice is its own state, shown only while editing: a metadata action (tag, pin, kind, rename) leaves it standing, and any edit-ending path retires it with the draft.
  • Off the event loop: the store's write path now stages through pinned directory syscalls, so the two store callers that still ran on the loop — api_artifacts_create in the artifacts handler and the auto-research report export (_handle_to_artifact) — go through _run_off_loop / asyncio.to_thread like every other store call; every remaining store.create/update caller (publish_sync, deploy/handlers, widget_artifacts) was already offloaded. The read/delete sites this diff touched to resolve the store asynchronously — the delete handler's pre-delete capture and delete, list_versions, the version and event reads, record_impression, and relocate's allowed_source_roots (it resolves paths and loads config) — go through _run_off_loop too. Thread-witness tests cover every one.
  • Declared behavior change: event_type validation moved to the top of store.update() (before any side effect), so an invalid event_type on a non-snapshot save is now a 400 instead of being silently accepted — previously it could also raise mid-write and leave a save partially applied.

Guarded save ordering (file-backed artifacts). A guarded save touches two files with no transaction spanning them, so the order is chosen to make every failure either side-effect-free or recoverable: (1) the store's own copy is staged beside current.html without being installed; (2) the source file is written as a compare-and-swap against the raw-byte hash the guard captured; (3) the staged copy is installed with one atomic rename. Consequences, all deliberate:

  • The source is written at most once (the CAS install) and never by any compensation path, so a failed save cannot alter source bytes — a non-UTF-8 source is never re-encoded through the lossy decode.
  • A lost CAS (conflict) discards the staged copy and answers 409 with nothing applied; there is no restore write that could itself fail.
  • A refused mirror (read-only file, foreign owner, path outside its authorizing root — no competing writer) installs the store copy and demotes the artifact to source_copy_only, visibly, instead of stranding the client in a permanent 409 loop. too_large demotes the same way: a source over MAX_CONTENT_BYTES is served truncated, so the client's token and the guard's read agree with each other but can never match the file — a 409 would hand back the token the client already holds, a loop no rebase can exit. The oversize source is never written (a write would truncate it). If the install then fails, the stage is discarded with the error — a refused mirror wrote nothing, so there is no committed intent to recover and the caller sees the save fail.
  • If the install fails (or the process dies) after the CAS committed, the staged copy is retained as the durable record of that commit. Reads are unaffected meanwhile (a live pointer serves the source; live_dirty flags the un-snapshotted state), and the next update() on the slug reconciles it under the store lock before doing anything else: source bytes equal to the staged content → the install is completed; a readable source that differs → the stage name carries a 16-hex prefix of the source hash the CAS compared against, so recovery can tell the two causes apart: a source still at that base means the commit never landed and the leftover is discarded; a source that has moved off both the staged content and its base may have been edited externally after the commit landed, so the leftover is retained (one WARNING per pass) rather than deleting the only copy of that edit; a hint-less staging-named entry (nothing the guarded save writes) or a store-only artifact → discarded; a source that cannot be read right now → retained until it can be judged. The exception: when the source is unreadable AND the update is itself about to write current.html, the newest leftover is installed first — otherwise that write's unreadable-source fallback would install over it and demote the pointer, and the next pass would discard the only copy of a committed edit. The stale save then 409s onto the pending content (a real rebase target) instead. An install by recovery is booked as the content change it is, and booked before anything else the triggering update does: comment anchors are re-validated against the recovered text under the lock, and upsert is owed from that moment and fired after the lock is released on every exit — the normal one, a token conflict, a validation error — because the install consumes the stage and nothing would remain to trigger a second pass. The version bump of a snapshot save is the one thing recovery does not reconstruct; that state stays visibly un-snapshotted until the next snapshot.

Staging is descriptor-pinned end to end. The store directory is pinned component-by-component (pinned_fs.pin_parent, one O_NOFOLLOW openat per component), the staging file is created through that descriptor with an unpredictable name and O_CREAT|O_EXCL|O_NOFOLLOW, and the descriptor stays open until the stage ends: the install renames and the discard unlinks through it by basename, and an ended stage is inert. After staging, no operation on the stage ever re-resolves a pathname, so a directory renamed, replaced, or swapped for a symlink cannot receive the install, hide the stage from cleanup, or expose a same-named bystander to a by-name unlink. Where dir-fd syscalls are absent (Windows) the stage is created with tempfile.mkstemp and handled by name. The store's pre-existing _write_text goes through the same pair, so the class is closed store-wide. The sensitive-path check runs before any directory is created, so a refused target leaves no trace. The staged-copy recovery scan is pinned the same way: the artifact directory is opened once (open_dir_pinned, its own name never followed), and enumeration, reads, unlinks and the reinstall all go through that descriptor. Where dir-fd syscalls are absent (Windows) the scan does not run at all — a leftover is retained rather than judged, because unlinking or installing by pathname would follow a swapped ancestor (a junction) into a directory the scan never inspected; retaining deletes nothing.

The install is a true compare-and-swap where the platform allows. Verifying the source's bytes through a pinned descriptor and then installing with rename() leaves the window POSIX itself carries — no conditional rename — in which an external tool's atomic save lands between the last check and the install and is silently replaced. For a verifying caller the write gate now installs by atomic exchange (renameat2(RENAME_EXCHANGE) on Linux, renameatx_np(RENAME_SWAP) on macOS, via the same native seam platform_compat already used for RENAME_NOREPLACE): the inode that was displaced is moved into the staging name instead of destroyed, inspected against the verified inode (held open through the exchange, so its number cannot be recycled) and the post-hash (st_mtime_ns, st_size), and — because an equal-length in-place rewrite with a restored timestamp leaves both identical — its bytes are re-hashed through that held descriptor and must still match the verified base; on any mismatch it is exchanged straight back with the verdict conflict. The newer file is never gone, not even for the duration of the check. A filesystem that answers ENOSYS/EINVAL/EOPNOTSUPP to the exchange (some network mounts) or refuses the first exchange with any other OSError (nothing has moved), and a platform without it (Windows; a glibc without the renameat2 wrapper reaches the syscall directly), keep the plain-rename install with the residual window it has always had — and the caller keeps its own snapshot, so the safe direction is preserved there. The one failure the protocol refuses to clean up is an exchange-back that itself fails: without the exchange no rename is conditional, so nothing further is renamed — the newer content stays under the staging name (never unlinked), the stale payload stays at the original name, the state is logged at ERROR with both names, and the caller still answers conflict so the client refetches rather than trusting its save. A restore-by-plain-rename was tried and rejected: any rename in that state is unconditional and would overwrite a further writer landing on the name. The exchange-back that succeeds is checked too: a writer who replaces the original name between the conflict check and the exchange-back is what that exchange moves under the staging name (its own replace already unlinked the payload), so the stage is compared by identity against the payload's descriptor — held open (readable) through the install, so its inode number cannot be recycled — and its bytes re-hashed through that descriptor against the payload's hash (an in-place rewrite of the payload while it sat at the original name keeps the identity and changes the bytes), before the spent-stage unlink is authorised. If the stage is not the payload, one more exchange puts that later save back at the original name, the content it displaced stays under the staging name, nothing is unlinked, and the state is logged at ERROR with both names. One window stays open by construction and is documented rather than closed: a writer that opens the payload inode for writing during the instants it holds the original name, and writes only after the spent stage is unlinked, writes into an orphaned inode — the same loss every atomic-replace save (including the pre-PR plain rename()) has always inflicted on an in-place writer racing it; POSIX exposes no other process's descriptors, and the only closure (never unlinking the stage after a conflict) would leave a .tmp beside the source on every 409.

Out of scope, deliberately. The refused-mirror path installs the store copy and then persists the demotion as two steps; a crash between them leaves reads serving the old source until the next save — a two-file crash-window class that is recoverable, visible, and not a data-loss path (nothing is deleted, and the store copy holds the edit).

Tests

Store (test/test_artifacts.py, TestConflictToken): matching token writes; stale token raises with recovery fields and writes nothing; omitted token keeps last-write-wins; token ignored on metadata-only updates; a silent save trips a stale token despite an unchanged version number (the reason the token is a hash, not the version); an external source-file edit trips the guard; an external edit confined to malformed UTF-8 bytes still trips it (raw-byte token) and the refetched token converges; the token follows the text for valid UTF-8 and store-only artifacts; the token is opaque (64 hex, not the SHA-256 of the content, stable per content, distinct per content); the key is persisted (a second store on the same root mints the same token and accepts it, a different root mints a different one, the key file is 32 bytes at 0600, meta.json carries the salt but never the token); a malformed or symlinked key file is refused at construction, not silently replaced (the link check is an lstat, so it holds on Windows where O_NOFOLLOW does not exist); an oversized key file (33 bytes and 16 MiB) is refused with a single bounded read (the requested size is recorded; the old unbounded read fails the test); a malformed expected_token on a content write is a validation error, not a conflict or a crash; a writer cannot mint a comparison token for a guess (a probe artifact with the same content, and an overwrite of the target itself, both land under a fresh salt; the token read before the write is stale; an external edit still trips the guard); a snapshot keeps the token domain; a snapshot-only save of a file-backed artifact with malformed UTF-8 bytes returns the same raw-byte token get mints and a save re-based on it proceeds (the old text-stamped token fails the test); a legacy meta.json without a salt tokenizes and gains one on its first write; a persisted salt that is non-ASCII or non-hex is refused as a malformed meta.json (the old code raised UnicodeEncodeError from the HMAC encode); historical reads carry no token while the current read does; settling a blank and creating an image rotate the domain; two legacy artifacts get distinct domains; the post-bind kick constructs the default store on a worker thread and both gateway entrypoints kick it after the bind; the async accessor constructs an unbuilt store on a worker thread, returns a built one without a thread hop, honours a replaced module getter, and no coroutine anywhere in the package calls the synchronous getter (package-wide source scan, 41 sites on the prior code); Auto Research constructs its store on the worker thread; a source write racing in between the compare and the mirror answers conflict instead of clobbering (CAS layer); unguarded mirrors still last-write-wins; to_dict carries/omits the token correctly. Existing _try_write_source_path tests updated to the verdict-string contract.

Store (test/test_artifacts.py, TestPersistence): staging never writes through a planted sibling; the install never follows a symlink swapped in after staging; a symlinked target is refused; a parent swapped for a symlink after resolution is refused at staging; an install lands in the directory the stage was created in even after that directory is swapped away; a discard reaches a stage whose directory was swapped; the recovery scan acts only on the directory it opened (a swapped-in link's target receives neither the unlink nor the reinstall); an ended stage is never re-addressed by pathname (a same-named bystander in a swapped-in directory survives); no descriptor leaks across every lifecycle ending; a failed install after a committed CAS recovers on the next update; an unreadable source retains the leftover; a pending leftover is installed ahead of a write while the source is unreadable, and the newest wins when several are undecidable; a refused mirror plus a failed install leaves nothing to recover; an install by recovery on a metadata-only update fires upsert and re-validates comment anchors (a plain metadata-only update still fires nothing); the same booking holds when the triggering update is itself a stale-token conflict — the stage is consumed, the anchors are rescanned, and exactly one upsert fires after the lock is released (the listener re-enters the store to prove it); both fail against the prior code; oversize / non-UTF-8 / planted-symlink staging lookalikes are removed. Every recovery test runs on both platform paths (a fixture parametrizes over the pinned scan and, by forcing _store_dir_fd_ok() false, the no-dir-fd path): the pinned leg keeps its assertions unchanged, the other asserts the documented retention — leftover untouched, current.html unchanged, no upsert, anchors not rescanned — so no platform skips the file. TestSourcePathSecurityHardening: a sensitive target is refused before any directory is created; an oversize source demotes on the guarded path instead of looping on 409, and the source is never written.

Write gate (test/test_hooks_coverage.py): an external atomic replace landing between hash-verify and staging answers conflict to a verifying caller (and stays refused for the unverified one), with no staging residue; an external atomic replace landing after the last-moment stat — the window rename() cannot close — answers conflict and the newer file wins (injected at the stat itself, so the test fails against a plain-rename install); the exchange disposes of the displaced verified inode on the happy path; an unlink-and-recreate with preserved size and mtime answers conflict (the verified inode is held open at exchange time, witnessed via /proc/self/fd); an equal-length in-place rewrite with a restored timestamp answers conflict (re-hash through the held descriptor); a filesystem without exchange falls back to the plain rename; a failed exchange-back preserves both files, attempts no further rename, and logs at ERROR; a third writer landing during a failed exchange-back is never touched; a third writer landing before a successful exchange-back is exchanged back to the original name and never unlinked (fails against the prior code, which unlinked it as the payload); an in-place rewrite of the payload at the original name before the exchange-back (same inode, different bytes) is likewise exchanged back and never unlinked (fails against an identity-only check); when that restoring exchange itself fails, both saves are preserved.

Handler (test/test_artifacts_handlers.py): stale token → 409 with current_token/version and content unchanged; matching token saves and returns the fresh token; malformed token → 400 not 409; detail response includes content_token; the wire token is neither the hash of the raw nor of the redacted content and no content_sha256 is emitted, yet it round-trips as the save token.

Component (website/src/test/ArtifactDetailPage.saveConflict.test.tsx, new — with a controlled Pierre editor stub so a buffer re-seed regression fails visibly): Save sends the token; a sync action's buffer flush sends it too and a 409 there aborts the action with the buffer intact (exactly one PATCH, the guarded flush); a retried sync action after the 409 sends the original token again and aborts again, and only the labelled Save then sends the 409's token (fails on the prior code, which rebased on the flush); after a 409, Cmd+Shift+S and the Snapshot button make no request and leave the banner alone (button disabled, title names Save as the one overwrite path), and plain Save then sends the 409's token (fails on the prior code: a second PATCH); 409 shows the conflict notice, relabels Save as the overwrite it now is, keeps the buffer, and refetches; a metadata edit after the 409 keeps the notice, its action and the label; non-409 errors keep the generic error path; a held Cmd+S never saves on its key-repeat after the 409 rebase (one PATCH, banner still up); a second save entering while one is in flight is dropped (one PATCH) — both fail against the prior handler.

Manual verification

Live two-writer race in an isolated pod: opened the artifact, dirtied the editor, issued a silent save from "another window" via the API, clicked Save → 409 banner with the buffer intact; clicked Save again → informed overwrite applied with the fresh token. Screenshots below are from a re-run of that race in an isolated instance of this worktree at 3f86d36 (same patch as the current head; the rebase since only adopted the store fence from #12514).

Screenshots / video

Stale save refused — banner, buffer preserved, Save still armed:

409 conflict banner with preserved draft

"View the newer content" opens the live version in a popout without leaving the edit buffer

view newer content popout

Sync-action abort state — the pre-sync flush before Snapshot is refused with 409: the sync banner shows the inline "Save refused — content changed" beside its action, the edit bar carries the conflict notice, the draft is kept, Save is relabelled as the overwrite, and Snapshot is disabled (its title says only Save overwrites). Captured through the real ArtifactDetailPage in the repo's capture-harness pattern (website/capture/artifact-sync-conflict.* + website/scripts/capture-artifact-sync-conflict.mjs, which asserts every one of those properties and that exactly one PATCH — the refused flush — was made before shooting), because the sync banner renders only with a registered publish provider, which a live gateway here cannot supply:

sync action aborted on 409, dark

Same state, light theme

sync action aborted on 409, light

Related Issues

Fixes #7751

Pattern harvest

Rule candidate: review-prompt
Pattern: "content-write endpoint accepts no base token — concurrent writers silently clobber (compare against #7470/#7089 class); a compare outside the writer's own lock, or a mirror to an externally-writable file without CAS, reopens the same hole"

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) — the PATCH /api/artifacts/{slug} row in docs/system-specs/modules/artifacts.md updated with the token, the 409 body, the 400 on a malformed token, and the opaque content_token (with the persisted key) on content-carrying responses
  • No secrets, credentials, or internal references in the diff

@peterhieuvu
peterhieuvu requested review from a team and hoang-phan98 September 2, 2026 06:45
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 2, 2026
@peterhieuvu

Copy link
Copy Markdown
Contributor Author

CI status note: the only red is Coverage Combine → "Upload combined coverage", which failed with a GitHub artifact-service error, not a test failure:

##[error]Failed to FinalizeArtifact: Received non-retryable error: Failed request: (403) Forbidden: Error from intermediary with HTTP status code 403 "Forbidden"

All test lanes on the run are green (backend, frontend, lint, build); Coverage Gate then fails closed because coverage-combine != success, which takes PR Readiness with it and holds back the AI review lanes (they trigger on CI success).

Could a maintainer re-run the failed jobs on run 33600280562? I'm holding off pushing anything — the diff is unchanged and a push would only re-arm the fork approval gate for the whole suite, which is more maintainer work than a re-run click.

@peterhieuvu
peterhieuvu force-pushed the fix/artifact-patch-conflict-token branch from 37db268 to 02a001e Compare September 2, 2026 08:09
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of b29c6ae3ccef5cb38da7be7478be9da3597a6d4c via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify the exchange install on real macOS (renameatx_np RENAME_SWAP): CI covers only the Linux and fallback legs; misbehavior degrades safely but silently.

[DESIGN-REVIEWED] b29c6ae

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — 🔴 changes requested (blocking)

Reviewed b29c6ae3ccef5cb38da7be7478be9da3597a6d4c via the fork AI-review pipeline; updated in place on each push.

1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

BLOCKING -- src/kiro_crew/hooks.py:3958 -- Verified writes fall back to an unconditional rename

# None: no exchange on this filesystem after all; fall through to
NFS/SMB/FUSE without exchange + external save after final stat -> plain rename overwrites newer content and reports success.
Anchor: residual/crash-data-loss-corruption
Fix: In verified mode, return conflict when exchange is unavailable; never use plain rename.
[BLOCK-MERGE] b29c6ae
[GPT-REVIEWED] b29c6ae

Adjudication (Opus 5) — is blocking on each finding proportionate?

Harm rung: HIGH-to-unbounded in kind (silent loss of an external editor's save, no backup) but bounded in reach — conditions confirmed: verifying caller only (base_hash path, patch artifacts.py hunk at _try_write_source_path, and dashboard/handlers/prompts.py:1966); held_fd armed only when use_dir_fd and RENAME_EXCHANGE_AVAILABLE (patch hunk at hooks.py:3711, availability resolved at platform_compat.py:314-339, None on Windows so the path is byte-identical to base); and the exchange must then raise at runtime (patch _install_by_exchange except (NotImplementedError, OSError): return None, new rename_exchange ENOSYS/EINVAL/EOPNOTSUPP mapping).
Recovery path: none — _pinned_replace returns "ok" (hooks.py:3698 on disk) and the caller reports success; the displaced bytes are unlinked with no copy kept.
Real-fix cost: conflict whenever exchange is unavailable turns every verified source write-back on Windows and on any NFS/SMB/FUSE mount into a permanent failure — the residual it would remove is the pre-existing plain-rename window already documented at hooks.py:3658-3662, which this PR narrows rather than creates (it widens it only by the two failed-exchange syscalls on a mount that advertises then refuses exchange).

[ADJUDICATION] b29c6ae3ccef5cb38da7be7478be9da3597a6d4c total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] b29c6ae3ccef5cb38da7be7478be9da3597a6d4c
[ADJUDICATION-FENCED] b29c6ae3ccef5cb38da7be7478be9da3597a6d4c fenced=1 flagged=1
FLAG F1 src/kiro_crew/hooks.py:3958 -- The loss needs a 2-4 syscall TOCTOU between the last-moment stat and the rename on a filesystem with no exchange, which is the pre-existing base behavior this PR narrows (identical on Windows, where `RENAME_EXCHANGE_AVAILABLE` is False), and the demanded remedy would make verified source write-back permanently impossible on Windows and every network mount.
[GPT-ADJUDICATED-FENCED] b29c6ae3ccef5cb38da7be7478be9da3597a6d4c

🏷️ Fenced finding(s) machine-flagged as likely edge case

The security fence keeps these findings blocking regardless of adjudication; the only clearance path is a human override recorded by a repository writer, who must independently verify a rationale before recording it — it is machine-authored, and a wrong override on a security-class finding ships exactly the class the fence exists to stop. (This lane's comment deliberately carries no override command.)

  • F1 src/kiro_crew/hooks.py:3958 — The loss needs a 2-4 syscall TOCTOU between the last-moment stat and the rename on a filesystem with no exchange, which is the pre-existing base behavior this PR narrows (identical on Windows, where RENAME_EXCHANGE_AVAILABLE is False), and the demanded remedy would make verified source write-back permanently impossible on Windows and every network mount.

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

Premise-level review of b29c6ae3ccef5cb38da7be7478be9da3597a6d4c via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The staged-copy recovery scan (~250 lines plus a pinned scan on every update) guards a loss the store's last-write-wins contract already accepts; discard failed stages instead.

Not justified as shipped

  • Item 6 — oversized: _recover_staged_store_copy + _StoreDirHandle adjudicate crash leftovers ("may be the only copy of a committed edit"), but the source file already holds the committed edit and reads prefer the source; the retained/installed cases protect content only against an external overwrite, which unguarded semantics let win everywhere else.
    Subtraction: delete _recover_staged_store_copy, _StoreDirHandle and the base_hint name-suffix plumbing; on a failed _install_staged after an "ok" CAS, discard the stage and keep the WARNING.
    Clears when: a named sequence where discarding the stage loses content that plain last-write-wins would have kept.
  • Item 7 — rides along, one consumer generalized: get_default_store_async(getter=…) — all 3 runtime wrappers (dashboard/handlers/artifacts.py, dashboard/handlers/knowledge.py, publish_sync.py; grepped the patch's call sites) pass the identical imported get_default_store; only test monkeypatching differs, and tests are not consumers.
    Subtraction: drop the getter parameter; call get_default_store_async().
    Clears when: a runtime caller passing a different getter exists, or the parameter is deleted.

What this change ships

Inventory (10 items) — 5 justified

Intent: refuse an artifact save based on outdated content (409 + rebase token) instead of silently overwriting another writer — an ADDITION of an opt-in guard, titled fix; the defect class it targets is on record (#7470/#7089 appear in base tests/specs). Capped at 10: the rename_exchange primitive folds into item 4, the async accessor into item 7.

  1. A save may send the token of what it read; a stale save answers 409 with a rebase token — justified
  2. Content reads return content_token; the store persists a .token_key file and per-artifact salt — justified
  3. Conflict UX: Save relabelled as overwrite, Snapshot disabled, banner with "View the newer content" — justified
  4. Guarded file-backed saves compare-and-swap the source file by atomic rename-exchange — justified
  5. Prompts PUT: a pre-staging swap now surfaces as its 409, not "write refused" — rides along (shared-primitive correction; the deleted pin's SEL-audit rationale is preserved verbatim)
  6. Every update scans for and adjudicates crash-orphaned staged copies — oversized (see above)
  7. Store built post-bind in background; store calls across publish/knowledge/research/comments moved off-loop — rides along (see above)
  8. Invalid event_type rejected before any write instead of mid-save — rides along (required by the new write ordering)
  9. Holding Cmd+S no longer repeat-saves — rides along (repeat would consume the armed overwrite)
  10. Conflict strings in 14 locales; a capture page/script for the abort state (365 sibling captures) — justified

[FIRST-PRINCIPLES-REVIEWED] b29c6ae

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — 🟡 CONCERNS

UX-level review of b29c6ae3ccef5cb38da7be7478be9da3597a6d4c via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: CONCERNS

A reflex second Cmd+S or double-click after the 409 is an irreversible overwrite of content the user never saw — only a relabel stands in the way.

Watch

  • Overwrite friction is label-only: the 409 instantly arms the same button/chord ("Save — overwrite newer content", attachment-01); a user re-pressing Cmd+S out of habit (a new press, not the guarded key-repeat) overwrites without reading. Low frequency × high impact (another writer's work lost) × every conflict. Smallest fix: briefly disarm Save (~1s) or require a fresh click after the relabel.
  • The overwritten "newer content" has no recovery path: a silent save is unversioned, so consuming the overwrite token permanently discards the other writer's edit. Fix: checkpoint the displaced live content as a version before applying the overwrite (the page already has the "saved as a version first, so nothing is lost" pattern).
  • Snapshot's disabled reason lives only in a title on a disabled button (no hover tooltip in some browsers, never reaches keyboard/AT), and Cmd+Shift+S after a conflict no-ops with zero feedback — a user sees Snapshot inert with no visible why beyond the banner.
  • No first-time reader has seen these controls (fork lane); a maintainer wanting the blind read can push the branch to this repo.

Suggestions

  • In the sync banner (attachments 03/04), "Save refused — content changed" answers a click on "Snapshot to publish" with a verb the user never used; prefer e.g. "Not published — content changed since you loaded it".

[UX-REVIEWED] b29c6ae

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

Reviewed 118203c9521e130a56035638396738c7688ad2ea via the fork AI-review pipeline; updated in place on each push.

Review details

Nothing blocks: one advisory finding on the guarded file-backed save path.

FINDING — src/kiro_crew/artifacts.py:2573 — a transient source read failure inside a guarded save takes mirror_verdict = "refused" when source_base_hash is None, which falls into the demotion block and persists art.source_copy_only = True, so one momentary OSError on the source (an EIO/ESTALE on a network or removable mount) permanently severs a live file-backed pointer while the token still matched and the 200 response looks like an ordinary save → Fix: in that branch re-read the source and only treat an unreadable base as "refused" when the second read also fails; otherwise raise ArtifactConflictError with the store-copy token so the client retries and source_copy_only is left alone.

[OPUS-REVIEWED] 118203c

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 2, 2026
@peterhieuvu
peterhieuvu force-pushed the fix/artifact-patch-conflict-token branch from 02a001e to 638025f Compare September 2, 2026 09:38
@peterhieuvu

Copy link
Copy Markdown
Contributor Author
  • fixed span=a1f47bacb15c — Source-first CAS can leave a failed save partially applied — fixed in 638025f

Writable source + failed current.html write -> source changes, PATCH returns 500, metadata and fallback remain stale.

The window is real and is now closed on both edges, in 638025f67:

  1. The deterministic trigger is gone: event_type validation is hoisted to the top of update(), before the mirror and every other side effect. Previously it sat inside the snapshot branch, so a rejected request could raise after the source write (this also fixes the pre-existing orphaned-versions/vN.html variant the old in-branch comment described).
  2. The nondeterministic trigger is compensated: on the guarded path, a current.html write failure after a successful source CAS now restores the source to its pre-save content and re-raises. The rollback is itself a CAS against the content we just wrote, so if an even-newer external write has landed in the meantime the rollback loses its race and correctly leaves the newer content in place. Locked in by test_store_write_failure_rolls_back_guarded_source_mirror and test_invalid_event_type_validates_before_any_write.

On the prescribed fix ("revert the source-first write"): reverting would reopen the exact hole the CAS exists to close — with current.html written first, a conflict detected at the source write would leave the losing writer's content in the store's fallback (served whenever the source later becomes unreadable), and the pre-CAS ordering allowed an external write landing after the guard's compare to be silently overwritten. Source-first + compensation keeps both invariants: a losing writer changes nothing, and an external winner is never clobbered — including by the rollback itself.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 2, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description / code mismatch

One item does not line up: the checklist asserts no module doc covers this endpoint, but docs/system-specs/modules/artifacts.md documents PATCH /api/artifacts/{slug} and is not updated for the new request field, the new response field, or the new 409.

1. Documented PATCH contract changes (new request field, new response field, new 409) with no spec update, and the Description states the opposite

The Description says —

  • Documentation updated (if applicable) — behavior documented in docstrings; no module doc covers this endpoint today

The code does — docs/system-specs/modules/artifacts.md:142 carries a PATCH /api/artifacts/{slug} row for this endpoint, so a module doc does cover it. The diff changes that endpoint's contract in three documented-surface ways and leaves the row untouched: the handler accepts a new optional expected_sha256 request field, rejects a non-string token with 400, and maps ArtifactConflictError to a 409 carrying {error, current_sha256, version} (src/kiro_crew/dashboard/handlers/artifacts.py); and to_dict adds content_sha256 to every content-carrying response (src/kiro_crew/artifacts.py). Docstrings are not a substitute here, because the spec row is the documented contract for this endpoint.

Risk — AGENTS.md:218 requires updating the spec in the SAME commit when an API, schema, or documented behavior changes. The artifacts spec is what the next contributor reads before touching a content-write path or writing a second client; leaving it silent means they will not know a token exists, that a 409 is now reachable, or that content_sha256 is part of the response contract. The checklist line makes this worse rather than neutral: it asserts there is no module doc to update, which removes the one prompt a reviewer would use to catch the omission. Docs Lint only validates index integrity, so no gate catches it either.

Required change — Extend the PATCH /api/artifacts/{slug} row at docs/system-specs/modules/artifacts.md:142 in this commit with: the optional expected_sha256 token, the 409 outcome and its {error, current_sha256, version} body, the 400 on a non-string token, and content_sha256 on content-carrying responses. Correct the checklist line "no module doc covers this endpoint today" to name the spec update. Store-side prose for ArtifactStore.update(expected_sha256=), ArtifactConflictError, and the file-backed compare-and-swap layer is welcome but optional, since that doc does not currently enumerate update()'s parameters or the other artifact exception classes.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 2, 2026
@peterhieuvu
peterhieuvu force-pushed the fix/artifact-patch-conflict-token branch from 638025f to d772887 Compare September 2, 2026 10:14
@peterhieuvu

Copy link
Copy Markdown
Contributor Author

You're right on both counts — the spec row exists and my checklist line asserted the opposite, which is exactly the kind of claim that hides the omission. Fixed in d77288726:

  • docs/system-specs/modules/artifacts.md — the PATCH /api/artifacts/{slug} row now documents the optional expected_sha256 token, the 409 outcome with its {error, current_sha256, version} body, the 400 on a non-string token, and content_sha256 on content-carrying responses (noting GET /{slug} carries it too).
  • PR description checklist line corrected to name the spec update instead of denying the doc exists.

I kept the store-side prose (update(expected_sha256=), ArtifactConflictError, the CAS layer) out of the doc per your "optional" note, since that page doesn't currently enumerate update()'s parameters or the exception classes — happy to add a paragraph if you'd prefer it documented there as well.

@peterhieuvu
peterhieuvu force-pushed the fix/artifact-patch-conflict-token branch from d772887 to ab9a547 Compare September 2, 2026 16:11
@peterhieuvu

peterhieuvu commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

CI on b88bbe877 — attribution. #13007 did its job: the crew-log vetting reds on Linux/Windows shard 7 and macOS shard 1 are gone. Remaining:

  • Frontend Lint — the MembersPage restyle ratchet; its fix fix(ci): record restyle-ratchet progress from #12805 so main lints again #13008 merged at 08:21 (21182a5e9), after this head was cut. Cleared by the next rebase.
  • Backend shard 4 (Linux) — test_dashboard_origin.py::TestFormatDashboardUrls::test_a_hanging_hostname_lookup_cannot_stall_startup, failed by conftest's data-home sentinel at teardown (_resolved_home == the runner's real ~/.kiro/crew). Not a test in this diff, passes locally alone and in three xdist passes of every server-booting shard-4 file, green on main at the identical base and on this PR's previous eight heads. Mechanism: that test class runs under patch.dict(os.environ, {}, clear=True), i.e. with the KIROCREW_HOME floor pin removed for ≥0.2 s, so any stray config_dir() on the worker during that window resolves the real home and is blamed on it. This PR's post-bind store warm-up is one such candidate alongside the pre-existing warm scavenge / search-index / orphan-reclaim kicks of the same shape; first sighting — if it recurs on the next head I treat it as mine and harden the warm-up.
  • Security Scope Review — infra: generate/validate/all three adjudications succeeded ("0 newly refused" on every OS) and the publish job then failed with "the prior conclusion for this head could not be read, so the lane fails closed". Re-runs on the next head.
  • GPT 5.6 Review — the Opus 5 adjudication stage did not run (no [GPT-ADJUDICATED] marker; the lane's comment was not updated for this head), so the verdict stands unreviewed. Two findings: F1 is the standing fenced plain-rename residual (override only). F2 — (await _store_async()).get/delete/list_versions in api_artifact_delete / versions / events stay synchronous on the loop — is on pre-existing read sites this diff touched only to move store construction off-loop, but the repo's rule is no sync store call from a coroutine, so I'm adopting it: the seven sites go through _run_off_loop with thread-witness tests, in the next round.
  • Coverage Gate fails closed on the shard-4 red.

Addendum 09:05 UTC: Opus 5 Review completed on this head — no blocking findings (the lane that was "review incomplete" on e4b38accd is fine after the re-run). macOS shards 2/3 — same main-side sets as every macOS run today: shard 3 the seven test_pr_readiness_evaluate.py tests reaching a real gh (#12987); shard 2 test_pdf_extract.py::TestBound::test_the_child_itself_exits_with_the_memory_report_under_the_profile plus a worker crash in TestChildCaps (#12925). Neither file is in this diff; macOS shard 1 is now green.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Round 28 → 3d9287cc4 (rebased onto 21182a5e9, which carries #13008 for the Frontend Lint red).

GPT 5.6 (on b88bbe877, adjudication did not run):

  • F1 hooks.py plain-rename fallback — the standing fenced residual; unchanged, override only.
  • F2 handlers/artifacts.py synchronous store I/O on the loop — adopted. The sites this diff had touched only to resolve the store asynchronously (the delete handler's pre-delete get and delete, list_versions, the version and event gets, record_impression) now resolve the store first and run the call through _run_off_loop; relocate's allowed_source_roots goes the same way because it resolves paths and loads configuration rather than reading an attribute. Every except-clause is unchanged. Six thread-witness tests, each failing on the previous handler (... ran on event-loop thread 'MainThread'). The one remaining on-loop read, api_artifact_detail's store.get, is an untouched line and stays with the sync-io baseline.

Local lanes on 96e77ebbf (the F2 fix + rebase): GPT (gpt-5.6-sol) no findings. Opus (claude-opus-5, CI's model) no blocking findings, one advisory — adopted: a snapshot-only update of a file-backed artifact read the source through the lossy decode and stamped the returned token over that text, while get stamps the raw bytes, so a source that is not valid UTF-8 handed back a token no expected_token compare could match. The snapshot branch now keeps the raw bytes it read and the return stamps them; new store test fails on the prior code (283f27… ≠ 799747…) and proves a save re-based on the returned token proceeds. That fix is the delta between the lane-reviewed commit and this head (4 source lines + the test); the CI lanes re-review it.

Gates on the new base: 1122 backend tests over the touched suites, mypy, flake8, isort, black hunk-parity on every touched file, comment-history, the sync-io gate; tsc, eslint. Body updated (token minting, off-loop sites, tests).

@peterhieuvu

peterhieuvu commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

CI on 3d9287cc4 — attribution (in progress). Eight reds so far, all one cause and none in this diff: the repository's GitHub App hit its installation API rate limit at ~09:20 UTC (##[error]API rate limit exceeded for installation, in Resolve desktop matrix), and every pull_request_target / workflow_run lane that reads the API through it failed closed at the same moment — Fork PR Description, Publish readiness signal, Screenshot Evidence, Internal Content Scan, Security Scope Review ("no leg reported"), and the GPT 5.6 and Opus 5 lanes, both "could not run — failed before producing a verdict". The same cluster is red on every other fork PR that ran in the window (e.g. the 2fdadc71a batch at 09:31, and #13004's GPT lane). The backend/frontend test shards run on the per-job token and are still in progress (67 green, 13 pending, no test reds yet).

A fork contributor cannot re-run a lane; they re-run on the next head or via the maintainers' override handler. Holding this head until the shards finish and the limit resets; I will append the shard results here.

Addendum 10:10 UTC — shards finished: Linux shard 4 is green (the test_dashboard_origin data-home sentinel from b88bbe877 did not recur, so it stays a single-sighting race). Remaining test reds, none in this diff: Windows shard 7 test_aws_control_backup.py::TestALostRunWriteDoesNotReUploadForever::test_run_identity_concurrent_failure_then_recovery — tracked as flake #13041 ("loses the first upload record on a contended runner"); macOS shard 1 was cancelled by the job timeout at 98 % with every test passing so far (the previous head's shard 1 needed 34 min; this runner was slower) — no test failed; macOS shards 2/3 the same main-side sets as every macOS run today (test_pdf_extract #12925; the seven test_pr_readiness_evaluate tests reaching a real gh). The fork lanes are running again for other PRs since ~10:01, so the rate-limit outage is over; this head's GPT/Opus/Security lanes stay "could not run" until a re-run.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Rebased -> 17c65c1a7 onto upstream/main at 5c23469f7 (53 commits). The PR had gone CONFLICTING.

One real conflict, in ArtifactDetailPage.tsx's Cmd+S handler, where #12817 (deterministic chord ownership) landed on the same block as this PR's repeat/conflict guards. Merged so both hold: the chord is owned whenever editing (always preventDefault, case-insensitive match, as #12817 requires), and it saves only when dirty, never on an auto-repeat, and Cmd+Shift+S is a no-op while a 409 is armed (as this PR requires). Every other hunk applied clean; the patch outside that block is byte-identical to 3d9287cc4.

Gates on the new base: 3309 backend tests over the touched suites, mypy, flake8, isort, comment-history (base upstream/main), sync-io gate, tsc, eslint, 935 frontend tests including the page suites and the diff-scoped i18n style gates, lint:i18n. One backend intermittent (test_knowledge_stats.py::test_library_behind_the_schema_is_reported_not_migrated, no such column: content_hash under xdist) reproduces 2/3 on a clean checkout of upstream/main with the same file set and passes alone on both trees; file not in this diff. The local black gate reports a graduated baseline entry (test/test_knowledge.py, identical to main), main-side.

This head re-runs the three lanes that never got a verdict on 3d9287cc4 (GPT 5.6, Opus 5, Security Scope; the 09:20 rate-limit outage) and the Windows shard-7 #13041 flake.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

CI on 17c65c1a7 -- attribution

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Rebased -> c22ba144c onto upstream/main at a118ae76f to inherit #13151 (the black-baseline prune behind the Backend Lint red on 17c65c1a7). Two upstream commits, no overlap with this diff; patch byte-identical to 17c65c1a7.

On the new base the baselined black gate passes; 2058 backend tests over the touched suites, mypy, flake8, isort, comment-history (base upstream/main), sync-io gate, tsc, eslint and 935 frontend tests (page suites + diff-scoped i18n gates) pass.

For the record on 17c65c1a7: all three fork lanes posted -- GPT 5.6 at the standing fenced residual only, Opus 5 no blocking findings, Security Scope green -- and every test shard that finished was green except the main-side lint gate; the three macOS shards had not finished when this head was cut.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

CI on c22ba144c -- attribution

  • Backend Tests (3.12, 7) -- test/test_aws_control_backup.py::TestALostRunWriteDoesNotReUploadForever::test_run_identity_concurrent_failure_then_recovery, the contended-runner race tracked as flake: test_run_identity_concurrent_failure_then_recovery loses the first upload record on a contended runner #13041 (open; it hit Windows shard 7 on 3d9287cc4 too). File not in this diff. Only red among the finished test shards; the Backend Lint gate that was red on 17c65c1a7 is green here (style(ci): drop test/test_knowledge.py from the black baseline #13151 inherited).
  • GPT 5.6 Review -- re-rolled two fenced findings on code byte-identical to 17c65c1a7 (where it raised only the standing residual), both machine-flagged by the adjudicator as edge cases. F2 (artifacts.py:4175, non-ASCII persisted content_salt -> uncaught UnicodeEncodeError on GET) is being fixed on the next head: the persisted salt is validated on load (empty legacy or 32 lowercase hex) and anything else raises ArtifactError, with a discriminating test. F1 (artifacts.py:1545, .token_key create/rename via the store root path) is rebutted in the round-29 disposition on the adjudicator's evidence.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Round 29 -> 1dd303f1a (rebased onto upstream/main at fddab6f83, 11 commits, no conflicts; code delta vs c22ba144c is the F2 fix below).

GPT 5.6 on c22ba144c -- two fenced findings, both machine-flagged by the adjudicator:

  • F2 -- fixed. _read_meta_file accepted any persisted content_salt, so a non-ASCII value in the store's own meta.json reached f"{salt}:{digest}".encode("ascii") and surfaced as an uncaught 500 on GET and on guarded saves. The persisted salt is now validated on load: the empty legacy value (absent or null) still loads and gains a salt on first write, exactly 32 lowercase hex characters is the only other accepted shape, and anything else raises ArtifactError("meta.json content_salt malformed: <path>") -- the same class and remedy as the existing meta.json missing slug. The five listing/iteration callers already catch ArtifactError, so one corrupt artifact is skipped rather than breaking the library view. Two tests (test_non_ascii_content_salt_is_rejected, test_ascii_non_hex_content_salt_is_rejected); the first fails on the prior code with UnicodeEncodeError: 'ascii' codec can't encode character '\xe5'. Repaired by a GPT-family delegate per the review-repair routing; verified on the tree.

  • F1 -- rebutted, not patched. The .token_key create/rename resolves through the store root path rather than a pinned directory descriptor. The adjudicator's flag states the case: the escape needs the root swapped in the window between the store's own resolve(strict=False) + is_sensitive_path validation and the once-per-process key publication; the stage is created 0600 and os.replace onto a final-component symlink overwrites the link rather than following it; the key it could misplace is one the same-uid actor able to swap that name can already read in place (artifacts is on neither the read gate's nor the sandbox mask's leaf list); and recovery is a fresh key at the true root costing one 409 per open editor -- the same cost as deleting the key. Pinning the key's directory descriptor would be new machinery for a nil marginal exposure, the same class as the retention residuals already on record. Override-only, like the plain-rename residual.

Local lanes on ad696d8e6 (F2 fix, pre-rebase; identical patch): GPT 5.6 (gpt-5.6-sol) no findings; Opus 5 (claude-opus-5) no findings.

Gates on the new base: 2060 backend tests over the touched suites, mypy, flake8, isort, black, comment-history (base upstream/main), sync-io, tsc, eslint, 935 frontend tests (page suites + diff-scoped i18n gates), lint:i18n.

@peterhieuvu

peterhieuvu commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

CI on 1dd303f1a -- attribution

  • Frontend Tests (1) -- src/test/SpecBuilderSettingsSaveGuard.test.tsx :: enables Save once the read lands, with the stored path seeded: a findByDisplayValue timed out while the settings modal was still mid-fade (the captured DOM shows the backdrop at opacity: 0.57). Spec Builder is not in this diff; the same shard is green on every other PR run this evening; the file passes 5/5 alone and inside a full local --shard=1/4 run of this head (575 files, 10287 tests). Single sighting, timing under runner load; if it recurs on a later head I treat it as ours. Frontend Coverage Merge fails closed on the missing shard blob.
  • GPT 5.6 Review -- the standing fenced plain-rename residual only (hooks.py); neither of the previous head's F1/F2 re-rolled, and the round-29 salt validation drew no finding.
  • The six CANCELLED entries (Automated Rule Check, Inclusive Language, PR Hygiene, SAST, Screenshot Evidence, same-repo GPT lane) are the 23:20 runs superseded by the 23:31 re-runs, all SUCCESS.

Addendum 00:25 UTC: Coverage Gate fails closed on the same missing frontend shard (frontend-test=failure frontend-coverage-merge=failure, backend and combine green). Lane verdicts on this head: Opus 5 no blocking findings; Security Scope CONCERNS with 0 confirmed newly-refused candidates (its unadjudicated notes on the fail-closed key file and the salt validation are the behaviours described in the PR body); GPT at the standing residual only.

Addendum 00:57 UTC: macOS shards 1 and 2 (shard 3 green) -- one failure each, both Linux-only assumptions running on darwin, both fixed together by open upstream PR #13202: shard 1 test_chat_threads.py::test_a_failed_sidecar_staging_leaks_no_descriptor lists /proc/self/fd directly (added in #12797 this morning; macOS has no /proc), shard 2 test_pdf_extract.py::TestBound::test_the_child_itself_exits_with_the_memory_report_under_the_profile pins a detail the darwin RSS watchdog answers differently (#13095). Neither file is in this diff. That completes CI on this head: every red is the review gate, the override-only GPT residual, or attributed main-side/flake.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Rebased -> 278cb8ef5 onto upstream/main at 5a2fe90e0 (111 commits absorbed), to inherit #13202 -- the darwin fix for the two macOS reds attributed on 1dd303f1a -- and re-run the single-sighting Spec Builder frontend shard-1 flake.

Clean rebase, no conflicts. Source and frontend byte-identical to 1dd303f1a. One PR-authored test needed the same adjustment the neighbouring warm-connections test already carries: TestArtifactStoreKick::test_both_gateway_modes_kick_it_after_the_bind asserted the store kick follows _start_site(site, port) in both entrypoints, but upstream's start_dashboard now serves its pre-reserved socket via SockSite (await site.start()), so the test resolves the serving step per entrypoint before asserting order. No production change.

Gates on the new base: 2319 backend tests over the touched suites; mypy, flake8, isort, black baseline gate, comment-history, sync-io; tsc, eslint, 935 frontend tests including the diff-scoped i18n register ratchets; lint:i18n.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

CI on 278cb8ef5: three reds, none in the diff -- re-run head pushed as c2e99d316 (rebased onto upstream/main at 7e40e2175, 15 commits, patch byte-identical).

  • Backend Lint / black gate -- the step died with exit code 143 (SIGTERM), not a formatting verdict: no ::error offender or graduated-baseline line was emitted. That is the runner memory kill the step's own ci_black_diagnostics.py wrapper exists to observe. The gate passes locally on this head, on the PR merge ref refs/pull/7818/merge, and on a clean upstream/main checkout, all with CI's pinned black 26.3.1 and RUNNER_ENVIRONMENT=github-hosted; the same step is green on the 8 other PR runs in the same hour.
  • Windows shard 7 -- test_runtime_cleanup_windows.py::test_windows_sync_provider_fallback_reclaims_grandchildren ("owned processes still alive"), the ci(windows): two backend tests fail once then pass on the same commit (subagent_continuable temporary-incognito timeout, runtime_cleanup_windows tree reclaim) #12359 family that has hit a dozen unrelated PRs; the file is not in the diff.
  • Frontend Tests (1) -- the shard blob records no failed test (the run exited 1 without a fail state), and the shard is green on all 15 other PR runs today. CI's exact vitest run --shard=1/4 passes locally on this head: 578 files, 311 s.

GPT 5.6 on 278cb8ef5: F2 (hooks.py:3651) is the standing fenced plain-rename residual, unchanged and override-only. F1 (artifacts.py:4512, recovery listing bound) re-rolled on unchanged code and the adjudicator downgraded it as a disproportionate remedy (peak memory is set by listdir itself; every enumerated leftover is unlinked on the same pass). Not adopted.

Gates on the new base: 1787 backend tests over the touched suites; mypy, flake8, isort, black baseline gate, comment-history (diff-scoped), sync-io; tsc, eslint, 935 frontend tests with the diff-scoped i18n ratchets; lint:i18n.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Round 30 -> f4d6bd876 (rebased onto upstream/main at c08b4e2b7; patch delta vs c2e99d316 is the two items below, 148 lines, same file set).

GPT F1 on c2e99d316 (artifacts.py:4583, recovery deletes the only copy of an interrupted save) -- FIXED. The finding held: a leftover stage whose bytes differ from a readable source was treated as "never committed" and unlinked, but that state is ambiguous -- the source compare-and-swap may have landed and the source been edited externally afterwards, leaving the stage as the only copy of the committed edit. Recovery can now prove which: the guarded save carries the first 16 hex of the source hash the CAS compares against in the stage name (.current.html.<random>.<16hex>.staged, both the dir-fd and mkstemp paths; the listing filter is unchanged). A mismatched stage whose hint equals the source's current hash means the source never left the base, so the commit never landed -> discarded as before. A hint that differs means the source moved off both -> RETAINED, one WARNING per pass naming the entry. A hint-less staging-named entry (nothing the guarded save writes) -> discarded as before. The name is still never trusted past inspection; the hint only chooses discard-vs-retain for an entry that already failed to match the source. Docstring updated. New test_failed_install_then_external_source_edit_retains_staged_copy (commit lands, install fails, source edited externally, update()) fails on the prior code with the stage gone and passes now; siblings pin the matching-hint and hint-less discards.

Opus (local lane, on the F1 fix) advisory at hooks.py:3261 -- FIXED. The first rename_exchange caught only NotImplementedError, while the shim maps only ENOSYS/EINVAL/EOPNOTSUPP/ENOTSUP to that; any other OSError from the exchange (EXDEV, EBUSY, EPERM) escaped to the enclosing except OSError: return "refused", and for a verifying caller refused installs the store copy and demotes the pointer while the save reports as applied. Since a failed exchange has moved nothing, it now takes the same plain-rename install the no-exchange mounts always take (matching the two later exchange sites). test_exchange_failing_with_an_unmapped_errno_falls_back_to_the_plain_rename fails on the prior code (refused) and passes now (ok).

Opus advisory not adopted: a planted regular file with a hint-shaped name is retained across passes (logged each time) and would be installed by the existing unreadable-source about_to_write path -- the same install any staging-named file planted just before such a save already got; a same-uid writer with that access can write current.html directly, and the proposed remedy (recording released stage names in meta.json) is retention machinery outside this change. Deferred.

Backend Lint on c2e99d316: the black step died with exit 143 a second time. Measured rather than assumed: black on this head's artifacts.py peaks at 99 MB vs 89 MB on upstream's, the whole tree at 331 MB and 15 s locally; the same step failed on 3 of 28 other PR runs today. Runner-side; re-runs with this head.

Local lanes on the F1 commit: GPT (gpt-5.6-sol) no findings; Opus 5 (claude-opus-5) no blocking findings, the two advisories above. The exchange fix is the only delta after the lanes; CI's lanes re-review it. Gates: 1791 backend tests over the touched suites; mypy, flake8, isort, black baseline gate, comment-history (diff-scoped), sync-io; tsc, eslint, 935 frontend tests with the diff-scoped i18n ratchets; lint:i18n. Body updated (recovery bullet; exchange fallback sentence).

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Bundle Size Gate on f4d6bd876 -> fixed in 118203c95 (rebased onto upstream/main at 5ad8818fa; delta vs f4d6bd876 is one entry in website/scripts/check-bundle-size.mjs, nothing else).

The all chunk came out 3.0 KB over its 12870 KB ceiling. Measured rather than assumed: main's tip alone builds it at 13,171,024 B (12862.3 KB), 7.7 KB under the ceiling after three days of merges spent the 5% headroom recorded on 2026-09-21; this PR adds 10,881 B (six new keys across the 13 locale catalogs plus the conflict banner in the detail page) and lands at 13,181,905 B. The catalogs are the chunk's irreducible content per the file's own notes, so there is no module to split out. Reset to the same 5% convention over the new measurement (13510 KB), with the attribution in the file. Any other PR adding more than 7.7 KB to that chunk would have hit the same wall.

Also on f4d6bd876: six check-runs read CANCELLED (PR Hygiene, SAST, Inclusive Language, Screenshot Evidence, Automated Rule Check, the same-repo GPT placeholder). Those are the edited-event runs my body update fired 47 s after the push, cancelled by the concurrency group; the push-triggered runs of the same workflows succeeded. This head re-runs them cleanly.

UX Review (advisory CONCERNS) on f4d6bd876: the overwrite-vs-checkpoint and popout-affordance items are the standing dispositions from rounds 26-27; the sync-banner "Snapshot to publish" note is noted for a follow-up, not this PR.

Gates on the new base: 1791 backend tests over the touched suites; mypy, flake8, isort, black baseline gate, comment-history (diff-scoped), sync-io; tsc, eslint, 935 frontend tests with the diff-scoped i18n ratchets; lint:i18n; vite build --mode analyze + check-bundle-size.mjs: 713 chunks within budget.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

GPT on 118203c95 (artifacts.py:2226, guarded writes use the plain replace on Windows) -- the standing plain-rename residual, rolled from the Windows angle; unchanged. Same anchor and same window as the hooks.py finding dispositioned on f89ae796e, 29b140d77 and every roll since: where the platform has no exchange-equivalent (RENAME_EXCHANGE_AVAILABLE false -- Windows, glibc < 2.28, some network mounts) the verifying write keeps the plain-rename install with the few-instruction window POSIX itself carries, strictly narrower than the unconditional overwrite it replaces. The proposed remedy -- fail closed where no exchange exists -- would refuse every guarded save on those platforms. The adjudicator flagged this roll as one a human would plausibly accept via override, as it did on the prior rolls; stated in the PR body under "The install is a true compare-and-swap where the platform allows". Override-only; not changed.

The round-30 code (recovery retain, exchange OSError fallback) drew no finding, and the bundle ceiling reset on this head has no reviewable code. Opus 5 and Security Scope pending.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

CI on 118203c95: three test-side reds, none in the diff -- rebased -> 4fa556755 onto upstream/main at a992d5cda (22 commits; patch byte-identical).

GPT on 118203c95: only the standing plain-rename residual (Windows angle), dispositioned above. Design PASS, First Principles PASS, UX advisory; Opus 5 and Security Scope did not post before the rebase and re-run here.

Gates on the new base: 1826 backend tests over the touched suites (crew-log emitter included); mypy, flake8, isort, black baseline gate, comment-history (diff-scoped), sync-io; tsc, eslint, 935 frontend tests with the diff-scoped i18n ratchets; lint:i18n; analyze build + check-bundle-size.mjs (713 chunks within budget; all at 12883 KB under the 13510 KB ceiling).

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Rebased -> 8a0d60a3d onto upstream/main at 0bbfc9052 (9 commits). The PR had gone CONFLICTING on website/scripts/check-bundle-size.mjs: upstream's #13607 tripled the all ceiling (38610 KB, a deliberate exception to the 5% rule), which supersedes the re-measured reset this PR carried since 118203c95. Resolved by taking upstream's file verbatim -- the budget file is no longer part of this diff. Everything else byte-identical.

Also on 4fa556755:

  • Opus 5 Review -- "review incomplete": the fork lane failed before a verdict (no comment stamped for the head; the last Opus verdict, on 118203c95, was no blocking findings). Re-runs on this head.
  • Backend Lint / black step, exit 143 (fourth head): CI: Backend Lint's black step killed by runner shutdown (exit 143) on 4 consecutive fork-PR heads #13386, open, routed needs-investigation; runner shutdown signal, no verdict, no fix to inherit. Re-runs here.
  • GPT: the standing plain-rename residual only (adjudicator upheld this roll, flagged the last -- same override-only class; disposition above stands).
  • Security Scope: CONCERNS with zero confirmed newly-refused candidates, as on prior heads. 88 checks green; macOS shards were still running.

Gates on the new base: 1791 backend tests over the touched suites; mypy, flake8, isort, black baseline gate, comment-history (diff-scoped), sync-io; tsc, eslint, 935 frontend tests with the diff-scoped i18n ratchets; lint:i18n; analyze build + check-bundle-size.mjs (713 chunks within budget under upstream's ceiling).

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

CI on 8a0d60a3d: 92 green, Opus 5 no blocking findings, two reds outside the diff -- re-run head pushed as f10ef3628 (rebased onto upstream/main at 0f791c855, 5 commits, no overlap, patch byte-identical).

  • macOS shard 1 -- cancelled by the job's 40-minute timeout at 96-97 % with zero failures: the shard log shows only passing markers (no F/E, no FAILED), the same slow-runner pattern as on 3d9287cc4; shards 2 and 3 finished green in 35 and 39 minutes on the same run. Not a test failure; needs the re-run this head gives it.
  • Backend Lint / black step, exit 143 (fifth head): CI: Backend Lint's black step killed by runner shutdown (exit 143) on 4 consecutive fork-PR heads #13386, still open with no fix PR. Re-runs here; nothing in the diff moves black's footprint (measured on the previous head).
  • GPT: the standing plain-rename residual only, this roll anchored at hooks.py:3656; same override-only class, disposition above stands.

Gates on the new base: 1791 backend tests over the touched suites; mypy, flake8, isort, black baseline gate, comment-history (diff-scoped), sync-io; tsc, eslint, 935 frontend tests with the diff-scoped i18n ratchets; lint:i18n.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Backend Lint on f10ef3628: exit 143 again -- six consecutive heads. Per the maintainers' triage on #13386, fork PRs run this step on hosted ubuntu-latest with black unbounded, while same-repo PRs run it on CodeBuild, so my earlier base-rate comparison was not like-for-like; six of six is the fork-PR rate. Datapoint with all six kills posted on #13386. This is a CI-infrastructure red that no head from the fork side can clear until #13386 is fixed upstream; no further re-run heads will be pushed for it alone. Everything else on this head is green or still running; GPT is the standing residual (artifacts.py:2575 angle this roll).

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

CI on f10ef3628 settled: 89 green; five reds, none in the diff, and none clearable from the fork side right now.

Every one of these clears on a re-run except the black kill, and a new head cannot clear that until #13386 is fixed upstream -- so no re-run head is pushed for the others alone. The next head is the rebase onto whatever fixes #13386; it re-runs all of them.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Rebased -> b29c6ae3c onto upstream/main at 3afddd85f (36 commits). The PR had gone CONFLICTING on three files, all against #13369 (hold the publication guard while an artifact is destroyed):

  • artifacts.py: both sides add a class at the same spot -- upstream's ArtifactReplacedError + _NO_GENERATIONS, this PR's ArtifactConflictError. Both kept.
  • handlers/artifacts.py, delete handler: upstream's guarded, generation-pinned removal block replaces this PR's store.delete(...) line; upstream already runs it through _run_off_loop with the store resolved inside the worker, so the off-loop property this PR added holds.
  • handlers/artifacts.py, cascade withdrawal pass: upstream's new generations map kept, with the store resolved via _store_async() rather than the synchronous get_default_store() the merge would otherwise have re-introduced on the loop (the package-wide coroutine scan this PR carries is what would have caught it).
  • publish_sync.py: import list, both names kept.

Outside those hunks the patch is byte-identical to f10ef3628. Gates on the new base: 1791 backend tests over the touched suites (including the coroutine store-construction scan); mypy, flake8, isort, black baseline gate, comment-history (diff-scoped), sync-io; tsc, eslint, 935 frontend tests with the diff-scoped i18n ratchets; lint:i18n.

This head re-runs the four attributed reds from f10ef3628 (Opus lane, Windows 7, macOS 1, black). The black step is expected to die again until #13386 is fixed; everything else should land green.

@peterhieuvu

peterhieuvu commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

CI on b29c6ae3c: 85 green; five reds, none in the diff. The three attributed reds from f10ef3628 that this head re-ran (Opus lane, Windows 7, macOS 1) all came back green; the conflict-merge against #13369 drew nothing.

The two shard flakes would clear on any re-run head; the black kill cannot until #13386 is fixed, so no re-run head is pushed for them alone -- the rebase onto that fix re-runs everything.

  • Opus 5 Review -- "review incomplete" (settled after the above): the fork lane failed before a verdict for the third head out of the last four; its last verdict (118203c95) was no blocking findings, and the local Opus 5 lane on the round-30 code was clean. Infra; re-runs with the next head.

@peterhieuvu

Copy link
Copy Markdown
Contributor Author

Proposing to split this PR. @bolichen97, since your "Changes requested" covers the whole thing, I'd like your view before anything is closed.

Why. After 30 review rounds this is about 5,200 lines across 49 files, for a fix #7751 describes in four steps. Most of the growth came from one early choice: guarding the write back to a file-backed artifact's source file with a compare-and-swap, when #7751 only asked for that file to be read for the comparison. The staging, the pinned-directory hardening, the rename-exchange install, the recovery scan and the plain-rename finding that re-rolls on every head all follow from it. I should have stopped and asked about scope much earlier.

The split:

What happens to this PR. If #14039 picks full compare-and-swap guarding, I'll rebuild this PR as that follow-up on top of #14075. Otherwise I'll close it. Until then I'm not pushing any more heads here.

Copy link
Copy Markdown
Contributor

Open-PR triage (2026-10-05): OVERLAPPING with #14075. Rebase is required before any further work.

I checked the full merge-base diff (3afddd85..b29c6ae3, 35 files, +5184/-228) against origin/main af1eb612.

What's on main now: nothing from this PR. origin/main has no content_token, expected_token or ArtifactConflictError for artifacts. The PATCH /api/artifacts/{slug} row in docs/system-specs/modules/artifacts.md:523 still describes an unconditional write. So #7751 (Issue, open) is not resolved on main, and this PR is not superseded.

Relationships:

Staleness: the PR is 1,507 commits behind main. git merge-tree against main conflicts in artifacts.py, hooks.py, auto_research/handlers.py, website/src/api/client.ts and ArtifactDetailPage.tsx. Since the PR was cut, main has split the store into src/kiro_crew/artifact_store/ (#14546, #14602, #15688), so the artifacts.py hunks would have to be re-ported into those modules.

Breaking change / P0: neither found. The declared tightenings (an invalid event_type is now a 400, and a pre-staging identity swap is now a 409 instead of "refused") are opt-in or fail-closed. @bolichen97's CHANGES_REQUESTED review still stands formally.

Recommendation: MERGE-DISCUSSION. Leave this PR parked, as the author proposed on 2026-09-26, and do not close it yet:

  1. Land fix(artifacts): refuse stale content writes with 409 instead of silently overwriting #14075 first. It is the minimal fix for Artifact PATCH has no stale-write protection — concurrent editors silently clobber each other's content #7751.
  2. Decide File-backed artifacts have no stale-write guard against external source edits #14039. If full source-file CAS guarding is chosen, rebuild this PR as a follow-up on top of fix(artifacts): refuse stale content writes with 409 instead of silently overwriting #14075 and the artifact_store/ split. If it is not chosen, close this PR then.

No further heads on this branch are useful until #14039 is decided.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you @peterhieuvu for all the work here, and for splitting it as you proposed.

Status check against main (74a249d48): the core of this PR is on main through your #14075 (2f5261c53, "refuse stale content writes with 409"). Its body says it "replaces the core of #7818".

What did not land: the file-backed hardening (stale-write guard against external edits to source_path, source compare-and-swap, staging recovery). #14075 moved that to issue #14039, which is still open and waiting on a maintainer decision.

Because part of this PR is still unlanded, I am leaving it open for now. No code or branch changes were made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Artifact PATCH has no stale-write protection — concurrent editors silently clobber each other's content

3 participants