Skip to content

refactor(cli): one turn runner shared by the server faces and the TUI - #549

Merged
ajianaz merged 1 commit into
developfrom
refactor/shared-turn-runner
Nov 10, 2026
Merged

ajianaz merged 1 commit into
developfrom
refactor/shared-turn-runner

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What

Part 2b of #525 (UI epic #523): turn_runner::{TurnPlan, run_turn_on, run_turn_with, resume_turn_on} describe how one turn is run, and run_session_turn and resume_session_turn (serve, ACP, MCP) and TuiSession::run_turn all go through it. Refs #525, does not close it.

Why

The server faces and the TUI each had their own copy of the sequence "build the session's provider, run the turn". The TUI also settles a turn parked mid-flight first and compacts when due; the server faces do neither. With one runner, "how a turn is run" lives in one place a new client (desktop, remote) can use, and the differences between faces are explicit fields, not diverging copies. Agreed with the owner on 2026-11-10 as part of the shared-primitives plan for #525 (not a literal merge of TuiSession into Sessions).

Changes

  • turn_runner.rs:
    • TurnPlan { cfg, registry, system_prompt, cancel, observer, resolve_parked, compaction }: resolve_parked and compaction are the TUI's two extras (the server faces set neither, which is exactly their old behavior).
    • run_turn_on (build the provider, then run_turn_with), run_turn_with (settle a parked turn when asked: a non-Final outcome there IS the answer and the new prompt is not run; compact when asked and due; run), resume_turn_on (the approvals-only resume of unattended ops: remote approval escalation via tole serve #200).
    • TurnRunError::{Provider, Storage}, so each face keeps its own error text: the server faces use into_message() (provider text, or the storage error as is), the TUI keeps its storage error: prefix.
  • session_host.rs: run_session_turn and resume_session_turn build a plan and call the runner. The memory recall before the turn and the memory write after it, the busy claim and the storage lock stay where they were.
  • tui_host.rs: run_turn builds a plan with resolve_parked: true and compaction: Some(..); its old inline sequence and two imports are gone.
  • CHANGELOG and docs/epics.md updated in the same PR (AGENTS.md §7); README unaffected.

Behavior and error text are unchanged: same order (provider, settle parked, compaction, run), same observer wiring, same outcome mapping. One thing the new tests pin down: on a parked session the core's run_turn refuses ("resolve the session first"), so the server faces, which never settled, still surface that error; that is exactly why the TUI asks for settling.

Testing

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo check -p tole-cli --no-default-features, cargo test --workspace (1182 passed: the previous 1179 plus 3). The unchanged tui_e2e, serve_*, ACP and MCP e2e suites run through the new runner.
  • Local cora review --staged: not run (cora is not installed in this environment); the CI Cora Review job is the verdict.
  • 3 new unit tests with the scripted MockProvider (no network): a plain turn runs the prompt and appends to the log; a parked turn (parked the way a crash does: user message durable, machine in Planning) is settled first only when the plan asks (TUI-style: the settling output goes to the parked turn and the next one answers the prompt; not settling: the core's refusal and nothing written; settling that does not end Final returns that outcome and the prompt never starts); compaction runs only when the plan asks (a forced pass of compaction: the fleet gateway reports no context window, so compaction is silently off; no overflow recovery #481 is consumed with the plan on, left pending with it off or with enabled: false).
  • Mutations, each caught: always settling a parked turn, never settling, always compacting.

Next in #525

Part 2c: the register settings (model, effort, name, compaction request) shared by TuiSession and the other faces. After that I will check the acceptance criteria of #525 against what shipped.

Related Issues

Refs #525, part of #523.


Generated by Claude Code

…#525)

turn_runner::TurnPlan and run_turn_on / run_turn_with / resume_turn_on describe how a turn is run: build the session provider, optionally settle a parked turn, optionally compact, run. run_session_turn, resume_session_turn and TuiSession::run_turn use it; their differences are explicit plan fields. Behavior and error text unchanged.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit bd98ad3 into develop Nov 10, 2026
15 of 16 checks passed
ajianaz added a commit that referenced this pull request Nov 10, 2026
## What

Part 2c of #525 (UI epic #523): `session_settings` owns a session's
durable settings: the register names (`fact/model`,
`fact/reasoning_effort`, `fact/session_name`), the label validation and
the writers. The TUI's `/model`, `/effort`, `/name` and `/compact` and
ACP's model picker write through it, and the readers use the same
constants. Refs #525.

## Why

The same registers were written in two places (`tui_host.rs` and ACP's
`set_model_option`) and named by repeated string literals in the writers
and readers (`turn_runner`, `status`, `acp`). A rename or a validation
tweak had to be found in each. Agreed with the owner on 2026-11-10 as
the last piece of the shared-primitives plan for #525.

## Changes

- `session_settings.rs` (new): `MODEL` / `EFFORT` / `NAME` register
constants; `clean_label` (moved from `tui_host.rs`: non-blank, at most
120 chars, no control characters); `set_model`, `set_effort` (validated
and canonicalised, or `None` clears the override back to the process
default), `set_name`, `request_compaction` (the forced pass of #481),
and `write_model` (store as given, for ACP, which validates against its
own model list first).
- `tui_host.rs`: the setters call the module (its private `commit`
helper and `clean_label` are gone; the window cache is still reset after
a model switch).
- `acp.rs`: `set_model_option` writes through `write_model` (its own
validation, busy check and error text stay); `MODEL_REGISTER` is the
shared constant.
- `turn_runner.rs` (`session_model`, `session_effort`) and `status.rs`
read through the constants.
- CHANGELOG and `docs/epics.md` updated in the same PR (AGENTS.md §7);
README unaffected.

Behavior and error text are unchanged (`invalid model id`, `invalid
name`, `invalid reasoning effort ...`, and the `storage error:` prefix
on a failed write).

## Testing

- [x] `cargo fmt --all -- --check`, `cargo clippy --workspace
--all-targets -- -D warnings`, `cargo check -p tole-cli
--no-default-features`, `cargo test --workspace` (1187 passed: the
previous 1182 plus 5)
- [ ] Local `cora review --staged`: not run (cora is not installed in
this environment); the CI Cora Review job is the verdict.
- [x] 5 new unit tests: label rules (trim, blank, control characters,
the 120-char limit); the model is stored where the readers look and a
bad id writes nothing; effort is validated, canonicalised (` HIGH ` →
`high`), a rejected level changes nothing, and `None` clears to the
process default; the name register renames and a bad name is refused
(the core's `session_name()` reads it); a compaction request is a
durable pending flag. The existing `tui_host` tests
(`switches_write_the_registers_the_next_call_and_resume_read`,
`name_and_compact_request_are_durable_registers`) run unchanged through
the new module.
- Mutations, each caught by the new tests and by those unchanged
`tui_host` tests: the name register key drifting from what the core
reads, clearing the effort being a no-op, and label validation disabled.

## What #525 looks like after this

Done as shared primitives inside `tole-cli`, per the owner's decision
(no new crate until a second consumer exists, sync API): tool
registration moved to the roster (#547), session create + index
registration (#548), one turn runner (#549), session settings (this PR).
I will post the acceptance-criteria status on the issue, including what
is not done: `TuiSession` still owns its single swappable storage handle
and `switch_session` (open an existing session by id through the index),
and the crate/publish decision is deferred with the crate.

## Related Issues

Refs #525, part of #523.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01GwJr9GzLbDFeXo3HZHZpyP)_

Co-authored-by: Claude <[email protected]>
@ajianaz
ajianaz deleted the refactor/shared-turn-runner branch November 11, 2026 04:10
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.

2 participants