diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.md index 6e5521ac0a..1e90b643da 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.md @@ -419,6 +419,11 @@ contract explicitly requires their receipt. Batch best-effort telemetry only; do not defer authoritative receipt persistence, weaken fsync/transaction guarantees or cache stale permission/lease decisions to meet a timing target. +For an admitted ordinary task, the built-in Worker view omits known empty +Todo summary lanes. The selected task, nonempty lanes, counts, references and +upstream truncation remain visible. The signed source and original reader +retain the complete summaries for recovery and diagnosis. + ### Governed lifecycle and external effects Use existing Goal/Agent/work/Turn identities, revisions, leases, effect ids and diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md index 2303929af4..a9faf84a23 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md @@ -289,6 +289,10 @@ Capability 指令仅在适用时提供;authority 不能从 prompt 文字推导 其延迟不能进入准入/结算事务。只批处理尽力而为的 telemetry;不能为满足时间目标而延迟 authority receipt 持久化、弱化 fsync/事务保证,或缓存过期权限/租约决策。 +普通任务获准执行后,内置 Worker 视图省去已知为空的 Todo 摘要列表。所选任务、 +非空列表、计数、引用与来源截断信息继续可见。签名来源和原有读取入口保留完整摘要, +供恢复与诊断使用。 + ### 受治理生命周期与外部副作用 通过统一工作契约使用既有 Goal/Agent/work/Turn 身份、revision、lease、effect id 与 receipt。 diff --git a/docs/reference/protocols/loopx-turn-v0.md b/docs/reference/protocols/loopx-turn-v0.md index 4383bf6f21..0027a3b7c2 100644 --- a/docs/reference/protocols/loopx-turn-v0.md +++ b/docs/reference/protocols/loopx-turn-v0.md @@ -110,6 +110,11 @@ settlement or completion authority. Generic adapter stdin and private journal recovery retain the complete v1 source; historical envelope-only v0 inputs keep their renderer. +For admitted ordinary work, an omitted known Todo summary lane is empty. +Nonempty lanes, counts, references, upstream truncation and unknown fields +remain visible. Complete summaries are available through the original source +reader when needed. + 内置模型 renderer 在校验 adapter 请求中的完整来源后派生 `loopx_turn_model_context_v0`。`task_context` 保留任务事实、backlog、必需读取、 范围、执行要求和未知新增信息。来源绑定、effect projection、scheduler/automation @@ -121,6 +126,9 @@ their renderer. 缺少必需证据仍暂停依赖该证据的工作。此呈现不是 adapter 请求,也不授予权限、结算或 完成权。通用 adapter stdin 和私有 journal 恢复仍保留完整 v1 来源;仅携带 envelope 的历史 v0 输入保留原 renderer。 +对于获准执行的普通任务,视图可以省去已知为空的 Todo 摘要列表。非空列表、计数、 +引用、来源截断信息和未知字段继续可见。需要完整摘要时,使用原有来源读取入口。 + Use `loopx turn plan --include-transaction-detail --format markdown` to inspect `should_run`, the effective action, reason and selected work summary. Its **Full plan** JSON block retains the complete source contract, session and transaction diff --git a/loopx/control_plane/quota/diagnostic_projection.ts b/loopx/control_plane/quota/diagnostic_projection.ts index d21a989c9b..bc7af7cd58 100644 --- a/loopx/control_plane/quota/diagnostic_projection.ts +++ b/loopx/control_plane/quota/diagnostic_projection.ts @@ -173,6 +173,31 @@ const DIAGNOSTIC_LANES = new Set([ "other_agent_bound_user_action_items", ]); +/** A task view can imply the emptiness of known diagnostic lanes. Preserve all + * counts, rows, references and upstream truncation evidence in their own fields. */ +export function omitEmptyTaskTodoLanes(payload: JsonObject): JsonObject { + const result = {...payload}; + for (const root of ["agent_todo_summary", "user_todo_summary"]) { + const summary = jsonObject(payload[root]); + if (summary?.schema_version !== "todo_summary_v0") continue; + const compaction = jsonObject(summary.payload_compaction); + const compactedLanes = jsonObject(compaction?.compacted_lanes); + if (Object.hasOwn(summary, "payload_compaction") && + (compaction?.schema_version !== "quota_todo_summary_payload_compaction_v0" || !compactedLanes)) continue; + const references = new Set(Object.values(summary)); + const visible = {...summary}; + for (const lane of DIAGNOSTIC_LANES) { + const rows = summary[lane]; + if (Array.isArray(rows) && rows.length === 0 && !Object.hasOwn(compactedLanes ?? {}, lane) && + !references.has(`$.${root}.${lane}`)) { + delete visible[lane]; + } + } + result[root] = visible; + } + return result; +} + /** Complete contracts keep one literal copy of equal summary lanes. A reference * names an array in this same signed document, never a fresh Todo read. Only * registered lanes participate; counts, candidate collections and unknown fields diff --git a/loopx/control_plane/quota/turn_envelope.ts b/loopx/control_plane/quota/turn_envelope.ts index ea50115021..e642c5932c 100644 --- a/loopx/control_plane/quota/turn_envelope.ts +++ b/loopx/control_plane/quota/turn_envelope.ts @@ -15,7 +15,7 @@ import {omitUnboundExploreResultWriteback, referenceExploreResultWriteback} from import {prepareContextDelivery, restoreContextDelivery} from "./context_delivery.ts"; import {updateNativeContextLifecycle} from "./native_context_lifecycle.ts"; import {contextProjectionChanges, contextProjectionIdentity, contextProjectionRetainFields, - contextSourceIdentity, projectQuotaDiagnostics, referenceQuotaSummaryLanes, resolveQuotaSummaryLanes, + contextSourceIdentity, omitEmptyTaskTodoLanes, projectQuotaDiagnostics, referenceQuotaSummaryLanes, resolveQuotaSummaryLanes, type ProjectionSourceValues} from "./diagnostic_projection.ts"; import {referenceExploreResultDelivery} from "../capabilities/explore_result_writeback.ts"; import {completeCliSettlementChannel} from "./settlement_plan.ts"; @@ -1889,9 +1889,10 @@ function hostModelContextChanges(decision: JsonObject): JsonObject { context.replan_action_packet = {...packet, writeback_contract: replanAuthoringContract(decision)}; delete interaction.cli_channel; context.interaction_contract = interaction; - // Preserve backlog and all unknown facts: task requirements and references - // can depend on them even when a Todo is already selected. - return contextProjectionChanges(decision, context); + // The work is already selected. Keep every candidate and unknown fact, + // while omitting the empty diagnostic lanes of known Todo summaries. + const ordinary = decision.effective_action === EffectiveAction.NORMAL_RUN && decision.normal_delivery_allowed === true; + return contextProjectionChanges(decision, ordinary ? omitEmptyTaskTodoLanes(context) : context); } /** A current private plan stores its one admitted source and transport header. diff --git a/tests/control_plane/host_process_fixture.py b/tests/control_plane/host_process_fixture.py index e55e6dd868..36ca8c1c3a 100644 --- a/tests/control_plane/host_process_fixture.py +++ b/tests/control_plane/host_process_fixture.py @@ -17,6 +17,15 @@ def assert_host_task_context(model_input, source): assert model_input["source_schema_version"] == "loopx_turn_host_request_v1" assert not {"work_contract", "turn_envelope", "turn_authority"}.intersection(model_input) context = model_input["task_context"] + if source.get("effective_action") == "normal_run" and source.get("normal_delivery_allowed") is True: + source = dict(source) + for key in ("agent_todo_summary", "user_todo_summary"): + complete_summary, model_summary = source.get(key), context.get(key) + if not isinstance(complete_summary, dict) or not isinstance(model_summary, dict): + continue + omitted = complete_summary.keys() - model_summary.keys() + assert all(complete_summary[lane] == [] for lane in omitted), omitted + source[key] = {field: value for field, value in complete_summary.items() if field not in omitted} outer_fields = {"schema_version", "contract_binding", "projection_envelope", "scheduler_hint", "automation_cadence_readback", "automation_liveness", "scheduler_execution_context"} assert set(context) == set(source) - outer_fields diff --git a/tests/control_plane_ts/turn_envelope.test.ts b/tests/control_plane_ts/turn_envelope.test.ts index b60c8be8bd..64d16ff6cc 100644 --- a/tests/control_plane_ts/turn_envelope.test.ts +++ b/tests/control_plane_ts/turn_envelope.test.ts @@ -214,8 +214,18 @@ test("operation preflight optionally shares the existing normalized session line test("Host task presentation is source-checked and keeps task and backlog facts", () => { const source = payload(); + source.normal_delivery_allowed = true; 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.agent_todo_summary = { + schema_version: "todo_summary_v0", monitor_due_items: [], + backlog_items: [{todo_id: "later", text: "Required dependency."}], future_attention: [], + }; + source.user_todo_summary = { + schema_version: "todo_summary_v0", gate_open_items: [], + first_open_items: [{todo_id: "review", text: "Review the unpublished artifact."}], + payload_compaction: {schema_version: "quota_todo_summary_payload_compaction_v0", + compacted_lanes: {gate_open_items: {shown: 0, total: 3}}}, + }; const complete = evaluateTurnEnvelope({operation: "compose_complete", payload: source, scheduler_execution_args: ""}); const envelope = buildTurnEnvelope({payload: complete, scheduler_execution_args: ""}); const before = structuredClone(complete); @@ -235,7 +245,11 @@ test("Host task presentation is source-checked and keeps task and backlog facts" else parent[key] = edit.from ? at(complete, edit.from as (string | number)[]) : edit.value; } assert.deepEqual(view.future_task_data, complete.future_task_data); - assert.deepEqual(view.agent_todo_summary, complete.agent_todo_summary); + assert.deepEqual(view.agent_todo_summary, { + schema_version: "todo_summary_v0", + backlog_items: [{todo_id: "later", text: "Required dependency."}], future_attention: [], + }); + assert.deepEqual(view.user_todo_summary, complete.user_todo_summary); assert.deepEqual(view.goal_boundary, complete.goal_boundary); assert.deepEqual((view.interaction_contract as JsonObject).agent_channel, (complete.interaction_contract as JsonObject).agent_channel); @@ -248,6 +262,18 @@ test("Host task presentation is source-checked and keeps task and backlog facts" assert.throws(() => evaluateTurnEnvelope({...request, payload: {...complete, reason: "tampered"}, include_model_context: true}), /integrity mismatch/); } + for (const variant of [ + {...source, normal_delivery_allowed: false}, + {...source, agent_todo_summary: {...source.agent_todo_summary as JsonObject, schema_version: "future_summary"}}, + {...source, agent_todo_summary: {...source.agent_todo_summary as JsonObject, + payload_compaction: {schema_version: "future_compaction", compacted_lanes: {}}}}, + ]) { + const captured = evaluateTurnEnvelope({operation: "compose_complete", payload: variant, scheduler_execution_args: ""}); + const checked = evaluateTurnEnvelope({operation: "host_context", payload: captured, include_model_context: true, + complete_host_request: {schema_version: "loopx_turn_host_request_v1", turn_key: `sha256:${"b".repeat(64)}`}}); + const edits = (checked.model_context_changes as JsonObject).changes as JsonObject[]; + assert.equal(edits.some(edit => (edit.path as string[])[0] === "agent_todo_summary"), false); + } assert.deepEqual(complete, before); }); diff --git a/tests/test_core_distribution.py b/tests/test_core_distribution.py index f39fae8197..c3e15597a4 100644 --- a/tests/test_core_distribution.py +++ b/tests/test_core_distribution.py @@ -708,7 +708,11 @@ def test_installed_core_codex_prepares_only_an_admitted_valid_request(core_pytho 'pathlib.Path("squares.json").write_text(json.dumps([n*n for n in range(8)]))\noutput_path = ')) home = tmp_path / "codex-home" home.mkdir() - environment = {"FAKE_CODEX_LOG": str(log), "CODEX_HOME": str(home)} + prompt_path = tmp_path / "worker-prompt.txt" + environment = { + "FAKE_CODEX_LOG": str(log), "CODEX_HOME": str(home), + "FAKE_CODEX_PROMPT_CAPTURE": str(prompt_path), + } command = [*prefix, "turn", "run-once", "--host", "codex-cli", "--goal-id", GOAL, "--agent-id", AGENT, "--todo-id", todo_id, "--project", str(workspace), "--codex-bin", str(binary), "--codex-model", "fixture-model", "--codex-reasoning-effort", "high", @@ -730,5 +734,19 @@ def test_installed_core_codex_prepares_only_an_admitted_valid_request(core_pytho replay = json.loads(_run(core_python, [*resume_command, "--resume-turn-key", result["resume_turn_key"], "--validation-command-json", json.dumps([core_python, "-I", "-c", VALIDATOR_SOURCE])], workspace, environment=environment).stdout) + model_input = json.loads(prompt_path.read_text(encoding="utf-8").split("Turn request:\n", 1)[1]) + capture = Path(model_input["detail_ref"]["captured_decision"]["path"]) + original = json.loads(capture.read_text(encoding="utf-8")) + context = model_input["task_context"] + assert original["agent_todo_summary"]["monitor_due_items"] == [] + assert original["user_todo_summary"]["gate_open_items"] == [] + assert "monitor_due_items" not in context["agent_todo_summary"] + assert "gate_open_items" not in context["user_todo_summary"] + assert ( + context["agent_todo_summary"]["first_executable_items"] + == original["agent_todo_summary"]["first_executable_items"] + ) + assert context["user_todo_summary"]["work_counts"] == original["user_todo_summary"]["work_counts"] + assert model_input["source_decision_hash"] == original["contract_binding"]["content_hash"] 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 diff --git a/tests/test_loopx_turn_codex_cli.py b/tests/test_loopx_turn_codex_cli.py index e6da11588f..a48b608bdc 100644 --- a/tests/test_loopx_turn_codex_cli.py +++ b/tests/test_loopx_turn_codex_cli.py @@ -138,6 +138,8 @@ def _fake_codex(tmp_path: Path) -> tuple[Path, Path]: args = sys.argv[1:] prompt = sys.stdin.read() +if os.environ.get("FAKE_CODEX_PROMPT_CAPTURE"): + pathlib.Path(os.environ["FAKE_CODEX_PROMPT_CAPTURE"]).write_text(prompt, encoding="utf-8") log = pathlib.Path(os.environ["FAKE_CODEX_LOG"]) with log.open("a", encoding="utf-8") as handle: handle.write(json.dumps(args) + "\\n")