Skip to content

Commit 249cf86

Browse files
author
trajn
committed
Configure delegation limits and coordinate explicit task groups
Join selected tasks with one deadline, validate control targets before acting, and show the same outcomes for explicit and automatic delivery. Keep superseded execution evidence separate from unsent follow-ups.
1 parent 6c09f52 commit 249cf86

19 files changed

Lines changed: 1053 additions & 463 deletions

‎README.md‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@ pi install git:github.com/jonascloud/pi-sub
1414

1515
Use `/reload` after installation or source changes.
1616

17-
## Subagent model
17+
## Settings
1818

19-
Run `/sub:model` to see the current selection and choose the model and thinking level for new tasks. To narrow a large catalog, use a filter such as `/sub:model sonnet`. The choice is saved for the Pi profile in `<agent-dir>/pi-sub-model.json` (normally `~/.pi/agent/pi-sub-model.json`). It does not change the parent model.
19+
Open `/sub:settings` to configure delegation for your Pi profile:
2020

21-
Each new task uses the saved selection immediately, without a reload. Queued tasks and follow-ups keep the model and thinking level assigned at creation. Multiple tasks can run in parallel on the same model. If no model is configured, or the selected execution is unavailable, pi-sub reports an error instead of substituting another model. The parent's model cycling scope does not restrict the picker.
21+
- **Model** — choose the model and thinking level for new tasks. Existing tasks, including queued tasks and follow-ups, keep their original choice. The picker is independent of the parent model and its cycling scope; delegation requires an explicit, available model.
22+
- **Max. parallel tasks** — the number of child executions one parent session may run at once (default: 4). Raising it admits waiting work immediately in the current session. Lowering it lets running work finish; no new execution starts until a slot is free.
2223

23-
Upgrading from `piSub.ladder`? Choose your model once with `/sub:model`; the old setting is ignored and can be removed.
24+
If the session limit differs from the profile limit, `/sub:settings` shows both. Opening or cancelling settings does not apply the profile limit; a session picks up changes saved elsewhere on its next successful `sub_task` call.
25+
26+
Use `/sub:settings sonnet` to go directly to models matching `sonnet`. The model and limit are stored independently in the Pi profile (`pi-sub-model.json` and `pi-sub-limit.json`); an existing model selection needs no migration.
2427

2528
## Parent tools
2629

2730
| Tool | Contract |
2831
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2932
| `sub_task` | Start bounded work with a `prompt` and optional `description`. Returns an ID immediately. |
3033
| `sub_message` | Send `{ id, message }`. Updates queued input or stops active execution, waits for closure, then continues the same session with the correction. Also answers ready, failed or paused tasks. |
31-
| `sub_result` | Inspect `{ id, wait?, timeout?, finish? }`, or page `{ report, offset?, limit? }`. `finish: true` explicitly accepts/removes a ready task. |
32-
| `sub_control` | `pause`, `continue` or `stop`, with optional `id`; omit it to control all applicable tasks. Stopping never rolls back side effects. |
34+
| `sub_result` | Inspect `{ ids, wait?, timeout?, finish? }` in input order, or page `{ report, offset?, limit? }`. `finish` accepts the selected tasks as a group. |
35+
| `sub_control` | Pause, continue or stop `ids: [a, b]`. Use `all: true` instead to act on all applicable tasks. Stop removes tasks without undoing their work. |
3336

34-
```text
35-
sub_task({ prompt: "Inspect the authentication entry points without modifying files.", description: "Review auth" })
36-
sub_result({ id: "<task-id>", wait: true, timeout: 30 })
37-
sub_message({ id: "<task-id>", message: "Use the production schema, then continue." })
38-
sub_result({ id: "<task-id>", finish: true })
39-
```
37+
Start with `sub_task` and carry on with independent work. The reply arrives automatically. If the next step depends on several replies, join just those tasks: `sub_result({ ids: [a, b], wait: true })`. For a single task, pass `[a]`. Use distinct IDs. With or without waiting, task results are a list in input order, including for one task. Add `finish: true` only if every selected task can be closed even on failure; acceptance removes all or none.
38+
39+
Use `sub_message` for a correction or follow-up in the same session. An unsent follow-up has no answer yet. If the previous execution fails while winding down, the task tells you that the follow-up was not sent. Its report ID points to the previous execution’s error and any partial answer, not an answer to the follow-up.
4040

41-
A wait only observes. It ends with a reply or failure, when its task pauses, at its timeout, or as soon as the user sends a message, so a waiting parent never holds the user back. None of these stops work. Reading a reply does not accept it, and a delivered reply needs no acknowledgement: the task stays open for follow-up until accepted or stopped. Accepted and stopped tasks cannot resume; cached reports survive task removal until eviction or runtime teardown. If acceptance is the first delivery, it includes the result. Otherwise it confirms only the task ID, accepted status and available report ID. `/sub:stop` also names any final report IDs without repeating replies. There are no idempotent task receipts.
41+
A wait observes until every selected task is ready or failed, even if some start out queued. A single timeout covers the group (default: 30 seconds). A timeout, any selected task pausing, or user steering returns the current states without stopping work. With `finish: true`, an incomplete group stays open; requesting immediate acceptance of an incomplete group is an error. An unknown or removed ID is an error, not a missing result to skip. Reading a reply does not accept it, and a delivered reply needs no acknowledgement: the task stays open for follow-up until accepted or stopped. Accepted and stopped tasks cannot resume; cached reports survive task removal until eviction or runtime teardown. If acceptance is the first delivery, it includes the result. Otherwise it confirms only the task ID, accepted status and available report ID. `/sub:stop` also names any final report IDs without repeating replies. There are no idempotent task receipts.
4242

4343
Replies and failures arrive on their own. At the next safe turn boundary, or once when the parent is idle, pi-sub batches unannounced ones into one message; a complete tool return already counts as delivery. Each completed execution has an immutable report ID. Serialized reports up to 2 KiB are inline; larger ones include a reference, a response preview of at most 512 bytes and an error preview of at most 240 bytes. A result or batch is at most 8 KiB; an oversized batch is cached as a report with a summary and reference.
4444

45-
Page a report with `sub_result({ report: "<report-id>", offset: 0, limit: 4096 })`. This returns plain text and the next offset without executing a child. Offsets are zero-based UTF-8 byte boundaries; limits are bytes, default 4096, minimum 4 and maximum 4096. The parent runtime has one 16 MiB FIFO cache of UTF-8 report payloads; reads do not refresh it. If FIFO eviction reaches a task’s current report before its first handoff, the cache keeps a temporary disk copy. After handoff or replacement by the task’s next execution, later writes may evict it. An expired reference returns “Report no longer available”. A single report over 16 MiB spills to a private temporary file until runtime teardown. A batch also spills if caching it would evict a report it references; later FIFO eviction is unchanged. The budget excludes JS heap, native history, pending input and journals. Session switch, fork, reload or shutdown tears down the runtime; preserve relevant findings before leaving.
45+
Page a report with `sub_result({ report: "<report-id>", offset: 0, limit: 4096 })`. This returns plain text and the next offset without executing a child. Offsets are zero-based UTF-8 byte boundaries; limits are bytes, default 4096, minimum 4 and maximum 4096. The parent runtime has one 16 MiB FIFO cache of UTF-8 report payloads; reads do not refresh it. If FIFO eviction reaches a task’s current report before its first handoff, the cache keeps a temporary disk copy. After handoff or replacement by a follow-up, later writes may evict it. An expired reference returns “Report no longer available”. A single report over 16 MiB spills to a private temporary file until runtime teardown. A batch also spills if caching it would evict a report it references; later FIFO eviction is unchanged. The budget excludes JS heap, native history, pending input and journals. Session switch, fork, reload or shutdown tears down the runtime; preserve relevant findings before leaving.
4646

4747
## Pause and continue
4848

@@ -54,17 +54,17 @@ Aborting the parent, for example with Escape, stops only the parent. Children ke
5454
/sub:stop [task-id]
5555
```
5656

57-
No ID means all applicable tasks. `/sub:pause` without an ID stops everything: it pauses every child and aborts the parent. Paused children stay paused until `/sub:continue`, a `sub_control` continue or a message. In RPC, send `prompt("/sub:pause")`.
57+
For these slash commands, omitting the ID means all applicable tasks. The model tool `sub_control` has no implicit target: the whole selection is checked before any task is changed. `/sub:pause` without an ID stops everything: it pauses every child and aborts the parent. Paused children stay paused until `/sub:continue`, a `sub_control` continue or a message. In RPC, send `prompt("/sub:pause")`.
5858

5959
Pausing terminates the process (SIGTERM, then SIGKILL) and continuation restarts it on the same session. It does not undo writes or external effects.
6060

6161
A failed execution leaves its task open. The parent receives the failure like a reply, and a message continues the session, resending instructions that never reached it. Nothing retries on its own. A lost or corrupt journal can prevent continuation.
6262

63-
Up to four executions run concurrently. Queued, paused and ready tasks hold no process. Shutdown, reload and session replacement close all executions and delete the temporary workspace; reopening a saved conversation starts without tasks.
63+
Queued, paused and ready tasks hold no process. Shutdown, reload and session replacement close all executions and delete the temporary workspace; reopening a saved conversation starts without tasks.
6464

6565
## Views and usage
6666

67-
Tool rows and transcript messages show task names, confirmed outcomes and compact previews; expand them for requests, full delivered text, IDs, execution and usage. The widget above the editor shows outstanding work: active and paused tasks, and replies or failures the parent has not seen. Delivered ones fold into a count; the summary shows native `↑input ↓output` tokens of all subagents.
67+
Grouped results show state counts, task names and reply or error previews, whether requested or delivered automatically. Expand a result for requests, full delivered text, IDs, execution and usage. The widget above the editor shows outstanding work: active and paused tasks, and replies or failures the parent has not seen. Delivered ones fold into a count; the summary shows native `↑input ↓output` tokens of all subagents.
6868

6969
Usage is read from each child's saved journal after every execution and charged to the parent session with the next subagent tool result, independent of acceptance. Pi offers extensions no other way into session totals, so work confirmed after a session's last subagent tool result is missing from them.
7070

‎docs/decisions/0002-process-lifetime-and-interruption.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ Reply/error/stopped are outcomes, not additional states. Retries and automatic c
1919

2020
A failure is the outcome of one execution, not the end of its task. A crash, a non-zero exit, a provider error or a missing response leaves the journal as an interruption does, so the task stays open: a message continues its session and resends input the journal does not prove. Admission failures are the same; nothing ran. A lost or corrupt journal can prevent continuation. A journal that never existed loses nothing, so a first start may repeat. Nothing retries on its own: the parent receives the failure like a reply and decides.
2121

22-
Active redirection retains the correction, interrupts the old process, waits for closure and final capture, then queues a new process on the same session. It never injects input into a busy native session. A pause between these steps prevents restart and retains the correction. Only new saved native user entries prove input persistence, not streamed message events emitted before the write. Instructions without that evidence are retained after interruption or failure; transformed inputs may be conservatively replayed.
22+
Active redirection retains the correction, interrupts the old process, waits for closure and final capture, then queues a new process on the same session. It never injects input into a busy native session. A pause between these steps prevents restart and retains the correction. If the outgoing execution fails, do not start the correction automatically. Report it as unsent, keeping the outgoing error and partial answer in that execution's report, not in the correction's answer. Only new saved native user entries prove input persistence, not streamed message events emitted before the write. Instructions without that evidence are retained after interruption or failure; transformed inputs may be conservatively replayed.
2323

2424
Aborting the parent stops the parent. Its children are separate work and keep running: an abort is most often the user interjecting, and stopping work as a side effect would have to be undone by someone. The coordinator therefore holds no interruption state, closes no admission and never delays, cancels or aborts user input or a parent run.
2525

2626
One consequence is kept: an aborted parent stays stopped. Replies and failures that arrive afterwards wait in the inbox and do not wake it until real interactive or RPC input, or an operator continue. They join that run at its boundaries.
2727

28-
Pausing is always explicit, for one task or for all. It requests native SIGTERM shutdown, escalates to SIGKILL on a bounded deadline and awaits exit. A paused task stays paused until it is continued or messaged. The global `/sub:pause` is the one command that stops everything: it pauses every task, aborts the parent and holds replies like an abort does.
28+
The control tool takes an explicit selection of task IDs or `all: true`; an omitted target never means all. Resolve the whole selection before changing any task. Pausing requests native SIGTERM shutdown, escalates to SIGKILL on a bounded deadline and awaits exit. A paused task stays paused until it is continued or messaged. The global `/sub:pause` is the one command that stops everything: it pauses every task, aborts the parent and holds replies like an abort does.
2929

30-
Replies and failures await an explicit parent decision, not an idle process. Delivery is independent of that decision: handing the reply to Pi in a tool result, a boundary entry or an idle message folds its widget row without removing the task. A new execution produces a fresh report ID ([0007](0007-bounded-report-cache.md)). Accepting or stopping removes the live task; cached reports survive until eviction or runtime teardown. There are no idempotent task receipts.
30+
Replies and failures await an explicit parent decision, not an idle process. Delivery is independent of that decision: handing the reply to Pi in a tool result, a boundary entry or an idle message folds its widget row without removing the task. Queueing a follow-up supersedes the previous reply immediately, even when no execution slot is free. A new execution produces a fresh report ID ([0007](0007-bounded-report-cache.md)). Accepting or stopping removes the live task; cached reports survive until eviction or runtime teardown. There are no idempotent task receipts.
3131

3232
After every execution, read final saved native entries, including late shutdown usage. Replace the task's cumulative usage snapshot; never add successive snapshots of the same journal. If final usage cannot be read, retain the confirmed pre-execution snapshot. Charge the growth of each confirmed snapshot once, independent of acceptance: delivered replies need no acceptance, so tying usage to task removal would leave most work uncharged. Pi exposes parent usage only through tool results, so charged usage waits for the next subagent tool result. Metrics and pending delivery outlive task removal. Shutdown, reload and session replacement terminate owned executions without model-managed collection, then dispose of the report cache and the temporary workspace. Reopening parent history does not restore tasks or artifacts. Already-delivered text remains ordinary conversation history, and project changes are untouched. Hard crashes may leave temporary files; no background collector is introduced.
3333

‎docs/decisions/0003-messages-not-child-ui.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Keep operating guidance in one stable system-prompt section and operation-specif
1616

1717
Ready tasks are the reply inbox, not a second queue of frozen reports. A failure is handed off through the same inbox as an answer, names its cause and wakes an idle parent; it has no separate notice or cleanup path. At native turn boundaries, batch the current unannounced replies into one persisted custom message. Complete tool returns suppress redundant announcements before the next request. Natural continuation satisfies the batch's continuation request; it does not add a second turn. Coalesce idle arrivals once per event-loop turn, without polling or a debounce delay. An aborted parent is not woken ([0002](0002-process-lifetime-and-interruption.md)); native dialogs defer delivery until they close. Oversized batches use one cached report handoff ([0007](0007-bounded-report-cache.md)). Delivery remains reply-specific and separate from reading or task acceptance.
1818

19-
Waiting observes and must not hold the user back. A steering message reaches the parent only after its current tool calls, so it ends every wait, and no wait blocks while one is queued. A wait also ends when its task pauses: nothing more can arrive. Ended this way, a wait returns the current state, not an error, and does not accept an unfinished task. Pi announces neither the queueing nor the withdrawal of a steering message, so an open wait checks for it while one is expected. Aborting remains an interruption.
19+
Waiting observes and must not hold the user back. A steering message reaches the parent only after its current tool calls, so it ends every wait, and no wait blocks while one is queued. A wait joins exactly the named tasks with one deadline. It ends when all are ready or failed, or early if any is paused. On timeout, pause or steering it returns every current state in request order: the parent can see what is still missing. Explicit acceptance is all-or-none; an incomplete join never removes an already settled peer. Pi announces neither the queueing nor the withdrawal of a steering message, so an open wait checks for it while one is expected. Aborting remains an interruption.
2020

2121
Optimize for the smallest sufficient handoff for the next decision or action, not isolated message length. Briefings include scope, success criteria and decisive context; replies include verification, decisive reasons and material uncertainty. Follow-ups add new information with enough context to interpret it. Native global and project context loading supplies standing instructions without a second copy in task messages. Brevity must not hide evidence needed to judge correctness. Stale reports alone must not trigger revisiting accepted/stopped tasks; deliberate review of cached reports remains valid.
2222

0 commit comments

Comments
 (0)