Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions docs/design/contracts/runtime-owner-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
| Goal → timelineTree | `inputs(id, inputs) → committed events`. One validated atomic batch for the Goal record and trigger. |
| Branch-detail RPC → timelineTree | `display(id) → {entry,purpose?,cutMessages?,end?}`. |
| History RPC and line-read tools → timelineTree | `batchEnd(id, sequence) → void`, `pageEnd(id, after, limit, through) → sequence`, and `page` at the same cutoff. Preserve complete batches and the fixed head of ended lines. |
| Context RPC → target branch | `agentLoop.compact` and `contextUsage.read`. |
| Context RPC → target branch | `contextPreparation.compact` and `contextUsage.read`; the owner contracts are [ContextPreparation](../plugins/ContextPreparation.md) and [ContextUsage](../plugins/ContextUsage.md). |
| Goal and Shell admission → timelineTree | `directory({id})` returns the matching directory entry or the unknown-branch error using a single-branch lookup. Goal reads ended history through `query`; writes retain the ended/unknown errors. |
| InputQueue and Collaboration approvals → target branch | `timelineTree.input`, `inputQueue.withdraw` after submission checks, and `approval.pending/decide` on the selected branch. |
| InputQueue and Collaboration approvals → target branch | `inputQueue.submit`, `inputQueue.withdraw` (the queue runs the submit checks for a Steer), and `approval.pending/decide` on the selected branch; see [InputQueue](../plugins/InputQueue.md). |
| PromptSuggestion → ContextUsage; Report and Agent configuration → Prompt | `contextUsage.read`, `prompt.adoptedConfiguration({}) → adopted configuration or null`. Report also uses `timelineTree.query` at the selected head for evidence. |
| Prompt and ToolBinding → `branchLifecycle` | `registerOpening(completion) → void`. Opening waits for admitted completions under its existing deadline and propagates their errors. |
| Fault producers and Session observers → `sessionLifecycle` | `reportFault(error) → void`, `failure({}) → SessionFault or null`, `observeFault(listener) → id`, `release(id) → boolean`. The listener receives the current failure (initially null) and subsequent reports. Caller unload releases the observation. The first fault wins until a storage failure supersedes it; the first storage failure wins. |
| Check providers and input admission → SubmitChecks | `register(name, check) → void`; `check({entry, branchId, user?, mode}, cancelled) → proceed{blocks, warnings} or block{message}`. Run in name order through the first block. Interrupted checks write nothing. |
| Compaction, stop and activity callers → `agentLoop` | `agentLoop.compact({}) → sequence`, `stopTurn({turnId, reason}) → sequence or null`; `agentLoop.state({}) → {phase, turnId?}`, `observe(listener)` delivers that snapshot. |
| Compaction → `contextPreparation`; stop and activity callers → `agentLoop` | `contextPreparation.compact(..)`; `agentLoop.stopTurn/state/observe`; see [Loop](../plugins/Loop.md) and [ContextPreparation](../plugins/ContextPreparation.md). |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Compaction row is updated, but lines 69-75 still define PrepareModelHost, PrepareContextHost, ContextModelHost, CompactionStrategyHost and prepare(...) -> ModelRequest. Loop.md uses RequestSettings, GuideEntries and ContextPreparation.prepare; ContextPreparation.md:166 says ContextFacts and SummaryStrategy replace the two hosts; ContextPreparation.prepare returns {}. Failure scenario: two contracts for the same operations and callers wire the old hosts. Fix: update lines 69-75 or state that they stay with #2025 and link the sibling target.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 851f531. runtime-owner-operations.md:69-76 now lists RequestSettings, ContextFacts, SummaryStrategy, ContextProjection and the new ContextPreparation operations; the old PrepareModelHost, ContextModelHost and CompactionStrategyHost rows are gone.


### Calls from a Session to a selected branch

Expand All @@ -43,9 +43,9 @@ own methods.

| Session caller | Target operation |
| --- | --- |
| Context RPC / PromptSuggestion | `contextUsage.read`. The `compactAndWait` variant runs the existing compact RPC handler: it calls `agentLoop.compact` and waits for the compaction fact matching that command sequence and returns the existing completed/skipped/failed reply. The committed sequence watch and bounded query run inside the selected branch for that wait. |
| Context RPC / PromptSuggestion | `contextUsage.read`; Context RPC's `compactAndWait` is `contextPreparation.compact`, which answers the outcome itself. |
| Session language / Agent configuration / Report | `prompt.configure` or `prompt.adoptedConfiguration` with the existing source, model and outcome records. |
| InputQueue management / Collaboration | `inputQueue.withdraw` with the existing command; the caller runs the existing submit checks for steer before writing. `approval.pending` returns the branch's existing pending requests, and `approval.decide` settles the selected request. Collaboration retains its ended response on closed/ended/unknown detail lookup. |
| InputQueue management / Collaboration | `inputQueue.withdraw` with the existing command; the queue runs the submit checks for a Steer. `approval.pending` returns the branch's existing pending requests, and `approval.decide` settles the selected request. Collaboration retains its ended response on closed/ended/unknown detail lookup. |

For a live main branch, Report captures its published head once at draft capture (`directory({id:"main"}).head`)
and stores it as `conversationThrough` on that draft. Activity evidence and later opt-in
Expand All @@ -58,20 +58,20 @@ substitutes a newer head.

| Caller → owner | New API |
| --- | --- |
| ToolBinding, Session language and Agent configuration → `prompt` | `prompt.initialCompletion({}) → void or opening error`; `prompt.configure({sources, model?}) → unchanged, adopted or superseded`. |
| Prompt and guide adoption → `contextPreparation` | `contextPreparation.publish({adopted, changes, model?, toolAdoption?, inputs}) → sequence or null`; `awaitPublished({sequence}) → sequence`. Publication commits adoption atomically. |
| ToolBinding, Session language and Agent configuration → `prompt` | `prompt.configure({sources, model?, tools?}) → unchanged, adopted or superseded`; the opening adoption is internal. See [Prompt adoption](../plugins/PromptAdoption.md). |
| Prompt and guide adoption → `prompt` | publication is `prompt.configure`; see [Prompt adoption](../plugins/PromptAdoption.md). |
| File read/edit/write tools → branch FileReads | `binding({path}) → TextFileBinding or null`, `writeBinding({path}) → absent, compacted or bound`, `record({path, binding, established}) → void`. The original read supplies the established sequence; file I/O stays on the file node. |

### Model preparation, history and tools

| Caller → owner | New API |
| --- | --- |
| Loop → PrepareModelHost | `prepare({turnId, requestId, history, availableTools}) → ModelSettings`, with pinned tool definitions in order. |
| ContextPreparation → PrepareContextHost | `prepare({request, source:{turnId, requestId, through}}, cancelled) → ModelRequest`. |
| Context accounting and compaction → ContextModelHost | `describe(model facts) → {contextWindow, outputTokens, thresholdTokens, algorithm?}`, `count(request) → tokens`, `contributions({model, fixed?, messages}) → {algorithm, fixed?, messages}`, `estimate({model, algorithm, contribution}) → tokens`. |
| Loop and ContextPreparation → CompactionStrategyHost | `describe(model facts) → {name, replacementSize}`; `compact(input, cancelled) → completed, skipped or failed` with StrategyDiagnostics. Input carries history, checkpoint, request, legal cuts, trigger, budgets, prior diagnostics and model facts. |
| Loop and ContextPreparation → HistoryRenderer | `context({branchId, through}) → ContextHistory`, `renderedContext({branchId, through}) → {context, history: HistoryEntry[]}`, `snapshot({context, retainFrom, anchor}) → RecoverySnapshot`, `streamCheckpoint({branchId, through, retainFrom, batch}) → ProjectionCheckpoint`. |
| Loop and ModelProvider → ContextPreparation | `prepare({source: ContextPrepareData, projection?}, cancelled) → ModelRequest`, `validate({requestId, request}, cancelled) → void`. Reuse the prepared projection at the original cutoff. |
| ContextPreparation and usage readers → ContextUsage | `read({through?}, cancelled) → {through, contextWindow, outputTokens, thresholdTokens, estimatedInputTokens, baselineSource}`. |
| Loop, ToolExecutor and Code Mode definition readers → `toolBinding` | `bind({requestId, through, tools, toolSources}) → void`, `bindCurrent({requestId, declared?}) → ToolDefinition[]`, `definitions({requestId}) → ToolDefinition[]`, `transfer({from, to}) → void`, `release({requestId}) → void`. ToolBinding retains the pinned handler generation. |
| Loop → RequestSettings | `settings() → settings`; the model profile's defaults before an adoption ([#2093](https://github.com/arcships/dim/pull/2093), target). |
| ContextPreparation → PrepareContextHost | The model profile's request builder stays the host port `prepare` calls; the owner contract is [ContextPreparation](../plugins/ContextPreparation.md). |
| Context accounting and compaction → ContextFacts | `describe`, `count`, `contributions`, `estimate`; ContextFacts is the owner ([#2093](https://github.com/arcships/dim/pull/2093), target). |
| ContextPreparation → SummaryStrategy | `describe(model facts) → {name, replacementSize}`; `compact(input, cancelled) → completed, skipped, failed or cancelled` with StrategyDiagnostics; SummaryStrategy is the owner ([#2093](https://github.com/arcships/dim/pull/2093), target). |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem: This row says SummaryStrategy's compact returns cancelled, but #2093's current SummaryStrategy returns completed, skipped or failed and makes cancelled an error (SummaryStrategy.md:72, 82 at head a4f2377). Only ContextPreparation's CompactionOutcome adds a cancelled outcome.

Failure scenario: A caller handles a variant that never arrives and misses the error.

Evidence: docs/design/contracts/runtime-owner-operations.md:72; #2093 SummaryStrategy.md:72, 82.

Fix: Drop or cancelled or name the two layers.

| Loop and ContextPreparation → ContextProjection | `renderedStream`, `renderedContext`, `snapshot`, `streamCheckpoint`, `snapshotFromCheckpoint`; ContextProjection is the owner ([#2093](https://github.com/arcships/dim/pull/2093), target). |
| Loop and ModelProvider → ContextPreparation | `prepare({source, projection}, cancelled) → void`, `validate({request}, cancelled) → void`, `compact({}, cancelled) → outcome`; the owner contract is [ContextPreparation](../plugins/ContextPreparation.md). |
| ContextPreparation and usage readers → ContextUsage | `read({through?}, cancelled) → UsageRead`, `estimate({requestId, through}, cancelled) → Estimate`, `confirm({requestId}) → void`; the owner contract is [ContextUsage](../plugins/ContextUsage.md). |
| Loop and ToolExecutor → `toolBinding` | `bind({requestId, turnId, through, declared, sources})`, `adopted({requestId}) → {adoption, tools}`, `claim({requestId, calls, context})`, `transfer({from, to})`, `release({requestId})`, `retain_only({requestId})`; settlement follows the line's facts and `retain_only` is the Loop's rebuild step ([#2100](https://github.com/arcships/dim/pull/2100), target). |
| Nested tool execution → `toolExecutor` | `open({parentCallId, context}, cancelled) → gateId`, `invoke({gateId, call}) → ToolResult`, `close({gateId}) → ToolEffect[]`. Close joins children in order; interruption releases the gate. |
13 changes: 7 additions & 6 deletions docs/design/contracts/session-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Not in this contract: `createdBy` (the Session's origin) and the `client` parame
| Result fact | `input/deleted { input_id }`, written only by InputQueue, only when it consumes an `input/withdraw` while it holds that input unapplied |
| Held | InputQueue holds an input from its `input/message` until it writes `input/applied` or `input/deleted` for it. |
| No effect | Unknown id, input already applied, or already deleted: InputQueue writes no result fact or replacement input and no failure event exists; the caller's reply is `notHeld` |
| Client path | `session.input.withdraw {sessionId, branchId, inputId, reason?, steer?}`, provided by InputQueue through `sessionMethods` (namespace `session.input`; Session-scoped part `InputMethods`, implemented in S1, that calls the branch's withdrawal service), so Rpc names no owning service → `{status: "deleted", sequence}` or `{status: "notHeld"}`. With `steer` (a `UserInput`), only a `deleted` reply also carries `steer: {inputId, sequence}` for the committed replacement, and with it `warnings?: [{check, message}]` for the submit checks' work that did not happen (Hooks A.6.2), absent when there is none. The warnings describe the replacement this call wrote, so they appear only with its receipt: a reply that wrote no replacement carries neither |
| Client path | `session.input.withdraw {sessionId, branchId, inputId, reason?, steer?}`, provided by InputQueue through `sessionMethods` (namespace `session.input`; Session-scoped part `InputMethods` that calls the branch's withdrawal operation; the queue runs the submit checks), so Rpc names no owning service → `{status: "deleted", sequence}` or `{status: "notHeld"}`. With `steer` (a `UserInput`), only a `deleted` reply also carries `steer: {inputId, sequence}` for the committed replacement, and with it `warnings?: [{check, message}]` for the submit checks' work that did not happen (Hooks A.6.2), absent when there is none. The warnings describe the replacement this call wrote, so they appear only with its receipt: a reply that wrote no replacement carries neither |
| Process and branch-part path | `sessions.withdraw` for process callers, InputQueue's branch withdrawal service for branch parts: by the `input_id` returned when the caller wrote the input |
| Write path | The service appends `input/withdraw`, then replies with InputQueue's decision for that command. InputQueue's recheck uses only its own decision state (held set), never a lock on another owner's facts |
| Withdraw and re-submit as Steer | InputQueue accepts the replacement only when it accepts withdrawal of the old held input. The replacement Steer `input/message` and the old input's `input/deleted` commit in one atomic result batch, with `input/deleted` last. A `notHeld` decision creates no replacement |
Expand All @@ -362,9 +362,10 @@ the message. If application wins, the original is consumed normally and no
replacement is created. Other held inputs and explicit new submissions, including
identical text, remain independent.

InputMethods runs the existing validation and submission checks before admitting
a Steer command. A blocked check writes neither a command nor a replacement and
leaves a still-held input retryable. Passing the checks is not a reservation:
InputQueue runs the existing submission checks before admitting a Steer command,
after InputMethods validates the operator's content. A blocked check writes
neither a command nor a replacement and leaves a still-held input retryable. See
[InputQueue](../plugins/InputQueue.md). Passing the checks is not a reservation:
InputQueue must still decide when it consumes the command. Two callers may both
pass their checks, but cannot both replace the same original input.

Expand Down Expand Up @@ -528,8 +529,8 @@ while the first write is still unpublished.
| `input` | `Session::input(InputMessageData, branch)` (existing; returns the committed input for an id the branch already holds); a key is `InputBlock::Raw { key: Some(name), retire }` |
| `lookup` | `Session::lookup(branch, submission_id)`, shared with `session.input_lookup`: a query of the branch's committed input identities; waits for the found input's publication |
| `history` | `Session::sequence(branch)`, failing `future_sequence` below `at_least`, then `AgentIndex::history_page(id, branch, after, limit, through)` |
| `withdraw` | `Session::service::<InputQueue>(branch)` then `InputQueue::withdraw(InputWithdrawData { input_id, reason, steer: None }) -> Result<Withdrawal, AgentError>`. The data face permits only plain withdrawal and returns `Deleted { sequence }` or `NotHeld`. `InputMethods` uses the Rust-only `withdraw_checked` for an already checked Steer candidate, retains its committed event, and confirms publication before returning the receipt (A.4). |
| `pending` | Capture `Session::publication(branch).sequence()`, wait through it with `Session::dispatch_watch(branch)` while observing publication closure, then `Session::service::<InputQueue>(branch)` and `InputQueue::pending(input_id) -> bool`: the branch's queue answers §2's rule; an id it does not hold is `false` |
| `withdraw` | `line_owner::<InputQueue>(line)?.withdraw(WithdrawInput { input_id, reason, steer }) -> Result<Withdrawal, InputQueueError>`; the queue runs the submit checks for a Steer and returns `Deleted { sequence }` or `NotHeld`. See [InputQueue](../plugins/InputQueue.md) (A.4). |
| `pending` | `line_owner::<InputQueue>(line)?.pending(PendingRequest { input_id, published_cutoff: None }) -> Pending`: the owner applies its published-cutoff default and answers §2's rule; an id it does not hold is `false` |
| `stop`, `idle` | `Session::stop`, `Session::idle` (existing) |
| `delete` | `AgentIndex::delete(id)` (S5c, crate-internal): admission gate, close, `SessionStore::delete_session`, forget |
| `SessionConfig` | Rust struct below |
Expand Down
2 changes: 1 addition & 1 deletion docs/design/contracts/session-boundary.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This contract defines three registration services in the language-neutral form o

Proposed (P3, with RemoteGateway; not implemented): Rpc decides what a connection is served from its `ConnectionEntry {name, deviceId}`: a local connection gets Session and management methods, a connection with a `deviceId` (a paired device through RemoteGateway) never gets management methods, and an exported rutis link gets management methods only when exported. Today Rpc serves every connection by the existing transport profile rules (A.3). There is no port and no Management plugin. Providers are optional plugins installed only when enabled. Rpc reads `managementMethods` on each call and depends on no provider, so a provider that is disabled, Pending, Failed or reloading affects only its own namespace (§3.2). The method tables and ToolRegistry do not depend on the parts that register with them; those parts depend on them. A tool registered later is offered from the next request, and a withdrawn one is no longer offered, without a Session reload (A.5).

Acting on a tool call or an input before it is committed is not a service of this contract. Approval and the Session input path are unchanged; InputQueue's withdrawal is its owner's change ([overview Appendix B](../overview.md#appendix-b-supplements-to-existing-plugins)).
Acting on a tool call or an input before it is committed is not a service of this contract. Approval and the Session input path are unchanged; the withdrawal operation is [InputQueue](../plugins/InputQueue.md)'s.

## 1. Structure

Expand Down
Loading