Repository navigation
feat(protocol): headless JSONL records as protocol types pinned by golden streams (HC4) - #34
Merged
Merged
Conversation
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
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
… architecture, plan, and ledger updates Slice: HC4
lg2m
added a commit
that referenced
this pull request
Sep 14, 2026
…ompt prefix (H18) (#38) * docs(ledger): start H18, close HC4 (#34) Slice: H18 * perf(provider): provider_encode bench with a counting allocator (H18) One MiB transcript plus 32 schemas encoded for each HTTP protocol; reports encode time, body size, and the request's peak heap above the transcript along the adapter path (build, per-attempt clone, body). Baseline at 43caaea: 4.4-4.7x payload, 335-555 us. test_support::encode_body exposes the wire structs without a transport. Slice: H18 * perf(provider): share the transcript and keep tool JSON as raw text (H18) ModelRequest.messages is Arc<Vec<Message>>: the per-attempt clone every adapter performs inside with_restart is a refcount bump. ToolSpec.input_schema and ContentBlock::ToolCall.arguments are Box<RawValue>: every codec embeds the compact text verbatim (or sends it as the string Responses and Chat want) instead of walking a Value tree or re-stringifying per request. Bedrock alone parses, because the Converse SDK wants a Document tree. provider_encode, 6 interleaved A/B pairs, release profile, separate target dirs: request heap 4.4-4.7x -> 2.7-2.9x payload; encode openai_responses 430 -> 305 us, openai_chat 479 -> 326, anthropic 342 -> 333, google 570 -> 504. Slice: H18 * perf(runtime): append to a shared transcript; schemas and arguments stay text (H18) The run holds Arc<Vec<Message>>, hands it to each turn's request by reference count, drops the provider stream before appending, and appends through Arc::make_mut, which copies nothing once the stream is gone (a test pins the same allocation across turns). Tool-call arguments keep the canonical string the run already produced; PendingToolCall loses its duplicate parsed Value and measure_message stops re-serializing. The catalog reads schema text straight from each spec instead of serializing on compile and carrying a parallel Arc<str> list. Slice: H18 * perf(runtime): build the plan-constant prompt prefix once and continue its digest (H18) CompiledAgentPlan holds a PromptPrefix per capability set (header, tool index, skill index, workspace instructions, persona) with its SHA-256 state; the common set is built at compile, others on first use. A run appends only its suffix (selected guidance, context blocks, output contract) to a copy and finalizes the cloned hasher over the suffix, so system_prompt_hash is unchanged from a whole-prompt digest; a test pins that across four capability sets and against the single-pass builder. Slice: H18 * perf(provider): escape transcript strings with a word-parallel scanner (H18) With RawValue fields in the request structs serde_json's per-byte escape loop lost 30-60% on a one MiB body, and the loss flipped with unrelated build changes (same instruction count, different loop alignment). Text<'a> and OwnedOrBorrowedText<'a> wrap every bulk string (message text, tool results, system prompt): a SWAR scan finds the next byte needing escape eight at a time, the clean run is copied once, and the literal reaches serde_json through its raw-value hook. Byte-identical output, pinned by an exhaustive per-lane test. The bench now also reports request heap from a shared Arc, the run loop's case. provider_encode vs 43caaea, 5 interleaved triples (base, cand, cand with debuginfo): openai_responses 429 -> 191 us, openai_chat 466 -> 212, anthropic 339 -> 194, google 559 -> 406; both candidate builds agree. Slice: H18 * docs(h18): ADR-0024 shared transcript, raw tool JSON, prompt prefix; architecture, plan, and ledger Slice: H18 * docs(ledger): link H18 PR #38
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.
HC4: headless JSONL records as protocol types, pinned by golden streams
Spec: docs/plans/speed-first-extensible-agent-harness.md#phase-5b--headless-contract-for-supervisors · docs/design/headless-contract.md (gap row "Pinning the contract") · ADR: docs/adr/0023-headless-records-as-protocol.md
Closes Phase 5b (HC1 #30, HC2
893e582, HC3 #33, HC4 this PR).What changed
qq_protocol::headless(new).HeadlessRecord { Trial | Event { envelope } | Outcome },HeadlessTrial,HeadlessOutcome,HeadlessStatus,HeadlessApproval. These were a privateserdeenum insrc/headless.rs; a supervisor had to read QQ source to learn the shapes. Now they are protocol vocabulary with strict decoding (deny_unknown_fields; unknowntype/statusfail). Identifiers and hashes are protocol types (WorkspaceId,ContentHash);HeadlessStatus::codeis the one exit table;HeadlessOutcome::is_well_formedchecksexit_code == status.code().HeadlessRecordRef<'_>, a borrowing mirror, so the streaming path still serializes eachSessionEventEnvelopeby reference — no clone per event. A unit test pins that the owned and borrowed views encode identically.src/headless.rsre-exportsHeadlessStatus/HeadlessApprovaland owns no record shape.crates/qq-protocol/tests/fixtures/headless/v19/— ten complete.jsonltrial streams:completed,completed_with_every_option(every optional trial field + an audit record),completed_final_output_valid,task_failed_final_output_invalid,task_failed,timed_out,budget_exhausted(exit 3 shared; status disambiguates),interrupted,harness_failure,invalid_configuration(outcome-only: startup failed before a session).tests/headless_fixtures.rsdecodes each line as a strictHeadlessRecord, requires byte-exact re-encoding, and checks framing (one trailingoutcomewhose exit code matches; one leadingtrialunless startup failed; only events between; strictly increasing cursors).QQ_UPDATE_FIXTURES=1rewrites the current directory only.v18/decode-only. The eight default-path streams re-pinned toprotocol_version: 18— they are byte-identical to v19 apart from that field, which is the compatibility statement the contract makes: additive fields only, older streams still decode.parse_recordsinsrc/headless.rstests now decodes every stdout line as aHeadlessRecordand asserts identical re-encoding, so the binary cannot drift from the crate.No
PROTOCOL_VERSIONor store-schema bump: the emitted bytes are unchanged (verified by the 38 existing headless tests passing under the strict round-trip).How verified
cargo test --workspace— 1,347 passed / 4 ignoredcargo 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— 162 passedqq_protocol::headless::tests(owned/borrowed parity; fail-closed on unknown type, field, status; optionals omitted notnull; exit table + wire spellings); 3tests/headless_fixtures.rs(current_version_streams_match_their_goldens,historical_streams_still_decode,the_exit_table_matches_the_contract).Measurements
None named. No hot-path change: the event record is still serialized by reference and the encoding is byte-identical.
Docs
docs/adr/0023-headless-records-as-protocol.md(Accepted);docs/adr/README.md(0022 → Accepted, 0023 added);docs/plans/progress/root.mddocs/design/headless-contract.md— records intro names the types and goldens; gap row → Shipped; compatibility policy (goldens per version, omitted-not-null, constructed-not-recorded)docs/design/protocol.md— new "Headless Records" sectiondocs/design/architecture.md§ Hosting BoundaryNow→ HC4 in review, closes Phase 5b;Next→ H18), task index, Phase 5b section; ledger receipt indocs/plans/progress/speed-first.md(also closes HC3 asShipped (24b6e5c, #33))Compatibility
qq-protocolgains a CLI-facing module. Bounded to the three record shapes and two enums; invocation options, text rendering, and approval behavior stay in the binary.HeadlessRecordboxes its payloads (Clippylarge_enum_variant); the binary never constructs the owned enum.src/headless.rs:HeadlessStatus::exit_code()becameheadless::exit_code(status)(the protocol type cannot depend onstd::process::ExitCodesemantics of the binary).HeadlessApproval::approval_mode()became a private free fn.Follow-ups
benchmarks/harbor/tests/make_fixtures.py, pinned at protocol 16) can be regenerated from the goldens when it next changes.