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
12 changes: 10 additions & 2 deletions benchmark/runtime/RUNTIME.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@ reads, native discovery and hook IO in treatment cost, not just the delta bytes.

Codex App setup uses the same product configuration renderer as the worker:
`loopx --format json quota context-config --context-delivery on --codex-app --codex-context-root DIR --goal-id GOAL --agent-id AGENT`.
It returns native hooks and persistent recovery instructions, without installing
files or changing trust. A shared root isolates journals by native session;
It returns native hooks, persistent recovery instructions and native output
`config_overrides`, without installing files or changing trust. The opted-in
worker applies those same overrides automatically: 64000-byte continuation
outputs, a 20000-token history limit and a shell-scoped reader declaration. Page
zero remains within the ordinary 7900-byte guard limit. Persistent instructions
request 22000 tokens per reader result and 24000 for code-mode emission, one
directly forwarded stdout at a time. Unknown budgets retain small pages. These
limits do not prove model retention or net cost savings. Fresh off trials install
none of this configuration; rollback also removes generated output overrides.
A shared root isolates journals by native session;
the trial-local single-session `--codex-context-dir` remains supported.
See [heartbeat setup](../../docs/heartbeat-automation-prompt.md#opt-in-native-context-delivery)
for activation, readback and rollback. Generated setup and a native
Expand Down
2 changes: 2 additions & 0 deletions benchmark/runtime/context_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@ def prepare_context_delivery(env: dict[str, str], home: Path) -> None:
# a failed SessionStart handler cannot erase the read-only recovery route.
native_args = ["-c", "hooks.state={" + ",".join(entries) + "}",
"-c", "developer_instructions=" + json.dumps(configuration["developer_instructions"])]
native_args += [argument for key, value in configuration["config_overrides"].items()
for argument in ("-c", key + "=" + json.dumps(value))]
env["LOOPX_CODEX_CONTEXT_TRUST_ARGS"] = json.dumps(native_args)
2 changes: 2 additions & 0 deletions benchmark/tests/test_shared_codex_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,8 @@ def request(method, params):
overrides = {trusted[i + 1].split("=", 1)[0]: trusted[i + 1].split("=", 1)[1]
for i, value in enumerate(trusted) if value == "-c"}
assert not any(key.startswith("model_provider") for key in overrides)
assert overrides["tool_output_token_limit"] == "20000"
assert json.loads(overrides["shell_environment_policy.set.LOOPX_CONTEXT_PAGE_OUTPUT_BYTES"]) == "64000"
assert "CODEX_ROLLOUT_TRACE_ROOT" not in env
assert not (home / "context-traces").exists()

Expand Down
14 changes: 12 additions & 2 deletions docs/heartbeat-automation-prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,22 @@ loopx --format json quota context-config --context-delivery on --codex-app \
--goal-id <goal> --agent-id <agent>
```

The result contains `native_config.hooks` and
The result contains `native_config.config_overrides`, `native_config.hooks` and
`native_config.developer_instructions`. Merge the hooks into the host's existing
`hooks.json` or inline hook configuration, and append the recovery instruction to
its existing developer instructions. Preserve other configuration. Review and
its existing developer instructions. Apply each flat key/value in `config_overrides`
to the native host configuration (or as a `-c key=value` override). This selects
64000-byte context continuations, a 20000-token history limit, and a shell-scoped
reader budget declaration. The initial guard stays small. Its instruction requests
22000 tokens per reader result and 24000 for code-mode emission, with one directly
forwarded stdout per call. Unconfigured hosts retain the small-page default;
the isolated benchmark worker applies this profile automatically when opted in.
Preserve other configuration. Review and
trust only these exact hooks through Codex's native hook trust surface; the CLI
does not install files, approve hashes, enable diagnostics or run a guard.
Rollback removes these generated output overrides along with the context hooks
and recovery instruction; restore any previous host values. The profile does not
establish model retention, task gains or net fee savings.
An already loaded native thread may keep its earlier hook configuration even
when `hooks/list` discovers the new handlers as enabled and trusted. That readback
does not deliver `SessionStart` or initialize its context journal. After active
Expand Down
34 changes: 27 additions & 7 deletions docs/reference/required-work-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Native `quota should-run` and the saved `context-project` entry share the same
paged presentation. Each returns page zero, a digest-pinned continuation and full
recovery without another admission. The inline page contains up to 3 KiB and shrinks
to keep the complete guard stdout, including recovery and instruction fields,
within 7900 UTF-8 bytes. Continuations
within 7900 UTF-8 bytes. Without the generated native output configuration, continuations
request up to 8 KiB of content with `--max-page-output-bytes 7900`, which bounds
successful JSON stdout including escaping, commands and newline. Consume the inline
page before following next_command; when the retained-history limit is unknown,
Expand All @@ -280,7 +280,16 @@ their separate confirmed-input contract.

For native setup, `quota context-config --codex-app --goal-id GOAL --agent-id AGENT`
under machine on prepares only that private transport leaf and renders the
existing hooks and recovery instructions. For an SSH Goal, replace `--codex-app`
existing hooks, recovery instructions and `config_overrides`. Applying those overrides
selects 64000-byte continuation outputs and a 20000-token native history limit;
the initial guard remains within 7900 bytes. The worker applies this configuration
automatically inside its isolated opt-in trial. The persistent instruction requests
22000 tokens for each context-read tool result and 24000 for its code-mode emission,
forwarding one stdout at a time. Unknown or unsupported output declarations retain
the small-page default. Remove the generated output overrides together with the
context setup on rollback; saving a machine preference alone does not apply them.
This output sizing does not prove retained input, lower fees or task benefit.
For an SSH Goal, replace `--codex-app`
with `--runtime-profile codex_app_ssh_goal` in setup and the thin/bootstrap prompt.
Its generated guard keeps the native Goal identity and visible-Goal settlement;
it does not become a hosted heartbeat. It does not install or trust hooks,
Expand Down Expand Up @@ -473,11 +482,17 @@ SSH Goal 使用 `--runtime-profile codex_app_ssh_goal` 生成 context-config 和
沿用可见 Goal 的执行与结算身份;仅启用差分时接入捕获目录,不转换成自动心跳。
原生 `quota should-run` 与已保存捕获的 `context-project` 共用分页呈现,直接返回第零页、
固定摘要的后续读取与完整恢复,不另行准入。内联正文最多 3 KiB,必要时缩小,使包含
恢复字段与完整指引的 guard stdout 不超过 7900 UTF-8 字节;后续命令最多请求
恢复字段与完整指引的 guard stdout 不超过 7900 UTF-8 字节。未应用生成的原生输出配置时,后续命令最多请求
8 KiB 正文,并用 `--max-page-output-bytes 7900` 将成功 JSON stdout(含转义、
后续命令与换行)限制为 7900 字节。先消费内联页,再跟随 next_command;保留历史
上限未知时,每次只读一个有界输出。该上限不证明模型保留。Code Mode 直接转发
exec stdout;把整包重打进哈希工具不构成原始字节已被保留的证明。
原生配置同时返回 `config_overrides`:应用后,续读输出上限为 64000 字节,原生历史
上限为 20000 token,首次 guard 仍保持 7900 字节。开启的 benchmark worker 在其
隔离会话内自动应用;持久指引要求每次续读直接输出预算 22000 token、Code Mode
输出预算 24000 token,每次直接转发一份 stdout。未知或不支持的输出声明保持小页。
回滚时同时移除生成的输出覆盖项;仅保存机器偏好并不会应用这些宿主配置。
该设置不证明输入保留、总费用降低或任务效果改善。
读取器校验不可变 capture 的摘要。Post-tool 适配层复用显式输入观察的字节范围校验,
先将实际 UTF-8 正文与可信 journal 指向的物理捕获及固定摘要核对,再合并读取范围。
正文改变、文件丢失或替换、符号链接及摘要失败均不得晋升基线;保留原始恢复引用,
Expand Down Expand Up @@ -551,7 +566,7 @@ exact digest and Turn receipt; they never rerun admission or spend quota.
With delivery on, a successful saved projection also returns page zero using
the existing `context_capture_page_v1` fields. Its content is bounded to 3 KiB
and shrinks against the final presentation's 7900-byte stdout limit, including
recovery, activation and instruction metadata. Subsequent native commands request up to
recovery, activation and instruction metadata. Without the generated output profile, subsequent native commands request up to
8 KiB of content within a 7900-byte successful JSON stdout limit. The optional
JSON-only `--max-page-output-bytes` flag shrinks content at UTF-8 boundaries and
preserves the limit in `next_command`. An insufficient limit returns an error
Expand All @@ -567,7 +582,10 @@ Codex 0.162.1 qualification uses a 10,000-token history setting and a 12,000-tok
code-mode result budget with one directly forwarded stdout per call. Unknown
budgets keep the existing 7900-byte native default. A larger requested result
alone never proves history retention; missing output still needs same-capture
recovery. This changes no host setting automatically.
recovery. The reader flag changes no host setting. The shared native setup described
above supplies the larger 64000-byte profile and its matching history/execution
budgets together; only the opted-in worker applies them automatically. A legacy
consumer that has not applied that setup keeps the existing small-page boundary.
Consume `content`, then follow `next_command` through `eof` for full byte coverage.
The reader verifies the original digest; do not retype or hash the content. The
existing `command` still restarts at zero for older readers or incomplete inline
Expand All @@ -585,7 +603,7 @@ input retention.

开启时,成功的已保存投影同时用现有 `context_capture_page_v1` 字段返回第一页。
该页内容最多 3 KiB,按最终呈现的 7900 字节 stdout 上限缩小,包含恢复、启用配置与
完整指引元数据;后续原生命令最多请求 8 KiB
完整指引元数据;未应用生成的输出配置时,后续原生命令最多请求 8 KiB
正文,成功 JSON stdout 限制为 7900 字节。可选的 JSON 专用参数
`--max-page-output-bytes` 按 UTF-8 边界缩减正文,并在 `next_command` 中保留。
上限不足时返回错误,不返回无进展的分页;增大上限后重读同一捕获。省略该参数
Expand All @@ -595,7 +613,9 @@ input retention.
上限才能请求超过 8 KiB 的正文,最大仍受既有 capture 大小限制;上限包含转义、
JSON 外层与换行,后续命令继承该值。Codex 0.162.1 定向验证采用 10,000 token 历史
设置和 12,000 token code-mode 输出预算,每次直接转发一份 stdout。未知预算保持
7900 字节原生默认;大输出请求不证明历史保留,缺失仍恢复同一 capture,不自动修改宿主设置。
7900 字节原生默认;大输出请求不证明历史保留,缺失仍恢复同一 capture。
读取参数本身不修改宿主设置。上述共享原生配置将 64000 字节分页与配套的历史和执行
预算一起提供,仅开启的 worker 自动应用;尚未应用该配置的旧读取方保持小页边界。
先读取 `content`,再沿 `next_command` 读至 `eof`,确保完整字节覆盖。
读取器校验原始摘要;无需重抄正文或计算哈希。
原有 `command` 仍从零开始,供旧读取方或内联输出不完整时重读;可选的首屏读取
Expand Down
25 changes: 16 additions & 9 deletions loopx/cli_commands/quota_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from ..control_plane.quota.error_codes import QuotaCommandValidationError, QuotaDecisionTransportError
from ..control_plane.turn_driver.decision_capture import (
validate_handoff_socket, CONTEXT_CAPTURE_READ_GUIDANCE, CONTEXT_CAPTURE_PAGE_GUIDANCE, context_capture_read_command,
NATIVE_CONTEXT_PAGE_BYTES, NATIVE_CONTEXT_PAGE_OUTPUT_BYTES,
NATIVE_CONTEXT_PAGE_OUTPUT_BYTES,
native_context_page_budget,
read_context_capture_file as _read_capture,
)

Expand All @@ -35,7 +36,8 @@ def native_context_activation(args: argparse.Namespace) -> dict[str, Any]:
def _capture_page(path: Path, raw: bytes, digest: str, *, offset: int, size: int,
output_limit: int | None, instruction: bool,
presentation: dict[str, Any] | None = None,
next_page_bytes: int | None = None) -> dict[str, Any]:
next_page_bytes: int | None = None,
next_page_output_bytes: int | None = None) -> dict[str, Any]:
end = min(offset + size, len(raw))
while end < len(raw) and raw[end] & 0xC0 == 0x80:
end -= 1
Expand All @@ -50,7 +52,7 @@ def page(text: str) -> dict[str, Any]:
result["read_instruction"] = CONTEXT_CAPTURE_PAGE_GUIDANCE
if cursor < len(raw):
result["next_command"] = context_capture_read_command(path, digest, offset=cursor, page_bytes=next_page_bytes or size,
max_page_output_bytes=output_limit)
max_page_output_bytes=next_page_output_bytes or output_limit)
return result

def fits(result: dict[str, Any]) -> bool:
Expand Down Expand Up @@ -78,7 +80,8 @@ def fits(result: dict[str, Any]) -> bool:


def read_context_capture(args: argparse.Namespace, *, presentation: dict[str, Any] | None = None,
next_page_bytes: int | None = None) -> dict[str, Any]:
next_page_bytes: int | None = None,
next_page_output_bytes: int | None = None) -> dict[str, Any]:
"""Bounded local IO over immutable JSON, not a new context/authority owner.

Verify the complete byte digest on every page. The cursor addresses bytes
Expand Down Expand Up @@ -120,7 +123,8 @@ def read_context_capture(args: argparse.Namespace, *, presentation: dict[str, An
raise ValueError("capture offset is outside the file or not a UTF-8 boundary; use the returned next offset")
return _capture_page(path, raw, digest, offset=offset, size=size,
output_limit=output_limit, instruction=bool(context_dir),
presentation=presentation, next_page_bytes=next_page_bytes)
presentation=presentation, next_page_bytes=next_page_bytes,
next_page_output_bytes=next_page_output_bytes)
except (OSError, ValueError, RecursionError) as exc:
# Recovery is presentation-only: keep failures separate from quota's
# collection error path and retain the existing receipt/capture.
Expand All @@ -147,8 +151,9 @@ def native_context_capture_view(projected: dict[str, Any], directory: Path, *,
mode, target = projected["mode"], projected["target"]
if mode == "full":
reference = {key: projected["recovery"][key] for key in ("path", "sha256")}
page_bytes, output_bytes = native_context_page_budget()
reference["command"] = context_capture_read_command(Path(reference["path"]), reference["sha256"],
page_bytes=NATIVE_CONTEXT_PAGE_BYTES, max_page_output_bytes=NATIVE_CONTEXT_PAGE_OUTPUT_BYTES)
page_bytes=page_bytes, max_page_output_bytes=output_bytes)
result = {"ok": True, **(metadata or {}), "mode": mode, **reference,
**({"target": target} if target else {})}
# The codec puts native continuity semantics before its change tree. Keep
Expand All @@ -167,7 +172,7 @@ def native_context_capture_view(projected: dict[str, Any], directory: Path, *,
page = read_context_capture(argparse.Namespace(capture_file=reference["path"],
capture_sha256=reference["sha256"], offset=0, page_bytes=3072,
format="json", max_page_output_bytes=NATIVE_CONTEXT_PAGE_OUTPUT_BYTES),
presentation=result, next_page_bytes=NATIVE_CONTEXT_PAGE_BYTES)
presentation=result, next_page_bytes=page_bytes, next_page_output_bytes=output_bytes)
if page["ok"]:
result = page
from ..control_plane.turn_driver.codex_context import register_native_context_view
Expand Down Expand Up @@ -482,7 +487,7 @@ def handle_native_context_command(args: argparse.Namespace, *, print_payload: Ca
cli_argv=cli_argv, scenario=activation["scenario"], session_root=bool(getattr(args, "codex_context_root", None)),
inherit_machine=bool(machine_runtime))
payload = {"ok": True, "context_delivery": activation, "native_config": config,
"activation": "Merge hooks and append developer_instructions to the existing native configuration; "
"activation": "Apply config_overrides, merge hooks and append developer_instructions to the existing native configuration; "
"review and trust only these exact hooks in Codex. "
"Existing loaded threads may retain their original hook configuration; enabled/trusted "
"discovery is not session initialization or live adoption. Start/resume through the host "
Expand All @@ -492,7 +497,9 @@ def handle_native_context_command(args: argparse.Namespace, *, print_payload: Ca
"Pass --context-delivery on with the same declared host mode, context location and a decision-output-root to heartbeat-prompt/should-run. ")
+
"Normal completed full reads establish an explicit continuity assumption; no input diagnostics or provider change is required. "
"Known invalidation or incomplete reads keep full recovery. Set --context-delivery off and remove context options to restore ordinary output. "
"The generated output profile uses 64000-byte continuations and a 20000-token native history limit; "
"unknown budgets retain small pages. Known invalidation or incomplete reads keep full recovery. "
"Set --context-delivery off and remove the generated context configuration, including its output overrides, to restore ordinary output. "
"This command installs nothing and grants no execution authority."}
except (OSError, ValueError, TypeError) as exc:
payload = {"ok": False, "reason": str(exc)}
Expand Down
Loading
Loading