Skip to content
Open
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
39 changes: 24 additions & 15 deletions docs/reference/required-work-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,21 +418,30 @@ After a Host claim, the ready guard uses the private
returns its writer digest with the fields needed to verify the same Todo and
Turn. The hook verifies that digest when it opens the original file. If the
file changed, the receipt preserves the claim and pins recovery to the original
bytes before work can continue. If readiness is interrupted, retrying the
same original decision capture reuses its managed claim operation. The
authority owner checks the original lease on replay. The native session
keeps the latest eligible live guard digest separately from the capture.
Presenting the exact saved decision preserves that binding. Older captures
and copies with different bytes remain readable. Preserve any original claim receipt and use
`quota should-run` with the same Goal, Agent, Todo and Turn and a fresh
capture if preparation is still required. A retired lease requires a fresh
eligible preparation capture.

中文:Host 重试绑定原始决策 capture 的领取操作,由权威 owner 验证原租约。
原生会话独立保存最新合格准入的摘要。重新展示逐字节一致的快照会保留绑定。
旧快照和字节不同的副本仍可读,保留已有领取回执。
仍需准备时,用原 Goal、Agent、Todo 和 Turn 运行 `quota should-run`,
生成新的 capture,再按当前准入结果准备。已退役的租约需要新的合格 capture。
bytes before work can continue.
The private native journal reserves automatic preparation before claiming a
bound capture and records the verified ready capture before projecting it. If
readiness or hook delivery is interrupted, the hook repeatably surfaces
readback for the original claim receipt, current lease and any verified ready
capture until delivery is confirmed, without repeating the claim or guard.
Follow the captured readiness check for the same Todo and Turn once the active
lease matches. An authorized retry of the same bound capture reuses its
managed claim operation, and the authority owner checks the original lease on
replay. The native session keeps the latest eligible live guard digest
separately from the capture. Presenting the exact saved decision preserves
that binding. Older captures and copies with different bytes remain readable.
Preserve any original claim receipt and use `quota should-run` with the same
Goal, Agent, Todo and Turn and a fresh capture if preparation is still
required. A retired lease requires a fresh eligible preparation capture.

中文:私有原生日志在对绑定 capture 发起领取前先登记自动准备,并在投影前记录已校验的
ready capture。若就绪检查或 Hook 送达中断,Hook 在确认送达前可重复提供原领取回执、
当前租约及已校验 ready capture 的回读入口,不再重复自动领取或准入。活动租约匹配后,
沿同一 Todo 与 Turn 完成就绪检查。对同一绑定 capture 的授权重试复用原受管领取操作,
由权威 owner 验证原租约。原生会话独立保存最新合格准入的摘要,重新展示逐字节一致的
快照会保留绑定。旧快照和字节不同的副本仍可读,保留已有领取回执。仍需准备时,用原
Goal、Agent、Todo 和 Turn 运行 `quota should-run`,生成新的 capture,再按当前准入
结果准备。已退役的租约需要新的合格 capture。

The Goal availability adapter still reads and UTF-8-validates the complete file
and hashes all bytes for its revision. With native context delivery off, only the path and revision of unmarked or mixed sources cross the
Expand Down
37 changes: 26 additions & 11 deletions loopx/cli_commands/quota_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def project_saved_context_capture(args: argparse.Namespace, *, hook_session: str
continuity_generation=getattr(args, "_context_delivery_generation", None),
progressive_enabled=activation["progressive_enabled"], selection_command_args_template=transport,
captured_decision_path=str(path) if args.initial_read and activation["progressive_enabled"] else None,
hook_session=hook_session)
hook_session=hook_session, saved_capture=True)
projected = prepared.delivery
initial_read_plan = prepared.initial_read_plan
native_prepared = True
Expand Down Expand Up @@ -939,11 +939,12 @@ def handle_native_context_command(args: argparse.Namespace, *, print_payload: Ca
from ..control_plane.turn_driver.codex_context import (
CONTEXT_LIFECYCLE_HOOKS, codex_context_directory, codex_context_hook,
native_context_event_eligible, native_execution_preparation_request,
record_native_execution_preparation,
record_native_execution_preparation, record_native_execution_preparation_delivered,
)
from ..control_plane.turn_driver.codex_execution_preparation import (
LegacyNativePreparationCapture,
codex_execution_preparation_context,
codex_execution_preparation_readback_context,
execute_codex_execution_preparation,
)

Expand All @@ -961,14 +962,18 @@ def handle_native_context_command(args: argparse.Namespace, *, print_payload: Ca
directory = codex_context_directory(directory=args.codex_context_dir,
root=getattr(args, "codex_context_root", None), session=event.get("session_id"), create=True)
payload = codex_context_hook(directory, event)
request = None
preparation_context = ""
try:
request = native_execution_preparation_request(directory, event)
workspace = Path(event.get("cwd") or "")
if workspace.is_absolute() and workspace.resolve() == Path.cwd().resolve():
request = native_execution_preparation_request(directory, event)
if request is not None:
workspace = Path(event.get("cwd") or "")
if workspace.is_absolute() and workspace.resolve() == Path.cwd().resolve():
if "claim_source_sha256" not in request:
raise LegacyNativePreparationCapture()
if "claim_source_sha256" not in request:
raise LegacyNativePreparationCapture()
if request.get("readback_only") is True:
preparation_context = codex_execution_preparation_readback_context(request) or ""
else:
capture = (
Path(tempfile.mkdtemp(prefix="prepared-", dir=directory)) / "ready"
if request.get("turn_instance_id") else None
Expand All @@ -995,6 +1000,7 @@ def handle_native_context_command(args: argparse.Namespace, *, print_payload: Ca
# pinned full recovery even if native projection
# fails. It never rereads authority or admits work.
digest = receipt.pop("capture_sha256")
receipt.pop("capture_path", None)
receipt["context"] = project_saved_context_capture(argparse.Namespace(**{
**vars(args), "quota_command": "context-project",
"capture_file": str(source),
Expand All @@ -1008,13 +1014,22 @@ def handle_native_context_command(args: argparse.Namespace, *, print_payload: Ca
receipt["context"]["recovery_command"] = context_capture_read_command(
source, digest, reader_argv=current_loopx_cli_argv())
preparation_context = codex_execution_preparation_context(receipt)
record_native_execution_preparation_delivered(
directory,
event,
source_sha256=request["source_sha256"],
)
except LegacyNativePreparationCapture as error:
preparation_context = str(error)
except (OSError, RuntimeError, subprocess.SubprocessError, ValueError, TypeError, RecursionError):
# Preserve the original explicit action and any context
# recovery output when Host-side preparation cannot prove
# its postcondition.
pass
# Reconcile only the attempted source. A concurrent guard
# can replace recovery, so it must never be reserved here.
if request is not None and request.get("turn_instance_id"):
readback = native_execution_preparation_request(
directory, event, readback_for=request["source_sha256"],
)
if readback is not None:
preparation_context = codex_execution_preparation_readback_context(readback) or ""
if preparation_context:
existing = payload.get("hookSpecificOutput")
existing_context = str(existing.get("additionalContext") or "") if isinstance(existing, dict) else ""
Expand Down
Loading
Loading