Skip to content

feat(hc1): headless run contract - #30

Merged
lg2m merged 8 commits into
mainfrom
feat/hc1-headless-run-contract
Sep 12, 2026
Merged

lg2m merged 8 commits into
mainfrom
feat/hc1-headless-run-contract

Conversation

@lg2m

@lg2m lg2m commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

`config check` with `(version: 1)` failed with "model must be configured"
before any other rule ran. Document finalization now checks every rule
(providers, policy, profiles, packs, MCP, delegation, audit) first and
raises ModelRequired last, so ConfigLoader::check can treat that single
error as "valid apart from the selection" and return Ok(None).
ConfigSnapshot::model() stays non-optional; every run-time consumer is
unchanged and load() still requires a model.

enforce_policy takes Option<&ModelRoute>: provider-level rules (custom
endpoints, literal secrets, HTTPS, the output cap) apply without a route,
the allow/deny provider lists only with one.

Slice: speed-first HC1 (minimal configuration check)
… (HC1)

qq run passed Correlation::default() to both CreateSession and SubmitPrompt,
so a supervisor had no way to attribute a run without parsing its own
stdout. `--correlation KEY=VALUE` (repeatable) is split on the first `=`
at parse time, validated as one set through Correlation::new before any
configuration is loaded (protocol bounds; a repeated key is rejected rather
than last-wins), and carried on both commands. The trial record gains an
optional `correlation` field that is omitted when empty, so the default
JSONL payload is unchanged; session snapshots already echo it.

Slice: speed-first HC1 (correlation from the CLI)
RunLimits.max_model_turns, every turn_ordinal on events, snapshots, and
store rows, the core turn loop bound, the budget meter's counter, and the
CLI's --max-turns were u16, so a supervisor could not request more than
65 535 turns and the loop failed with "exhausted the durable u16 ordinal
space". All of them are u32 now. SQLite INTEGER is 64-bit, so no store
migration is needed.

PROTOCOL_VERSION 17 -> 18. The accepted wire range grew; no field was
renamed or removed, so every version-17 record still decodes. The fixture
harness reads tests/fixtures/v<PROTOCOL_VERSION>/ for the byte-exact
goldens and keeps v17 decode-only under a new historical_fixtures_still_
decode test. Boundary tests pin 65 536 and u32::MAX on the wire and drive
the budget meter past 65 535 without a provider.

BREAKING: a version-17 client rejects a max_model_turns or turn_ordinal
above 65 535; clients and servers must agree on version 18.

Slice: speed-first HC1 (--max-turns width)
…covery (HC1)

SessionRuntime::open ran recover_interrupted_runs unconditionally against a
store nothing prevented a second process from also opening. Two qq processes
on one file (a TUI beside qq serve, two runs sharing XDG_DATA_HOME, a
supervisor retrying before its previous attempt exited) would each recover,
cancel, and settle runs the other was executing; ADR-0012 made settlement
idempotent in-process but not across processes. HC1's `qq run --session`
makes that case routine.

The store worker now takes an OS advisory lock on a sibling <store>.lock
(std::fs::File::try_lock) before SQLite is opened. A held lock is reported as
the typed SessionRuntimeError::StoreBusy after a bounded 1.5 s handoff grace;
the loser performs no database I/O. The lock is released after the connection
drops, so a successor never sees a live WAL writer, and process death
releases it with no cleanup. ADR-0022 (proposed).

Tests that held a live subscription across a "restart" drop it first (a
subscription clones the store handle); tests that simulated death while a
task still owned the runtime stop the worker directly; tests that opened a
second Store on a live runtime's file read through the runtime's store.

Slice: speed-first HC1 (resume into an existing session, part i)
qq run always created a session; SubmitPrompt on an existing one existed
only through the server. `--session ID` submits into an existing idle root
session of the workspace. Unknown ids and sessions of other workspaces are
one invalid_configuration refusal (the id's existence elsewhere is not
disclosed); spawned sub-agent sessions and busy sessions are refused by
name. The invocation decides the run exactly as for a new session: the
model selection, --profile, and --approval are written to the session
before the prompt is submitted, and the event stream starts at the new
prompt rather than at the session's history or those writes.

Store ownership and the recovery sweep precede all of this, so a run the
previous process left executing is already settled as interrupted when the
resume is examined; the regression test kills a process mid-turn (the new
SessionRuntime::abandon_for_test stops the store worker as a crash would),
resumes, and checks that the interrupted turn was not re-executed and that
the resumed request carries the runtime's do-not-retry notice.

Slice: speed-first HC1 (resume into an existing session, part ii)
Mark the four HC1 gap rows Shipped with their commits, move the plan's Now
row to HC1-in-review / HC3-next, record PROTOCOL_VERSION 18, close
decision #4 (HC1 bumps alone; HC3 will bump to 19), and add the ledger
entry with per-commit verification.
@lg2m
lg2m force-pushed the feat/hc1-headless-run-contract branch from 3fa37f8 to 1a2e6b3 Compare September 12, 2026 06:21
…I /quit

qq run --session ID was only usable by a supervisor reading session_id from
the JSONL trial record; a person running text mode, or leaving the TUI, was
never shown an id. Both surfaces now end with the same lines on stderr:

  To continue this session:
    qq run --session <id> "<prompt>"

qq run prints it in text format when stderr is a terminal, after any
outcome (an interrupted or exhausted run is exactly when someone wants to
continue). JSONL output never carries it, and a piped stderr receives
nothing, so scripted consumers and the Harbor adapter are unaffected. The
TUI's run loop already returned the App; terminal::run now returns
app.focused() after the terminal guard is dropped, and main prints the hint
on the normal screen.

Slice: speed-first HC1 follow-up (session id visibility)
…th --session

The interactive surface had no way to open a specific session: bare `qq`
focused the newest one and the only path to another was the in-TUI list. The
entry points now share one shape with `qq run`: bare `qq` starts a new
session, `qq --session ID` opens that one.

qq-client's `create_initial_session: bool` plus an optional model becomes
`InitialSession::{New(model), Open(id), Existing}`. `New` creates before the
first snapshot; `Open` focuses the named root session and fails bootstrap
with a typed `SessionNotInWorkspace` or `SessionIsChild` before anything
paints (unknown and foreign ids read the same, so an id's existence
elsewhere is not disclosed); `Existing` is what a client attaching to a
server it does not own gets, and what every reconnect uses, so a reconnect
never creates a second session or fails on an id deleted since launch.
`TuiError::ClientStopped` now carries the last client-reported failure so a
refused `--session` is explained on the restored terminal.

Slice: speed-first HC1 follow-up (interactive session entry points)
@lg2m
lg2m merged commit abad2de into main Sep 12, 2026
4 checks passed
@lg2m
lg2m deleted the feat/hc1-headless-run-contract branch September 12, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant