Repository navigation
Description
Maintainer review narrowed this issue to direction B: minimal admission narrowing for the Session ids that output directories are derived from, instead of the booking lifecycle the issue previously carried. This body is the direction record the maintainer decision asks for: it states the chosen scope, the collision check and its storage format position before the implementation PR starts.
The problem
Every output directory a Session uses is derived from its raw id: the workspace tools write below <output_root>/<session_id>/ (workspace_tools/mod.rs), the daemon hands the tools <database directory>/command-output/ as that root (storage/mod.rs), the persistent shell writes below <home>/.dim/exec/<session_id>/<branch_id> (shell_session.rs), and deletion removes the derived directories (files.rs).
On a volume that folds case, two ids that differ only in case address the same directory: Abc and abc become two rows sharing one directory, deleting one removes the other's output, and a newly admitted id can likewise share a directory with a stored record whose id differs only by case.
Chosen direction
Direction B is chosen: narrow the admission of new ids, and check collisions with stored ids through an index. The maintainer's comment of 2026-11-27:
Direction B is the right scope: it closes the remaining admission finding without a new format, while A adds a booking format, cross-root release and crash reclaim that the merged review record does not require. One correction: B's collision check cannot scan every stored id; either prove the legacy case-variant set is empty and enforce lowercase-ASCII admission alone, or specify the indexed lookup. This is a maintainer decision, so record the chosen direction before the PR starts.
The collision check is the indexed lookup, and the lowercase ASCII admission of the proposed direction B stays. Proving the legacy case-variant set empty is not possible from the repository alone: explicit-id write paths have always accepted arbitrary one-component ids, backup and restore preserve them byte for byte, and admission alone cannot protect deployments that already hold such records. The two parts are complementary: the shape rule makes every newly admitted id folding-free, and the index covers records that predate the rule.
Admission of new ids
On current main, plain creation always generates its own UUIDv4 (agent.rs), so the entries that still admit a caller-selected id are CreateSessionOptions::prepare in the runtime (agent.rs), and the store face's createOwnedSession plus a fork's target id (dispatch at face.rs, implemented at timeline.rs and timeline.rs). The product's own prepared creations pass generated UUIDv4 ids (agents.rs), including its fork path (agents.rs), and the offline migration regenerates UUIDv4 ids as well (native.rs).
At these entries a new id is limited to one to sixty-four characters, each a lowercase ASCII letter, digit, underscore or hyphen, and must not be one of the Windows reserved device names: con, prn, aux, nul, com0 through com9, lpt0 through lpt9. An id failing the rule is rejected with InvalidInput before the creation prepares, writes or publishes. The rule tightens the existing one-path-component validation at these entries (agent.rs); deletion and a fork's source keep that validation unchanged, and restoration continues to load stored ids as written, so records stored before this rule stay operable.
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.
Indexed collision check
The SQLite store gains a derived index agent_sessions_session_id_nocase on agent_sessions(session_id COLLATE NOCASE), created at open with the existing derived indexes (sqlite.rs, creation at sqlite.rs and sqlite.rs). ASCII case folding is exact for this check: every admitted candidate is lowercase ASCII, and a stored id that differs from it only by case can itself contain only ASCII letters.
The check runs at the two entries that write agent_sessions (sqlite.rs): the insertion helper that the low-level createSession storage face and createOwnedSession share (timeline.rs, timeline.rs), inside their write transactions, and the final transaction of a fork copy (timeline.rs). When the index shows a stored id equal to the candidate under the case-insensitive collation, the write refuses it: a candidate byte-identical to a stored id keeps the existing rejection as a Storage error, and only a candidate that differs by case alone is rejected with InvalidInput.
A fork copy is checked twice. Once before its first chunk transaction, because the copy writes branches, arrays, content, events and snapshots in bounded transactions before the final transaction inserts the session row (timeline.rs), and its failure path drops all rows of the fork id (timeline.rs); a refusal there writes nothing and invokes no cleanup, so nothing of a pre-existing Session of the same id can be removed. It is checked once again inside the final IMMEDIATE transaction, before the insert, which closes the race against a concurrent insertion that commits while the chunks copy.
Format position
The format marker stays at version 53 (sqlite.rs): the new index is a derived index that carries no data and no decode rule, and the schema comparison ignores the derived names at open. The format document records this precedent and its cost, which applies here unchanged (native-storage-format.md): a binary built before this change does not know the new derived name, treats it as an unknown schema object, and refuses to open a database that already carries the index with the unsupported-schema error; the database itself is preserved, its rows unchanged, and a current binary can open it again.
Stored data
Records stored before this change are neither migrated nor rewritten. Deletion and use as a fork source keep the one-component validation, and restoration continues to load stored ids as written; a stored id with uppercase letters remains operable as before, and the collision rule only refuses new ids that would share a directory with it.
Out of scope
The booking lifecycle is not implemented: no output-name booking in the output roots, no cross-root release, no crash reclamation and no cross-database ownership arbitration. Output ownership stays per-file rows in session_output_owners under ADR 013. If explicit non-generated ids or several databases sharing one output root ever become supported, the booking lifecycle can come back as its own design.
Regression coverage
The regression tests are written first and fail on code without this change. They cover: a prepared creation whose id violates the admission rule rejected with InvalidInput before any write, and the same rejection through the store face's owned create; a creation and a fork target that differ only by case from a stored id rejected with InvalidInput; a byte-identical duplicate still rejected with a Storage error; a fork whose target is byte-identical to a stored id refused in the pre-check, copying no rows, invoking no cleanup and deleting nothing of the existing Session; a pre-change record with an uppercase id staying deletable and usable as a fork source; the collision check using the covering index rather than scanning the table. The explicit ids the existing flow tests already use, such as named-session, shared, fork and copy, all conform to the admission rule, so no existing test id changes; the two index lists in the storage flow tests gain the new derived name.
Refs #2202.
Activity
revert(runtime): withdraw the Session id booking
[-]Session id booking: a crash leaves a booking nothing reclaims, and Sessions stored before it hold none[/-][+]Session output-name booking: one owner for its whole life in every output root[/+]refactor(runtime): name a prepared creation's Session once (#2202)
yyhhyyyyyy commentedon Nov 26, 2026
With #2202 merged, I re-read this issue against current main and want to confirm scope before implementing. Two candidate directions are below; my read is that the smaller one is what the review record actually asks for, but this issue's body carries the larger one, so I would like direction first.
Current state on main, after the options refactor: plain creation always generates its own UUIDv4, so the only entries that still admit a caller-selected id are
CreateSessionOptions::prepareand the store face'screateOwnedSession/fork(dispatch; the underlyingtimelineStore/sqliteStoragecreateSessionstorage step is not part of this scope). The product's own prepared creation passes a generated UUIDv4 (agents.rs), and the migration generates fresh UUIDv4 ids as well, so stored data in practice has no case-folding pairs.There is no reservation anywhere today: output directories are derived lazily from the raw session id in both roots,
<database dir>/command-output/<id>for workspace tools (mod.rs) and<home>/.dim/exec/<id>/<branch>for the persistent shell (shell_session.rs), ownership is per-file rows insession_output_owners(ADR 013 D2), and delete removes the derived directories before the rows commit (files.rs). Legacy delete and fork apply only the pre-existing one-component check, so records stored before any future admission rule stay operable as the body requires.The open gap this leaves is narrower than the body describes but real: a caller-selected id admitted through
prepareor the store face is validated only as one path component, not for filesystem compatibility or uniqueness on a case-folding volume, so an embedder can still publish a Session whose output fails on first write or shares a directory with a case variant. That is exactly the remaining acceptance of 6062659262 and of 6067362514, narrowed there to verification rather than reservations.Direction A, the full design as the body now reads: book the id's output name in every enabled output root before prepare, writes or publication, with the marker recording the originally booked id and serialized with creations in flight; resolve output directories from the booking instead of the raw id; release only with the final owner, retryably; reclaim crash orphans at startup. This satisfies every acceptance in the body and all four reviews, at the cost of a new native format version, roughly 400-600 lines across storage, runtime, capabilities and host-platform, and a long lifecycle review. Note that 6067362514 explicitly says its remaining acceptance is "not a request to reintroduce reservations", so A goes beyond what the merged review record requires.
Direction B, minimal admission narrowing: keep everything as it is and narrow only the entries that can still admit explicit ids, namely
prepare,createOwnedSession, and a fork's new target session id, requiring a caller-selected id to be a bounded lowercase ASCII name: characters limited to[a-z0-9_-], length 1-64, excluding the Windows reserved device names (con,prn,aux,nul,com0-com9,lpt0-lpt9), rejected before prepare, storage writes or publication. If accepting only generated ids is preferred, the rule can tighten further to lowercase UUIDv4. Delete, restore, and a fork'ssourceSessionIdkeep the existing one-component check unchanged, so legacy records stay operable. Two honest consequences: two ids admitted under this rule can never collapse into each other under case folding, since lowercase ASCII has no folding variants, and the reserved-name and length rules close the Windows and Unicode-folding hazards by construction; but a new id can still share a directory with a pre-existing stored record whose id differs only by case; no such record exists in practice, since stored ids are all lowercase UUIDv4. Admission therefore compares the candidate's lowercase form against the lowercase form of every stored id and rejects the candidate when they collide, even though the candidate itself is already lowercase. Every existing test id on main, the explicit ids inagent_options_flow,storage_flow,transport_flowand friends such asnamed-session,shared,fork,copy,orphan, already matches this shape, so none of those tests needs to change; under a lowercase-UUIDv4-only rule all of them would have to be rewritten. Cost is roughly 30-60 lines and no format change; the price is that the booking, crash recovery and release lifecycle in the body are not implemented, and the issue would be narrowed accordingly.I lean toward B: stored data has no folding pairs in practice, the merged review record closed its findings at the admission level rather than asking for the reservation lifecycle back, and A's cost buys protection against scenarios no current data can reach; if explicit non-generated ids ever become a supported embedder pattern, the booking lifecycle can come back as its own design. Either way I would write the regression tests first: for B, a prepared creation with a non-canonical or folding-alias id is rejected before any write; for A, deleting an unbooked legacy record on a case-insensitive volume leaves the other Session's reservation and output intact.
@zerob13, could you confirm this scope belongs to this issue, and whether you expect direction A or B here?
eric8810 commentedon Nov 27, 2026
Direction B is the right scope: it closes the remaining admission finding without a new format, while A adds a booking format, cross-root release and crash reclaim that the merged review record does not require. One correction: B's collision check cannot scan every stored id; either prove the legacy case-variant set is empty and enforce lowercase-ASCII admission alone, or specify the indexed lookup. This is a maintainer decision, so record the chosen direction before the PR starts.
[-]Session output-name booking: one owner for its whole life in every output root[/-][+]Session output names: lowercase ASCII admission for new ids and indexed case-collision rejection [/+][-]Session output names: lowercase ASCII admission for new ids and indexed case-collision rejection [/-][+]Session output names: lowercase ASCII admission for new ids and indexed case-collision rejection[/+]yyhhyyyyyy commentedon Nov 27, 2026
The direction is recorded: the title and body of this issue now carry direction B, narrowed to lowercase ASCII admission for new ids with the indexed lookup for the collision check. The check is the second branch of the maintainer decision above: an index on
agent_sessions(session_id COLLATE NOCASE)consulted at both write entries, inside the write transactions, instead of scanning every stored id. Newly admitted ids carry no case-folding variants, and the index covers records that predate the rule. Byte-identical duplicates keep the existing Storage error, a case-only variant is rejected with InvalidInput, a fork copy is pre-checked before its first chunk transaction and re-checked inside the final transaction, and the format marker stays at version 53, with the documented derived-index cost that a binary older than this change refuses to open a database carrying the new index while preserving it. The booking lifecycle, cross-root release and crash reclamation are out of scope, as direction B decided.eric8810 commentedon Nov 27, 2026
PR #2283 now implements direction B. The issue is still P3, and the PR gate requires an accepted issue (P0/P1/P2). Should #2204 be accepted and promoted now, or remain P3? I won't change the priority without this decision.
2 remaining items
fix(app-server): reject new Session ids sharing an output directory w…
fix(app-server): precedence and coverage fixes for legacy Session id …
fix(app-server): admit caller-selected Session ids at the store's ins…
fix(app-server): resolve relative segments before comparing legacy Se…
test(app-server): admit ids through the sqliteStorage createSession d…
fix(app-server): judge legacy Session output overlaps by the resolved…
fix(app-server): bound the literal resolution branch within the state…
style(app-server): reflow the canonical id formatting in the output-r…
style(app-server): drop the unused literal root spelling from the out…
test(app-server): admit the windows isolation control in a fresh stor…
fix(app-server): resolve trailing-space parent segments onto the pare…
test(app-server): seed the owner agent and cover the rooted shapes an…
fix(app-server): refuse the undecidable state-cap shapes and resolve …
Merge pull request #2283 from arcships/hui/session-id-nocase