diff --git a/loopx/chat/result_files_api.py b/loopx/chat/result_files_api.py index 12fab1242d..b06060a1b8 100644 --- a/loopx/chat/result_files_api.py +++ b/loopx/chat/result_files_api.py @@ -7,6 +7,7 @@ from ..capabilities.manager_context.roundtrip import read_chat_return_file from ..chat_attachments import CHAT_IMAGE_MAX_BYTES, CHAT_IMAGE_TYPES +from ..control_plane.content_digest import BARE_SHA256_PATTERN from ..control_plane.effect_runtime import effect_runtime_request_scope @@ -116,7 +117,7 @@ def _serve_chat_history_image(self, parts) -> bool: self._send_error("Conversation images are only available to the original App.", status=403) return True try: - if not re.fullmatch(r"[0-9]{1,3}", parts[7]) or not re.fullmatch(r"[a-f0-9]{64}", parts[8]): + if not re.fullmatch(r"[0-9]{1,3}", parts[7]) or not BARE_SHA256_PATTERN.fullmatch(parts[8]): raise KeyError("image unavailable") mime, body = read_chat_history_image( self.server.chat_store, unquote(parts[3]), unquote(parts[5]), int(parts[7]), parts[8]) diff --git a/loopx/control_plane/capabilities/native_child_result_inbox.ts b/loopx/control_plane/capabilities/native_child_result_inbox.ts index 9f92ba66ef..331236d8c6 100644 --- a/loopx/control_plane/capabilities/native_child_result_inbox.ts +++ b/loopx/control_plane/capabilities/native_child_result_inbox.ts @@ -8,6 +8,7 @@ import {constants} from "node:fs"; import {open, readdir} from "node:fs/promises"; import {isAbsolute, join, toNamespacedPath} from "node:path"; +import {ENVELOPED_SHA256_PATTERN} from "../content_digest.ts"; import type {JsonObject} from "../effect_program.ts"; import {EffectRuntimeRequestError} from "../effect_runtime_errors.ts"; import {atomicWriteJson, atomicWriteText, withFileMutationLock} from "../effect_runtime_io.ts"; @@ -106,7 +107,7 @@ async function readEntry(source: ReturnType, id: string): Promise< fail("host terminal receipt id is invalid"); } requireStringLiteral(row.outcome, [...OUTCOMES], "native child result outcome"); - if (typeof row.content_sha256 !== "string" || !/^sha256:[0-9a-f]{64}$/u.test(row.content_sha256) + if (typeof row.content_sha256 !== "string" || !ENVELOPED_SHA256_PATTERN.test(row.content_sha256) || !Number.isSafeInteger(row.content_bytes) || Number(row.content_bytes) < 0 || Number(row.content_bytes) > MAX_CONTENT_BYTES) fail("native child result content identity is invalid"); instant(row.created_at, "result creation time"); diff --git a/loopx/extensions/lark/private_conversations.py b/loopx/extensions/lark/private_conversations.py index 33d14cb766..df3789b0e5 100644 --- a/loopx/extensions/lark/private_conversations.py +++ b/loopx/extensions/lark/private_conversations.py @@ -31,6 +31,7 @@ from ...chat_attachments import CHAT_IMAGE_MAX_COUNT, normalize_chat_image_attachments from ...chat_store import CHAT_MESSAGE_SCHEMA_VERSION, ChatSessionStore, TERMINAL_TURN_STATES, _atomic_write_json, _read_json from ...control_plane.collaboration import conversation_reply_context +from ...control_plane.content_digest import BARE_SHA256_PATTERN from ...control_plane.effect_runtime import effect_runtime_request_scope from ...file_lock import exclusive_file_lock from ...presentation.markdown import markdown_scalar @@ -1534,13 +1535,13 @@ def _historical_image_plan(self, record: Mapping[str, Any], plan: Mapping[str, A raise ValueError("invalid original image repair fields") if (not isinstance(plan["message_id"], str) or not LARK_MESSAGE_ID_PATTERN.fullmatch(plan["message_id"]) or not isinstance(plan["answer_sha256"], str) - or not re.fullmatch(r"[a-f0-9]{64}", plan["answer_sha256"]) + or not BARE_SHA256_PATTERN.fullmatch(plan["answer_sha256"]) or not isinstance(plan["images"], list) or not 1 <= len(plan["images"]) <= CHAT_IMAGE_MAX_COUNT): raise ValueError("invalid original image repair target") images = [] for image in plan["images"]: if (not isinstance(image, dict) or set(image) != {"url", "sha256"} - or not isinstance(image["sha256"], str) or not re.fullmatch(r"[a-f0-9]{64}", image["sha256"]) + or not isinstance(image["sha256"], str) or not BARE_SHA256_PATTERN.fullmatch(image["sha256"]) or not isinstance(image["url"], str)): raise ValueError("each original image requires a URL and its SHA-256") images.append({"url": public_url(image["url"]), "sha256": image["sha256"]}) @@ -1556,9 +1557,8 @@ def _load_historical_image_plan(self, path: Path, record: dict[str, Any]) -> dic raise ValueError("invalid original request reference") # This is a private local operator input, scoped to the existing receipt. # It is never loaded from a project, provider message or model response. - spec = self.root / "historical-answer-images" / path.name try: - with spec.open("rb") as handle: + with (self.root / "historical-answer-images" / path.name).open("rb") as handle: raw = handle.read(40_001) except FileNotFoundError: return None diff --git a/tests/architecture/test_content_digest_single_owner.py b/tests/architecture/test_content_digest_single_owner.py index 932e673e24..24cfd06eaf 100644 --- a/tests/architecture/test_content_digest_single_owner.py +++ b/tests/architecture/test_content_digest_single_owner.py @@ -180,6 +180,7 @@ "loopx.capabilities.periodic_report.machine_defaults", "loopx.capabilities.periodic_report.review", "loopx.capabilities.progress_review.receipt", + "loopx.chat.result_files_api", "loopx.chat_action_normalization", "loopx.capabilities.manager_context.chat_history", "loopx.cli_commands.quota_context_reader", @@ -219,6 +220,7 @@ "loopx.control_plane.work_items.progress_review_policy", "loopx.domain_packs.issue_fix", "loopx.extensions.lark.document_comment_provider", + "loopx.extensions.lark.private_conversations", "loopx.extensions.openviking_semantic_preference.history_export", "loopx.extensions.presentation", "loopx.hosts.checkpoint_retention", diff --git a/tests/control_plane_ts/content_digest_single_owner.test.ts b/tests/control_plane_ts/content_digest_single_owner.test.ts index 5d5b913834..284f257815 100644 --- a/tests/control_plane_ts/content_digest_single_owner.test.ts +++ b/tests/control_plane_ts/content_digest_single_owner.test.ts @@ -109,6 +109,7 @@ const CANONICAL_CONSUMERS = [ "control_plane/capabilities/explore_result_page.ts", "control_plane/capabilities/external_evidence.ts", "control_plane/capabilities/goal_capability_organization.ts", + "control_plane/capabilities/native_child_result_inbox.ts", "control_plane/capabilities/trajectory_assessment.ts", "control_plane/capabilities/trajectory_input_usage.ts", "control_plane/capabilities/trajectory_tool_context.ts",