Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d2f1293
feat(appserver): add session.branch_set_default and defaultBranchId
yyhhyyyyyy Nov 20, 2026
23408ee
feat(appserver): route the Session's defaults to the default branch
yyhhyyyyyy Nov 20, 2026
b8e9a02
feat(collaboration): follow each member's own default branch
yyhhyyyyyy Nov 20, 2026
560f98b
feat(sessions): let a data-face reader see a Session's default branch
yyhhyyyyyy Nov 20, 2026
8c066bf
feat(scheduler,eventhub): target the default branch when unnamed
yyhhyyyyyy Nov 20, 2026
1ec5c4b
fix(appserver): keep the root's meanings on a root-only protocol
yyhhyyyyyy Nov 20, 2026
5d4c391
fix(storage): republish the new default's activity on a switch
yyhhyyyyyy Nov 20, 2026
c8a9d07
fix(appserver): read the default and the directory from one snapshot
yyhhyyyyyy Nov 20, 2026
8986816
fix(collaboration): keep a request and its reads on the delivery line
yyhhyyyyyy Nov 20, 2026
32ae56b
fix(eventhub): admit a publish before resolving its targets
yyhhyyyyyy Nov 20, 2026
918c515
fix(capabilities): bind a prompt suggestion to its line
yyhhyyyyyy Nov 20, 2026
68284bd
test(collaboration): wait for the request's own result
yyhhyyyyyy Nov 20, 2026
7f3370b
style: format the review's changes
yyhhyyyyyy Nov 20, 2026
e08ca12
test(storage): pin the switch's activity on an empty line
yyhhyyyyyy Nov 20, 2026
242a197
docs(design): state the root-only compatibility rule and the new cursor
yyhhyyyyyy Nov 20, 2026
7ad31f6
fix(appserver): pass the borrowed Session to the unnamed target
yyhhyyyyyy Nov 20, 2026
e7b3944
docs(architecture): regenerate the module graph
yyhhyyyyyy Nov 20, 2026
32c4fa5
fix(storage): date an empty default line by its opening
yyhhyyyyyy Nov 20, 2026
a702c22
fix(storage): fail on an undecodable opening event
yyhhyyyyyy Nov 20, 2026
490a295
fix(eventhub): answer an unresolvable target and check subscribe first
yyhhyyyyyy Nov 20, 2026
7eac5d8
fix(collaboration): stop the delivered line when a request recovers
yyhhyyyyyy Nov 20, 2026
ff6a551
docs(design): state the per-target receipt and the recovery line
yyhhyyyyyy Nov 20, 2026
551afe5
test(appserver): read the attach cursor beside the listed record
yyhhyyyyyy Nov 20, 2026
a22976a
Merge remote-tracking branch 'origin/main' into hui/branch-default-ro…
yyhhyyyyyy Nov 20, 2026
fdf4e80
fix(eventhub): answer every resolution failure in the target's receipt
yyhhyyyyyy Nov 20, 2026
432a789
test(collaboration): give the seeded store up before the relaunch
yyhhyyyyyy Nov 20, 2026
c982431
docs(appserver): keep the default cursor on the attach reply alone
yyhhyyyyyy Nov 20, 2026
73da4dc
Merge remote-tracking branch 'origin/main' into hui/branch-default-ro…
yyhhyyyyyy Nov 20, 2026
64768a6
fix(eventhub): resolve an omitted target Session once, failure included
yyhhyyyyyy Nov 20, 2026
e42c7bb
fix(eventhub): resolve a subscribe's omitted branch before its Sessio…
yyhhyyyyyy Nov 20, 2026
ec337c6
docs(eventhub): say where a subscribe's and an unsubscribe's Session …
yyhhyyyyyy Nov 20, 2026
dc50e54
fix(appserver): date a storeless summary by a line's opening
yyhhyyyyyy Nov 20, 2026
436a83d
fix(appserver): keep a storeless summary valid when its line ends
yyhhyyyyyy Nov 20, 2026
2d9085f
docs(appserver): bound a storeless summary's re-read
yyhhyyyyyy Nov 20, 2026
0410295
fix(runtime): classify a branch's lifecycle in one tree lock
yyhhyyyyyy Nov 20, 2026
f775bdb
Merge remote-tracking branch 'origin/main' into hui/branch-default-ro…
yyhhyyyyyy Nov 21, 2026
f28ee51
Merge remote-tracking branch 'origin/main' into hui/pr1917-r2
yyhhyyyyyy Nov 21, 2026
a50b350
Merge remote-tracking branch 'origin/main' into hui/pr1917-r2
yyhhyyyyyy Nov 21, 2026
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
153 changes: 125 additions & 28 deletions crates/dim-agent-capabilities/src/prompt_suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ use dim_agent_runtime::{
SessionLifecycle,
};
use dim_agent_types::{
DEFAULT_BRANCH_ID, EventKind, Message, MessageContent, MessagePart, ModelRequest, Role,
TurnOutcome,
EventKind, Message, MessageContent, MessagePart, ModelRequest, Role, TurnOutcome,
};
use futures_util::StreamExt;
use rutis::Ctx;
Expand Down Expand Up @@ -406,6 +405,10 @@ enum Settled {

struct InFlight {
turn_id: String,
/// The line whose turn this generation continues, fixed when the request
/// was admitted: a `branch/default` after it cancels the flight, and the
/// publication rechecks the line before it offers anything.
line: String,
/// The identity of this invocation, told apart from another request for
/// the same turn: only the invocation still in the slot may change it or
/// announce anything.
Expand All @@ -424,6 +427,11 @@ struct InFlight {

#[derive(Default)]
struct State {
/// The line the cached turn and every offer above belong to: the line the
/// Session's conversation was on when they were read. A move clears them,
/// so a request for the former line's turn never answers for the new one
/// (design §9, §15).
line: Option<String>,
latest_turn: Option<String>,
completed: bool,
call: Option<Call>,
Expand Down Expand Up @@ -706,6 +714,27 @@ impl Part {
}
}

/// Clears what the line the conversation left cached: the generation in
/// flight (announced when it had started), the shown offer, and the turn
/// facts read from that line. Called under the state lock, so an offer can
/// never follow the clearing that withdrew it.
fn clear_for_branch(&self, state: &mut State) {
let flight = state.cancel_in_flight().filter(|(_, started)| *started);
let clear = state.take_offer().or(flight.map(|(turn_id, _)| turn_id));
if let Some(turn_id) = clear {
self.notice(
"cleared",
json!({"turnId": turn_id, "reason": "branch_changed"}),
);
}
state.latest_turn = None;
state.completed = false;
state.call = None;
state.content = None;
state.streamed = None;
state.newer_input = false;
}

/// A committed write on the source: read the new document, and clear the
/// shown offer and the request in flight only when the switch turned off.
/// A `maxChars` change alone leaves them alone, because they were valid
Expand Down Expand Up @@ -773,12 +802,36 @@ impl Part {
let SessionBroadcastEvent::Event { branch_id, event } = record else {
return;
};
if branch_id != DEFAULT_BRANCH_ID {
return;
}
// The suggestion follows one line: the line the Session's conversation
// is on. The commit of a move clears the turn, the offer and the
// generation the previous line left, so nothing read from it is ever
// offered or admitted on the new one (design §9, §15).
let switched = match &event.kind {
EventKind::BranchDefault(data) => Some(data.branch.clone()),
_ => None,
};
// The notice is emitted under the state lock, so the order of
// notices matches the order of the state changes they report.
let mut state = self.state.lock().unwrap();
if let Some(branch) = switched {
if state.line.as_deref() != Some(branch.as_str()) {
self.clear_for_branch(&mut state);
state.line = Some(branch);
}
return;
}
if state.line.is_none() {
// The first event names the line through the tree, not through
// itself: a line opened beside the conversation also broadcasts.
let Ok(default) = self.hosts.tree.default_branch() else {
return;
};
state.line = Some(default);
}
let line = state.line.clone().expect("the line is set");
if branch_id != &line {
return;
}
let mut clear: Option<(String, &'static str)> = None;
match &event.kind {
EventKind::TurnStart(data) => {
Expand Down Expand Up @@ -858,13 +911,23 @@ impl Part {
let token = cancel.child_token();
let settings = self.read_settings(token.clone()).await?;
let max_chars = settings.max_chars.clamp(10, 200);
// The line this request continues, read once: admission, the
// compaction precheck and the publication all check this line
// (design §9, §15).
let line = match self.hosts.tree.default_branch() {
Ok(line) => line,
Err(error) => return Err(RpcError::service("failed", error.to_string())),
};
// The state lock leaves the request either registered as this
// turn's owner, or holding the flight it shares and waits on.
let mut registered = None;
let shared = {
let mut state = self.state.lock().unwrap();
state.enabled = Some(settings.enabled);
match self.decision(&state, &params.turn_id, &settings, None) {
if state.line.is_none() {
state.line = Some(line.clone());
}
match self.decision(&state, &params.turn_id, &settings, None, &line) {
Decision::Refused(reason) => return Ok(refused(reason)),
Decision::Shared => {
let flight = state
Expand All @@ -890,6 +953,7 @@ impl Part {
let (sender, outcome) = watch::channel(None);
state.in_flight = Some(InFlight {
turn_id: params.turn_id.clone(),
line: line.clone(),
invocation,
cancel: token.clone(),
started: false,
Expand Down Expand Up @@ -923,7 +987,7 @@ impl Part {
// The pending registration holds the slot across the preflight, so a
// settings change, a new input, a dismissal or the Session's close
// cancels this request like one already in flight.
if self.compaction_due(max_chars, token.clone()).await {
if self.compaction_due(max_chars, &line, token.clone()).await {
settle(
&mut self.state.lock().unwrap(),
Settled::Refused("compaction_due"),
Expand Down Expand Up @@ -952,20 +1016,22 @@ impl Part {
.as_ref()
.is_some_and(|flight| flight.invocation == invocation);
if !ours || token.is_cancelled() {
let reason = self.cancelled_reason(&state, &params.turn_id, &settings, invocation);
let reason =
self.cancelled_reason(&state, &params.turn_id, &settings, invocation, &line);
settle(&mut state, Settled::Refused(reason));
return Ok(refused(reason));
}
let ready = match self.decision(&state, &params.turn_id, &settings, Some(invocation)) {
Decision::Refused(reason) => {
settle(&mut state, Settled::Refused(reason));
return Ok(refused(reason));
}
// `ours` was just checked: the slot holds this invocation,
// and a decision about its own flight is never shared.
Decision::Shared => unreachable!("a request never shares its own flight"),
Decision::Ready(call, content) => (call, content),
};
let ready =
match self.decision(&state, &params.turn_id, &settings, Some(invocation), &line) {
Decision::Refused(reason) => {
settle(&mut state, Settled::Refused(reason));
return Ok(refused(reason));
}
// `ours` was just checked: the slot holds this invocation,
// and a decision about its own flight is never shared.
Decision::Shared => unreachable!("a request never shares its own flight"),
Decision::Ready(call, content) => (call, content),
};
state.enabled = Some(settings.enabled);
if let Some(flight) = state.in_flight.as_mut() {
flight.started = true;
Expand Down Expand Up @@ -1031,10 +1097,11 @@ impl Part {
/// and the settings as they are now.
async fn shared_refusal(&self, turn_id: &str, invocation: u64) -> Result<Value, RpcError> {
let settings = self.read_settings(self.stopping.child_token()).await?;
let line = self.hosts.tree.default_branch().unwrap_or_default();
let state = self.state.lock().unwrap();
Ok(refused(
self.cancelled_reason(&state, turn_id, &settings, invocation),
))
Ok(refused(self.cancelled_reason(
&state, turn_id, &settings, invocation, &line,
)))
}

/// What a request cancelled during its preflight answers. The gates see
Expand All @@ -1046,28 +1113,36 @@ impl Part {
turn_id: &str,
settings: &PromptSuggestionSettings,
invocation: u64,
line: &str,
) -> &'static str {
match self.decision(state, turn_id, settings, Some(invocation)) {
match self.decision(state, turn_id, settings, Some(invocation), line) {
Decision::Refused(reason) => reason,
Decision::Shared | Decision::Ready(_, _) => "dismissed",
}
}

/// `own` names the invocation whose pending registration this decision
/// is about: the gates ask whether a *different* request is in flight.
/// `line` is the branch the request continues, read once by the caller:
/// cached turn facts from another line are never admitted
/// (design §9, §15).
fn decision(
&self,
state: &State,
turn_id: &str,
settings: &PromptSuggestionSettings,
own: Option<u64>,
line: &str,
) -> Decision {
if !settings.enabled {
return Decision::Refused("disabled");
}
if !self.root {
return Decision::Refused("not_root");
}
if state.line.as_deref() != Some(line) {
return Decision::Refused("branch_changed");
}
if state.latest_turn.as_deref() != Some(turn_id) || state.newer_input {
return Decision::Refused("not_latest_turn");
}
Expand Down Expand Up @@ -1099,8 +1174,11 @@ impl Part {
Decision::Ready(call, content)
}

async fn compaction_due(&self, max_chars: u32, cancel: CancellationToken) -> bool {
let Ok(branch) = self.hosts.tree.get(DEFAULT_BRANCH_ID) else {
/// The compaction precheck of the request's own line: the branch the
/// admission read, never a default re-read that a move could have
/// changed (design §9, §15).
async fn compaction_due(&self, max_chars: u32, line: &str, cancel: CancellationToken) -> bool {
let Ok(branch) = self.hosts.tree.get(line) else {
return false;
};
let Ok(preparation) = branch.service::<ContextPreparation>() else {
Expand Down Expand Up @@ -1164,12 +1242,31 @@ impl Part {
// order of notices matches the order of the state changes they
// report, so an offer can never follow the clearing that withdrew it.
let mut state = self.state.lock().unwrap();
let current = state
let flight = state
.in_flight
.as_ref()
.is_some_and(|flight| flight.invocation == invocation);
if current {
state.in_flight = None;
.filter(|flight| flight.invocation == invocation)
.map(|flight| flight.line.clone());
let Some(flight_line) = flight else {
drop(state);
#[cfg(feature = "testing")]
if let Some(completion) = &completion {
completion.passed_now();
}
return;
};
// The publication rechecks the line the request was admitted on: a
// move that committed while the generation ran withdraws this
// generation instead of offering it on the new line (design §9, §15).
let line = self.hosts.tree.default_branch().ok();
let moved = line.as_deref() != Some(flight_line.as_str());
state.in_flight = None;
if moved {
self.notice(
"cleared",
json!({"turnId": turn_id, "reason": "branch_changed"}),
);
} else {
match outcome {
Ok(text) => {
state.offer = Some(Offer {
Expand Down
20 changes: 12 additions & 8 deletions crates/dim-agent-capabilities/src/shell_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use dim_agent_runtime::{
AgentBuilder, Names, SessionConfig, SessionHold, SessionIdentity, SessionLifecycle,
SessionPhase,
};
use dim_agent_types::{DEFAULT_BRANCH_ID, InputMessageData, InputMode};
use dim_agent_types::{InputMessageData, InputMode};
use rutis::Ctx;
use rutis::host::{BoxFuture, CtxHost, DynPlugin, Effect, Key, TypeKey};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -75,15 +75,12 @@ struct RunParams {
/// Read by Rpc to route the call; the provider already serves this Session.
#[serde(rename = "sessionId")]
_session_id: String,
#[serde(default = "default_branch")]
branch_id: String,
#[serde(default)]
branch_id: Option<String>,
run_id: String,
command: String,
mode: Mode,
}
fn default_branch() -> String {
DEFAULT_BRANCH_ID.into()
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
Expand Down Expand Up @@ -224,7 +221,14 @@ impl ShellInput {
}
check_run_id(&p.run_id)?;
self.admit(&self.registry.lock().unwrap(), &p.run_id, &cancel)?;
self.tree.get(&p.branch_id)?;
// A run that names no line belongs to the line the Session's
// conversation is on, resolved once for the whole run (design §9,
// §15).
let branch_id = match p.branch_id {
Some(branch_id) => branch_id,
None => self.tree.default_branch().map_err(RpcError::from)?,
};
self.tree.get(&branch_id)?;
let built = async {
#[cfg(feature = "testing")]
testing::pause(&self.cwd).await;
Expand Down Expand Up @@ -262,7 +266,7 @@ impl ShellInput {
})?;
let info = RunInfo {
run_id: p.run_id,
branch_id: p.branch_id,
branch_id,
mode: p.mode,
command: p.command,
started_at: SystemTime::now()
Expand Down
Loading