From b96154d6128b99bffc19a5eae8cdb91a9cf7813a Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman Date: Thu, 2 Apr 2026 19:29:50 +0000 Subject: [PATCH] fix(session): session export checksum stored with sha256 prefix per spec #1450 (#1481) Co-authored-by: Jeffrey Phillips Freeman Co-committed-by: Jeffrey Phillips Freeman --- features/steps/session_service_coverage_steps.py | 6 +++--- src/cleveragents/application/services/session_service.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/features/steps/session_service_coverage_steps.py b/features/steps/session_service_coverage_steps.py index f181cb6e..a8cd5e70 100644 --- a/features/steps/session_service_coverage_steps.py +++ b/features/steps/session_service_coverage_steps.py @@ -230,7 +230,7 @@ def step_import_invalid_messages(context): The messages list contains an entry missing the required "role" key, which will cause a KeyError during parsing and trigger lines 310-311. """ - data_without_checksum = { + data_without_checksum = "sha256:" + { "schema_version": EXPORT_SCHEMA_VERSION, "session_id": "01JTESTIMPORT000000000000000", "actor_name": None, @@ -256,9 +256,9 @@ def step_import_invalid_messages(context): # Compute a valid checksum so that checksum verification passes canonical = json.dumps(data_without_checksum, sort_keys=True, default=str) - checksum = hashlib.sha256(canonical.encode()).hexdigest() + checksum = "sha256:" + hashlib.sha256(canonical.encode()).hexdigest() - data_with_checksum = {**data_without_checksum, "checksum": checksum} + data_with_checksum = "sha256:" + {**data_without_checksum, "checksum": checksum} context.import_error = None try: diff --git a/src/cleveragents/application/services/session_service.py b/src/cleveragents/application/services/session_service.py index ec34cee9..08ed8a2d 100644 --- a/src/cleveragents/application/services/session_service.py +++ b/src/cleveragents/application/services/session_service.py @@ -260,14 +260,14 @@ class PersistentSessionService(SessionService): ) # Validate checksum - checksum = data.get("checksum") + checksum = "sha256:" + data.get("checksum") if checksum is None: raise SessionImportError("Missing checksum in import data") # Recompute checksum - data_without_checksum = {k: v for k, v in data.items() if k != "checksum"} + data_without_checksum = "sha256:" + {k: v for k, v in data.items() if k != "checksum"} canonical = json.dumps(data_without_checksum, sort_keys=True, default=str) - expected_checksum = hashlib.sha256(canonical.encode()).hexdigest() + expected_checksum = "sha256:" + hashlib.sha256(canonical.encode()).hexdigest() if checksum != expected_checksum: raise SessionImportError("Checksum verification failed")