Repository navigation
refactor(runtime): name a prepared creation's Session once - #2202
Conversation
`Agent::create_session(config, options)` takes the id, the prepare step and the Session extension; `restore_session(id, options)` takes the protocol projection gate. The four creation methods and the two restore methods are deleted, and every caller moves to the options. Tests adapt their call sites only; assertions, expectations and timeouts are unchanged. Refs #2020
`CreateSessionOptions` no longer holds the Session id twice: `id` is the only name, and `prepare` receives it when creation runs, so a prepared step commits the rows of the Session being created and cannot disagree with it. The options flow test covers a prepare step with an explicit id and without one, alongside the explicit-id and extension creations, and the thin-instances example states a call that compiles. Refs #2020
eric8810
left a comment
There was a problem hiding this comment.
One ID now drives the runtime entry and the preparation callback, and the callback still runs only after runtime capacity is reserved. App Server cold acquisition explicitly supplies the recorded protocol version, whereas bare runtime restore preserves the stored configuration. The new options flow and the existing idle-unload restore/fork and native lifecycle flows passed in exact Linux CI; Windows and ci-ok also passed.
This approval is for the standalone tree, not a change in integration order. When combining with #2174, keep cold process calls on the acquire/hold path so they preserve older protocol projection as well as retaining the hold through the owner reply. The standalone options test cannot prove that composition.
zerob13
left a comment
There was a problem hiding this comment.
The option migration preserves the default creation and restore paths and the existing test assertions. Two behavior requirements remain for the new explicit-ID entry point:
- Validate the ID before creation. Preserve legal explicit IDs; reject IDs that violate the Session identifier contract before prepare, storage writes, or publication. Otherwise the runtime can publish a Session incompatible with RPC addressing and per-Session output storage.
- Leave the existing Session untouched when duplicate creation fails. With two Agents sharing a TimelineStore, a duplicate write can fail before the second Agent owns any state, yet its error cleanup releases the existing Session's cached state and clears recorded write failures. A rejected duplicate must leave the first Agent's Session, records, and failure state intact. A same-Agent duplicate returns earlier and does not exercise this path.
These are static findings. The exact-head CI passed, but the existing successful creation and restore flows do not cover these two rejection cases.
An explicit id is rejected unless it is one normal path component, the form Session command-output storage addresses, and the check runs before the prepare step, the first storage write and publication, so a rejected id leaves no Session and no rows. The check moves into the runtime so Session admission and the App Server boundaries share one definition instead of two.
…ejected A creation that fails now undoes only what it committed: a rejected duplicate no longer releases admission state or clears a recorded write failure that belongs to the Session another Agent already created under that id. Creation that fails before committing rows leaves the store untouched, and a restore, which loads an existing Session, releases the load it admitted.
…licate The duplicate-creation regression test now reads the existing Session's stored configuration and branch directory before the rejected creation, and asserts they are unchanged afterwards, so a rollback of those rows fails it.
|
Both points are fixed. Validate the ID before creation: Leave the existing Session untouched when duplicate creation fails: a creation now unwinds only what it committed. A failed A failed create or prepare step no longer calls release: its cleanup stays Both defects are also present on main with the earlier entry points, so they were not introduced by this change: the id was unchecked in |
|
Noted. When combining with #2174, cold process calls stay on the acquire/hold path, so they preserve the older protocol projection and hold through the owner reply. |
eric8810
left a comment
There was a problem hiding this comment.
I rechecked the two fixes on 2bbc7cd: explicit ID validation now runs before preparation, storage writes, or publication and uses the same check as App Server; a rejected duplicate no longer runs cleanup against the existing Session. Both regression tests and create_and_restore_options_apply_their_fields passed in the Linux job for this head.
I'm holding a fresh approval while ci-ok is red. That Linux job failed in goal_beta_flow::beta_5_edit_supersedes_the_request, timing out while waiting for the held model call after Skills registry wait warnings. The log doesn't establish that this refactor caused it. Please rerun the failed job on this head and investigate the startup path if it repeats.
zerob13
left a comment
There was a problem hiding this comment.
The shared-store duplicate rollback is fixed, and ID validation now happens before preparation or publication.
One part of the original ID acceptance remains. The runtime check validates path syntax, not filesystem compatibility. The output path still uses the ID directly. An accepted but unusable component can fail only when command output is first created, and distinct accepted IDs can resolve to the same directory on a case-insensitive volume. Acceptance: IDs that cannot be backed by a usable output directory are rejected before preparation, storage writes, or publication; accepted IDs retain their value and get distinct output directories. The implementation is up to you. This is a static finding; the hosted Windows job does not run the new ID tests.
Separately, exact Linux CI timed out in beta_5_edit_supersedes_the_request. I have not established a link to this delta, so this is an unresolved CI gate, not a second code finding.
An explicit Session id is one path component, but nothing proved the filesystem could back it with a directory: a name over the component limit, one a case-insensitive or normalization-insensitive volume equates with another id, or one another Session already uses failed only when command output was first written, or silently shared that output. Agent::create_session now books the id below the host's command-output root at <root>/.session-ids/<id> with an exclusive create_dir before its prepare step, storage write or publication, so an id this filesystem cannot back, or one already booked, is refused with InvalidInput and leaves no booking, row or published Session. A creation that fails releases its booking with its rows. SessionStore's delete removes the booking with the output directory, under the same rows-here rule, so a delete of an id this database does not store cannot free another database's name. WorkspaceToolsConfig::output_root is the root the Agent is given; the command-output directory itself stays lazy, as ADR 013 D4 expects. The design note and its Chinese copy record the booking, and two flow tests cover an id this filesystem cannot hold and two ids it cannot tell apart.
|
The Linux job for 2bbc7cd failed in The job ran three test binaries at once with That 20 s bound starts at about 17:41:02Z. Ten seconds later, the log records four startup reports: the The code path is the Session creation entry point, and this change keeps its order intact: I read this as a startup bound on a loaded runner rather than a consequence of this change. Every one of the last 20 runs on main that ran the test step shows this test passing and no startup report; two of those runs had no verify job at all. Four other pull requests passed the same test in their Linux jobs this week. Locally, 20 single runs and 5 whole-file runs on this head, and the same on its base commit, all passed with no startup report. A second round then reproduced the job's overlap on main: If it recurs, the startup reports in that job will show whether it is the same wait. The failure itself, including the load timeline and the test-only repair direction, is now tracked in #2203, assigned. A rerun of this job is not something I can do here, so the next Linux run of this head will serve as the observation either way. |
A creation that fails before its prepare step and one that fails after its rows are committed both release the id's booking, with the rows in the second case, so the same id can be created again. The test drives both exits through the output root the product configures.
A Session named `.session-ids` would own the booking root below the output root, so its command output would be every other Session's booking and deleting it would remove all of them. `check_session_id` now rejects that name, and every spelling a case-insensitive filesystem folds to it, before any booking, prepare step, storage write or publication. The rejection is shared: the App Server's delete, fork and owned-creation steps call the same check.
The delete's output removal already took the creation's booking of the id with the Session's own directory, and nothing exercised it. The new case books a name, deletes the Session, and then books the same name again, which only succeeds because the delete removed the first booking.
The booking refuses a name another creation booked; it says nothing about a Session stored before it, one written through the store's own creation and fork steps, or the persistent shell's directory on another volume. The paragraph now states those limits, the cross-database refusal, and the reserved booking name, in both languages.
Windows strips a directory name's trailing dots and spaces, so `.session-ids.` and `.session-ids ` would name the bookings entry itself, and the reservation let them through. `check_session_id` now folds the id the way such a volume does before comparing it, and the admission test covers both spellings besides the case variants.
The four spellings do not fit one rustfmt line.
Clippy asks for the character list rather than a closure.
The new sentences ran past the width the surrounding paragraphs keep.
A booking protects a booked name, not every Session: an id stored before the booking, or written by another face of the store, holds none. Say so in the two rustdoc comments that claimed otherwise.
The booking is an empty directory a creation holds; the owner file was left over from a design that was not adopted.
An id whose Unicode case folding is the booking name is refused, so the long s and sharp s spellings fail with the ASCII ones; trailing dots and spaces are trimmed first.
The rejected-id flow test adds the long s and sharp s spellings of the booking name, which the check accepts before this fix.
|
Both acceptance conditions are in #2204. The reservation is withdrawn from this PR in commit 6867cb6, so the two lifecycle cases it did not cover become part of that design instead of open in this change. Output isolation for the life of the output. #2204 now requires the reservation to cover every enabled output root, including the persistent shell directory that can be on another volume; to survive a create rollback that fails and a delete that fails; to keep a name while a fork source or the fork still needs the output; and to release the reservation in the root where it was made. Once the final owner is gone, deletion must release the reservation in the actual configured root, and an accepted ID keeps its original value with usable, distinct storage in every enabled output root. Previously accepted stored IDs. #2204 now requires a Session stored before the design, or under a name the admission refuses, to stay deletable and usable as a fork source, or an explicit migration to preserve those operations without touching another Session's output. The only refusal this change adds is the one-component check on the new explicit-ID creation path; delete and fork apply the check they applied before, so an ID that was deletable and forkable stays so. The extra refusals in the reservation, the reserved booking root and the names the filesystem cannot back, leave with it. The duplicate-create rollback fix you verified stays. The ID acceptance finding in 6062659262 continues in #2204, and the reservation scheme described in the earlier reply on this PR (issuecomment-7175873195) is withdrawn. Do you agree to move this design to #2204 and advance it there separately? |
eric8810
left a comment
There was a problem hiding this comment.
The scope split resolves my blocker. This diff no longer creates or releases an output-name reservation, so deletion cannot introduce the reservation-ownership failure from my previous review. That does not fix legacy filesystem aliases or guarantee isolation across output roots; those requirements stay in #2204.
For the scoped refactor, the runtime chooses one ID and passes it to preparation. The single-component check still runs before preparation or writes, and a refused duplicate does not roll back another Session's state. I verified all three agent_options_flow tests passed in the exact-head Linux job; the overall check passed as well. I did not run local tests.
zerob13
left a comment
There was a problem hiding this comment.
Removing the reservation closes the wrong-owner cleanup and legacy delete/fork findings. The duplicate-create rollback also remains fixed.
Remaining acceptance: plain Rust creation must not admit a Session whose command output is unusable or shared with another Session. The previous plain create path generated its own UUID. The new plain path accepts caller-selected IDs after a lexical check, but the enabled output roots still use that ID as a filesystem name. A Session can be published successfully and only fail on first output, or distinct admitted Sessions can resolve to the same output location. This is the earlier output-isolation requirement narrowed to the newly opened plain Rust path, not a request to reintroduce reservations or change legacy/fork handling. Preserve the former generated-ID behavior there, or verify that accepted caller-selected IDs get usable, distinct output directories across the enabled roots.
Exact-merge CI passed. Its selected native checks do not establish this filesystem invariant; the finding is from static review.
`CreateSessionOptions` no longer takes a standalone id: a plain creation is always created under a generated UUIDv4, and the only caller-named id is `prepare(id, step)`, whose step receives that same id. The App Server's prepared creation passes the id it generated with the step, and the flow test moves its explicit-id cases to `prepare` and asserts that two plain creations get distinct valid UUIDv4 ids.
|
Plain Rust creation is back to the generated-id behavior both plain creation methods had on On the previous head the plain path compiled with an explicit id: a creation with The prepared path keeps what it did on The flow test covers both sides. The change is in commit fe40ba4. |
eric8810
left a comment
There was a problem hiding this comment.
Plain creation now always generates a UUIDv4, including when an extension is supplied, and only prepared creation accepts an explicit ID. This restores the old plain-create behavior without reintroducing output reservations.
Blocking: the current merge result does not compile. The Linux build reports E0061 for two create_session calls in tests/integration/tests/environment_clients.rs (lines 591 and 809), and one restore_session in tests/integration/tests/environment_settings.rs (line 253). Those fixtures still use the old one-argument signatures. Please sync with main and migrate the three callers to the matching default options, keeping their test coverage intact. The build stopped before it could run the updated options tests. This is separate from #2204.
The integration flows added on main call the creation and restore entries with the previous arity, so they gain the options argument the rest of the workspace passes.
zerob13
left a comment
There was a problem hiding this comment.
Reviewed fe40ba4700548f08a2b32ea76910944a7b458db6. The plain-create ID finding is closed: plain creation generates its own UUIDv4 even with extension options. Prepared creation and the earlier rollback and compatibility findings stay closed.
The only remaining blocker is the current merge-build failure already identified in Eric’s review, which I independently verified in the exact Linux job. Update the three affected callers added on main to the options API, preserve their assertions, and verify the merged workspace builds and runs those flows. I found no additional code blocker.
The README creation example passed only the configuration, so copying it no longer compiled and failed with E0061. It now passes CreateSessionOptions::default() and imports the type in the same example.
zerob13
left a comment
There was a problem hiding this comment.
Approved at 08b73bfa8180a53e1a8a58de48a14150d3c1a440. The last review condition is met: all three callers use the options API without weakening their assertions, and exact-merge Linux CI passed the workspace build and affected flows. The earlier UUID, prepared creation, rollback, and compatibility findings remain closed.
This approval does not clear the separate GitHub merge gate. The Windows CLI test process exited with 0xc0000374, and ci-ok is red. The cause is not established; the reviewed delta does not touch CLI source or dependencies.
eric8810
left a comment
There was a problem hiding this comment.
The three integration-test callers now use the matching default options without changing their assertions. The Linux job for this merge result compiled successfully and passed all three affected environment tests and all three agent_options_flow tests. This resolves my previous build blocker.
The overall gate is not green: the Windows CLI test process exited with STATUS_HEAP_CORRUPTION (0xc0000374) without naming a failing test. This log does not establish the cause. The approval is for the scoped refactor; Windows still needs a clean result. I did not rerun it locally.
|
Thanks both for the approvals. Replying to the Windows note in zerob13's review (#2202 (review)) and eric8810's review (#2202 (review)). The windows-cli job failed in attempt 1 (https://github.com/arcships/dim/actions/runs/45748707092/job/139671084955): the dim-cli lib test process exited with 0xc0000374 (STATUS_HEAP_CORRUPTION) and no failing test was named. The same head was rerun as attempt 2 (https://github.com/arcships/dim/actions/runs/45748707092/job/139677776735), windows-cli passed, and ci-ok is green. In the crates compiled into that test binary, this PR's changes are safe Rust only: no unsafe code, no FFI and no changes to concurrency or allocation, and the dim-cli lib tests do not call the entry points this PR changes. It did not reproduce: the same suite passed on the rerun of the same head, and it also passes on macOS built from the same head, although the Windows-only FFI tests are not part of that run. On that basis we do not think this PR caused it. If it shows up again in another run, we will open an issue with the job log. |
Simon-He95
left a comment
There was a problem hiding this comment.
Reviewed at 08b73bfa.
The direction is sound: creation has one id source (CreateSessionOptions::prepare), the prepared step receives that same id, and the id is checked before preparation, the first write or publication (crates/dim-agent-runtime/src/agent.rs:60-105, :132-150). Plain creation keeps the generated UUIDv4 and no longer accepts a caller id, so the previous output-name ambiguity on the plain path is not reintroduced. The rollback/release split is explicit (Cleanup), and the old six-method surface is gone without changing the app-server wire: protocol.rs only moves check_session_id to the runtime, and no client request or reply field changes. The Rust-embedding API break is internal to this workspace at this stage.
The remaining filesystem-name isolation (case-folding volumes, all enabled output roots) stays open in #2204 exactly as the body says; I am not treating it as a blocker for this scoped refactor. CI is green at this head. Approve from my side.
Sync main after #2202 folded session creation into options. The conflict in the TypeScript transport flow is resolved by keeping this PR's approved deletion of node_branch_opening_completion_can_refuse_session_creation and taking main's version of every other case. The new integration tests pass an options argument to create_session.
Refs #2020.
Agent::create_session(config, options)takes the prepared creation's id and step and the Session extension;Agent::restore_session(id, options)takes the protocol projection gate. The four creation methods and the two restore methods are deleted, and every caller in the workspace moves to the options.Agent::restore_sessionkeeps the behavior of the method it replaces: a restore without a protocol version applies no projection gate and loads the stored configuration as written.A plain creation is always created under a generated UUIDv4, as both plain creation methods did on
main. A caller names the Session id only throughCreateSessionOptions::prepare(id, step), which takes the id with the step, so the id has one source: the step commits the rows of the Session being created and cannot name another.An id given to
preparemust be one normal path component, and it is checked before the prepare step, before the first storage write and before publication, so an unusable id returnsInvalidInputwith no side effects. Covered byagent_options_flow::an_explicit_id_is_admitted_only_as_one_path_component.A creation that fails unwinds only what it committed, so a rejected duplicate leaves the existing Session, its admission state and its recorded write failures as they were. Covered by
agent_options_flow::a_rejected_duplicate_keeps_the_existing_sessions_state.This change does not reserve output names, and a plain creation names no output with a caller id. An earlier revision of this branch carried a reservation, and it is withdrawn. A prepared creation still takes its id from its caller, as the prepared creation method did on
main: two ids that the volume folds together, such asAbcandabc, are both accepted there and address one command-output directory, and an accepted id whose output directory the filesystem cannot create fails only when command output is first created. A design that owns a name for the life of the output, in every output root the Session uses, is tracked in #2204.This change applies to
mainalone. It has no code dependency on the other base changes in #2015's plan, and the merge order is the maintainer's.It touches 733 call sites in 82 source files: 12 in non-test program code (the App Server and the repository tooling), 7 in examples, 713 in existing tests across 75 files, and one internal delegation in the runtime that is deleted. The test changes add the options argument and adapt the extension and prepared calls to the new shape; no assertion, expectation, timeout or test name changes. The 75 files are recorded in the main-tests basis under P13.
The new flow test covers a prepared creation's explicit id, a plain creation's generated id (two creations, distinct and each a valid UUIDv4), a Session extension, restore with and without a protocol version, and the rejection cases above.