Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
1c47d7b
fix(app-server): admit only lowercase ASCII Session ids and reject ca…
yyhhyyyyyy Nov 27, 2026
9c13cf4
fix(app-server): check fork id conflicts inside the first copy transa…
yyhhyyyyyy Nov 27, 2026
a3b7694
fix(app-server): reject new Session ids sharing an output directory w…
yyhhyyyyyy Nov 27, 2026
bab7214
fix(app-server): precedence and coverage fixes for legacy Session id …
yyhhyyyyyy Nov 28, 2026
0340e6f
docs(app-server): read the v48 format summary as historical
yyhhyyyyyy Nov 28, 2026
81f46c6
fix(app-server): admit caller-selected Session ids at the store's ins…
yyhhyyyyyy Nov 28, 2026
66aa7d7
fix(app-server): resolve relative segments before comparing legacy Se…
yyhhyyyyyy Nov 28, 2026
471dd90
test(app-server): admit ids through the sqliteStorage createSession d…
yyhhyyyyyy Nov 28, 2026
98b8ea5
fix(app-server): judge legacy Session output overlaps by the resolved…
yyhhyyyyyy Nov 28, 2026
57fb8eb
fix(app-server): bound the literal resolution branch within the state…
yyhhyyyyyy Nov 28, 2026
bb8f65f
style(app-server): reflow the canonical id formatting in the output-r…
yyhhyyyyyy Nov 28, 2026
b3e3e34
style(app-server): drop the unused literal root spelling from the out…
yyhhyyyyyy Nov 28, 2026
08be230
test(app-server): admit the windows isolation control in a fresh stor…
yyhhyyyyyy Nov 28, 2026
743e9c0
fix(app-server): resolve trailing-space parent segments onto the pare…
yyhhyyyyyy Nov 28, 2026
1587144
test(app-server): seed the owner agent and cover the rooted shapes an…
yyhhyyyyyy Nov 28, 2026
0f71e78
fix(app-server): refuse the undecidable state-cap shapes and resolve …
yyhhyyyyyy Nov 28, 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
31 changes: 30 additions & 1 deletion crates/dim-agent-runtime/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ impl CreateSessionOptions {
/// completes. Without it, the Session is created under a generated UUIDv4.
///
/// The id must be one normal path component, which is what Session
/// command-output storage addresses ([`check_session_id`]);
/// command-output storage addresses ([`check_session_id`]), and have the
/// shape every newly admitted id has ([`check_new_session_id`]);
/// [`Agent::create_session`] rejects any other id before it prepares,
/// writes or publishes.
pub fn prepare<F>(mut self, id: impl Into<String>, prepare: F) -> Self
Expand Down Expand Up @@ -110,6 +111,33 @@ pub fn check_session_id(id: &str) -> Result<()> {
}
Ok(())
}
/// The Windows device names a directory can never be named, with or without
/// an extension: on a Windows output volume they alias the device.
const WINDOWS_DEVICE_NAMES: &[&str] = &[
"con", "prn", "aux", "nul", "com0", "com1", "com2", "com3", "com4", "com5", "com6", "com7",
"com8", "com9", "lpt0", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9",
];
/// Requires the shape every newly admitted Session id has (#2204): one to
/// sixty-four characters, each a lowercase ASCII letter, digit, underscore or
/// hyphen, and never a Windows reserved device name. Lowercase ASCII has no
/// folding variants, so two ids admitted under this rule can never address
/// the same output directory on a volume that folds case; the length bound
/// and the reserved names close the Windows aliasing and overlong-name
/// hazards by construction. Only creation entries apply it — deletion, a
/// fork's source and restoration keep [`check_session_id`], so ids stored
/// before this rule stay operable.
pub fn check_new_session_id(id: &str) -> Result<()> {
if id.is_empty()
|| id.len() > 64
|| !id.bytes().all(|byte| {
byte.is_ascii_lowercase() || byte.is_ascii_digit() || byte == b'_' || byte == b'-'
})
|| WINDOWS_DEVICE_NAMES.contains(&id)
{
return Err(AgentError::InvalidInput(format!("invalid Session id {id}")));
}
Ok(())
}
impl Agent {
pub(crate) fn new(builder: AgentBuilder, assembly: Assembly, placement: Placement) -> Self {
Self(Arc::new(AgentInner {
Expand Down Expand Up @@ -144,6 +172,7 @@ impl Agent {
let (id, start) = match prepare {
Some((id, prepare)) => {
check_session_id(&id)?;
check_new_session_id(&id)?;
(id, SessionStart::Prepared(prepare))
}
None => (Uuid::new_v4().to_string(), SessionStart::Create),
Expand Down
1 change: 1 addition & 0 deletions crates/dim-app-server/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ pub fn run_with(
.unwrap_or_else(|| product_home.join("rust")),
)
.join(crate::storage::COMMAND_OUTPUT_DIRECTORY);
config.output_root = Some(output_root.clone());
defaults::install_local_execution(
&mut builder,
ModelProviderPlugin::process,
Expand Down
22 changes: 19 additions & 3 deletions crates/dim-app-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ pub struct ServerConfig {
pub pipe_name: Option<String>,
pub websocket_address: Option<SocketAddr>,
pub database_path: Option<PathBuf>,
/// The root Session output directories join under, when it is not
/// `<database directory>/command-output` (session files §3.1): a host
/// whose command-output layout moves away from the database — the CLI's
/// split home, the xtask harness — names it here so the Session-id
/// admission compares resolved output directories against the root the
/// writing side actually uses (#2204). Rust-internal: it stays out of
/// every serialized configuration and protocol surface.
pub output_root: Option<PathBuf>,
pub target_home: Option<PathBuf>,
pub product_home: Option<PathBuf>,
/// The user home the process reports, `$HOME` by default. A host that
Expand Down Expand Up @@ -147,6 +155,7 @@ impl Default for ServerConfig {
pipe_name: None,
websocket_address: Some(([127, 0, 0, 1], 0).into()),
database_path: None,
output_root: None,
target_home: None,
product_home: None,
platform_home: None,
Expand Down Expand Up @@ -955,14 +964,21 @@ pub async fn serve(mut builder: AgentBuilder, mut config: ServerConfig) -> Resul
if let (Some(path), Some(files_root)) = (&config.database_path, session_files_root) {
let path = path.clone();
let assembly_progress = assembly_progress.clone();
let output_root = config.output_root.clone();
rows.push(register_part(
&mut builtins,
builder.catalog(),
move |_| {
Ok(Box::new(match &assembly_progress {
Some(assembly_progress) => storage::SqliteStoragePlugin::new(path.clone())
.with_assembly_progress(assembly_progress.clone()),
let plugin = match &output_root {
Some(output_root) => storage::SqliteStoragePlugin::new(path.clone())
.with_output_root(output_root.clone()),
None => storage::SqliteStoragePlugin::new(path.clone()),
};
Ok(Box::new(match &assembly_progress {
Some(assembly_progress) => {
plugin.with_assembly_progress(assembly_progress.clone())
}
None => plugin,
}))
},
)?);
Expand Down
62 changes: 55 additions & 7 deletions crates/dim-app-server/src/storage/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,13 @@ fn same_schema(actual: &[(String, String)], mut expected: Vec<(&str, String)>) -
}
/// The read indexes the daemon creates at open: the latest-turn window's
/// ([session-history-window §5.1](../../../../docs/design/appserver/session-history-window.md#51-the-derived-index)),
/// the policy window's turn starts, and the event query's by kind, which carries
/// the event id so a kind read needs no table body for it (ADR 019 D4). They
/// carry no data and no decode rule, so they are not part of the format: `schema`
/// and the format gate ignore them, and every open recreates them.
/// the policy window's turn starts, the event query's by kind, which carries
/// the event id so a kind read needs no table body for it (ADR 019 D4), the
/// case-insensitive Session id lookup the creation collision checks run, and
/// the stored ids outside the newly admitted alphabet, which the
/// output-directory conflict lookup reads (#2204). They carry no data and no
/// decode rule, so they are not part of the format: `schema` and the format
/// gate ignore them, and every open recreates them.
const DERIVED_INDEXES: &[(&str, &str)] = &[
(
"timeline_history_anchors",
Expand All @@ -645,6 +648,14 @@ const DERIVED_INDEXES: &[(&str, &str)] = &[
"timeline_policy_turns",
"CREATE INDEX IF NOT EXISTS timeline_policy_turns ON timeline_events(session_id, branch_id, kind, sequence, event_id) WHERE kind = 'turn/start'",
),
(
"agent_sessions_session_id_nocase",
"CREATE INDEX IF NOT EXISTS agent_sessions_session_id_nocase ON agent_sessions(session_id COLLATE NOCASE)",
),
(
"agent_sessions_session_id_non_ascii_word",
"CREATE INDEX IF NOT EXISTS agent_sessions_session_id_non_ascii_word ON agent_sessions(session_id) WHERE session_id GLOB '*[^0-9A-Za-z_-]*'",
),
];
/// The schema objects of `connection`'s database that belong to the format,
/// sorted by name.
Expand Down Expand Up @@ -1269,6 +1280,12 @@ pub struct SqliteStorage {
admission: Mutex<Admission>,
idle: tokio::sync::Notify,
pub(super) path: PathBuf,
/// The root Session output directories join under (session files §3.1):
/// `<database directory>/command-output`, or the root an embedding host
/// names through [`SqliteStorage::open_with_output_root`] when its
/// command-output layout differs. The Session-id admission compares a
/// stored id's resolved output directory against this root (#2204).
pub(super) output_root: PathBuf,
upgraded_from: Option<u32>,
/// What the v50 image conversion measured about its own work, kept for a
/// flow test that bounds it; feature `testing` only.
Expand Down Expand Up @@ -1462,11 +1479,22 @@ impl Drop for Operation {
}
impl SqliteStorage {
pub fn open(path: PathBuf) -> Result<Arc<Self>> {
Self::open_reporting(path, None)
Self::open_reporting(path, None, None)
}
/// Opens the store with the output root its Sessions write under, when
/// the host's command-output layout is not `<database directory>/command-output`.
/// The admission boundary compares resolved output directories against
/// this root (#2204); every write path of the store shares it.
pub fn open_with_output_root(path: PathBuf, output_root: PathBuf) -> Result<Arc<Self>> {
Self::open_reporting(path, None, Some(output_root))
}
/// Opens the store; with `ctx`, a format upgrade reports its progress to
/// that plugin's opening and keeps the CLI's progress note current.
pub(crate) fn open_reporting(path: PathBuf, ctx: Option<&Ctx>) -> Result<Arc<Self>> {
pub(crate) fn open_reporting(
path: PathBuf,
ctx: Option<&Ctx>,
output_root: Option<PathBuf>,
) -> Result<Arc<Self>> {
let parent = path
.parent()
.filter(|path| !path.as_os_str().is_empty())
Expand Down Expand Up @@ -1890,6 +1918,11 @@ impl SqliteStorage {
lease: Some(admission),
}),
idle: tokio::sync::Notify::new(),
output_root: output_root.unwrap_or_else(|| {
path.parent()
.map(|directory| directory.join(super::COMMAND_OUTPUT_DIRECTORY))
.unwrap_or_else(|| PathBuf::from(super::COMMAND_OUTPUT_DIRECTORY))
}),
path,
upgraded_from,
#[cfg(feature = "testing")]
Expand Down Expand Up @@ -1941,6 +1974,10 @@ impl SqliteStorage {
lease: None,
}),
idle: tokio::sync::Notify::new(),
output_root: path
.parent()
.map(|directory| directory.join(super::COMMAND_OUTPUT_DIRECTORY))
.unwrap_or_else(|| PathBuf::from(super::COMMAND_OUTPUT_DIRECTORY)),
path,
upgraded_from: None,
#[cfg(feature = "testing")]
Expand Down Expand Up @@ -2966,15 +3003,25 @@ fn storage_failure(error: AgentError) -> BridgeError {

pub struct SqliteStoragePlugin {
path: PathBuf,
output_root: Option<PathBuf>,
assembly: Option<Arc<AssemblyProgress>>,
}
impl SqliteStoragePlugin {
pub fn new(path: PathBuf) -> Self {
Self {
path,
output_root: None,
assembly: None,
}
}
/// The output root the host's Sessions write under, when it is not
/// `<database directory>/command-output` (#2204): the admission boundary
/// compares resolved output directories against the root the writing
/// side actually uses.
pub fn with_output_root(mut self, output_root: PathBuf) -> Self {
self.output_root = Some(output_root);
self
}
/// Reports the opening's progress in the startup note after this store's
/// own note is gone; the host removes it when its listeners open.
pub(crate) fn with_assembly_progress(mut self, assembly: Arc<AssemblyProgress>) -> Self {
Expand All @@ -2990,8 +3037,9 @@ impl Plugin for SqliteStoragePlugin {
async fn apply(&self, ctx: &Ctx, (): Self::Deps) -> rutis::Result {
let path = self.path.clone();
let reports = ctx.clone();
let output_root = self.output_root.clone();
let storage = tokio::task::spawn_blocking(move || {
SqliteStorage::open_reporting(path, Some(&reports))
SqliteStorage::open_reporting(path, Some(&reports), output_root)
})
.await
.map_err(|error| rutis::Error::from(ErrorKind::PluginFailed(error.into())))??;
Expand Down
Loading
Loading