Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion loopx/chat/result_files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -106,7 +107,7 @@ async function readEntry(source: ReturnType<typeof scope>, 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");
Expand Down
8 changes: 4 additions & 4 deletions loopx/extensions/lark/private_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]})
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/architecture/test_content_digest_single_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading