Skip to content

feat(serve): delegate and discuss for server sessions (#994) - #1348

Merged
ajianaz merged 10 commits into
developfrom
feat/server-delegate-discuss
Nov 29, 2026
Merged

ajianaz merged 10 commits into
developfrom
feat/server-delegate-discuss

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

What

Server (tole serve, and tole acp, which shares the policy) sessions get the tools delegate, delegate_poll, discuss, discuss_status and discuss_stop, through the shared assembly (owner decision B on #994, 2026-11-29). The five docs/faces.md rows that said drift #945 are now policy rows with their reasons; cargo test -p tole-cli --test face_parity passes.

Why

Server sessions are what the desktop, the phone and the gateway drive. A person there could start and follow a discussion over the /discussions routes, but a model in the session could not delegate or discuss, so the capability existed on one face only (AGENTS.md section 6, "one capability, every face"). Closes #994.

Changes

  • FacePolicy::SERVER_SESSION is AgentsPolicy::Delegating (the Classic variant stays, a published enum keeps its variants).
  • New session/owner_delegation.rs (same shape as owner_mcp): the owner's profiles, [delegation] limits and data dir, set once at startup by tole serve and tole acp through registry::install_owner_setup, never from a request or from the served repository (the config layering takes delegation and profiles from the user layer only). A host that forgets to set it fails to open a session instead of running without limits.
  • No new route (serve/scope.rs is untouched). Starting a child or a discussion is a tool call inside a prompt (POST, full scope). A child's own approvals are the existing durable queue: GET /approvals lists dap-* rows and POST /approvals/{id}/decision answers them; a read-only device token gets 403 on both.
  • Every call is Risk::Write: an apr- approval in the server queue unless the owner typed --allow delegate; no --trust preset covers them. The three Destructive layers and "MCP tools are always Write" are unchanged. A plan-mode server or session has none of the five tools.
  • An allow list a server session hands to a child gets denies for agent_start, delegate and discuss (owner_delegation::inheritable), so a child can never start grandchildren without the owner: the owner's own --allow delegate still covers the session's own starts. The CLI faces are unchanged.
  • consult children really are read-only now (--plan-mode, shared code, so the CLI faces change too): main.rs accepts --plan-mode for a delegated child (the delegation log and node its launch sets), not only for a discussion participant, and a plain tole mission --plan-mode is still refused. A consult child with a role is refused at start. These are breaking changes for existing CLI users and the CHANGELOG lists them under BREAKING.
  • A model-started discussion is registered in the process (discuss::owner::driven_by_session, with a drop guard), so GET /discussions/{id} no longer reports it interrupted and the owner's resume cannot start a second driver.
  • dap- rows are redacted with the egress secret set (fix(serve,acp): error answers carry storage and provider error text with no wire redaction; the process secret set is replaced on every turn #1314), like apr- rows.
  • Shutdown: tole serve (REST and --transport mcp) ends the children it spawned during its drain (SIGTERM, then SIGKILL after a grace; only a child whose lease, pid plus start time, is still the same live process; dead groups are pruned; pid 0 and 1 are never signalled); tole acp sends one SIGTERM when stdin closes; a CLI session and a server killed with SIGKILL do not. Nothing is promised on non-unix.
  • Docs: docs/faces.md, docs/threat-model.md (a row per surface with the residuals), docs/mobile-control.md, docs/approving-delegated-work.md, README, docs/epics.md, CHANGELOG. The design note is kept out of the repository.
  • Size guard (entries only go down; tole-cli crate 84445 on the earlier base to 84189 now): whole-file moves of public-API test modules to tests/ (session/host.rs roster tests to tests/server_roster.rs, the assemble.rs face-policy tests to tests/face_policy.rs, delegation/serve_delegation_tests.rs is untouched, two lease tests to tests/ledger_leases.rs), same test names.

This PR is larger than the usual 15 to 20 files (45 files, 10 commits stacked in order: a pure test move, the feature with its tests and faces.md, then review rounds). They do not split cleanly: the feature, the shutdown hardening and the consult fix rest on each other, and splitting would leave a develop where server sessions can delegate without the limits or the fixes.

Callers and impact (cora callers/impact/affected, each verified by grep): FacePolicy::SERVER_SESSION is read by the roster assembly and the session host; install_owner_mcp had two call sites (tole serve, tole acp), replaced by install_owner_setup; delegate::launch is shared by every face; check_*, jailed and the guard paths are not touched.

Testing

  • New: tests/server_delegation.rs, server_delegation_unset.rs, serve_delegated_child_e2e.rs (the real tole serve and a scripted provider: delegate stops at an apr- approval; after the owner allows it, the child's Write appears in GET /approvals as dap-*; a read-only token gets 403 on allow and deny and the request stays pending; the full token allows it and the child writes the file; a --plan-mode server lists none of the five tools; a SIGTERM to the server ends its child), serve_delegation_e2e.rs, delegate_children.rs (fake child binary), delegate_consult_real.rs (the REAL tole binary: a consult child started through delegate reaches its model with no write tools, and a plain mission with --plan-mode is refused), discuss_registry.rs, ledger_leases.rs, face_policy.rs, server_roster.rs (moved). Mutation checks: SERVER_SESSION set to AgentsPolicy::None fails face_parity, both serve e2e tests and three of the five server_delegation tests; with may_plan reverted delegate_consult_real fails by timeout; with inheritable neutralised, server_delegation fails; with the kill removed the shutdown test fails.
  • cargo fmt, clippy -D warnings for tole-cli in the default, --no-default-features and --no-default-features --features shell-tools profiles; the full --lib suite and 19 integration test binaries (layering, hermetic_audit, face_parity, server_*, serve_*, serve_shutdown, acp_*, delegated_approval_e2e, agents, participant_mission_e2e...) pass; scripts/arch-check.sh ok; cora review --staged --no-llm no issues. In the workers' root container assemble_golden (no gh in the roster) and the two mission_e2e secrets tests fail identically on a clean develop; CI is the check.
  • Independent read-only security review (a fresh agent, same model family, real experiments against a scratch copy), three rounds, all SECURE with no must-fix: privilege (the child's workspace is always the served root, allow lists only narrow, a profile cannot re-enable a spawning tool, the owner setup cannot be influenced by a request or the repository, --allow delegate covers only delegate), device tokens (read-only gets 403, no new data beyond what it could read), resource bounds (about nine to ten children per goal by the step carve 200, 100, 50, 25, 13, 6, 3, 2, 1; a model cannot reopen its own session; an unanswered dap- request expires to a denial and nothing auto-approves), plan mode (the five tools absent), ACP and MCP (child approvals expire to a denial after approval_secs), kill on shutdown (pid-reuse lease check, only own children). The should-fix items were all fixed: nested delegation through an inherited agent_start, consult not read-only, the discussion drop guard, vacuous or leaking tests, the egress union on dap- rows, kill on shutdown.
  • Cora as the agent's reviewer (scripts/review-local.sh --agent, fresh read-only agents), two rounds: round 1 found a CRITICAL that the security reviews had not (consult children could not start at all, because main.rs refused --plan-mode for anything but a discussion participant and the earlier tests used fake tole scripts): fixed with a real-binary test; pid 0 could have made kill(-0) signal the server's own process group: fixed; round 2 verified the fixes and found minor items (the drain exited right after SIGTERM so the SIGKILL escalation was dead code, dead groups were never pruned, todo_write stays in a plan-mode child, doc arithmetic), all fixed.
  • Residuals, in the threat model: the goal budget is per host instance (a session reopened after resume or eviction starts a new goal; only a full-token client can reopen, and every call needs approval); GET /approvals scans at most 64 delegation logs (a pending child request can go unlisted and then expires to a denial: fail-closed); dap- rows lack the feat(core): plain-language action summary in the shared approval row #1041 action summary (rendering drift); MCP and ACP child approvals expire to a denial; tole acp sends SIGTERM only; a child that leaves its process group by setsid is not reached; nothing is ended on non-unix.
  • Not verified: every end-to-end test uses a scripted provider (no real model, no concurrent load test); Windows is cfg-gated and not compiled here.

The size guard only lets session/host.rs shrink, and the next change to the
server session host needs a few lines there. The module roster_tests moves
unchanged except for its paths (it used only the public API of the host) and
the start-up calls the entrypoint makes; the guard's entries for the file and
for the crate go down by the moved 165 lines.
Owner decision of 2026-11-29 on #994: a session hosted by `tole serve` or
`tole acp` gets delegate, delegate_poll, discuss, discuss_status and
discuss_stop, built by the shared assembly like the CLI faces' (AGENTS.md
section 6, one capability, every face).

- FacePolicy::SERVER_SESSION is AgentsPolicy::Delegating (the Classic
  variant stays for embedders).
- session::owner_delegation holds the owner's Setup (profiles, `[delegation]`
  limits, data dir), installed once at start-up by `tole serve` and `tole acp`
  from the user config through registry::install_owner_setup; the session host
  and the serve mission registry read it from there and from nowhere else. An
  unset cell is an error, not a default.
- A discussion that a session's `discuss` tool drives is registered in the
  process, so GET /discussions/{id} says `running` and the owner's resume and
  stop cannot start a second driver next to it.
- docs/faces.md: the five rows are `policy` with a reason, none points at a
  closed issue; face_parity passes.

No route is added (the device-token scope is untouched), every call stays
Risk::Write behind the server's approval queue, a plan-mode server or session
registers none of the tools, and a delegated child's own approvals reach the
`GET /approvals` list as dap-* rows that only a full token answers.

Tests: tests/server_delegation.rs (roster, plan mode, approval gate, the
machine guard queues a server session's child and starts no process, the
discussion registry), tests/server_delegation_unset.rs (no setup, no
session), tests/serve_delegated_child_e2e.rs (real `tole serve`: the start is
an approval, the child's approval is listed, a read-only token gets 403, the
full token lets the child proceed; a plan-mode server has none of the tools).
The guard's entry for the crate ends 89 lines below develop's.
The threat model gets a section for the new surface with its residuals (one
goal budget per session host instance, the 64-log scan of GET /approvals, a
child outliving the server, the serve token as approval authority), the
mobile-control and approving-delegated-work pages say where a server
session's children and discussions show up, and the README tool table, the
epics status and the CHANGELOG name the behavior change.
- A child no longer inherits an allow entry that starts more children. A
  server session hands its delegation host the allow list plus
  `!agent_start`, `!delegate` and `!discuss` when a positive pattern covers
  one of them (owner_delegation::inheritable): an owner's `--allow
  agent_start` used to cover only the session, because a classic child had no
  agent tools, and is now the alias of `delegate`.
- `consult` is enforced: a consult child is launched with `--plan-mode` on
  every face (it was only a discussion participant), so "consult never
  writes" holds because no Write tool exists. Shared code, so the CLI faces
  change too.
- The registration of a model-started discussion ends with its driver's
  thread by a drop guard, so a panic or a thread that cannot start does not
  leave it running for the life of the process.
- A serve that drains (REST and --transport mcp) sends SIGTERM to the process
  groups of the children its sessions started (delegation::spawned, recorded
  with pid and start time and the host's own kill function, no new unsafe).
- A dap-* row and its decision are redacted with the egress set an apr-* row
  uses (serve_delegation::egress).

Tests that fail before: server_delegation (inheritance), delegate_children
(consult argv, terminate_all), discuss_registry (started through DiscussTool,
panic path), serve_delegated_child_e2e (SIGTERM ends the child),
serve_delegation_e2e (a merged secret), server_roster (plan-mode absence is
no longer vacuous: a data dir makes the tools present first).
server_delegation is one test with a TestDir, so no tole-* directory is left.
The CHANGELOG no longer says nothing is looser: it lists exactly what changes
for an existing config (spawning allow entries are not inherited by a child,
a stopped serve ends its children, a dap row is redacted with the egress set,
and a consult child runs in plan mode on every face). The threat model gets a
row for each finding, marks the per-session goal budget, the 64-log scan and
the expiry of MCP and ACP child approvals as accepted residuals, and says
that tole acp has no drain and a CLI session keeps its children.
…round 1 (#994)

The layering test wants an ALIASES entry for the new top-level re-export
spawned, and the test that an ordinary delegate child is not a participant
used a consult child, which is now launched in plan mode on purpose: it uses
an execute child, which still shows that the restrictions hang on the
participant task only. The spawned registry takes a type alias for clippy.
…tdown (#994)

A consult child is launched with --plan-mode, but main.rs refused that flag
for anything but a discussion participant, so a real ordinary consult child
died before its first model call. spawned::may_plan lifts the refusal for a
delegated child as well (the delegation log and node its launch sets; the
participant marker and its approver behavior are untouched) and a plain
mission in plan mode stays refused. tests/delegate_consult_real.rs runs the
real binary.

- spawned: a pid of 0 or 1 and a lease without a start time are never
  recorded, and the group signal refuses a pgid of 0 or 1, so the server's own
  group is never signalled; each child gets one SIGTERM and, after 5 seconds,
  one SIGKILL; a leader that is gone leaves its group to be ended too; tole acp
  ends its children once when its editor closes the pipe.
- consult with a role is refused at the start (plan mode has no handoff tool).
- The face policy tests move to tests/face_policy.rs (same names) and gain the
  server session's no-worktrees assertion; the delegate_children tests are
  serialized and reap their children; the serve harness stops a serve that
  delegated with SIGTERM so no parked child outlives a failed test.
- CHANGELOG and threat model: which faces end their children, that an owner's
  allow for delegate, discuss or * never authorises nested delegation on a
  server, that consult children lose every Write tool on every face, and the
  arithmetic of what bounds one goal.
#994)

The serve drain sent SIGTERM and left at once, so the SIGKILL escalation never
ran. It now waits (within its own grace) until the recorded child groups are
gone, escalates after 5 seconds, and kills what is left when the grace ends
(REST and --transport mcp). A gone leader's group is ours only while it has a
non-zombie member, so zombie-only groups are forgotten instead of re-signalled
and the signalled count is exact.

Docs: BREAKING entry for the consult and allow-list changes, the carve
arithmetic (the tenth child is refused), the non-unix caveat, which faces end
their children, todo_write stays in a consult child. Tests: a child that
ignores SIGTERM, the zombie group, the reused pid, serial() drop order, the
harness drain only for a running serve, and the disk-queue test zeroing every
other threshold. Two lease tests move to tests/ledger_leases.rs.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

⚠️ Review could not complete. LLM API error after retries: Unknown error — check workflow logs


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 2fa1036 into develop Nov 29, 2026
38 of 39 checks passed
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.

docs: five faces.md parity rows still say "drift #945" (delegate, delegate_poll, discuss, discuss_status, discuss_stop)

1 participant