Skip to content
Merged
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
52 changes: 29 additions & 23 deletions crates/dim-agent-runtime/src/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ pub const SESSION_GROUP: &str = "session";
/// Instanced loader group of one branch, nested in [`SESSION_GROUP`].
pub const BRANCH_GROUP: &str = "branch";

#[derive(serde::Serialize, serde::Deserialize)]
pub(crate) struct OpeningAdvanced(pub PluginId);
#[derive(Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub(crate) enum OpeningAdvanced {
Plugin(PluginId),
Instance(String),
}
impl rutis::Event for OpeningAdvanced {
const NAME: &'static str = "dim/opening-advanced";
type Value = ();
Expand All @@ -41,15 +45,8 @@ impl rutis::Event for OpeningAdvanced {
/// work runs on a blocking thread reports from there. A context whose plugin
/// has no live fiber reports nothing: the report would be dropped anyway.
pub fn opening_advanced(ctx: &Ctx) {
let instance = ctx.instance();
let id = ctx
.diagnostics()
.plugins
.into_iter()
.find(|plugin| plugin.instance == instance)
.map(|plugin| plugin.id);
if let Some(id) = id {
let _ = ctx.emit(OpeningAdvanced(id));
if !ctx.cancellation_token().is_cancelled() {
let _ = ctx.emit(OpeningAdvanced::Instance(ctx.instance().to_string()));

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 new cancellation_token().is_cancelled() guard is a caller-visible behavior change that the /// above does not state. A live fiber whose generation was cancelled (rollback, restart, reload) still appears in diagnostics, so before this change its opening_advanced call emitted and could renew an inactivity interval; now it reports nothing. I agree with the guard because it matches A3's "Restarting the same row does not renew it", and the no-live-fiber sentence above remains true because a destroyed fiber yields a pre-cancelled token. The missing case is the cancelled generation. Failure scenario: a caller keeps reporting during teardown, when the row is still live, and now silently loses those reports with no hint in the contract that cancellation gates them. Fix: extend the sentence to say that a context whose generation was cancelled reports nothing. Not blocking.

}
}

Expand All @@ -68,7 +65,7 @@ pub struct StartupProgress {
ctx: Ctx,
started: tokio::time::Instant,
timeout: Duration,
active: Arc<Mutex<HashMap<PluginId, tokio::time::Instant>>>,
active: Arc<Mutex<HashMap<OpeningAdvanced, tokio::time::Instant>>>,
report: Arc<Mutex<Option<ProgressReport>>>,
listeners: Vec<rutis::Disposer>,
}
Expand All @@ -84,7 +81,7 @@ impl StartupProgress {
if event.to == FiberState::Active {
let inserted = {
let mut changes = changes.lock().unwrap();
match changes.entry(event.plugin_id) {
match changes.entry(OpeningAdvanced::Plugin(event.plugin_id)) {
std::collections::hash_map::Entry::Vacant(entry) => {
entry.insert(tokio::time::Instant::now());
true
Expand Down Expand Up @@ -114,7 +111,7 @@ impl StartupProgress {
changes
.lock()
.unwrap()
.insert(event.0, tokio::time::Instant::now());
.insert((*event).clone(), tokio::time::Instant::now());
notify_progress(&reports);
Ok(None)
})?);
Expand Down Expand Up @@ -150,15 +147,24 @@ impl StartupProgress {
.into_iter()
.flat_map(|id| subtree(&snapshot, id))
.collect();
let last = self
.active
.lock()
.unwrap()
.iter()
.filter(|(id, _)| members.contains(id))
.map(|(_, time)| *time)
.max()
.unwrap_or(self.started);
let last = {
let active = self.active.lock().unwrap();
let by_plugin = members
.iter()
.filter_map(|&id| active.get(&OpeningAdvanced::Plugin(id)));
let by_instance = snapshot
.plugins
.iter()
.filter(|plugin| members.contains(&plugin.id))
.filter_map(|plugin| {
active.get(&OpeningAdvanced::Instance(plugin.instance.to_string()))
});
by_plugin
.chain(by_instance)
.copied()
.max()
.unwrap_or(self.started)
};
deadline = last + self.timeout;
if deadline <= tokio::time::Instant::now() {
return None;
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-agent-runtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl BranchLifecycle {
let mut pending: FuturesUnordered<_> = receipts.into_iter().collect();
while let Some(result) = pending.next().await {
result?;
ctx.emit(crate::assembly::OpeningAdvanced(scope))?;
ctx.emit(crate::assembly::OpeningAdvanced::Plugin(scope))?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-agent-runtime/src/timeline_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl TimelineContext {
if dispatched > sequence {
sequence = dispatched;
if inner.lifecycle.phase() == BranchPhase::Loading
&& let Err(error) = inner.ctx.emit(OpeningAdvanced(inner.view.id))
&& let Err(error) = inner.ctx.emit(OpeningAdvanced::Plugin(inner.view.id))
{
inner.dispatcher.fail(error.into());
}
Expand Down
10 changes: 8 additions & 2 deletions crates/dim-agent-runtime/tests/opening_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ async fn opened(reports: bool) -> dim_agent_runtime::Result<()> {
gap: Duration::from_millis(60),
reports,
});
if !reports {

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 new sibling case covers filtering for a root-level sibling, and opened(true) covers the instance path for a directly registered root plugin. No committed test calls opening_advanced from a mounted or loader-created nested row while a shorter inactivity interval is running. The SlowAssemblyRow fixture in the_startup_note_reports_assembly_progress_until_the_server_opens does call it from a required row, but that test uses the default 10 s startup interval and asserts the note counter, not renewal of a shorter interval; InputQueue recovery under a branch is the production caller, and the rows whose identity this change resolves through snapshot.plugins are nested. The base tests cited in the PR body (nested_instances_preserve_optional_rows_and_cleanup_across_create_restore_and_failure, a_row_cancelled_while_its_child_waits_ends_the_wait) do not call opening_advanced, so they do not cover this path. Failure scenario: a regression that resolves the instance key incorrectly for loader-created rows would make an opening whose only progress comes from such a row time out after one interval, and no test would fail. Fix: add a nested variant of this test, for example a parent apply that mounts a reporting child and calls wait_active on the parent with a 150 ms interval while the child works for 360 ms. I ran that variant locally and it passes. Not blocking.

root.plugin(Progressing {
steps: 6,
gap: Duration::from_millis(60),
reports: true,
});
}
let result = wait_active(
&root,
std::slice::from_ref(&view),
Expand All @@ -56,9 +63,8 @@ async fn an_opening_that_reports_progress_outlives_its_interval() {
.expect("reported progress renews the interval");
}

/// The same opening without reports ends at the interval.
#[tokio::test]
async fn an_opening_that_reports_nothing_times_out() {
async fn progress_in_a_sibling_does_not_renew_an_opening() {
let error = opened(false)
.await
.expect_err("an inactive opening must time out");
Expand Down