Repository navigation
feat(runtime): typed final output contract for qq run (HC3) - #33
Merged
Merged
Conversation
Add OutputContract on SubmitPrompt, FinalOutput on RunFinished and RunSnapshot, and their bounds; bump PROTOCOL_VERSION to 19. Add the bounded qq-core output module: a reference-free JSON Schema subset compiled once per run with byte, depth, value, and repair-turn ceilings, and a validator whose error payloads are bounded to 8 KiB. Slice: HC3
…ith bounded repair turns (HC3) Store schema 27 adds runs.output_contract_json and runs.final_output_json. SubmitPrompt.output is compiled at admission (an unenforceable schema is InvalidOutputContract, not a run failure), persisted with the run row, recompiled at claim so a restart enforces the accepted contract, and carried into the run loop. At the completion boundary — after audit and steering — the answer is validated; a failure within the contract's repair allowance pushes the bounded errors as a runtime notice and continues; otherwise Completed carries the FinalOutput verdict, which settle_run writes with the outcome and publishes on RunFinished. Repair turns share the ordinary turn budget; exhaustion publishes no verdict. Slice: HC3
The schema file is read (bounded to the ceiling plus one byte) and compiled in prepare_headless before configuration loads, so every defect is invalid_configuration (exit 2) naming the path. The contract rides SubmitPrompt; the trial record gains output_schema_sha256 and output_repair_turns; the outcome record gains final_output. A completed run whose answer never validated exits 1 (task_failed) with the typed verdict; text format prints the validated document instead of the raw answer. PROTOCOL_VERSION 19 goldens under fixtures/v19, v18 retained decode-only; LimitCapabilities advertises the schema and repair bounds. Slice: HC3
…ure, plan, and ledger updates Slice: HC3
lg2m
added a commit
that referenced
this pull request
Sep 14, 2026
…lden streams (HC4) (#34) * docs(ledger): start HC4, close HC3 (#33), reserve ADR-0023 Slice: HC4 * feat(protocol): headless JSONL record types shared by qq run (HC4) HeadlessRecord/HeadlessTrial/HeadlessOutcome/HeadlessStatus/HeadlessApproval move into qq-protocol so the trial-stream shapes are protocol vocabulary a consumer can decode strictly. The binary emits through the borrowing HeadlessRecordRef; encodings are unchanged. Slice: HC4 * test(protocol): golden qq run JSONL streams per PROTOCOL_VERSION (HC4) tests/fixtures/headless/v19/: ten complete trial streams covering every exit status, the default payload, every optional trial field, and both final_output verdicts; byte-for-byte checked and framing-validated. v18/ holds the same default-path streams re-pinned to 18, decode-only, which is the compatibility statement: additive fields, older streams still decode. The headless tests now decode every stdout line as a strict HeadlessRecord and require it to re-encode identically. Slice: HC4 * docs(hc4): ADR-0023 headless records as protocol; contract, protocol, architecture, plan, and ledger updates Slice: HC4 * docs(ledger): link HC4 PR #34
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HC3: typed final output for
qq runSpec: docs/plans/speed-first-extensible-agent-harness.md#phase-5b--headless-contract-for-supervisors · docs/design/headless-contract.md (gap row "Typed final output") · ADR: docs/adr/0014-typed-final-output.md
What changed
qq run --output-schema PATH [--output-repair-turns N](N 0–8, default 2, requires the schema). The file is read (bounded to the 64 KiB ceiling + 1) and compiled inprepare_headlessbefore configuration loads; unreadable, oversized, malformed,$ref-bearing, or unsupported-keyword schemas exit2naming the path. Text format prints the pretty-printed validated document instead of the raw answer.SubmitPrompt.output: Option<Box<OutputContract>>;RunFinished.final_outputandRunSnapshot.final_output: Option<Box<FinalOutput>>(valid { value, repair_turns }|invalid { errors, repair_turns });LimitCapabilitiesdeclares the four bounds. All optional and omitted when absent; every default-path v18 golden is byte-identical to v19 apart from the version field (capabilitiesgains the four bounds).v19/goldens added (+3 new fixtures);v17/,v18/retained decode-only.qq_core::output: a closed JSON Schema subset (type,enum,const,properties,required,additionalProperties,items, length/count/range bounds,anyOf/oneOf/allOf/not; no references, no regex) with byte/depth/value ceilings, linear-time validation, RFC 6901 pointer errors, and 8 KiB / 16-entry payload caps. No validator crate added.SessionRuntimeError::InvalidOutputContract→ HTTP invalid / exit 2) and persists it (runs.output_contract_json, store schema 27); the claim recompiles it so a restart enforces the accepted contract.FinalOutput::Invalid— no newRunOutcomevariant.RuntimeEvent::Completed { final_output }→settle_runwritesruns.final_output_jsonin the settlement transaction and publishes it onRunFinished. No verdict for cancelled/failed/budget-exhausted runs.trialgainsoutput_schema_sha256andoutput_repair_turns;outcomegainsfinal_output. A completed-but-invalid answer maps totask_failed(exit 1) with a message naming the errors; exit codes are unchanged.How verified
cargo test --workspace— 1,329 passed / 4 ignored (one new ignored measurement test)cargo fmt --all -- --check;cargo clippy --workspace --all-targets --all-features -- -D warningscleancargo build --workspace;cargo test -p qq-provider --no-default-features --features test-support(149 passed)output::tests(semantics, pointers, fence, bounds, payload caps); 9sessions::tests— valid first answer; repaired within allowance with notice contents; never-validates → typed failure and exactly N repairs; zero repairs; no contract → no verdict/no prompt change; unenforceable refused at admission with no run row; audited revision is what the contract judges and does not reset repairs; repair turn as budget-final response →budget_exhausted, no verdict; contract survivesabandon_for_testrestart and is enforced by the recovering runtime; schema-27 migration keeps history null; 6headless::tests(JSONL valid/repaired/invalid records, text prints the document, no fields without a contract); 2cli::tests; 1main::tests(every exit-2 path before config loads); 3 protocol goldens.Measurements
b0a18be)read_tool_loopmed / p95 (15 interleaved A/B pairs × 3000 iters, release, I/O pressure ~28%)Evidence:
target/qq-perf/hc3-2026-09-12/(untracked) in the main checkout.Docs
docs/adr/0014-typed-final-output.md(Accepted),docs/adr/README.md,docs/plans/progress/root.mddocs/design/headless-contract.md— invocation, record tables, exit table, gap row → Shipped, bounds & keyword subset, compatibility policydocs/design/protocol.md— version 19 history,run_finishedrow,submit_prompt.output, new "Typed final output" sectiondocs/design/architecture.md§ Structured Input And Steeringdocs/plans/progress/speed-first.mdCompatibility
PROTOCOL_VERSION18 → 19 (strict event/snapshot decoders; additive fields). Harbor trace fixtures re-pinned to 19.runs; historical rows read as "no contract".DESCRIPTOR_VERSION,CAPABILITIES_VERSIONunchanged.Follow-ups / decisions needed
trial/outcomeboth with and withoutfinal_output.sessions.rssplit) is unblocked.Review note: touches
sessions.rssettlement → independent second review required perdocs/plans/workflow.md§ 4.