From a789e210c3fb68a69418e31f9fb8b6b33fd9a926 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Sat, 21 Nov 2026 21:31:46 +0800 Subject: [PATCH] Bound native Markdown Inbox reader output Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/capabilities/manager_context/README.md | 10 ++++++---- loopx/cli_commands/manager_inbox.py | 7 ++++--- .../turn_driver/native_context_profile.py | 3 +++ tests/test_delegation_turn_context.py | 11 ++++++----- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/loopx/capabilities/manager_context/README.md b/loopx/capabilities/manager_context/README.md index 14130fb5f8..06f2ee018c 100644 --- a/loopx/capabilities/manager_context/README.md +++ b/loopx/capabilities/manager_context/README.md @@ -368,8 +368,9 @@ The progressive quota hook's required command requests the Inbox Markdown view. When every item on a page has the same `instruction`, `next_action` or `receiver_followthrough`, apply that exact field from `shared_item_guidance` to each item on that page. Differing values and all request bodies, current state, read receipts, warnings, and -cursors are delivered in full. If a Markdown page exceeds the 12,000-byte tool -output budget, the command returns a private, digest-checked reader for that +cursors are delivered in full. Markdown Inbox responses use a 5,000-byte +serialized output limit, including reader commands and navigation. If a page +is too large, the command returns a private, digest-checked reader for that exact Inbox result. Compare each page's digest with the opening and use its direct recovery command if the reference is unavailable. Read the captured bytes to EOF, then use the Inbox `--cursor` or `--operation-cursor` for the next @@ -382,8 +383,9 @@ delivery is explicitly off. 渐进 quota 的必读命令使用 Inbox Markdown 视图。当前页每条的 `instruction`、 `next_action` 或 `receiver_followthrough` 完全相同时,从 `shared_item_guidance` 读取原值并应用到本页每条。 -不同指引、请求全文、当前状态、读回执、警告和游标均完整交付。Markdown 页超出 -12,000 字节工具输出预算时,命令给出绑定原 Inbox 结果摘要的私有 reader。逐页与开场 +不同指引、请求全文、当前状态、读回执、警告和游标均完整交付。Markdown Inbox +的序列化输出上限为 5,000 字节,含读取命令和导航。页面超限时,命令给出绑定原 Inbox +结果摘要的私有 reader。逐页与开场 摘要核对,引用不可用时使用直接恢复命令。先按字节偏移 读到 EOF,再按 Inbox 的 `--cursor` 或 `--operation-cursor` 读后续请求;这两类分页 不能混用。交付失败不表示 Inbox 为空。读回保存结果不会再次记 Inbox 读取回执、消费 diff --git a/loopx/cli_commands/manager_inbox.py b/loopx/cli_commands/manager_inbox.py index 88fde04b81..635542152a 100644 --- a/loopx/cli_commands/manager_inbox.py +++ b/loopx/cli_commands/manager_inbox.py @@ -110,9 +110,9 @@ def _render_read_markdown(result: dict) -> str: def _read_markdown(result: dict, *, runtime_root: Path) -> tuple[str, bool]: """Deliver the already-recorded scoped read without repeating its effects.""" - from ..control_plane.turn_driver.native_context_profile import NATIVE_CONTEXT_FIRST_READ_FALLBACK_BYTES + from ..control_plane.turn_driver.native_context_profile import NATIVE_INBOX_MARKDOWN_OUTPUT_BYTES - limit = NATIVE_CONTEXT_FIRST_READ_FALLBACK_BYTES + limit = NATIVE_INBOX_MARKDOWN_OUTPUT_BYTES view = _share_item_guidance(result) body = _render_read_markdown(view) size = len((body + os.linesep).encode("utf-8")) @@ -142,7 +142,8 @@ def _read_markdown(result: dict, *, runtime_root: Path) -> tuple[str, bool]: "Follow next_command through eof in UTF-8 byte-offset order. Compare each reported digest with " "this opening's SHA-256. Check each " "page's content length against its offsets, and complete coverage through total_bytes. " - "If output is missing or truncated, reread that range of the same capture with a smaller page. " + "If output is missing or truncated, reread that range of the same capture with smaller " + "--page-bytes and --max-page-output-bytes. " + CONTEXT_CAPTURE_CODE_MODE_GUIDANCE + "Apply any shared_item_guidance to the items on this page. After the page is complete, " "follow its next_cursor, operation_handoff_next_cursor, or native_child_results.next_cursor with the original Inbox command. " diff --git a/loopx/control_plane/turn_driver/native_context_profile.py b/loopx/control_plane/turn_driver/native_context_profile.py index 7888d5262a..037d9b8fd1 100644 --- a/loopx/control_plane/turn_driver/native_context_profile.py +++ b/loopx/control_plane/turn_driver/native_context_profile.py @@ -10,6 +10,9 @@ # Native openings cross a tool boundary, whether attached or linked. When # that tool's cap is unknown, avoid the bulk-reader profile. NATIVE_CONTEXT_FIRST_READ_FALLBACK_BYTES = 12000 +# Native shell tools can clip a 12 KB Markdown Inbox response in model history. +# Leave headroom for their own framing, including on multilingual pages. +NATIVE_INBOX_MARKDOWN_OUTPUT_BYTES = 5000 # Keep the configuration declaration usable by older installed readers too. NATIVE_CONTEXT_LARGE_OUTPUT_BYTES = 64000 NATIVE_CONTEXT_HISTORY_TOKENS = 20000 diff --git a/tests/test_delegation_turn_context.py b/tests/test_delegation_turn_context.py index ab46e15a5d..a55805e06d 100644 --- a/tests/test_delegation_turn_context.py +++ b/tests/test_delegation_turn_context.py @@ -216,7 +216,8 @@ def test_unbound_cli_first_read_leaves_inbox_rows_to_its_required_read(tmp_path, def invoke(argv): result = subprocess.run(argv, cwd=project, capture_output=True, timeout=40) assert result.returncode == 0, result.stderr - assert 0 < len(result.stdout) <= 12_000 + # This view and its continuation run through the native shell tool. + assert 0 < len(result.stdout) <= 5_000 return result.stdout.decode() def read_receipts(): @@ -257,7 +258,7 @@ def read_receipts(): if logical_pages == 1: reference_path.unlink() failed = subprocess.run(shlex.split(page["command"]), cwd=project, capture_output=True, timeout=40) - assert failed.returncode == 1 and len(failed.stdout) <= 12_000 + assert failed.returncode == 1 and len(failed.stdout) <= 5_000 assert "content" not in json.loads(failed.stdout) recovered = json.loads(invoke(direct)) assert recovered["offset"] == 0 and recovered["sha256"] == pinned @@ -294,7 +295,7 @@ def test_large_inbox_does_not_fall_back_to_unbounded_output(flow): invocation = [sys.executable, "-m", "loopx.entrypoint", "--registry", str(registry), "--runtime-root", str(root), "manager-inbox", "read", "--format", "markdown", "--goal-id", "research", "--agent-id", "worker"] result = subprocess.run(invocation, cwd=root, capture_output=True, timeout=40) - assert result.returncode == 1 and len(result.stdout) <= 12_000 + assert result.returncode == 1 and len(result.stdout) <= 5_000 output = result.stdout.decode() failure = json.loads(output.split("\n```json\n", 1)[1].removesuffix("\n```\n")) assert not failure["ok"] and not failure["read_complete"] @@ -331,7 +332,7 @@ def test_large_inbox_reader_commands_run_verbatim_in_powershell(flow, directory) opening = subprocess.run([*powershell, "-Command", required_read["command"]], cwd=root, env=environment, capture_output=True, timeout=60) assert opening.returncode == 0, opening.stderr - assert 0 < len(opening.stdout) <= 12_000 + assert 0 < len(opening.stdout) <= 5_000 markdown = opening.stdout.decode().replace("\r\n", "\n") view = json.loads(markdown.split("\n```json\n", 1)[1].removesuffix("\n```\n")) before = {p.relative_to(root): p.read_bytes() for p in _root(root).rglob("*.json")} @@ -342,7 +343,7 @@ def test_large_inbox_reader_commands_run_verbatim_in_powershell(flow, directory) output = subprocess.run([*powershell, "-Command", command], cwd=root, env=environment, capture_output=True, timeout=60) assert output.returncode == 0, output.stderr - assert 0 < len(output.stdout) <= 12_000 + assert 0 < len(output.stdout) <= 5_000 page = json.loads(output.stdout) assert page["ok"] and page["offset"] == len(original) and page["sha256"] == view["sha256"] original.extend(page["content"].encode())