t8y2/dbx · error
a cancellation token is always available
Error message
a cancellation token is always available
What it means
In the single-driver install path, the code builds active_cancellation from either an owned token (created from operation_id via begin_install_cancellation) or a caller-supplied cancellation token. The expect("a cancellation token is always available") enforces the invariant that at least one of operation_id/cancellation is present; if both are None the program panics instead of proceeding.
Source
Thrown at crates/dbx-core/src/agent_service.rs:1137
}
None => &[],
};
let _driver_guard = lock_or_cancel(&driver_lock, command_tokens).await?;
// Use the command-scoped token when one was registered before any awaitable
// setup (blocker check, lock wait, registry fetch) so a cancel fired during
// that window is observed here instead of being lost. Otherwise register a
// token owned by this call keyed by a fresh operation id so two concurrent
// installs of the same driver cannot replace each other's token.
let owned_operation_id: Option<String> =
if cancellation.is_some() { None } else { Some(uuid::Uuid::new_v4().to_string()) };
let owned_cancellation: Option<Arc<AgentInstallCancellation>> = match owned_operation_id.as_deref() {
Some(operation_id) => Some(am.begin_install_cancellation(&install_cancellation_key(operation_id)).await),
None => None,
};
let active_cancellation: &AgentInstallCancellation = owned_cancellation
.as_deref()
.or_else(|| cancellation.map(|token| token.as_ref()))
.expect("a cancellation token is always available");
if active_cancellation.is_cancelled() {
if let (Some(operation_id), Some(token)) = (owned_operation_id.as_deref(), owned_cancellation.as_ref()) {
am.finish_install_cancellation(&install_cancellation_key(operation_id), token).await;
}
return Err(AGENT_DOWNLOAD_CANCELED_ERROR.to_string());
}
let result = install_agent_driver_with_batch_unlocked(
am,
db_type,
source,
progress,
current,
total_drivers,
&[active_cancellation],
)
.await;
View on GitHub (pinned to c0390bff16)
Solutions
- Guarantee every caller supplies an operation id or a cancellation token before entering the install path.
- Create a token when missing: call begin_install_cancellation with a fresh operation id instead of expecting.
- Convert the expect into an explicit error return if the path can legitimately run without cancellation.
- Add an integration test covering the None/None input combination.
Example fix
// before
let active_cancellation = owned_cancellation.as_deref()
.or_else(|| cancellation.map(|t| t.as_ref()))
.expect("a cancellation token is always available");
// after
let Some(active_cancellation) = owned_cancellation.as_deref()
.or_else(|| cancellation.map(|t| t.as_ref())) else {
return Err("no cancellation token provided".to_string());
}; Defensive patterns
Strategy: validation
Validate before calling
// validate inputs before the single-driver install path
assert!(operation_id.is_some() || cancellation.is_some(),
"install requires an operation id or a cancellation token"); Type guard
fn has_install_cancellation(op_id: Option<&OperationId>, token: Option<&AgentInstallCancellation>) -> bool {
op_id.is_some() || token.is_some()
} Try / catch
let active = owned_cancellation.as_deref()
.or_else(|| cancellation.map(|t| t.as_ref()))
.ok_or_else(|| "no cancellation token provided for install".to_string())?; Prevention
- Thread a cancellation token through every install call site.
- Generate an operation id (and thus a token) when a caller has none.
- Replace expect with ok_or/else returning an error for optional token resolution.
- Cover all-None inputs with a regression test.
When it happens
Trigger: Invoking the install path with neither an operation id nor a borrowed cancellation token — e.g. a new caller passes None for both, or refactoring changed the fallback order so cancellation is consumed before the expect.
Common situations: Call sites added after the invariant was introduced that forget to thread a cancellation token; internal callers that previously always created an operation id start passing None; test harnesses constructing the context manually with all-None fields.
Related errors
- a batch cancellation token is always available
- driver token registered
- checked one driver
- checked one native platform
- root count checked above
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/094e01870a21af19.
Report an issue: GitHub.