Skip to content

fix(app-server): admit only lowercase ASCII Session ids and reject case-colliding writes (#2204) - #2283

Open
yyhhyyyyyy wants to merge 16 commits into
mainfrom
hui/session-id-nocase
Open

yyhhyyyyyy wants to merge 16 commits into
mainfrom
hui/session-id-nocase

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2204. This PR implements direction B as the issue body records it: lowercase ASCII admission for new Session ids, plus indexed collision checks on the entries that write agent_sessions, extended to the filesystem identity rules under which a stored legacy id could share its output directory with a newly admitted one.

Admission of new ids

The entries that admit a caller-selected id (CreateSessionOptions::prepare in the runtime (agent.rs), the store face's createOwnedSession and a fork's target (timeline.rs and timeline.rs)) reject a new id that is not one to sixty-four characters of lowercase ASCII letters, digits, underscore and hyphen, or that is one of the Windows reserved device names con, prn, aux, nul, com0 through com9 and lpt0 through lpt9, before anything prepares, writes or publishes. The check is check_new_session_id. The admission also runs at the shared SQLite insertion boundary itself, in the create_session helper ahead of its collision checks: the low-level face the review named, the plugin-exported SqliteStorage.createSession dispatched at sqlite.rs, reaches that helper through SqliteStorage::create_session, so an id chosen by a caller of that face is refused before its first write too. Restoration and import write rows they read back through their own statements and never reach this helper, so stored ids load unchanged. 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, and the length bound plus the reserved names close the Windows aliasing and overlong-name hazards by construction.

Two derived indexes

The store gains two derived indexes created at open with the other derived indexes (sqlite.rs): agent_sessions_session_id_nocase on agent_sessions(session_id COLLATE NOCASE), and the partial index agent_sessions_session_id_non_ascii_word on agent_sessions(session_id) WHERE session_id GLOB '[^0-9A-Za-z_-]', which covers exactly the ids stored before this admission rule that sit outside the new alphabet. The case-collision query case_conflicts resolves through the covering NOCASE index, and non_ascii_word_conflicts reads only the legacy rows the partial index selects, so a store without legacy rows answers in constant time and neither check scans every stored id. The EXPLAIN QUERY PLAN tests case_collision_check_uses_the_derived_index and directory_shape_check_uses_the_derived_index pin both lookups against the production SQL.

Conflict checks at the write points

The rejection decision reject_conflicting_id runs at every point that inserts into agent_sessions: the creation insertion helper create_session inside its write transaction, the fork copy inside the first chunk transaction that also writes the copy's first rows (timeline.rs), and the final IMMEDIATE transaction before it inserts the session row (timeline.rs). The first check shares the write lock with the first copy writes, so a conflicting Session committed before the transaction started is seen and none can commit after it, and a refusal there rolls the transaction back: the fork writes nothing and no cleanup runs. The final re-check closes the race against an insertion committed while the chunks copied.

Cleanup only after the first chunk committed, only rows the fork still owns

A fork refused before its first write commits is rolled back inside the first chunk transaction, so cleanup does not run at all. Only once the first chunk transaction has committed, the copy's first failure point ahead of a commit, does a later failure call drop_fork_rows, and every delete transaction there first re-checks that the id still names no stored Session: while that check holds the rows are provably the copy's own, because the copy is the only writer that ever writes rows of the id without its session row. Once another connection has committed a Session of the id, the rows can no longer be told apart, so the cleanup stops deleting and reports the rows as kept rather than removing a Session that won the race. Before this change a fork whose target was byte-identical to an existing Session copied rows, failed its final insert, and dropped the existing Session's rows through the old cleanup.

Byte-identical keeps Storage, case variants and directory shapes are InvalidInput

A candidate byte-identical to a stored id keeps the existing rejection as a Storage error, checked first in reject_conflicting_id even when a case variant or a directory-shape collision is stored beside it; only a candidate that differs from a stored id by case alone, or one that would share an output directory with a stored legacy id, is rejected with InvalidInput. The directory judgment resolves the stored id's path before comparing it: the stored id parses under the union of the POSIX parse and the Windows parse (shares_output_directory), each parse against the output root's real forms of its own platform, and branch_overlaps_candidate walks each resolved branch against the candidate's directory segment by segment, where equality or one side containing the other refuses, because writing and deletion follow the directory recursively. An id resolving onto the output root itself or one of its ancestors overlaps every candidate's directory, so it refuses all candidates until its row is deleted, and a shape whose destination no static comparison can place is refused conservatively. An embedder whose command-output layout moves away from the database passes the real output root through ServerConfig.output_root, and the admission compares against it. The comparison applies the identity rules of the supported filesystems wherever the store runs: a casefolding volume (APFS, HFS+ or a Linux casefold directory) with its Unicode folding pairs (the Kelvin sign, the long s, ß/ẞ, the ligatures) and its stripping of Unicode default-ignorable code points (casefold_name), and a Windows volume with its case mapping, backslash and alternate-stream separators, trimmed trailing dots and spaces (windows_names_share) and its 8.3 short names, classic and hashed (windows_8_3_collides). Refusing too much is safe, missing a collision is not: a store moving between platforms keeps its isolation.

Stored data and format position

Restoration continues to load stored ids as written, and deletion plus use as a fork source keep the existing one-path-component validation unchanged, so records stored before this rule stay operable: a stored id with uppercase letters can still be read, forked from and deleted, and deleting the legacy row unblocks the shape it conflicted with. The format marker stays at version 53 (sqlite.rs), because the new indexes are derived indexes carrying no data and no decode rule, which the schema comparison ignores at open. One user-visible consequence applies, recorded in the format document (native-storage-format.md): a binary built before this change does not know the new derived names and refuses to open a database that already carries them with the unsupported-schema error; the database itself is preserved, its rows unchanged, and a current binary can open it again.

Regression coverage

The new tests live in admission.rs. The admission rule is pinned by prepared_creation_admits_only_lowercase_ascii_ids, owned_creation_admits_only_lowercase_ascii_ids, store_creation_admits_only_lowercase_ascii_ids and fork_target_outside_the_admission_rule_or_in_case_collision_writes_nothing, each asserting the refused write publishes nothing. the_sqlite_storage_create_session_dispatch_applies_the_admission_boundary reaches the insertion boundary through the host_key sqliteStorage createSession HostDispatch a plugin call takes: malformed and reserved ids, a case-only variant and a directory-sharing candidate come back with the wire code invalid and no row written, and a byte-identical duplicate keeps its storage code. Byte-identical precedence is pinned by owned_creation_rejects_case_variants_and_keeps_storage_error_for_byte_duplicates, a_byte_identical_duplicate_beats_a_case_variant_on_both_write_entries and a_byte_identical_duplicate_beats_a_directory_shape_variant_on_both_write_entries, and stored_uppercase_ids_remain_operable pins the unchanged behavior of stored uppercase ids. The concurrency behavior the first review asked for is deterministic through triggers on the test database: a_concurrent_creation_during_the_first_copy_write_is_refused_and_the_winner_survives commits a competing Session as the copy's first write lands and asserts the winner's rows survive intact, a_concurrent_creation_caught_by_the_final_recheck_keeps_the_winner_intact does the same at the final re-check, and the_final_recheck_rejects_a_case_variant_with_invalid_input pins the re-check's error kind. The zero-write guarantee is pinned row by row: a_fork_conflicting_by_case_is_refused_with_zero_writes_and_zero_cleanup, a_fork_conflicting_by_directory_shape_is_refused_with_zero_writes_and_zero_cleanup and a_fork_refused_before_its_first_write_deletes_no_preexisting_rows record every write through a ledger trigger and assert none lands for the refused fork. The output-directory isolation has one regression per shape: the Unicode folding pairs, default-ignorable stripping, the Windows separators, alternate streams, trailing characters and case mappings, the 8.3 short names both classic and hashed, and the relative-segment resolution, including windows_parent_segment_climbs_out_and_back_to_the_candidate, windows_dot_segment_is_dropped_before_the_directory_is_accessed, windows_trailing_dot_segment_lands_on_the_parent, windows_inner_parent_segment_cancels_into_the_first, windows_reentry_after_a_climb_out_passes_through_the_root_name and forward_slash_parent_segment_resolves_on_posix. The root-wide shapes refuse every candidate: windows_resolution_landing_on_the_root_refuses_every_candidate, dot_resolution_lands_on_the_root_and_refuses_every_candidate, parent_resolution_lands_above_the_root_and_refuses_every_candidate, backslash_resolution_is_the_volume_root_and_refuses_every_candidate and drive_root_resolution_is_the_volume_root_and_refuses_every_candidate pin the bidirectional containment of the output root and its ancestors, while unc_id_proves_no_disjoint_volume_and_refuses, verbatim_unicode_id_is_the_device_namespace_and_refuses, device_namespace_id_resolves_no_destination_and_refuses and drive_relative_id_resolves_no_destination_and_refuses pin the undecidable shapes. The trailing-space parent segment is pinned by trailing_space_parent_segment_resolution_into_the_root_refuses, trailing_space_parent_resolution_lands_on_the_root_and_refuses_every_candidate and trailing_space_parent_segment_keeps_its_literal_branch, whose backslash form refuses the candidate its literal branch passes through while admitting an unrelated one. The shapes that only exist relative to the test store's own output root are computed from it: windows_rooted_resolution_inside_the_root_refuses, windows_drive_absolute_resolution_inside_the_root_refuses, windows_verbatim_resolution_inside_the_root_refuses and posix_absolute_resolution_inside_the_root_refuses refuse, with the_opened_output_root_is_the_one_the_admission_compares_against pinning the configured root. The admitted side is pinned too: windows_climb_out_without_reentry_shares_nothing, windows_resolution_leaving_the_root_sideways_shares_nothing, windows_rooted_path_replaces_the_output_root and windows_resolution_deeper_than_one_segment_shares_nothing assert those shapes lock no candidate. an_empty_8_3_stem_blocks_no_long_candidate pins that an empty 8.3 stem blocks no long candidate, and deleting_the_legacy_row_unblocks_the_shape_it_conflicted_with plus deleting_the_row_of_a_root_wide_shape_unblocks_the_candidates pin the recovery paths. fork_with_a_byte_identical_target_is_refused_without_touching_the_existing_session is the case that reproduces the cleanup defect on code without this PR: on the merge base the existing Session's rows do not survive a fork whose target is byte-identical to it. The two index lists in the storage flow tests gain only the new derived names, and one other existing test changes: the transport_flow store-face test seeds a protected id no admission-conformant creation entry can write anymore, so its seeding step now writes the stored row with a short-lived SQL connection instead of raw.create_session, matching how a store from before #2204 holds it; the assertions, the has_records check, the rollback cleanup and the test name are unchanged. The Windows filesystem coverage lives in windows_output_isolation_flow.rs, where the drive-anchored resolution the comparison mirrors actually governs the directories Sessions write: drive_absolute_overlap_refuses_create_and_fork and verbatim_overlap_refuses_create_and_fork verify against the test store's real output root that a legacy id resolving back inside it refuses creation and the fork before either writes, that the disjoint rooted shape is admitted, and legacy_single_component_ids_remain_operable pins a legacy id's read, deletion and use as a fork source; the three names are registered in scripts/test-windows-native.mjs, and the windowsNative path list in scripts/ci-changes.mjs covers crates/dim-app-server/src/storage/timeline.rs and the new test file, so the windows-cli job runs them natively. scripts/ci-changes.test.mjs gains exactly two appended lines for the two new paths; every other explicit id the flow tests already use conforms to the admission rule.

Known limitations

A legacy id resolving onto the output root itself or one of its ancestors, or one whose destination no static comparison can place, refuses every candidate until its row is deleted, and the product's deletion entry cannot remove such rows through its normal path: the validation that entry applies accepts only a single ordinary path component, so on POSIX the dot, double-dot and slash-carrying rows fail it, and on Windows the backslash-carrying, prefixed and multi-component rows fail it as well. Lifting the block takes deleting the legacy row in SQLite directly. Such rows only ever come from writes outside the product's creation entries: the low-level face, a plugin, an older version or external SQL. The deletion side is not covered by the configured output root: remove_output still derives the output directory from the database directory rather than a custom root, so a host that moves the command-output layout away from the database deletes nothing there. A drive-relative id of the c:abc form cannot be judged statically, because Windows resolves it against the current directory of that drive: a letter matching the output root's volume is refused conservatively, while a provably different drive shares nothing.

Refs #2202.

…se-colliding writes (#2204)

New ids admitted through CreateSessionOptions::prepare, the store face's createOwnedSession and a fork's target are limited to [a-z0-9_-]{1,64} without the Windows reserved device names, rejected with InvalidInput before anything prepares, writes or publishes; lowercase ASCII has no folding variants, so ids admitted under the rule can never share an output directory on a volume that folds case.

The store gains the derived index agent_sessions_session_id_nocase on agent_sessions(session_id COLLATE NOCASE), created at open with the other derived indexes and ignored by the schema comparison, so the format marker stays at 53. The creation insert helper and a fork copy check it for a stored id equal to the candidate under the case-insensitive collation: a byte-identical duplicate keeps its Storage error while a case-only variant is rejected with InvalidInput. A fork copy checks before its first chunk transaction and again inside the final IMMEDIATE transaction; the pre-check refusal writes nothing and runs no cleanup, so a target byte-identical to a stored Session can no longer drop that Session's rows through the copy's cleanup.

Restoration, deletion and use as a fork source are unchanged: ids stored before the rule keep their bytes and stay operable, and legacy mixed-case records are neither migrated nor rewritten. Refs #2202.

@eric8810 eric8810 left a comment

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 narrow direction in #2204 is the right scope: protect existing Session output and data, keep legacy IDs readable/forkable/deletable, and use the derived index rather than a scan or a new booking lifecycle. The format note also correctly distinguishes unchanged v53 from an older binary refusing a database with the new index.

Blocking: a failed fork can still delete a Session it never owned. In crates/dim-app-server/src/storage/timeline.rs:3163–3167 the first check runs outside the first IMMEDIATE chunk transaction, and every copy error still calls drop_session by target ID. The copy and ordinary writer use different connections, and the low-level create path does not take the owned-store mutex. If that writer commits the target ID before the first chunk acquires the write lock, the branch insert fails and cleanup can delete the now-existing Session. The final check is never reached on this path. The existing duplicate test starts with the target already committed and therefore does not cover this window.

Please put the initial indexed check inside the same IMMEDIATE transaction as the first copy writes, make cleanup conditional on the fork having committed and still owning the rows it removes, and retain the final in-transaction collision check. Add a deterministic concurrent-create regression that verifies the winning Session and its data remain intact when the fork is refused. This is a source-review finding on the pinned head, not a CI failure; the check run was still in progress when reviewed.

@zerob13 zerob13 left a comment

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.

Reviewed 1c47d7b3130b67aaf334dfc64993574e7fa953b0 against #2204. I independently checked the existing rollback finding in review 6089948558 and am not repeating it.

New ID admission must preserve isolation from legacy Session directories. The database comparison for new IDs and the identity rules of supported filesystems are not equivalent for all retained legacy IDs. The new admission rule therefore does not fully establish the claimed output-directory isolation. Acceptance: before a new Session or fork publishes anything, reject any new ID that would share an output directory with a retained legacy Session. Preserve legacy ID bytes and existing read, close, and fork-source behavior. This is a static compatibility finding, not a live filesystem test.

An isolated ordinary ASCII fixture confirmed use of the covering index. See exact CI for platform coverage.

…ction and clean up only rows the fork still owns (#2204)

A Session committed by another connection between the copy's first conflict check and its first write could be deleted by the failed copy's cleanup, which dropped every row of the target id. The first check now runs inside the first chunk transaction so the refusal rolls back before any write, and the cleanup deletes only while the id names no stored Session, re-checking inside every delete transaction; once a Session of the id exists the copy's rows stay as unreachable rows instead of the cleanup reaching the Session that owns the id.

Regression tests inject the concurrent commit through INSERT triggers on the copy's own writes, deterministic in both the first-chunk window and the mid-copy window the final re-check covers: the fork keeps its Storage refusal, the winning Session's rows survive field by field, and a case-only variant still refuses with InvalidInput.
…ith a legacy one under filesystem identity rules (#2204)

A retained legacy Session id can collide with a newly admitted lowercase id on a supported filesystem even when it differs byte-for-byte and under ASCII case folding: casefold volumes strip default-ignorable code points and fold the Unicode pairs (Kelvin sign, long s, sharp s, ligatures), and Windows trims trailing dots and spaces, reads a backslash or colon suffix as a path inside or a stream of the base name, maps the dotted and dotless i, and can serve a long name as its 8.3 short name, plain or hashed. The write entries now look up every stored id outside the admitted alphabet through the new covering partial derived index agent_sessions_session_id_non_ascii_word - inside the create_session write transaction, the fork copy's first chunk transaction and the final re-check, all before publishing anything - and refuse the candidate with InvalidInput when the union of the casefold and Windows rules shares the output directory, while byte-identical duplicates keep their Storage error. FORMAT stays 53; the index carries no data, and the format gate ignores it as it does the other derived indexes, so an older binary refuses a store that has it while the store itself is preserved. Deleting the legacy row unblocks the id it blocked, restoration and deletion of stored ids are unchanged, and dim-agent-runtime is untouched.
…isolation (#2204)

Windows 8.3 short-name tails accept multi-digit ASCII sequences with a non-empty stem: a legacy id like abcde~12 is refused as colliding, while an empty stem like ~1 no longer blocks every long candidate.

The default-ignorable ranges add U+180F per DerivedCoreProperties.txt, so a legacy id carrying it no longer shares a casefold directory silently.

A byte-identical duplicate keeps its Storage error even when a case variant or a directory-shape collision is stored beside it; create_session now shares the one rejection helper instead of its own copy.

The fork copy runs its cleanup only after its first chunk transaction committed, so a refusal ahead of the first write deletes nothing, and the ownership-check database error inside the cleanup propagates instead of being reported as a concurrent creation.

resource-faces.md and the plugin.d.ts contract comment now state the id admission shape and the output-directory rule; deletion keeps its single path component check.
The summary below v37 called itself the current format at v48; the current format is v53, so state it as the v48 decision it describes.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#2283 (review) Fixed in 9c13cf4, bab7214

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#2283 (review) Fixed in a3b7694, bab7214

@eric8810 eric8810 left a comment

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 initial fork check now shares the first write transaction, and an early refusal no longer runs cleanup. The final check stays in place, and late cleanup rechecks for an existing Session before every delete transaction. That addresses the original delete-on-refusal path. The trigger fixtures check the resulting row state, but they do not run a second connection through the production creation API, so they are not a two-writer integration test.

Blocking: the low-level SQLite creation face still admits new IDs outside the rule. SqliteStorage.createSession is exported to plugins (npm/plugin.d.ts:667,764); its dispatch (crates/dim-app-server/src/storage/sqlite.rs:2765) passes the caller's ID straight to SqliteStorage::create_session. That method (storage/timeline.rs:669–679) reaches the shared insert helper (:2520–2550), which checks collisions but never calls check_new_session_id. The caller-selected ID is therefore not limited by the shape or reserved-name rule when no stored row conflicts. Checking CreateSessionOptions::prepare and createOwnedSession does not cover this separate writer. This leaves the new-vs-legacy boundary in #2204 unenforced at the storage face. Please enforce the same admission rule at the shared SQLite insert boundary, or show that the lower-level face cannot accept an independently chosen ID. Pin the behavior at the low-level entry and keep read, delete, and fork-source behavior for already stored legacy IDs unchanged.

Static review on this head; hosted CI was still running.

@zerob13 zerob13 left a comment

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.

Re-reviewed 0340e6f12955b468328111f0b4bd412f02b13e3a. The early fork refusal no longer enters cleanup; the peer's separate low-level admission review is not duplicated here.

Still blocking: preserve output-directory isolation when opening a retained store on Windows. The updated directory check compares a legacy ID's first literal component, but Windows can resolve relative components before accessing the directory. After moving a store from a platform with different path syntax, the comparison can therefore disagree with the directory actually used for Session output. Both creation and fork use this check. The result can be two Sessions sharing one output directory.

The original acceptance is unchanged: refuse a new Session or fork before publication whenever its resolved output directory would be shared with a retained legacy Session. Preserve legacy IDs byte for byte and keep their existing read, close, and fork-source behavior. This is a static compatibility finding. The current CI is green, but the Windows comparison fixtures ran on Linux and Windows CLI was skipped.

Directory check · Output path

…ertion boundary

The storage creation the SqliteStorage.createSession and timelineStore.createSession faces dispatch to only checked collisions, so a caller-selected id bypassed the lowercase-ASCII shape rule and the Windows reserved-name exclusion every other creation entry applies before writing storage (#2204).

Add the same check_new_session_id admission to the shared insertion helper, ahead of the collision check: shape refusals are InvalidInput before anything is written, a byte-identical duplicate keeps its Storage error, and case-variant plus directory-shape collisions stay InvalidInput. Restoration, migration and import write stored ids through their own statements and never reach this helper, so ids already stored stay readable, deletable and usable as fork sources unchanged.

Document the id admission in the createSession face contract and the TimelineStore binding JSDoc.
…ssion output directories (#2204)

The directory check compared a legacy Session id's first literal component, but a Windows volume resolves . and .. segments before it accesses the directory, so a store moved from a platform with different path syntax could compare against a directory the id never lands in: x\..\abc and .\abc escaped the comparison while abc\..\def refused candidates it shares nothing with.

The comparison now resolves the stored id against the output root the way the platform accessing it does — both separators, . and .. segments, trailing dots and spaces — and refuses a candidate only when the resolved directory is the candidate's own or inside it, which deletion follows recursively. Ids resolving onto the root itself, outside it, or sideways refuse nothing; a climb out of the root can still re-enter through the root's real components, which the comparison checks. Component equality keeps the casefold and Windows identity rules and the 8.3 short names, now in both directions.
…ispatch and seed the protected row by SQL (#2204)

The storage_flow admission tests reached the insertion boundary only through the Rust binding, while the entry eric8810's review named is the SqliteStorage.createSession plugin face. Cover it through the host_key("sqliteStorage") HostDispatch. Malformed and reserved ids, a case-only variant and a directory-sharing candidate are refused with the wire code invalid before anything is written, and a byte-identical duplicate keeps its storage code.

The protected id the transport_flow store-face test seeds is one no admission-conformant creation entry can write anymore, so the seeding writes the stored row around the boundary with a short-lived SQL connection instead of raw.create_session, matching how a pre-#2204 store holds it; the assertions, the has_records check, the rollback cleanup and the test name are unchanged.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#2283 (review) Fixed in 81f46c6, 471dd90

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#2283 (review) Fixed in 66aa7d7

@zerob13 zerob13 left a comment

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 normalization covers the earlier relative-component case, and the shared SQLite creation rule is now enforced.

Remaining acceptance: preserve output-directory isolation for retained Windows stores. The directory comparison still treats classes of retained locations as disjoint without establishing that their resolved filesystem destinations are distinct. Creation and fork can therefore disagree with the destination the filesystem actually uses. Refuse either operation before publication when its destination overlaps a retained Session's output directory. Preserve legacy ID bytes and existing read, close, and fork-source behavior. This is a static compatibility finding; the existing coverage does not establish this destination comparison on Windows.

@eric8810 eric8810 left a comment

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.

My low-level creation finding from the prior review is resolved at 471dd90f. The plugin's sqliteStorage.createSession dispatch now reaches check_new_session_id inside the shared IMMEDIATE transaction, before the conflict checks or inserts. The new test exercises that exact dispatch and checks zero rows on invalid, a successful ordinary ID, and the existing storage error on a byte-identical duplicate. Legacy restoration still uses its separate write path.

I'm not approving the full PR on this head. The separate Windows isolation finding remains open. In particular, resolve_output_directory classifies rooted paths as disjoint without first comparing their destination with the actual output root, and the current fixture asserts that classification rather than verifying it on Windows. Please cover publication refusal for both create and fork using a retained-store fixture against the actual destination on Windows. The exact workflow skipped windows-cli; I checked source and test coverage but did not run a native Windows test.

… destination and refuse undecidable shapes (#2204)

The admission comparison refused by lexical category: a rooted or drive-anchored id was declared disjoint from the output root without ever resolving it, so \<root components>\abc, C:\<root components>\abc, \\?\C:\<root components>\abc and the POSIX-absolute spelling all passed while resolving into the candidate's own output directory, and c:/../abc lost its POSIX reading when the drive prefix was stripped. The comparison now parses every stored id under both platforms' rules and compares the resolved destinations: each output root form is canonicalized through its longest existing prefix and parsed per platform with normalized volume anchors (verbatim drive and UNC forms unified), the id resolves into POSIX and Windows destination branches with a state cap on the ambiguous trailing-trim segments, and a positional prefix walk over the shorter side decides the overlap. Branches whose segments diverge, and anchors provably disjoint, share nothing; ids landing on the root or an ancestor of it refuse every candidate until their row is deleted, and shapes no static resolution can place (the device namespace, a drive-relative path on its own volume, a UNC share that cannot be proven disjoint) refuse as well.

The output root the admission compares against is the one the writing side actually uses. SqliteStorage::open_with_output_root names it for an embedding host whose command-output layout is not <database directory>/command-output, wired through ServerConfig.output_root, the CLI's split home and the xtask serve harness; the field stays inside Rust and out of every serialized configuration and protocol surface.

Windows-only coverage runs in the windows-cli job: windows_output_isolation_flow seeds drive-absolute and verbatim legacy ids from the store's own output root and refuses create and fork on the filesystem whose resolution the comparison mirrors, registered in scripts/test-windows-native.mjs and the windows_native paths.
…nt in the output comparison (#2204)

A segment of nothing but dots and spaces trims to an empty string, so the trimmed == ".." comparison it was tested with never held and `.. `, `.. .` or `...` kept the current directory instead of resolving onto the parent Windows normalizes them to: the resolved destination of `abc/.. /def` was never judged. A segment trimming to empty now falls back to the parent when it begins with `..`, and the admission regressions cover the shape landing inside the root, the one landing onto the root itself, and the literal branch the trailing-space reading leaves behind.
…d legacy operability in the windows isolation flow (#2204)

The writer connection enforces foreign keys and the owned creation inserts session_owners.agent_id against agents, so the flow seeds the owner agent before admitting anything; without it the admissions it exercises fail on Windows with FOREIGN KEY constraint failed instead of judging the isolation. The drive-absolute flow gains the rooted id resolving inside the output root as a refusal and the disjoint \unshared-root\abc as an admission, and a legacy single-component id is read, forked as a source and deleted through the product entries with its bytes unchanged.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Fixed in 98b8ea5, 57fb8eb, 08be230, 743e9c0, 1587144.

The directory comparison no longer classifies paths; it compares resolved destinations. The stored id is parsed under the union of the POSIX parse (slash separators) and the Windows parse (both separators plus prefix handling), the output root keeps its normalized volume anchor in both its literal spelling and the spelling its longest existing prefix canonicalizes to, and each resolved branch is walked against the candidate's directory segment by segment: equality or one side containing the other refuses. A legacy id resolving onto the output root itself or one of its ancestors overlaps every candidate's directory and refuses all candidates until its row is deleted. Shapes whose destination no static comparison can place are refused conservatively: the device namespace, a verbatim prefix naming neither a drive nor a UNC share, a UNC share that cannot be proven disjoint from the root's volume, and a drive-relative id whose letter matches the root's volume. Legacy id bytes and the read, close and fork-source behavior of stored ids are unchanged. An embedder whose command-output layout moves away from the database passes the real output root through ServerConfig.output_root, and the admission compares against that root.

The regression coverage lives in crates/dim-app-server/tests/storage_flow/admission.rs, one case per shape with creation and the fork both refused before either writes and zero rows asserted: windows_resolution_landing_on_the_root_refuses_every_candidate, dot_resolution_lands_on_the_root_and_refuses_every_candidate, parent_resolution_lands_above_the_root_and_refuses_every_candidate, backslash_resolution_is_the_volume_root_and_refuses_every_candidate, drive_root_resolution_is_the_volume_root_and_refuses_every_candidate, unc_id_proves_no_disjoint_volume_and_refuses, verbatim_unicode_id_is_the_device_namespace_and_refuses, device_namespace_id_resolves_no_destination_and_refuses, posix_parent_segment_resolution_into_the_root_refuses, trailing_space_parent_segment_resolution_into_the_root_refuses, trailing_space_parent_resolution_lands_on_the_root_and_refuses_every_candidate, drive_absolute_parent_segment_resolution_refuses, trailing_space_parent_segment_keeps_its_literal_branch, and the shapes computed from the test store's own output root: windows_rooted_resolution_inside_the_root_refuses, windows_drive_absolute_resolution_inside_the_root_refuses, windows_verbatim_resolution_inside_the_root_refuses, drive_relative_id_resolves_no_destination_and_refuses, posix_absolute_resolution_inside_the_root_refuses, the_opened_output_root_is_the_one_the_admission_compares_against and deleting_the_row_of_a_root_wide_shape_unblocks_the_candidates.

One boundary is deliberate: a trailing-space parent segment keeps both its Windows resolution reading and its literal reading, and the state count is capped, so the two-branch coverage is not unconditional. That bound is documented in the Known limitations section of the pull request body.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Fixed in 08be230, 1587144.

The native Windows coverage now exists: crates/dim-app-server/tests/windows_output_isolation_flow.rs seeds a retained legacy store around the validation layers and exercises it against the actual output root of its own test store, whose drive layout and real components it reads dynamically from the runner instead of hardcoding a letter. drive_absolute_overlap_refuses_create_and_fork verifies that a drive-absolute legacy id resolving back inside the output root refuses both the creation entry and the fork before either writes a row, with zero rows asserted for the refused candidate, while the disjoint \unshared-root\abc is admitted; the rooted coincidence the review named, the root's own segments followed by abc, refuses on the same volume. verbatim_overlap_refuses_create_and_fork does the same for the verbatim spelling canonicalize returns on Windows. legacy_single_component_ids_remain_operable pins the unchanged behavior of a single-component legacy id such as Legacy-9: its stored rows read back as written, it serves as a fork source, and deletion removes it as before. Both isolation tests run create and fork each in a fresh store, and the fixtures seed the owner agent the writer foreign key requires so the insertions really execute.

The three test names are registered in scripts/test-windows-native.mjs, and scripts/ci-changes.mjs gained crates/dim-app-server/src/storage/timeline.rs and the new test file in its windowsNative path list, so the windows-cli job runs on this head instead of being skipped. windows-cli has not finished running on this head yet, so this is coverage and wiring, not a passed native run.

@eric8810 eric8810 left a comment

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 resolution handles the previously reported same-volume rooted and drive-absolute cases, and the native Windows tests are now wired into the PR job. I did not run them independently; the exact Windows job was still running.

Blocking: the ordinary create/fork path now probes the filesystem while holding SQLite's write lock, even when the legacy index is empty. directory_conflict resolves the output root before it reads the indexed legacy rows. real_root_forms may call canonicalize repeatedly up the path. Every successful ordinary create now takes that path under its write transaction, and fork takes it in both the initial and final write transactions. A slow or unavailable configured output volume can hold up unrelated writes to an otherwise healthy local database, even when there are no legacy IDs to compare. #2204 calls for a minimal indexed admission check, not a filesystem dependency for ordinary creates.

Please make the empty-legacy case return from the indexed lookup without probing the filesystem, and keep blocking filesystem resolution out of the write-lock interval. Keep the authoritative collision lookup and insertion in the same transaction, including the final fork recheck. A focused test that makes root resolution observable (or fail if invoked) and proves that an empty legacy index never invokes it would protect the fast path.

@zerob13 zerob13 left a comment

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 configured output-root comparison and the exact-head Windows CI close the previously reported destination cases. The native tests also confirm ordinary legacy read, delete, and fork-source behavior.

One part of the original output-isolation condition remains open in crates/dim-app-server/src/storage/timeline.rs: a bounded comparison that reaches its limit does not establish disjointness. Create and fork should both refuse before publication when separation from a retained Session's output remains unresolved, while keeping the bound and preserving operations on the legacy source. This is a static finding; the passing Windows cases do not cover that outcome. The separate SQLite lock-duration concern in Eric's review remains independent.

…the output root outside the write lock (#2204)

A Windows resolution state forks into its normalized and literal readings at every segment of nothing but dots and spaces, and the cap kept only the resolution reading once it tripped: the literal branches were the only ones that could still prove an overlap, so an id with nine of those segments compared disjoint from everything it shares a directory with. The comparison now ends the resolution as undecidable when the fork would pass the cap, creation and the fork refuse it before either publishes anything, and the stored rows keep their bytes, reads, POSIX deletion and fork-source refusal until the row is deleted. A provably disjoint volume answers the comparison before any segment resolution, so the undecidable reading cannot widen a disjoint drive into a refusal.

The directory-shape comparison resolved the output root through the filesystem inside the SQLite write lock and the connection mutex on every creation and fork, and even a store without a single legacy row paid those probes. Creation and the fork now admit in two phases: the first IMMEDIATE transaction runs only the indexed lookups, so an empty legacy index inserts and commits in that one transaction with no filesystem access and no second connection, a nonempty one rolls back unwritten, resolves the root outside the write lock, and the second transaction re-runs the authoritative conflict lookup against it together with the insertion; the fork's copy resolves once outside its chunk transactions and the final recheck reuses that resolution in the inserting transaction, which keep the rejection atomic with the insert. The testing hooks observe and hold the resolution by output-root path, and the regressions pin zero resolutions across every admission entry of an indexed store, a second write transaction committing while the resolution is held, and the cap shape refusing creation and fork with zero writes.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Fixed in 0f71e78.

Creation and fork now start with one IMMEDIATE transaction that only runs the indexed lookups: the case-collision check against the covering NOCASE index and the legacy-row listing through the partial index. When no conflict surfaces the insertion commits in that same transaction without touching the filesystem or opening a read connection, so an empty legacy index, or one whose only non-conforming rows are pure ASCII, never resolves the output root at all. Only when the index lists a suspect legacy row does the first transaction roll back unwritten, the output root resolve outside the write lock and the connection mutex (spawn_blocking on the creation entries, the copy's own blocking thread and a local reused result on the fork), and a second IMMEDIATE transaction re-runs the authoritative collision lookup against the resolved root and inserts in that same transaction. The fork keeps both of its admission rechecks, the first-chunk check and the final re-check, inside their respective IMMEDIATE transactions as before.

The regression coverage pins both properties deterministically through the output-root resolution hooks: the_indexed_admission_never_resolves_the_output_root observes every root resolution across store opening, both creation entries and the fork on an empty index and on pure-ASCII legacy rows and asserts zero invocations, including a case-colliding candidate refused by the case lookup alone; root_resolution_happens_outside_the_write_lock holds the resolution at its entry with a legacy row stored, proves a second connection with no busy timeout can begin and commit an IMMEDIATE transaction in that interval, and asserts the conflict is still refused with zero writes once the resolution completes.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Fixed in 0f71e78.

A Windows resolution whose ambiguous segments would fork past the RESOLUTION_STATES cap (16, unchanged) no longer continues on the resolution reading alone: advance_windows returns None and the whole outcome counts as undecidable. An undecidable legacy row overlaps every candidate, so creation and fork are both refused before either publishes anything, with zero writes. The ordering keeps the cap from widening anything: a provably disjoint volume answers before segment resolution runs, so only rows sharing the root's volume can reach the cap, while drive-relative, device and malformed prefixes short-circuit to undecidable ahead of it. Operations on the legacy source are unchanged: the stored row keeps its bytes, its reads and POSIX deletion work as before, and deleting the row unblocks the candidates; while the row is stored a fork naming it as source is refused too, because the target cannot prove its directory disjoint from a destination no bounded comparison can place.

The regression coverage is windows_state_cap_is_undecidable_and_refuses_create_and_fork: a legacy id with nine trailing-space parent segments exceeds the cap, creation and fork of the affected candidate come back InvalidInput before either writes with zero rows asserted, the row's read-back, its use as a fork source (refused while stored) and its POSIX deletion are pinned, and after the row is deleted the same candidates are admitted.

@zerob13 zerob13 left a comment

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 remaining output-isolation finding is resolved. Create and fork refuse before publication when the bounded comparison cannot establish separation, and the final fork transaction rechecks the current database rows. Retained IDs can still be read, deleted, and used as fork sources under the existing rules.

The empty-index path no longer probes the filesystem. If root resolution is needed, it runs outside the SQLite write lock; the indexed check and write still occur in the same transaction. Approved at 0f71e781 based on the reviewed delta and applicable prior Windows evidence. Exact-head CI is still running and remains an independent gate.

@eric8810 eric8810 left a comment

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.

Re-reviewed 0f71e781. The SQLite write-lock finding is resolved. Both creation entries commit directly when the indexed legacy lookup is empty, without touching the filesystem. When resolution is needed, the first transaction rolls back unwritten, the filesystem work runs outside the write lock and writer mutex, and a new IMMEDIATE transaction checks the current rows before inserting. Fork preserves that ordering before its first write and at its final Session-row insert.

The tests observe zero root resolutions on the normal path and prove a second SQLite write transaction can commit while a legacy-root resolution is held. I also checked the bounded-resolution change: reaching the limit now leaves the destination unresolved and refuses the new write instead of treating a truncated comparison as disjoint.

Exact-head CI passed Windows CLI, Linux verification, macOS native and ci-ok. No independent native run. Approved.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session output names: lowercase ASCII admission for new ids and indexed case-collision rejection

3 participants