# Offline treatment planner-response validation Version 1.0. **Development tooling; defaults are unfrozen.** Tests use temporary artificial assembly/response fixtures, not model outputs or study observations. The validator stages proposals only: it never delivers an instruction, schedules another turn, replaces live memory, or calls a model. A structural pass is not permission or evidence of improvement. ## Usage and outputs Python 3.9+ and the standard library are sufficient. Copy [response-validation.template.json](response-validation.template.json) and supply the exact assembled-input file/hash, raw response file/hash, bounds, and token-count attestations: ```sh python3 -B validate_planner_response.py --manifest /coordinator/response-validation.json \ --staging-dir /staging/new-proposed-handoff \ --validation-dir /coordinator/new-validation-record ``` Paths in the manifest resolve relative to it, or may be absolute. The two output directories must be new, disjoint, and have existing parents. Existing destinations, including symlinks, are refused. Exit 2 reports a validation/I/O error on stderr; it does not repair, strip prose, truncate, merge, or retry a response. Exit 0 creates: - Staging `next-prompt.txt`: the **exact decoded `next_prompt` UTF-8 bytes**, including supplied leading/trailing whitespace and newlines; no JSON quotes or added newline. - Staging `proposed-memory.json`: the canonical serialized **full replacement array**, not a patch, append operation, or live-state update. `[]` is a valid empty replacement proposal. - Separate coordinator `validation-record.json`: the assembled-input, raw-response and manifest hashes; bounds/attestations; staged-file paths/hashes; and explicit limits on what was checked. It contains an optional-use `next_assembly_memory_descriptor` in the assembler's existing shape, pointing only at the staged proposal. It does not authorize copying that proposal into a live store. All input files remain unchanged. Preflight rejection creates no staging directories. An I/O failure can leave partial new output; use results only after exit 0 and a complete validation record matching both staged hashes. Retry with fresh paths. No operational record is appended to the directive. Folder separation does not enforce confidentiality. Do not pass the whole staging/audit directory to a worker or treat the validation record as model-facing context. ## Input binding and unchanged contract The manifest has exactly `validation_manifest_version` (`"1.0"`), `validation_id`, `assembled_input`, `planner_response`, `bounds`, and `token_attestations`. File descriptors have exactly `path` and lowercase `sha256`. `validation_id` is coordinator-only. Both expected hashes must match the exact file bytes before a response can pass. The validation record binds this particular raw response to this particular input; it does **not** prove the response was actually generated from that input or establish model authorship. The validator recovers the five canonical JSON blocks produced by the [assembler](README.md), then reconstructs and hash-checks the unchanged matched-template wrapper. Modified principles/output instructions, extra surrounding input text, noncanonical blocks, unresolved markers, or malformed input objects are rejected. It reuses the assembler's public task/source identifier parser, strict JSON parser, canonical serializer, and shared evidence/typed-memory checks. Those checks were factored into public helper functions without changing the assembler's rendering or validation behavior; its original regression tests remain included. Only the supplied assembled prompt and raw response are read, alongside the validation manifest. Original task files, instruction files, memory stores, assembly audit records, assessor material, and external identifier catalogs are not reopened. The public packet's task-ID heading and Rn/Sn conventions remain those of the completed task assets. Chronology and original file provenance are not independently reconstructed from a prompt that intentionally omits such metadata. The raw response must be a single JSON object with **exactly** `observed_gap`, `evidence`, `uncertainty`, `next_prompt`, and `memory`. JSON whitespace outside the object is allowed; prose, code fences, trailing objects, duplicate keys at any depth, unknown fields and missing fields are rejected. `observed_gap` and `uncertainty` are strings; `next_prompt` is a non-whitespace string. Its text is not stripped during export. An empty uncertainty string is allowed; no hidden semantic criterion is added. `evidence` is an array of objects, each with exactly one of `artifact_id`, `source_id`, or `requirement_id` and a nonempty `location` string. IDs must belong to the supplied current/earlier artifacts or public Rn/Sn definitions. The top-level array may be empty because the unchanged output contract specifies an array without a minimum count; this is not a semantic judgment that an uncited change is justified. Instruction IDs, memory IDs, and invented artifact IDs are not evidence sources. `memory` is the existing typed array: entries have exactly `id`, `kind`, `statement`, `evidence`, and `status`; kinds are `observation` or `provisional_tactic`, statuses `current`, `unresolved`, or `superseded`. Statements and memory evidence arrays are nonempty. Proposed IDs are unique and cannot collide with task/source/artifact/instruction identities. IDs from previous memory can be retained in the replacement; omitted entries are not silently restored. Every memory reference must resolve within the supplied identifier set. JSON patch objects, untyped strings, extra scoring fields, and unsupported references are rejected. ## Bounds and token-count attestations The blank manifest supplies reversible development defaults: 2 MiB assembled input, 64 KiB raw response, 32 KiB decoded directive, 32 KiB canonical memory, 32 memory entries, and 64 references **per evidence array**. Memory-entry limits also apply when checking the supplied input memory. Excesses are rejected without truncation. Token allowances can be lowered but cannot exceed the unchanged **800-token `next_prompt` / 1,200-token memory** contract. These are not a complete request-cost budget or model-context guarantee. Both `token_attestations.next_prompt` and `.memory` are mandatory, even for empty proposed memory. Each has exactly `tokenizer`, `sha256`, and `token_count` (positive integer within its cap; booleans/floats are invalid). Hash/count targets are: - **next_prompt:** exact decoded string's UTF-8 bytes, including whitespace; count the standalone directive with the intended tokenizer. - **memory:** UTF-8 bytes from the assembler's `canonical(memory)` helper: sorted keys, compact separators, `ensure_ascii=False`, no trailing newline; count the serialized JSON value including array/record syntax. Use the intended tokenizer outside this standard-library tool without model execution, then bind the count to that exact value hash. Different worker/planner tokenizers may be declared explicitly. The validator checks the declared count's type/cap and hash binding; it **cannot verify tokenizer counts**, tokenizer identity, or context-dependent accounting. No whitespace word count is substituted for tokenization. Raw response hashing is separate from these value hashes, so JSON formatting does not redefine the exported directive or canonical memory. ## Limits and focused checks Identifier membership and a nonempty location string do not establish that the location exists or supports the claim. Structural checks cannot verify semantic support, distinguish observations from invented explanations, or detect restricted requests embedded in otherwise valid text. The validator deliberately supplies no keyword-based permission gate, external score, or hidden semantic evaluator. The record marks tokenizer/semantic/restricted-request verification false. A staged proposal still requires the study's separately specified boundary/enforcement procedure; success never certifies a safe or substantively compliant worker instruction. ```sh python3 -B -m unittest -v test_validate_planner_response.py test_assemble_observation.py ``` Tests cover exact decoded directive preservation, canonical replacement memory, input/response hashes, no live-state changes, old-ID reuse/empty proposals, schema/types, duplicate keys and surrounding prose, unsupported evidence, excess bounds, attestations, modified wrappers, missing original assembly sources, output refusal, and the unchanged assembler behavior. Fixtures are temporary and deleted. No task answers, actual study inputs, model calls, experiments, credits, production changes, or submissions are generated.