From eb760eb440eea6d5b03c7158fb075e8538d1a40a Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 16 Aug 2026 12:53:34 -0400 Subject: [PATCH] fix(snippets): read the stored provenance before writing the fresh stamp into the response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fields aliases data['snippet'], so stamping the response first made the staleness check compare the new stamp to itself — the background persist never fired. Caught by test_current_code_confirms_and_refreshes_provenance on run 3811, which exists for exactly this write. Co-Authored-By: Claude Fable 5 --- src/scribe/services/snippets.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/scribe/services/snippets.py b/src/scribe/services/snippets.py index cdb218e..5f7b828 100644 --- a/src/scribe/services/snippets.py +++ b/src/scribe/services/snippets.py @@ -1049,13 +1049,18 @@ async def attach_live_body(note, data: dict) -> None: data["body_source"] = "forge" data["body_freshness"] = "current" if fetched.commit_sha: + # Read the stored stamp BEFORE writing the fresh one into the + # response: `fields` aliases data["snippet"], so the other order + # makes the staleness check compare the new stamp to itself and + # the persist never fires (caught by the unit test, run 3811). + stored_prov = fields.get("provenance") or {} + stale = stored_prov.get("commit_sha") != fetched.commit_sha prov = compose_provenance(commit_sha=fetched.commit_sha) # Reflected in THIS response as well as persisted — the reader # shouldn't need a second pull to see the stamp they caused. if isinstance(data.get("snippet"), dict): data["snippet"]["provenance"] = prov - stored_prov = fields.get("provenance") or {} - if stored_prov.get("commit_sha") != fetched.commit_sha: + if stale: spawn( _refresh_provenance(note, fetched.commit_sha), site="pull provenance-refresh",