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
11 changes: 11 additions & 0 deletions docs/reference/protocols/loopx-turn-v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ For ordinary admitted work, matching recognized ready lease preparations stay
with the launcher and settlement reader. The Worker retains the admitted task,
scope, required reads and validation conditions. Unready, differing and
extended preparations stay in the task view.
For `steering_audit_then_one_step`, the built-in prompt asks the Worker to
check direction, then choose the largest coherent work segment it can reliably
complete and verify given its capabilities, budget, admitted task, scope and
execution profile. A Todo groups related steps toward one verifiable outcome;
`one_step` is a work segment, not a single operation. The standard mixed
accounting clause stays with the executor. Unrecognized policy text stays in
the task view because it can carry additional constraints.
The model receives the original `source_decision_hash`, reader references and
`source_schema_version`; that hash commits the original source, not the task
view. Inline task context does not require a filesystem read of a private
Expand All @@ -137,6 +144,10 @@ Goal、Agent 和停用状态。已知的空观察
两种已登记格式的字段表由 canonical Todo 读取入口提供,未知格式保留其元数据。
普通任务准入后,完全一致且可识别的就绪租约记录留在启动和结算入口。Worker 保留已准入
任务、范围、必需读取与验证条件。未就绪、有差异或带扩展字段的记录继续交付给 Worker。
在 `steering_audit_then_one_step` 模式下,内置提示要求 Worker 先核对方向,再按
自身能力、预算、已准入任务、范围和执行要求,选择能可靠完成并验证的最大连贯工作段。
同一可验证结果的相关操作归在一个 Todo;`one_step` 指一个工作段。标准的混合扣额条款
留在执行器,无法识别的策略原文继续交付给 Worker,因为它可能带有额外约束。
模型仍收到原始
`source_decision_hash`、reader 引用和 `source_schema_version`;该 hash 绑定原始
来源,不绑定任务视图。已内联的任务上下文不要求 sandbox 读取不可访问的私有 capture,
Expand Down
7 changes: 5 additions & 2 deletions loopx/control_plane/quota/turn_envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1932,10 +1932,13 @@ function hostModelContextChanges(decision: JsonObject): JsonObject {
else delete context.todo_write_hint;
}
const heartbeat = object(decision.heartbeat_recommendation);
// Other modes can include read, repair or wait conditions inside spend_policy.
// Only the standard legacy rule has a known split: accounting stays with
// settlement, and the built-in renderers explain the work segment. Keep
// unfamiliar text intact; it can carry additional execution conditions.
if (decision.normal_delivery_allowed === true &&
heartbeat.recommended_mode === "steering_audit_then_one_step" &&
typeof heartbeat.spend_policy === "string") {
heartbeat.spend_policy === "append exactly one heartbeat spend only after scope-bounded work " +
"is validated and written back; one_step: mode, not an operation limit") {
delete heartbeat.spend_policy;
context.heartbeat_recommendation = heartbeat;
}
Expand Down
9 changes: 8 additions & 1 deletion loopx/control_plane/turn_driver/codex_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,15 @@ def _render_prompt(request: Mapping[str, Any], *, checked: Mapping[str, Any] | N
'completed_phases must be exactly ["host_execute","typed_result"], and turn_key must match the request.',
]
if complete:
from .host_candidate import TURN_EXECUTION_BOUNDARY_RULE, goal_acceptance_prompt_instruction
from .host_candidate import (
TURN_EXECUTION_BOUNDARY_RULE,
goal_acceptance_prompt_instruction,
ordinary_work_segment_instruction,
)

work_segment = ordinary_work_segment_instruction(model_request)
if work_segment:
instructions.insert(2, work_segment)
instructions.insert(2,
"Read the supplied task_context before dependent work. "
"The host has validated the complete original observation and derived this task view. "
Expand Down
18 changes: 18 additions & 0 deletions loopx/control_plane/turn_driver/host_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,20 @@ def goal_acceptance_prompt_instruction(authority: Mapping[str, Any]) -> str:
return GOAL_ACCEPTANCE_READ_RULE if authority.get("vision_continuation_audit") else ""


def ordinary_work_segment_instruction(model_input: Mapping[str, Any]) -> str:
task = _mapping(model_input.get("task_context"))
heartbeat = _mapping(task.get("heartbeat_recommendation"))
if task.get("normal_delivery_allowed") is not True or heartbeat.get("recommended_mode") != "steering_audit_then_one_step":
return ""
return (
"Check the direction first. one_step means one work segment, not one operation. "
"Within the admitted task, execution_profile, permissions and available budget, "
"prefer the largest coherent work segment you can reliably complete and verify with your capabilities. "
"Keep related steps toward the same verifiable outcome in one Todo. "
"Split work at independent outcomes or necessary dependency, approval or validation boundaries."
)


def render_prompt(authority: Mapping[str, Any], *, allow_completion: bool = False) -> str:
"""Wrap one signed Turn authority packet in a typed JSON result request.

Expand All @@ -330,6 +344,9 @@ def render_prompt(authority: Mapping[str, Any], *, allow_completion: bool = Fals
)
if model_input is not None:
detail = _mapping(model_input.get("detail_ref"))
work_segment = ordinary_work_segment_instruction(model_input)
if work_segment:
work_segment += "\n"
input_prompt = (
"You are executing one bounded LoopX-governed work segment.\n"
"Use task_context for the admitted work. The outer executor retains "
Expand All @@ -347,6 +364,7 @@ def render_prompt(authority: Mapping[str, Any], *, allow_completion: bool = Fals
"The selected Todo summary is not its full requirements, and Todo "
"completion cannot close the Goal. Use execution_profile to size and "
"qualify work, including artifact, validation, outcome and degradation rules.\n"
f"{work_segment}"
"For required additional detail, use detail_ref.full_decision from the "
"saved original observation identified by detail_ref.captured_decision; "
"verify Goal/Agent/Turn and source_decision_hash. Never re-enter admission "
Expand Down
5 changes: 4 additions & 1 deletion tests/control_plane/host_process_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def assert_host_task_context(model_input, source):
heartbeat = expected.get("heartbeat_recommendation")
if (source.get("normal_delivery_allowed") is True and isinstance(heartbeat, dict)
and heartbeat.get("recommended_mode") == "steering_audit_then_one_step"
and isinstance(heartbeat.get("spend_policy"), str)):
and heartbeat.get("spend_policy") == (
"append exactly one heartbeat spend only after scope-bounded work "
"is validated and written back; one_step: mode, not an operation limit"
)):
expected["heartbeat_recommendation"] = {k: v for k, v in heartbeat.items() if k != "spend_policy"}
observations = expected.get("turn_start_capability_hook_dispatch")
rendered_observations = context.get("turn_start_capability_hook_dispatch")
Expand Down
5 changes: 5 additions & 0 deletions tests/control_plane_ts/turn_envelope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ test("Host task presentation is source-checked and keeps task and backlog facts"
const source = payload();
source.future_task_data = {instructions: "Preserve the final stop. ".repeat(200), value: -0};
source.agent_todo_summary = {backlog_items: [{todo_id: "later", text: "Required dependency."}]};
source.normal_delivery_allowed = true;
source.heartbeat_recommendation = {recommended_mode: "steering_audit_then_one_step",
spend_policy: "append exactly one heartbeat spend only after scope-bounded work " +
"is validated and written back; one_step: mode, not an operation limit; stop after the readback"};
const complete = evaluateTurnEnvelope({operation: "compose_complete", payload: source, scheduler_execution_args: ""});
const envelope = buildTurnEnvelope({payload: complete, scheduler_execution_args: ""});
const before = structuredClone(complete);
Expand All @@ -238,6 +242,7 @@ test("Host task presentation is source-checked and keeps task and backlog facts"
}
assert.deepEqual(view.future_task_data, complete.future_task_data);
assert.deepEqual(view.agent_todo_summary, complete.agent_todo_summary);
assert.deepEqual(view.heartbeat_recommendation, source.heartbeat_recommendation);
assert.deepEqual(view.goal_boundary, complete.goal_boundary);
assert.deepEqual((view.interaction_contract as JsonObject).agent_channel,
(complete.interaction_contract as JsonObject).agent_channel);
Expand Down
24 changes: 19 additions & 5 deletions tests/test_core_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,7 @@ def test_installed_core_codex_prepares_only_an_admitted_valid_request(core_pytho
"--expected-version", str(lease["version"])], workspace)
binary, log = _fake_codex(tmp_path)
binary.write_text(binary.read_text().replace("prompt = sys.stdin.read()",
'prompt = sys.stdin.read()\npathlib.Path("worker-context.json").write_text('
'prompt.split("Turn request:\\n", 1)[1], encoding="utf-8")'
'prompt = sys.stdin.read()\npathlib.Path("worker-prompt.txt").write_text(prompt, encoding="utf-8")'
).replace('output_path = ',
'pathlib.Path("squares.json").write_text(json.dumps([n*n for n in range(8)]))\noutput_path = '))
home = tmp_path / "codex-home"
Expand All @@ -728,12 +727,25 @@ def test_installed_core_codex_prepares_only_an_admitted_valid_request(core_pytho
workspace, environment=environment).stdout)
assert result["status"] == "committed" and result["validation"]["status"] == "passed", result
assert json.loads((workspace / "squares.json").read_text()) == [0, 1, 4, 9, 16, 25, 36, 49]
model_input = json.loads((workspace / "worker-context.json").read_text(encoding="utf-8"))
prompt = (workspace / "worker-prompt.txt").read_text(encoding="utf-8")
instructions, task_context_json = prompt.split("Turn request:\n", 1)
assert "one_step means one work segment, not one operation" in instructions
assert "largest coherent work segment you can reliably complete and verify with your capabilities" in instructions
assert "same verifiable outcome in one Todo" in instructions
assert "dependency, approval or validation boundaries" in instructions
model_input = json.loads(task_context_json)
capture = Path(model_input["detail_ref"]["captured_decision"]["path"])
original = json.loads(capture.read_text(encoding="utf-8"))
assert original["todo_write_hint"]["agent_todo_command_template"].startswith("loopx todo add")
for field in ("agent_todo_command_template", "user_action_command_template", "user_gate_command_template"):
command_template = original["todo_write_hint"][field]
assert command_template.startswith("loopx todo add")
assert command_template not in prompt
assert original["promotion_readiness_warning"]["requires_readiness_run"] is True
assert "spend_policy" in original["heartbeat_recommendation"]
spend_policy = original["heartbeat_recommendation"]["spend_policy"]
assert "append exactly one heartbeat spend" in spend_policy
assert "one_step: mode, not an operation limit" in spend_policy
assert "append exactly one heartbeat spend" not in prompt
captured_bytes = capture.read_bytes()
assert original["execution_preparation"]["lease_proof"]["expected_version"] > 0
assert original["interaction_contract"]["cli_channel"]["execution_preparation"] == original["execution_preparation"]
model_task = model_input["task_context"]
Expand All @@ -743,6 +755,7 @@ def test_installed_core_codex_prepares_only_an_admitted_valid_request(core_pytho
context = assert_host_task_context(model_input, original)
assert "todo_write_hint" not in context
assert "spend_policy" not in context["heartbeat_recommendation"]
assert context["execution_profile"] == original["execution_profile"]
users = context["interaction_contract"]["agent_channel"]["work_context"]["user_todos"]
model_proof = users["authority_read"]["todo_read_model"]
assert model_proof["schema_version"] == "loopx_todo_domain_read_record_v0"
Expand All @@ -758,3 +771,4 @@ def test_installed_core_codex_prepares_only_an_admitted_valid_request(core_pytho
workspace, environment=environment).stdout)
assert replay["replayed"] is True and all(value is False for value in replay["effects"].values())
assert len(log.read_text().splitlines()) == 1 and _spends(runtime) == 1
assert capture.read_bytes() == captured_bytes
Loading