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",