Repository navigation
feat(workflow): make Workflow script-only - #2513
Conversation
zerob13
left a comment
There was a problem hiding this comment.
I reviewed dc84609b1354f9ea9c8a9d9c4caa1236dde60d51 against the script-only scope in #2510. Five issues affect the promised control, recovery and client flows:
- Serialize control decisions with settlement. A paused attempt reads its stop/pause flags before awaiting its stages. A Stop accepted during that wait can write
stopping, then the settling attempt can overwrite it withpaused. Two concurrent resumes can also both observepausedand no live owner before entering the admission lock. Please make an accepted stop settle once asstopped, with at most one executing attempt after concurrent resumes. Status and notices should agree on that outcome. Control admission · Settlement - Confirm child settlement after an accepted input. Production stage launch submits input before returning the child Session. Cancellation while locating its input ID can return
Cancelledbefore a withdrawal or stop. The later cancellation path also discards the results of both owner calls. A failed running-activity write exits before child settlement. Retain the child and submission identity through those paths. A run should reportstoppedonly after the owner confirms the input was withdrawn or its turn ended; if the outcome is unknown, preserve that state for reconciliation. Child handoff · Input lookup · Cancellation - Recover from the authoritative archive records. If a crash occurs after
run.jsoncommits but before its index update, a well-formed stale index can hide the run or suppress its pending report. Ifresult.jsoncommits just before the terminalrun.json, recovery marks the run paused and requires replay. Please reconcile these crash boundaries on startup and arm reports from the reconciled records. Acceptance is that a committed result becomes visible and its pending report is delivered once, without rerunning the script. Completion write order · Startup recovery - Preserve durable
sessions.launchretries across upgrade. The fingerprint now serializestoolsandskillsas null when both options are omitted. Old records omit those keys, and lookup compares serialized strings. An identical pre-upgrade request with the samelaunchIdis therefore rejected as a different request. Preserve the old representation for omitted options and the mismatch check for actual changes. Is there a separate decision extending #2510’s Workflow archive reset to the shared App Server Session launch keys? Fingerprint · Comparison - Restore discovery in
/tasksafter reattach. Opening the panel now reads only IDs the client already knows. A management-started run withreport_topointing to this Session can start while the client is detached. Until it ends, there may be no tool result or report in history and no new notice. The user then cannot find or stop it. On panel open, recover the recent runs associated with the displayed Session before refreshing their details, as the panel contract specifies. Panel read · Panel contract
These findings come from tracing the changed production paths. The focused local test build timed out before it returned test results. Windows and macOS checks passed, and Linux workspace verification was still running at review time. CI
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES
PR 2513 makes Workflow script-only (Fixes #2510): one .js file with strict JSON meta, run-owned snapshots, an rquickjs runtime with workflow.stage/log/phase, replay-based pause/resume/stop, a file archive under the product home, the five-action tool, local management methods, durable reports and session.notice events. The structure follows the accepted design and the module split is clean. Script isolation, the submit permission path, per-workspace project enablement and the deletion plan all check out. Four defects in the run control and archive paths need fixes before merge.
P1. The run's captured policy is not the policy later stages run under
Problem. After the first stage records policy_cap, stage_launch stops naming the starter and sends only policy (crates/dim-workflow/src/script_stage.rs:573-592). The sessions face caps every launch without a starter by the host Session defaults: bound = self.session_defaults.permission_policy and policy = requested.cap(&bound) (crates/dim-app-server/src/agents/sessions.rs:584-600), and the product defaults are workspace-write (crates/dim-app-server/src/cli.rs:199-202). So a run started from a full-access branch runs stage 0 at full access and every later stage at workspace-write; branch pre-approved entries in allowedTools are also dropped by cap, which keeps only tools both sides allow unconditionally (crates/dim-agent-types/src/permission.rs:35-60). The implementation contract says the opposite: after the first stage the run uses the recorded policy "as the request policy, no longer carries the starting branch, and is no longer re-adjudicated" (docs/design/research/workflow-script-implementation-contract.md:430), and Workflow.md says a stage Session runs with its own captured policy (docs/design/plugins/Workflow.md:162).
Failure scenario. The user runs a workflow from a full-access session. Stage 0 (build) runs fine. Stage 1 calls a process tool: under workspace-write the call becomes an approval request on a non-interactive Session nobody can answer, so the stage hangs until max_stage_ms (2 hours) and the run fails with limit_exceeded. In addition, run.json records policy_cap: full-access while the stages actually ran narrower, so status reports a cap the stages did not have. The deleted steps engine had the same shape (origin/main crates/dim-workflow/src/engine.rs:732-750), so this is not a regression, but this PR rewrites the path and its new contract now states the intended behavior.
A second gap in the same function: a management-started run never names a starter and has no policy_cap, so requested falls to PermissionPolicy::default() (read-only, crates/dim-app-server/src/agents/sessions.rs:595-599). Every stage of a workflow started with dimcode workflow start or the TUI panel is read-only and cannot write files or run processes at all, which makes the CLI/TUI start surface shipped in this PR unusable for write workflows.
Fix. Either keep naming the starter branch on every stage of a tool run (the face's cap against the live branch never widens beyond the recorded cap), or change the sessions face so an explicit policy without a starter is its own bound, and update docs/design/appserver/sessions-service.md:199-211 accordingly. Decide and document what a management run's policy is (an explicit policy on workflow.start, or the host session defaults) instead of the implicit hard read-only. Add one flow test that starts a multi-stage run from a full-access branch and asserts every stage's effective policy.
P2. Control writes the run record concurrently with the run task
Problem. The contract requires one writer per run: every modification, including pause and stop, goes through the run handler's queue (docs/design/research/workflow-script-implementation-contract.md:652-665). Instead, control does its own read-then-write of run.json from the caller's task (crates/dim-workflow/src/script_run.rs:235, 242-260, 292-316) while the run's own task writes the same record from execute (crates/dim-workflow/src/script_engine.rs:516-537) and adopt_policy (crates/dim-workflow/src/script_engine.rs:809-829).
Failure scenario. The user stops a run that completes in the same instant: control read the record as running, the run task wrote completed with report.state=pending and its result file, then control overwrites it with stopping and stopped from its stale snapshot. The completed run now shows stopped, result_file is gone from the record and the pending report is never armed or delivered. The mirror case with pause overwrites a completed record with paused, and deliver then returns early because a paused run does not report (crates/dim-workflow/src/script_report.rs:147-149); the result only comes back after the user happens to resume.
Fix. Route control through the run's writer: hand the pause/stop request to the run task (a per-run mailbox or completing the control token and letting only the run task write the state transition), or at minimum re-read the record under a per-run lock and refuse the control action when the state changed since the read.
P2. runs/index.json updates race and recovery trusts only the index
Problem. update_index is an unlocked read-modify-write of the index file (crates/dim-workflow/src/run_archive.rs:974-992), and it is called concurrently from every run task (RunEngine::write_run, crates/dim-workflow/src/script_engine.rs:533-537), from control (crates/dim-workflow/src/script_run.rs:343-348) and from report settlement (crates/dim-workflow/src/script_report.rs:247-259). Two concurrent writers can each read the index without the other's entry and one update is lost. Recovery then iterates only index entries (crates/dim-workflow/src/script_owner.rs:663-700), so a run missing from the index is never turned from running to paused and its pending report is never armed, because the index is valid JSON and is not rebuilt.
Failure scenario. Two of the four allowed active runs settle at the same time; one index entry is dropped. After a later crash and restart, that run stays running in run.json forever (invisible to recent and unrecoverable by resume, since resume requires paused), and if it had completed, its pending report is never delivered.
Fix. Serialize index updates with a mutex inside RunArchive (one process per product directory is already the accepted model), and make startup recovery reconcile the index against the run directories, not only against index entries.
P2. A lost stage Session is re-dispatched and the script never sees stage_lost
Problem. When a resume reconciles a recorded activity whose Session no longer exists, resolve writes a lost record and then immediately falls through, resets the same record to queued and launches again (crates/dim-workflow/src/script_engine.rs:1111-1154). With the real runner the relaunch hits the stored launch key and fails with session_closed (crates/dim-app-server/src/agents/sessions.rs:820-823), so the script receives stage_failed with an owner error message instead of the documented stage_lost, and the event stream announces a lost state the archive no longer holds. If the launch key is also gone, the stage silently re-executes a call whose earlier execution may already have had external effects. The contract says lost activities are reconciled, not re-created, and stage_lost is part of the script error table (docs/design/research/workflow-script-implementation-contract.md:382, 633-641, 676-677).
Fix. After the lost write, settle the dispatch with StageError::Lost so the script sees the documented code; re-dispatch only when prior.session_id is None (a queued call that was never launched).
P2. The input-delivery retry loop ignores cancellation
Problem. deliver loops on waitPublished and, on a retryable error, sleeps and retries forever without observing any cancel token (crates/dim-workflow/src/script_stage.rs:141-171). It is reached from launch via ensure_input (crates/dim-workflow/src/script_stage.rs:505), which also never checks the token it was given, and the stage deadline only cancels the token, it does not bound the launch. Since Attempt::settle_stages awaits every stage task (crates/dim-workflow/src/script_engine.rs:774-782), a launch stuck in this loop blocks the run's settlement.
Failure scenario. The user stops or pauses a run whose stage is still delivering its input while the Sessions service keeps answering retryable (for example a long reload): the run stays stopping/settling indefinitely, stop never reaches stopped, and resume is refused with "the paused run is still settling its stages" (crates/dim-workflow/src/script_run.rs:261-273) until the process is restarted.
Fix. Thread the dispatch's cancel token into deliver and ensure_input and select on it between retries; treat a cancelled delivery as StageError::Cancelled.
P3. Contract lines not implemented
- Old data notice: contract 14.14 says startup records an "ignored" notice when it finds the old
runs.json, old settings or old.yaml(docs/design/research/workflow-script-implementation-contract.md:964-965). The files are preserved and never read (good, and consistent with the accepted no-migration decision), but nothing scans for them, so an upgrading user just sees an empty workflow list with no explanation. - Progress file: contract 3.2 and 6.6 batch logs and phase marks into
progress.jsonlat stage end and run end (docs/design/research/workflow-script-implementation-contract.md:183-188, 483-490), and run_archive.rs:4,29 still documents the file. Nothing writes or reads it; progress exists only as in-memory session notices and disappears on restart. Either write the promised file or remove it from the contract and the module docs. - Crash-matrix tests: contract 15.1 asks for one test per row of section 9 (docs/design/research/workflow-script-implementation-contract.md:972-982). Covered: index corruption and orphans, running run recovered as paused, queued without session, recorded session attached, recorded failure replayed. Not covered: result.json written but the run record not terminal, report delivered but the state not written, and the running-activity-with-missing-Session row (no test touches the lost path at all). Also, section 9 row 1 says incomplete run directories are deleted while section 7.1 says orphans are kept and listed (docs/design/research/workflow-script-implementation-contract.md:533-535 vs 670-672); the implementation keeps them, so fix the contract text.
Verified
- Script isolation: the runtime evaluates only the wrapped body with
argsand theworkflowobject; host objects are reachable only through the stage/log/phase wrappers (crates/dim-workflow/src/script_engine.rs:1414-1572). The lockdown removes clock, timers, random, network and process entries (crates/dim-workflow/src/script_engine.rs:1526-1546); the context is a plain rquickjsCtx::fullwith default intrinsics and never loads the QuickJS std or os modules, so noprintor file entry exists to leak to the daemon. A CPU-bound script is stopped by the interrupt handler and by pause/stop/deadline (crates/dim-workflow/src/script_engine.rs:1291-1301, testa_cpu_bound_script_is_interrupted_by_pause); a script awaiting a never-resolving promise is bounded by the same select (crates/dim-workflow/src/script_engine.rs:701-731). - Permission: the tool keeps the pre-existing risk
workflow, which Permission classifies as unclassified, so full-access allows, workspace-write asks and read-only denies (crates/dim-agent-capabilities/src/permission.rs:761-837); this matches the claim that submit is an ordinary high-risk action and is unchanged from main (origin/main crates/dim-workflow/src/session.rs:119). The tool fillscallerfrom trusted context only (crates/dim-workflow/src/script_session.rs:158-168) and the service re-derives the session id from the calling scope (crates/dim-workflow/src/script_owner.rs:219-228). Management methods are local-only: the web entry serves them only if explicitly allow-listed (crates/dim-app-server/src/connection.rs:628-655). Admission (max 4 active runs, paused excluded) and the visibility rule for status/control are enforced (crates/dim-workflow/src/script_run.rs:62-68, 140-153, 205-217). - Enablement and trust: project scripts start disabled, enablement is per absolute workspace path in
enabled.json, enabling parses the script first, andresolve_scriptrefuses a disabled project script (crates/dim-workflow/src/script_definition.rs:332-428, 529-567). A stage Session is non-interactive, so the workflow tool refuses to run inside it (crates/dim-workflow/src/script_session.rs:155-157), and a stage tool name no source offers fails the launch (crates/dim-app-server/src/agents/sessions.rs:752-781, testa_stage_that_asks_for_an_unknown_tool_fails_with_a_code). - Compatibility: the old steps engine, v1/v2 readers, the Settings source,
runs.json, the.yamlproject files and the TypeScript package owner are fully deleted; a repo-wide search finds no code path reading them, the new store is a separateworkflow/tree, and npm/branch-services.d.ts was regenerated. No secrets, credentials or private-account content appear in the diff. - Faces:
workflowRunsis provided and registered in the catalog with updated generated declarations;xtaskstatic checks pass on CI.
Verdict: the design, the deletion plan and the isolation model are sound, but the stage policy capture is broken for the mainline multi-stage case, and the control/index/lost/cancellation defects can each lose a run's outcome or hang its settlement. Fix those (or amend the contract where the behavior is intended) and this is ready.
| fn stage_launch(run: &RunRecord, request: &StageRequest) -> Launch { | ||
| let policy = run.policy_cap.clone(); | ||
| let starter = match run.started_by { | ||
| StartedBy::Tool if policy.is_none() => Some(Starter { |
There was a problem hiding this comment.
After the first stage records policy_cap, no stage names the starter, so the sessions face caps the request by the host Session defaults (crates/dim-app-server/src/agents/sessions.rs:593, 600; product defaults are workspace-write, crates/dim-app-server/src/cli.rs:201). A full-access branch's run gets stage 0 at full access and stage 1+ at workspace-write, and branch allowedTools are dropped, while run.json records the wider cap. This also contradicts the contract's "no longer re-adjudicated" (docs/design/research/workflow-script-implementation-contract.md:430). Separately, a management run never carries a policy, so every CLI/TUI-started stage is read-only (sessions.rs:599 falls to PermissionPolicy::default()). Keep naming the starter on later stages, or make an explicit policy its own bound, and define the management run's policy.
There was a problem hiding this comment.
Still open at 87870da: the three commits since my review changed only the tool text, the schema and the parameter validation; stage_launch still names the starter only until the first policy record (crates/dim-workflow/src/script_stage.rs:573-591), every later stage is still capped by the host Session defaults (crates/dim-app-server/src/agents/sessions.rs:584-600), and a management-started run still has no starter or policy, so its stages request PermissionPolicy::default(), read-only (crates/dim-app-server/src/agents/sessions.rs:595-599). The contract lines cited in the review still state the opposite behavior.
There was a problem hiding this comment.
Fixed for the normal path at 5946bf6: stage_launch names the starter on every tool stage and carries run.policy_cap, the Sessions face returns cap(requested, starter) (crates/dim-app-server/src/agents/sessions.rs:596-601), a management run takes the host Session default, the first launch is gated for parallel siblings, and a_stage_runs_under_the_policy_its_run_captured asserts both surfaces. What remains: launch_stage sets admitted after a failed or attaching first launch without adopting a policy (crates/dim-workflow/src/script_engine.rs:1188-1199), so the first successful new Session is never recorded as the cap. A run whose first stage launch fails then re-adjudicates every later stage under the live starting-branch policy and can end with policy_cap null. See the P2 in the review.
There was a problem hiding this comment.
Fixed in 4a732a6. policy_recorded() now gates the first launch (crates/dim-workflow/src/script_engine.rs:929-937), the gate only opens the fast path once the cap is in the record, and the fast path adopts the reply policy (1283-1303). a_failed_first_launch_does_not_release_siblings_without_a_policy asserts the first successful policy is recorded and carried to the next stage (crates/dim-workflow/tests/script_engine_flow.rs:683-721). The queued re-dispatch path in the same commit has a separate policy issue, reported as the P2 in the review.
| if let Some(control) = shared.runs.lock().expect("workflow runs").get(run_id) { | ||
| control.stop(); | ||
| } | ||
| run.state = RunState::Stopping; |
There was a problem hiding this comment.
Control writes run.json from the caller's task while the run's own task writes the same record, which the contract's single-writer rule forbids (docs/design/research/workflow-script-implementation-contract.md:652-665). If the run settles between the read at the top of control and this write, a completed run with a pending report is overwritten with stopping/stopped from the stale snapshot and the report is never delivered; pause has the same overwrite. Route the transition through the run task, or re-read and refuse when the state changed.
There was a problem hiding this comment.
Still open at 87870da: the new commit changed only the recent-runs path in crates/dim-workflow/src/script_run.rs; control still reads and writes run.json from the caller's task without serializing with the run task (crates/dim-workflow/src/script_run.rs:235, 256-259, 284-287, 302-315), while the engine writes the same record from finish and adopt_policy (crates/dim-workflow/src/script_engine.rs:515-537, 809-829), contrary to the single-writer rule (docs/design/research/workflow-script-implementation-contract.md:652-665).
There was a problem hiding this comment.
Fixed in 5946bf6: control re-reads the record under RunArchive::with_run_lock and refuses when the state differs from the one it read (crates/dim-workflow/src/script_run.rs:233-292). The engine, adopt_policy and report settlement take the same per-run lock (crates/dim-workflow/src/script_engine.rs:539-545, 836-846; crates/dim-workflow/src/script_report.rs:253-271), so a stale control cannot overwrite a completed run or its report state. a_control_that_lost_the_race_never_overwrites_the_completed_record covers it.
There was a problem hiding this comment.
Fixed in 4a732a6. settle re-reads the record under the run lock and lets an accepted stop decide the terminal write (crates/dim-workflow/src/script_engine.rs:464-490, 624-635), so a pause cannot overwrite stopping and a stop cannot overwrite a completion. The pause/stop and concurrent-resume tests cover the remaining races, and this commit does not change the path.
|
|
||
| /// Upserts one run's summary, rebuilding a missing or corrupt index first. | ||
| pub fn update_index(&self, run: &RunRecord) -> Result<RunIndex, ArchiveError> { | ||
| let mut index = match self.read_index() { |
There was a problem hiding this comment.
update_index is an unlocked read-modify-write called concurrently from every run task, control and report settlement. Two writers can drop one entry, and since startup recovery iterates only index entries (crates/dim-workflow/src/script_owner.rs:663-700), a run lost from the index is never recovered to paused and its pending report is never armed. Serialize index updates inside RunArchive and reconcile the index against the run directories at startup.
There was a problem hiding this comment.
Still open at 87870da: update_index is still an unlocked read-modify-write (crates/dim-workflow/src/run_archive.rs:974-992) called from the run task, control and report settlement, and startup recovery still reconciles only index entries (crates/dim-workflow/src/script_owner.rs:750, report arming at 778-786), so a run missing from the index is never recovered to paused and its pending report is never armed.
There was a problem hiding this comment.
Fixed in 5946bf6: update_index holds one index mutex across the read and the write (crates/dim-workflow/src/run_archive.rs:1008-1027), so simultaneous updates of different runs keep both entries. Startup recovery now rebuilds the index from the run directories and arms every pending report (crates/dim-workflow/src/script_owner.rs:778-824). simultaneous_index_updates_keep_every_run and startup_recovery_reconciles_a_stale_index cover both.
There was a problem hiding this comment.
Fixed in 4a732a6. update_index still holds one index mutex across the read and the write (crates/dim-workflow/src/run_archive.rs:1008-1027), and startup recovery still rebuilds from the run directories (crates/dim-workflow/src/script_owner.rs:779-824). The new commit does not change either path.
| } | ||
| StageLaunch::Failed(error) => return self.finish(dispatch, error), | ||
| StageLaunch::Absent => { | ||
| if prior.session_id.is_some() { |
There was a problem hiding this comment.
After writing the lost record the code falls through, resets it to queued and launches again. With the real runner the relaunch hits the stored launch key and fails session_closed, so the script gets stage_failed instead of the documented stage_lost, the lost write is transient, and if the launch key is gone the stage silently re-executes a call whose earlier effects are unknown. Contract 8.5 says lost activities are reconciled, not re-created. Return StageError::Lost here and re-dispatch only when prior.session_id is None.
There was a problem hiding this comment.
Still open at 87870da, with one correction to my earlier note: after the lost write, resolve falls through and relaunches with prior=None (crates/dim-workflow/src/script_engine.rs:1130-1146), and the runner returns Absent for a missing recorded session (crates/dim-workflow/src/script_stage.rs:480-488), so no stored launch key is reused and no session_closed fires. The stage silently re-executes under a fresh Session and the script still never sees stage_lost.
There was a problem hiding this comment.
Fixed in 5946bf6: when resolve gets Absent for a prior with a session id, it writes the Lost record and returns stage_lost, and it re-dispatches only when prior.session_id is None (crates/dim-workflow/src/script_engine.rs:1127-1145). The same applies to a Lost answer from ensure_input. a_lost_stage_session_is_recorded_and_not_dispatched_again asserts the lost state, the stage_lost code and no second launch.
There was a problem hiding this comment.
Fixed in 4a732a6. resolve writes Lost with the session id for an Absent prior and re-dispatches only when prior.session_id is None (crates/dim-workflow/src/script_engine.rs:1217-1235). The new commit does not change this path, and a_lost_stage_session_is_recorded_and_not_dispatched_again still covers it.
| return Err(refusal(error)); | ||
| } | ||
| if error.retryable { | ||
| sleep(POLL).await; |
There was a problem hiding this comment.
This retry loop observes no cancel token, and neither does ensure_input, so a launch stuck in it cannot be bounded by stop, pause or the stage deadline; settle_stages then awaits it and the run never settles (resume is refused while the run is still settling). Select on the dispatch's cancel token between retries and report StageError::Cancelled.
There was a problem hiding this comment.
Still open at 87870da: deliver still retries waitPublished in a loop with no cancel observation (crates/dim-workflow/src/script_stage.rs:141-171), ensure_input at crates/dim-workflow/src/script_stage.rs:505 still receives no token, and settle_stages still awaits the stuck stage (crates/dim-workflow/src/script_engine.rs:774-782), so stop and pause cannot bound a launch stuck in delivery.
There was a problem hiding this comment.
Fixed in 5946bf6 for the retry loop: deliver selects on the dispatch cancel for the input write, waitPublished and the retry sleep (crates/dim-workflow/src/script_stage.rs:116-186), ensure_input maps the cancelled delivery to StageError::Cancelled (340-393), and the stage deadline now bounds the wait. a_cancelled_delivery_stops_retrying_publication covers it. What remains is a separate P2: the cancelled launch never stops the Session it already created (crates/dim-workflow/src/script_stage.rs:274-324, 340-393), so stop or the stage deadline can leave that Session running after the run settles; the review body details it.
There was a problem hiding this comment.
Fixed in 4a732a6. The retry loop observes the dispatch cancel (crates/dim-workflow/src/script_stage.rs:116-186), and the launch now withdraws its input and stops the Session it created before answering Cancelled or Lost (531-573, 624-633). a_cancelled_delivery_stops_retrying_publication, a_launch_cancelled_while_locating_its_input_stops_the_child and a_release_the_owner_cannot_confirm_is_recorded_as_lost cover the loop and the release.
zerob13
left a comment
There was a problem hiding this comment.
I checked the first-stage policy flow on e1d5a333e70160d92f0814b6e0a63568147602e4. The updated tool description and parameter documentation are consistent with the current permission and page-limit rules. The earlier control, settlement, recovery, launch-key and reattachment findings are still open. Prior review
Persist the first declared stage’s effective policy before admitting parallel siblings or handing over input. Each initial stage currently starts a separate dispatch task and independently reads run.json. Launch submits that stage's input before returning the effective policy for capture. Two initial stages can therefore both launch before the run has durably recorded its cap. The first handoff to finish can determine which policy gets recorded. The direct-base implementation serialized first admission and checked that capture succeeded before admitting siblings. Current dispatch · Current handoff · Previous admission order
Please retain the established Sessions policy boundary during the fix. Later stages request the recorded cap and Sessions applies its host bound. Management starts keep the documented default. Acceptance is a normal parallel run in which the first launch acknowledgement is delayed: siblings wait for the first effective policy to be persisted, and each subsequent stage uses the effective policy returned by Sessions. Please align the implementation contract’s wording with that behavior. Confirmed A17 decision · Sessions contract
This additional finding comes from source inspection. The intervening commits changed the model-facing tool description, schema descriptions and their assertions. The other reviewer has documented the separate lost-stage, cancellation-retry and index-write cases. Peer review · PR checks
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES
Round 2 of PR 2513 (make Workflow script-only, fixes #2510), reviewed at head 87870da. Since the previous review the branch gained the commit "fix(workflow): reject fields from the wrong action" (crates/dim-workflow/src/script_owner.rs, script_run.rs, script_session.rs, +210 -23). It enforces per-action field allowlists with RunRequest::validate_action_fields (crates/dim-workflow/src/script_owner.rs:134-197, called at 303), gives the tool's status action the recent-runs fallback that the description has promised since the last head, filters that fallback by the caller's visibility (script_run.rs:372-398), and updates the tool text accordingly (script_session.rs:113). The round-2 finding about the status/run_id description drift is therefore fixed at this head. None of the five round-1 findings are touched, because the commit changes neither the stage launch path nor the run record writes it performs reads of. The control and recovery machinery is unchanged.
P1. The recorded policy is not the policy later stages run under (still open)
Problem. stage_launch names the starter only until the first stage records policy_cap; every later stage sends the recorded policy without a starter (crates/dim-workflow/src/script_stage.rs:573-591). The sessions face caps every starter-less launch by the host Session defaults, bound = session_defaults.permission_policy (crates/dim-app-server/src/agents/sessions.rs:593-594), which the product assembly sets to workspace-write (crates/dim-app-server/src/cli.rs:199-206); cap keeps only what both sides allow (crates/dim-agent-types/src/permission.rs:35-60). The implementation contract says the opposite: after the first stage the run uses the recorded policy "as the request policy, no longer carries the starting branch, and is no longer re-adjudicated" (docs/design/research/workflow-script-implementation-contract.md:430), and Workflow.md says a stage Session runs "with its own captured permission policy" (docs/design/plugins/Workflow.md:162).
Failure scenario. A run started from a full-access Session: stage 0 runs full access and records that cap, then stage 1's process call becomes an approval request on a non-interactive Session nobody can answer, hanging until max_stage_ms and failing with limit_exceeded. run.json reports the recorded cap while every later stage ran narrower. Separately, a management-started run (CLI/TUI start) names no starter and has no policy, so requested falls to PermissionPolicy::default(), read-only (crates/dim-app-server/src/agents/sessions.rs:595-599, crates/dim-agent-types/src/permission.rs:20-24); every stage of a CLI-started write workflow is hard read-only, which makes the management start surface shipped here unusable for write workflows.
Fix. Either keep naming the starter on every stage of a tool run (the face's cap against the live branch never widens beyond the recorded cap), or make an explicit policy without a starter its own bound and document the choice in docs/design/appserver/sessions-service.md:193-215. Decide and document what a management run's policy is instead of the implicit hard read-only. Agree with zerob13 that the first stage's effective policy must be durably recorded before parallel siblings launch (crates/dim-workflow/src/script_engine.rs:804-829); their capture race folds into the same fix. Add one flow test that starts a multi-stage run from a full-access branch and asserts every stage's effective policy.
P2. Control writes the run record concurrently with the run task (still open)
Problem. The contract requires one writer per run, with every modification including pause and stop going through the run handler's queue (docs/design/research/workflow-script-implementation-contract.md:652-665). control still read-modify-writes run.json from the caller's task (crates/dim-workflow/src/script_run.rs:235, 256-259, 284-287, 302-315) while the run's own task writes the same record from finish and adopt_policy (crates/dim-workflow/src/script_engine.rs:515-537, 809-829).
Failure scenario. Stop and completion in the same instant: control read the record as running, the run task wrote completed with a pending report, then control overwrites with stopping/stopped from its stale snapshot. The completed run now shows stopped, the result file pointer is gone from the record and the report is never delivered. The pause mirror leaves a completed run paused, and deliver then skips it because a paused run does not report (crates/dim-workflow/src/script_report.rs:147-149).
Fix. Route control through the run's writer (a per-run mailbox, or completing the control token and letting only the run task write the transition), or at minimum re-read the record under a per-run lock and refuse the action when the state changed since the read.
P2. runs/index.json updates race and recovery trusts only the index (still open)
Problem. update_index is an unlocked read-modify-write (crates/dim-workflow/src/run_archive.rs:974-992) called from every run task (crates/dim-workflow/src/script_engine.rs:533-537), control (crates/dim-workflow/src/script_run.rs:343-347) and report settlement (crates/dim-workflow/src/script_report.rs:248-259). Two writers can each read the index without the other's entry and one update is lost. Startup recovery then iterates only index entries (crates/dim-workflow/src/script_owner.rs:750) and arms reports from the same entries (script_owner.rs:778-786), so a run missing from the index is never turned from running to paused and its pending report is never armed; the index is valid JSON, so it is not rebuilt.
Failure scenario. Two of the four allowed active runs settle at the same time; one index entry is dropped. After a later crash and restart that run stays running forever, is invisible to recent and cannot be resumed (resume requires paused), and its pending report is never delivered.
Fix. Serialize index updates with a mutex inside RunArchive (one writer per product directory is already the accepted model) and make startup recovery reconcile the index against the run directories.
P2. A lost stage Session is re-dispatched and the script never sees stage_lost (still open)
Problem. When resolve gets Absent for a recorded activity whose Session no longer exists, it writes the lost record and then falls through, resets the same record to queued and relaunches (crates/dim-workflow/src/script_engine.rs:1111-1124, then 1130-1146). Correction to my first-round note: the relaunch passes prior=None, and the runner returns Absent for a missing recorded session (crates/dim-workflow/src/script_stage.rs:478-488), so no stored launch key is reused and no session_closed fires; the stage silently re-executes under a fresh Session. The contract's stage_lost is part of the script error table (docs/design/research/workflow-script-implementation-contract.md:168, 281) and lost activities are meant to be reconciled, not re-created (contract 633-641, 676-677).
Failure scenario. A resumed run whose recorded stage Session was deleted re-executes the stage call with a new Session, although the earlier execution may already have had external effects; the script receives a normal stage result, never stage_lost, while the event stream announced a lost state the archive no longer holds.
Fix. After the lost write, settle the dispatch with StageError::Lost; re-dispatch only when prior.session_id is None (a queued call that was never launched).
P2. The input-delivery retry loop ignores cancellation (still open)
Problem. deliver loops on waitPublished and, on a retryable error, sleeps and retries without observing any cancel token (crates/dim-workflow/src/script_stage.rs:141-171); ensure_input at crates/dim-workflow/src/script_stage.rs:505 passes no token either, and the stage deadline only cancels the token, it does not bound the launch. settle_stages awaits every stage task (crates/dim-workflow/src/script_engine.rs:774-782), so a stuck launch blocks settlement.
Failure scenario. Stop or pause during a stage that is still delivering input while the Sessions service keeps answering retryable (for example a long reload): the run stays settling, stop never reaches stopped, and resume is refused with "the paused run is still settling its stages" (crates/dim-workflow/src/script_run.rs:261-273) until the process restarts.
Fix. Thread the dispatch's cancel token into deliver and ensure_input and select on it between retries; treat a cancelled delivery as StageError::Cancelled.
P3. Contract lines not implemented (still open)
- Old-data notice: contract 14.14 wants an "ignored" notice when startup finds the old runs.json, old settings or old .yaml (docs/design/research/workflow-script-implementation-contract.md:964-965). The files are preserved and never read, but nothing scans for them, so an upgrading user sees an empty workflow list with no explanation.
- Progress file: contract 3.2 and 6.6 batch logs and phase marks into progress.jsonl at stage end and run end (docs/design/research/workflow-script-implementation-contract.md:183-188, 483-490), and crates/dim-workflow/src/run_archive.rs:4, 29 still document the file. Nothing writes or reads it.
- Crash-matrix tests: contract 15.1 asks one test per row of section 9 (contract 972-982). Covered: index corruption and orphans, running recovered as paused, queued without session, recorded session attached, recorded failure replayed. Not covered: result written but the run record not terminal, report delivered but the state not written, and the running-activity-with-missing-Session row (the lost path has no test). Section 9 row 1 says incomplete run directories are deleted while section 7.1 says orphans are kept and listed (contract 533-535 vs 670-672); the implementation keeps them, so fix the contract text.
New in this head (the fix commit)
- The status/run_id drift from the last review is fixed: the tool's status without run_id now serves recent runs, visible to the caller (crates/dim-workflow/src/script_owner.rs:366-381, crates/dim-workflow/src/script_run.rs:372-398), and the description now says exactly that (crates/dim-workflow/src/script_session.rs:113). The per-action allowlist is enforced on both the tool and the service call paths (call_checked at script_owner.rs:302), required fields are still enforced per branch (script_owner.rs:325, 350, 386-388), and the three new unit tests cover the allowlist. This part checks out.
- Optional, P3: recent now reads every run.json and, through summary, every result file on each call, including on the management path that was index-only before this commit (script_run.rs:382-391; the management caller passes viewer=None at script_owner.rs:909, so the visibility reads buy it nothing). Contract 7.1 says lists show index summaries and read run.json only for details (contract 533-535). With permanently retained archives each status-without-run_id call is O(n) file reads; keep the index-only fast path for viewer=None, or accept the cost in the contract.
Round-1 disposition (same five threads)
- 4779318208 (stage policy): still open, replied.
- 4779318218 (control race): still open, replied.
- 4779318224 (index race): still open, replied.
- 4779318229 (lost redispatch): still open, replied. The clause "the relaunch hits the stored launch key and fails with session_closed" is withdrawn; the relaunch is a fresh submission with prior=None (crates/dim-workflow/src/script_engine.rs:1143-1146, crates/dim-workflow/src/script_stage.rs:480-488). The defect stands.
- 4779318234 (deliver cancellation): still open, replied.
- Round-2 status drift: fixed at 87870da, no thread exists for it, no further action.
- Cross-PR: flags for #2479 and #2490 withdrawn (no shared files). #2488 still rewrites the same sessions.rs surface (both PRs add tools and skills to LaunchRequest and to the launch fingerprint, crates/dim-app-server/src/agents/sessions.rs), #2485 still touches crates/dim-agent-capabilities/src/skills/session.rs and the plugin_manager paths, #2483 still edits files this PR deletes (crates/dim-workflow/src/owner.rs, crates/dim-app-server/src/settings/workflow_files.rs). All are drafts; none blocks this merge. #2500 merged into main since round 1 touches only crates/dim-app-server/src/skills_management.rs, no overlap.
Verified
- Delta verified against the worktree at 87870da: the commit changes exactly the three files above; stage launch (script_stage.rs), the engine (script_engine.rs), the archive (run_archive.rs) and the report path are untouched, so the P1 and P2 evidence above is current at this head. The new tests (script_owner.rs:1004-1095) assert the allowlist matrix and were read assertion by assertion; they match the validated behavior.
- CI at head 87870da: static-checks, scripts, dependencies and changes pass; macos-native, verify (linux), web and windows-cli are in progress; acp-registry skipped. Not waited on.
- Not verified locally: the pinned toolchain 1.100.1 is not installed and the worktree has no target dir and dev-deps pull dim-app-server, so the changed crate was checked by reading, not by a local cargo run. No runtime probes were performed.
Verdict: the fix commit is correct and closes the description drift it targeted, but the five round-1 run-control and archive defects are untouched. Fix those, or amend the contract where a behavior is intended, and this is ready. The earlier opinions to withdraw are only the launch-key mechanism clause in 4779318229 and the conflict flags for #2479 and #2490.
zerob13
left a comment
There was a problem hiding this comment.
The Linux workspace suite exposes a new regression in the scenario evaluation profile. The native probe uses a model configuration and creates a disposable home, but serve_home passes None to Workflow for that profile. Workflow then returns before registering its Session tool. The probe’s required tool inventory still includes workflow, and the same profile is used by scenario children. As a result, the inventory assertion fails and isolated scenarios can stop at preflight before reaching the behavior under test. Give Workflow the scenario’s disposable home in both paths. The acceptance is that the existing native run-list assertion passes and an ordinary isolated scenario passes tools-product and reaches its expected outcome. Profile setup · Workflow installation · Registration guard · Inventory assertion
Linux verification failed in Run compiled workspace tests, and ci-ok failed because a selected job failed. Linux verify · Aggregate gate
The existing change requests still apply. First review · Peer review · Latest review
Required CI and independent approvals remain merge gates.
Replace steps, v1/v2 and the old run store with the script-only design: run-owned snapshots, activity records, pause/resume replay, Session events, permanent retention and the new status/control contract.
The script runtime of Phase B now runs behind the process owner and the Session tool: - The `workflow` tool has `list`, `start`, `submit`, `status` and `control`; `control` carries `pause`, `resume` and `stop`. - The management namespace has `workflow.list`, `.save`, `.enable`, `.start`, `.submit`, `.status` and `.control`. Script files and per-workspace enablement use the `script_definition` boundary only: user and project sources, no package. `workflow.stop` stays as a temporary alias of `control` with `stop` for the current panel and CLI. - `SessionStages` runs one stage as one non-interactive Session of the `sessions` service: the activity's `submission_id` is the launch key, so a relaunch attaches to the Session it already created; the input carries the same id, so delivery, lookup and withdrawal are idempotent across a resume. `agent` and `model` reach the launch; `tools` and `skills` are refused with `stage_failed` because the launch contract cannot carry them. - `RunEngine` executes every start, submit, resume and replay. Admission counts `running` and `stopping` runs (at most four); pause terminates the runtime and lets stages settle; stop cancels and settles; status reads the archive and pages activities by `call_index:attempt`. - The terminal write stamps `report.state = pending` and the stable submission id, and the owner delivers the result as one Steer input with backoff, on startup and after settlement. A status read never delivers. - Startup rebuilds a missing or corrupt run index, turns an unfinished run into `paused` and a `stopping` run into `stopped`, and arms the reports a previous process left pending. No run is resumed automatically. The steps modules still compile and their tests still describe the old tool and method shapes; they fail until Phase D removes them. Refs #1588
A run now announces its changes on the Session that owns its interface, through the existing Session notice (source `workflow`, kind `event`) with a per-run in-memory sequence that `status` reports. `script_events` owns the events, the sequence and the sink, so the owner and the engine publish the same records and a test can assert them without a loaded App Server. The engine writes the run record before it announces it, and serializes activity writes with their announcements so the announced order is the stored order; progress entries are announced at the call they describe. A stage now reports the effective policy of the Session it created, and the run records it once as `policy_cap`: later stages carry that cap instead of naming the starting branch, so a later change of the branch policy cannot raise a stage. The report is again the `<dim-workflow kind="report">` input the Session guide explains, delivered as runtime content, with stage states, the result preview and guidance on its last line. `status` bounds a page at the requested limit (1 to 50) and answers the live event sequence.
A stage Session now learns it is a stage: its input opens with <dim-workflow kind="stage" run call phase label>, and the Session guide explains that marker together with the run report. The steps owner registers the same guide text, from one definition. The workflow tool's description names the five actions, the explicit opt-in and the authoring Skill. `workflow-authoring` ships as a bundled Skill: the crate carries the SKILL.md, the owner writes it under the product workflow directory and registers that root with the process Skills catalog as plugin `workflow`, withdrawing it on unload. It stays on demand; no action requires it. Stage options now reach the Session: sessions.launch gains `tools` and `skills`, carried into SessionConfig and the launch fingerprint. A stage's tools are its mount list, still capped by the effective policy; a name no tool source offers, or one the policy disallows, fails the launch instead of running the stage without it. A stage's Skills narrow what its list and `skill` tool offer. Both are part of the activity record and the input hash. The task-view test that discovered workflow runs through facts no longer depends on ANSI-split rows or on a quiet wire: it passes. The read-failure test stays ignored: the CLI never adopts a run whose first read failed, so the panel has no row to mark unavailable.
Submit now states the ordinary Permission path, and the status page cap matches the contract's 50.
The model needs the script contract and routing, not the stage Session implementation. Keep the non-interactive constraint in the guide and authoring Skill.
Only action is required at the schema boundary. Each field now names the action that uses it and the description lists the per-action required subset.
Only action is required in the schema; each action now validates its own allowed field set, and status without a run id reads visible recent runs.
Every stage of a tool-started run now names the starting branch as its starter and carries the policy recorded at the first launch, so a later change of the starting branch can only narrow a stage. The first launch of an attempt is admitted alone until that policy is recorded; parallel siblings wait for it and launch under the recorded policy. A launch with no starter and no policy now takes the host Session default as both bound and requested policy instead of a read-only fallback, so a management-started workflow runs under the host Session default. The xtask model-profile server installs Workflow with the temporary home, so an eval product has a run archive for the CI eval test.
91aaae9 to
5946bf6
Compare
|
Addressed the review findings at the rebased head.
Local: |
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES
Round 3 of PR 2513 (make Workflow script-only, fixes #2510), reviewed at head 5946bf6. The branch was rebased onto main 5aef64f while this round was running; the base...head patch is unchanged (same 138 files, 15383 insertions, 22321 deletions, and the workflow, sessions and doc files cited here are byte-identical to the 91aaae9 state reviewed earlier), so the rebase moved no feature semantics and the old docs/release/README conflict is gone. GitHub now reports the PR MERGEABLE.
Four of the five round-1 findings are fixed at this head. Two real defects remain in the new policy and cancellation code, and crash-matrix rows 2 and 3 still contradict section 7.1.
P2. A run whose first stage launch fails never records policy_cap
Problem. launch_stage sets admitted after every launch, including a failed or attaching one (crates/dim-workflow/src/script_engine.rs:1188-1199), but adopt_policy runs only in the gate branch and only for a StageLaunch::Session that carries a policy (1195-1198). Once admitted is set, later launches take the fast path at 1188-1190 and never adopt. adopt_policy (825-847) is the only writer of the in-memory and recorded cap, and execute copies only the in-memory value at the end (437-439); stage_launch reads run.policy_cap for every request (crates/dim-workflow/src/script_stage.rs:606-624).
Failure scenario. A script's first stage asks for a tool no source offers. The Sessions face creates the Session, deletes it and returns the create error (crates/dim-app-server/src/agents/sessions.rs:756-777); the engine writes stage_failed and the script catches it (the catch path is tested at crates/dim-workflow/tests/script_engine_flow.rs:634-669). The next stage takes the admitted fast path and launches with run.policy_cap still None, so it is re-adjudicated by the starting branch's policy at its own launch. If the branch policy is later widened, every later stage widens with it, and the run ends with policy_cap: null although stages ran. The same happens when the first launch attaches to a recorded Session and no cap exists. That contradicts the contract's "the first launch records the effective policy" and "a later change ... can only narrow" (docs/design/research/workflow-script-implementation-contract.md:430; docs/design/plugins/Workflow.md:101-109).
Fix. Call adopt_policy after every launch that returns a Session; it already ignores all but the first policy. Set admitted only once a cap is in the record (or the run already had one), so a failure or an attach does not release siblings into a cap-less launch. Add a test whose first launch fails and whose second succeeds, asserting the second policy is recorded and carried to a third stage.
P2. A cancelled launch leaves the stage Session it created running
Problem. The runner creates the stage Session before delivering input (crates/dim-workflow/src/script_stage.rs:274-324), and ensure_input returns StageError::Cancelled as soon as delivery observes the dispatch cancel (340-393, mapping at 390; deliver at 116-186). resolve then finishes the activity as cancelled (crates/dim-workflow/src/script_engine.rs:1126; finish at 1245-1254) without recording the Session id, which only settle_stage writes (1203-1217). The only stop_line/withdraw calls are in Turn::cancel (script_stage.rs:733-738), reached only from wait (440-443), so this path never stops the Session. That violates the runner's own contract: a runner that observes cancel "should cancel its Session and answer StageError::Cancelled" (script_engine.rs:302-306).
Failure scenario. Stop, or the stage deadline, while a launch is delivering input (the reloading case from the round-1 thread). The input has already been committed, the run settles stopped or the stage cancelled, but the stage Session stays alive. After the line reloads it can publish and consume the input, so a stopped run still executes a stage and its external effects, and the Session is leaked because nothing recorded or stopped it; the app-server never unloads idle Sessions (docs/design/appserver/sessions-service.md:84).
Fix. When a Session has been created and the launch is cancelled, withdraw the input (look it up by submission id) and call stop_line before returning StageError::Cancelled, or return the Session with the error so the engine can settle and stop it. Add a test where cancel arrives during delivery and assert the Session is stopped.
P2. Crash-matrix rows 2 and 3 still contradict 7.1
Problem. Section 9 row 1 was fixed to keep an incomplete run directory and list it as an orphan (docs/design/research/workflow-script-implementation-contract.md:667), matching section 7.1's "a run directory without run.json is ignored, listed as an orphan and not deleted" (530). Rows 2 and 3 still say to delete the residual directory for a directory with only script.js or only args.json (668-669). Those directories have no run.json, so 7.1 and the implementation keep them (crates/dim-workflow/src/script_owner.rs:778-786; crates/dim-workflow/src/run_archive.rs:1029-1093), and no test covers rows 2 and 3 while 15.1 requires one test per row (971).
Failure scenario. An implementer following the matrix deletes directories that 7.1, row 1 and the code keep. The two rows cannot both be satisfied, and the crash-matrix coverage the contract requires has no test for either.
Fix. Amend rows 2 and 3 to keep and list the residual directory as an orphan, or implement deletion and amend 7.1 and row 1; add the two row tests, or state that the orphan test covers them. This is a text-only fix if the keep behavior is intended.
P3. A queued stage re-dispatched after a crash can be rejected by the stored launch id
Problem. stage_launch sends run.policy_cap as the request policy and the submission id as the launch id (crates/dim-workflow/src/script_stage.rs:606-624), while the Sessions launch key fingerprint includes the request policy (crates/dim-app-server/src/agents/sessions.rs:237-252, 510-515). If the process dies after adopt_policy records the cap (crates/dim-workflow/src/script_engine.rs:836-846) but before settle_stage writes the activity Running (1203-1217), the activity is still queued with no session id. This window predates the rework, but the reworked policy plumbing keeps it, and it was not raised earlier.
Failure scenario. On resume, begin requeues the activity and resolve launches it with the recorded cap (script_engine.rs:1018-1024, 1148-1173). The first attempt's launch key recorded policy None, so the fingerprint differs and the face answers "launchId was already used with a different request" (sessions.rs:510-515); the stage fails instead of attaching to the Session that already exists.
Fix. Send the first launch's request shape (starter, no policy) when re-dispatching a queued activity with no recorded session, and adopt the reply policy; or exclude the policy from the launch key identity for workflow stage submissions. Add a crash test for the cap-written, activity-not-written point.
P3. Optional
- The Session-visible status without run_id still reads every run.json and result file (crates/dim-workflow/src/script_run.rs:409-441) although contract 7.1 says lists show index summaries (530-531). The management path is now index-only and tested; the visibility filter needs the caller from the record. Amend 7.1 to allow the visibility read, or accept the cost.
- The zh sessions-service gets the updated diagram and test text but not the new English paragraph saying a launch with neither starter nor policy runs under the host default (docs/design/appserver/sessions-service.md:43-50). Add the mirror paragraph under the docs/zh rule in AGENTS.md.
- Contract 8.7 still says only the run handler writes run.json (647-659), while control, report settlement and recovery now write under the per-run lock, the alternative accepted in round 1. Amend 8.7 to describe the lock.
Prior findings
- 4779318208 (stage policy): partially fixed. Every tool stage now names the starter and carries run.policy_cap, the face returns cap(recorded, starter) (crates/dim-app-server/src/agents/sessions.rs:583-601), management runs take the host default, the first launch is gated, and
a_stage_runs_under_the_policy_its_run_capturedasserts full-access tool stages and workspace-write management stages. The first finding above is what remains. - 4779318218 (control race): fixed.
controlre-reads underwith_run_lockand refuses on a state change (script_run.rs:233-292); the engine, adopt and report settlement use the same lock (script_engine.rs:539-545, 836-846; script_report.rs:253-271); the lost-race test covers it. - 4779318224 (index race): fixed.
update_indexholds one mutex across read and write (run_archive.rs:1004-1027); recovery rebuilds from the run directories and arms pending reports (script_owner.rs:778-824); the simultaneous-update and stale-index tests cover it. - 4779318229 (lost redispatch): fixed.
resolvewrites Lost and returns stage_lost when the prior has a session id, and re-dispatches only when it is None (script_engine.rs:1127-1145); the lost-stage test covers it. - 4779318234 (delivery cancellation): fixed for the retry loop, stop and the stage deadline; the Session-stop gap above is a separate defect in the same area. Pause still lets in-flight stages settle by design (Workflow.md:111-113), so a paused run can stay settling until the stage ends; that is the documented behavior, not the old unbounded wait.
- P3 cluster: the old-data notice is implemented (script_definition.rs:219-345; script_owner.rs:271-291 and 640-642; listing at script_run.rs:444-459; tests at script_foundation.rs:838-875 and script_owner_flow.rs:876-914). The progress file is fixed by amending contract 3.2 and 6.6 to progress events (183-187, 480-486) and removing the file. The three named crash-matrix gaps are covered (startup_completes_a_run_whose_result_committed_before_its_terminal_record, a_report_delivered_before_its_state_was_written_is_delivered_once, a_lost_stage_session_is_recorded_and_not_dispatched_again). Rows 2 and 3 remain as above.
- Round-2 optional recent: fixed on the management path; the Session path remains optional above.
Permission picture
The recorded-cap rule holds on the fixed paths: later stages request the recorded cap and the face computes requested.cap(bound), a subset of the recorded cap, with the starter's live branch as the bound; management stages take the host default. One deliberate change is broader than workflow: a sessions.launch with neither a starter nor a policy now runs under the host Session default instead of read-only (crates/dim-app-server/src/agents/sessions.rs:596-601; the transport expectation changed from read-only to host_policy at crates/dim-app-server/tests/transport_flow/sessions.rs:817-823; documented at docs/design/appserver/sessions-service.md:43-50 and 220-222). The ceiling is unchanged because such a caller could already request any preset capped by the same defaults, but callers that relied on the old read-only fallback now run at workspace-write by default. Confirm the broad change is intended; if it is only for management workflows, scope it to them. The management start surface is defined and documented (Workflow.md:101-109; contract 430).
Cross-PR and base
The PR now bases on main 5aef64f and is MERGEABLE; the former docs/release/README conflict is gone. The known draft overlaps remain: #2483 (owner.rs, settings/workflow_files.rs, settings.rs, npm branch types, docs), #2485 (skills/session.rs, plugin_manager.rs, npm/plugin.d.ts, docs), #2488 (agents/sessions.rs, session_typescript.rs, sessions-service.md, p6-p7 bindings, npm, runtime test), and the rest of the #2478-#2495 data-face stack shares files this PR deletes or rewrites. All are drafts, so none blocks this merge; whichever side lands first will force a rebase on the other. Of the non-draft PRs, #2421 touches the same transport sessions test and sessions-service doc, and #2509 touches tui.rs; both are mergeable and their hunks do not overlap this PR's small edits there. No other open PR blocks this merge.
Verified
- The rebase changed no feature semantics: the 91aaae9 and 5946bf6 base...head patches are identical apart from hunk offsets and index lines, and the files cited here are identical between the two heads. The pinned toolchain 1.100.1 is not installed (only 1.100.0), the worktree has no target directory, and dev-dependencies pull dim-app-server, so the changed crate was checked by reading, not by a local cargo run. No runtime probes were started, so there are no residual processes.
- CI at 5946bf6: static-checks, scripts, dependencies, macos-native, web, windows-cli and changes pass; verify (linux) is pending; acp-registry is skipped. Not waited on.
- Both inline anchors are lines added by this PR in crates/dim-workflow/src/script_engine.rs and are present in the GitHub files patch. The full PR diff is over GitHub's 20000-line API cap, so the files endpoint omits some patches, but the anchors are in an added file.
Verdict: the policy, control, index, lost-stage and delivery-loop fixes are sound and tested, but two real defects remain in the new code (the cap is not recorded after a failed or attaching first launch, and a cancelled launch does not stop its Session), and the crash matrix still contradicts 7.1 in rows 2 and 3. Fix those and this is ready.
Opinions to withdraw from earlier rounds: the P1 failure scenario as written (later stages capped by host defaults; management runs hard read-only), the original control, index, lost-stage and unbounded-delivery defects, the round-2 optional management-path read cost, and the docs/release/README conflict.
| if let StageLaunch::Session { policy, .. } = &launch { | ||
| self.adopt_policy(policy.clone()); | ||
| } | ||
| let _ = self.admitted.set(()); |
There was a problem hiding this comment.
admitted is set after every launch, including StageLaunch::Failed and StageLaunch::Absent, while adopt_policy is called only for a Session in the gate branch above (1195-1198). A failed first launch (for example a stage tool no source offers, rejected and its Session deleted at crates/dim-app-server/src/agents/sessions.rs:756-777) or an attach with no recorded cap leaves run.policy_cap None. The next stage takes the fast path at 1188-1190 and never adopts, so every later stage is re-adjudicated by the starting branch's policy at its own launch, and the run can end with policy_cap: null although stages ran. The contract says the first launch records the effective policy and that a later branch change can only narrow (docs/design/research/workflow-script-implementation-contract.md:430, docs/design/plugins/Workflow.md:101-109). Call adopt_policy after every launch that returns a Session (it already ignores all but the first) and set admitted only once a cap is in the record; add a test whose first launch fails and whose second succeeds.
There was a problem hiding this comment.
Fixed in 4a732a6. A failed first launch no longer opens the fast path: policy_recorded() is false until the cap is in the record (crates/dim-workflow/src/script_engine.rs:929-937), the gate serializes the next launch, and the fast path adopts the reply policy (1283-1303). a_failed_first_launch_does_not_release_siblings_without_a_policy runs a failed first stage followed by two more and asserts the first successful policy is recorded and carried (crates/dim-workflow/tests/script_engine_flow.rs:683-721). The new queued re-dispatch shape in the same commit bypasses the cap for a stage whose launch key never existed; that is a separate path, reported as the P2 in the review.
| StageLaunch::Session { session, .. } => { | ||
| return self.settle_stage(dispatch, session, timed_out).await; | ||
| } | ||
| StageLaunch::Failed(error) => return self.finish(dispatch, error), |
There was a problem hiding this comment.
This arm also receives StageLaunch::Failed(StageError::Cancelled) from a launch that already created a Session: SessionStages::launch creates it before delivering input (crates/dim-workflow/src/script_stage.rs:274-324), and ensure_input returns Cancelled as soon as delivery observes the dispatch cancel (script_stage.rs:340-393). finish then writes stage_cancelled without recording the Session id; only settle_stage writes it (1203-1217), and it is skipped. The only stop_line/withdraw calls are in Turn::cancel (script_stage.rs:733-738), reached only from wait (440-443), so the created Session is never stopped. A stop or stage deadline during input delivery leaves it running and able to consume the committed input after the stop, and it leaks because nothing recorded it; the app-server never unloads idle Sessions (docs/design/appserver/sessions-service.md:84). The trait contract at 302-306 says a runner that observes cancel should cancel its Session before answering Cancelled. Stop the Session before returning, or return it with the error so the engine can, and add a test that cancels during delivery and asserts the Session is stopped.
There was a problem hiding this comment.
Fixed in 4a732a6 for the child the launch created: SessionStages::launch releases the Session on an ensure_input failure (crates/dim-workflow/src/script_stage.rs:531-573, 624-633), wait maps a cancelled turn to Cancelled or Lost after the same release (830-844), and the child id is recorded on the terminal activity through StageLaunch::Failed { session } (crates/dim-workflow/src/script_engine.rs:1211-1216). One narrower path remains: cancelling a resumed attempt while a stage waits at the engine gates answers Cancelled with no session and never reaches the runner (crates/dim-workflow/src/script_engine.rs:1290-1296, 1167-1170), so an attached prior Session is not stopped and its id is dropped. I noted it as Optional in the review.
Pause no longer converts an admitted but undelivered stage into a terminal cancellation; the stage receives its input and settles, and resume reuses the result.
|
Fixed the Pause→Resume regression at Pause no longer converts an admitted but undelivered stage into a terminal Also added |
zerob13
left a comment
There was a problem hiding this comment.
Approved on fe2433866fdef3b21d40e9cfb797ac77217162f6. When Pause precedes the first launch reply, the admitted stage now receives its input after the effective cap is durable and drains before the run settles paused. Resume returns the same-input completed output directly from the activity record without a second stage dispatch. Stop keeps its separate cancellation path. The held-launch Pause/Resume test, the recorded-stage replay test, and Stop during pause drain all passed on this head. Previous review · Delivery · Replay · Held-launch fixture
The previously verified native Session outcome, cap capture and background cleanup fixes remain intact. The archive example and crash matrix now document the cleanup marker and retry. Author update · Archive contract
Required CI is still running on this head. The independent changes request covered the prior head. Required CI and independent current-head approvals remain merge gates. CI · Prior independent review
zerob13
left a comment
There was a problem hiding this comment.
Requesting changes on fe2433866fdef3b21d40e9cfb797ac77217162f6 for the required Linux PTY fixture. The Pause/Resume and Stop evidence from the prior approval still applies. Prior review · Linux job
The fake daemon rejects the first workflow.status before any successful inventory, detail, or Workflow notice has populated a row. Tool facts only identify the run for a status read. The failed read stops automatic refresh, leaving the executing command as the only observed task. The terminal waits for ◐ 2 tasks before opening /tasks, while the daemon waits for requests that require the panel to open. The base fixture expected two tasks after it had already populated the Workflow row. Failure injection and wait · Header expectation · Base fixture
Synchronize the initial failed read and expect the single observed command before opening the panel. Keep the assertions that incomplete inventory blocks stop-all and that reopening restores the Workflow row and permits stopping both targets. Equivalent fixtures that deterministically establish and observe those states are fine. Linux failed in this fixture and ci-ok failed as a consequence. Read failure and row adoption · CI aggregate
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES
Round 8 of PR 2513 (make Workflow script-only, fixes #2510), reviewed at head fe24338. The new commit 7e21eab takes Pause out of the abandon check: only a cancelled stage token, which Stop and the run-level deadline still set, releases the child, while a Pause accepted during a launch lets the stage receive its input under the durable cap, drain and record Completed. The held-launch fixture now runs through Resume and asserts the recorded result is reused. The contract run.json example now lists stage_sessions_cleaned, the crash-matrix row states the marker and the background retry, and the merge of main 0588e86 is exactly git's automatic three-way merge. The round-7 blocker and the round-7 optional are fixed. One blocker remains outside the fix: the workflow read-failure test changed by the earlier merge resolution waits for a chip state its own fixture cannot reach, and verify (linux) fails at this head.
P2. The merged workflow read-failure test waits for a chip that cannot appear
Problem. tui_workflow_read_failures_block_stop_all_until_reopen_and_stops_follow_other_targets waits for a 2 tasks chip at crates/dimcode/tests/cli_flow/tasks.rs:2575 before it sends any input. At that point the projection holds one unfinished task, the main-command Command from the history reply (tasks.rs:2506). The facts name the run run-a (tasks.rs:2510), but a Workflow row is created only when a workflow.status read is adopted (crates/dim-cli/src/projection.rs:1590-1643 through crates/dim-cli/src/session_host/workflow.rs:347), and the test answers the first status read with the injected store busy error (tasks.rs:2511-2512). The client's error arm calls fail (crates/dim-cli/src/session_host/workflow.rs:329), which stops automatic reads until the panel reopens (workflow.rs:60-63, 204-208). The activity row counts unfinished Command and Workflow tasks (crates/dim-cli/src/ui/tui.rs:10428-10431), so the only label the fixture can reach is 1 task. The merge commit 014acb2 (be58bec merged with 422a7cd) changed this wait from the branch's 1 in background, which counted the same one task, to 2 tasks while adopting main's chip labels, so the test now blocks for the 60 s harness timeout on every run.
Failure. verify (linux) at fe24338 fails job 144283262990 in exactly this test: test result: FAILED. 125 passed; 1 failed; 1 ignored, Terminal did not show "◐ 2 tasks" at crates/dimcode/tests/support/cli_harness.rs:1096, and the captured screen shows ◐ 1 task. The daemon then panics with an EOF parse at tasks.rs:2251 while the harness tears down, which is a consequence. ci-ok fails with the job. macos-native passes and its log names no cli_session_flow test, so it does not cover this suite. The same job failed at the round-7 head 3b7bb02, where its log was unavailable, so this is the first head where the failure is identified.
Fix. Wait for 1 task before the panel opens and let the panel flow create the run row, or open the panel first and wait for the row after the successful retry. Keep the injected failure on the read the panel is meant to report; if the row must exist before the panel opens, make the first status read succeed and inject the failure on a later read.
The Pause fix
RunControl::pause cancels only the pause token (crates/dim-workflow/src/script_engine.rs:130-132). stage_cancel is a child of the stop token (156-158), and Pause does not touch it, so a paused launch keeps its dispatch token. resolve launches, writes the reservation, adopts the cap and only abandons the child when the stage token is cancelled (1372-1379), which Stop and the run-level deadline still do. A paused launch therefore writes Running with the durable cap and identity, receives its input and settles. The fixture asserts one delivery, session-0, a Completed activity with its session id, and a stored policy_cap after the Pause, then resumes and requires the stage output as the completed result (crates/dim-workflow/tests/script_engine_flow.rs:969-1036). A Completed activity replays as a recorded reply (script_engine.rs:1190), so Resume does not deliver the input twice; the fixture asserts one delivery across both attempts. Stop is unchanged: the semaphore wait still selects on the dispatch token (1275-1281), the resolve check still abandons on a cancelled stage token, and the per-stage timer still cancels the dispatch child that delivery observes. The cap ordering is unchanged: adopt_policy stays before the Running write and before delivery.
Prior findings
- Round 7 P2, Pause before a stage input failed the stage on Resume: fixed as above. The fixture now covers the resumed attempt.
- Round 7 optional, contract marker: the run.json example lists
stage_sessions_cleaned: false(docs/design/research/workflow-script-implementation-contract.md:430) and the crash-matrix row states the marker and the background retry (702). Section 8.3 step 3 still describes a refused delete as "only logs" (606); that is the remaining optional below. - Thread 4785208114 and the earlier rounds remain fixed; this commit changes only the launch path and does not reopen their behavior.
Optional
- Contract 8.3 step 3 (docs/design/research/workflow-script-implementation-contract.md:606) still says a refused
sessions.deleteat run end only logs and keeps the id. The run is now marked unclean withstage_sessions_cleaned: falseand startup recovery retries in the background. Add that sentence so the step matches the crash-matrix row and the other owner documents. - Pause also settles stage calls that were queued behind the concurrency limit. A call issued before Pause whose dispatch task is waiting for a slot still launches after Pause: the slot wait selects on the stop child only (crates/dim-workflow/src/script_engine.rs:1275-1281), Pause cancels only the pause token, and
settle_stagesawaits the spawned dispatch tasks (966-974). Before this commit the pause check abandoned such a dispatch after its launch; now it drains. A temporary probe withmax_concurrent_stages1, removed afterwards, showed a second stage queued before the pause launching, receiving its input and recording Completed after it, with the run settling Paused. Contract 8.4 step 4 names only stages already running (docs/design/research/workflow-script-implementation-contract.md:617) and Workflow.md says Pause stops new dispatch (docs/design/plugins/Workflow.md:128-130). If the wider settle is intended, say that calls already issued settle; otherwise gate the slot wait on the pause token and leave the Queued record for Resume.
Merge resolution and base
The head is fe24338. Since the reviewed 3b7bb02 the branch gained 7e21eab (3 files, +24 -11: script_engine.rs, script_engine_flow.rs, contract) and then merged origin/main 0588e86 in fe24338 (tui.rs +34 -1 from #2509); the complete delta is 4 files, +58 -12. The merge is exactly git's automatic three-way merge: git merge-tree --write-tree 7e21eab4 0588e86651 produces tree 04171621a29dc19ef0148eed5ee9271e9694f77b, the same tree the merge commit holds, so no side lost content and no manual resolution was needed. The combined diff is only tui.rs, where the branch's WorkflowControl effect (4/2 lines against main) and main's draft restore and test sit in different regions. macos-native passes at this head, which compiles the merged tui.rs.
Cross-PR and base
The PR base is main 0588e86 (the head now contains it through the merge), and GitHub reports the PR open and MERGEABLE. Against the other open non-draft heads, #2322 conflicts in crates/dim-cli/src/projection.rs, #2421 in docs/design/appserver/sessions-service.md and its zh mirror, #2528 in crates/dim-app-server/src/agents/sessions/tests.rs, and #2530 in crates/dim-workflow/src/engine.rs, a file this PR deletes and #2530 edits. #2399, #2449, #2455, #2517, #2518, #2526, #2529, #2531, #2533 and #2536 merge cleanly. These are merge-order conflicts with other open PRs, not blockers for this PR.
Verified
- Head fe24338; I read the full fix commit, the complete delta 3b7bb02..fe24338 (4 files, +58 -12), the merge parents and tree, and the cited paths and documents at this head.
- Tests with RUSTUP_TOOLCHAIN=1.100.0, LC_ALL=en_US.UTF-8 and the real HOME for cargo:
cargo test -p dim-workflow --lib --locked15 passed;cargo test -p dim-workflow --test script_engine_flow --locked45 passed, includinga_pause_accepted_before_the_first_launch_answers_delivers_and_resumes;cargo test -p dim-workflow --test script_foundation --locked22 passed;cargo test -p dim-workflow --test script_owner_flow --locked20 passed. The temporary queued-call probe was removed after its run and the worktree is clean; no residual processes. - CI at this head: changes, dependencies, macos-native, scripts, static-checks, web and windows-cli pass. verify (linux) failed in the test above (job 144283262990: 125 passed, 1 failed, 1 ignored); ci-ok failed with it and acp-registry is skipped. Not waited on.
Not verified
The full workspace suite, the Windows atomic-write fallback, the GUI and a real Sessions store across a process restart with the Workflow owner. The pause path was verified with the archive and the test fakes, and the real token behavior by reading RunControl.
Verdict: the Pause fix and the contract additions are sound and the round-7 blocker is fixed, but verify (linux) fails deterministically in the workflow read-failure test that the earlier merge resolution changed. Fix the wait and this is ready.
Opinions to withdraw: the round-7 P2 on Pause and the round-7 optional on the run.json field and the crash-matrix sentence are fixed. The remaining items above are optional except the P2 test failure.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
APPROVE
Round 9 of PR 2513 (make Workflow script-only, fixes #2510), reviewed at head f2ce9eb. The head moved twice after the round-8 review: db3b78d carries the two one-line fixes, and f2ce9eb merges origin/main f9957c0 (#2517, the ACP delete flake test) into the branch. The merge is exactly git's automatic three-way merge: git merge-tree --write-tree db3b78dc f9957c01288092a059fe4f3a2614fdfe55cef64e produces tree 4b4ca941252b651d12d602bfe2dfc7d64962b232, the same tree the merge commit holds, and its only content change is the acp.rs test from main. Both round-8 items are fixed and I found no new blocker.
The two fixes
The fixture. The round-8 blocker was the initial wait in tui_workflow_read_failures_block_stop_all_until_reopen_and_stops_follow_other_targets: it waited for ◐ 2 tasks before opening the panel. The fixture records one unfinished Command task from the history reply (crates/dimcode/tests/cli_flow/tasks.rs:2506) and names run-a only through tool facts (tasks.rs:2510). A Workflow row is created only when a workflow.status read is adopted, and the test answers the first read with the injected store busy error (tasks.rs:2511-2512), after which the client stops automatic reads until the panel reopens (crates/dim-cli/src/session_host/workflow.rs:329; the failure path is at 322-329 and the reopen at 200-218). The activity row counts unfinished Command and Workflow tasks (crates/dim-cli/src/ui/tui.rs:10428-10431), so the reachable label was ◐ 1 task, which is exactly what the failed verify (linux) screen showed at fe24338 (job 144283262990: Terminal did not show "◐ 2 tasks", 125 passed, 1 failed). The new wait at tasks.rs:2575 matches the fixture and the captured screen, and the rest of the test is unchanged, so the panel assertions that were previously unreachable can run.
The contract. Step 3 of contract 8.3 now says a refused sessions.delete keeps stage_sessions_cleaned=false and startup recovery retries in the background (docs/design/research/workflow-script-implementation-contract.md:606). The implementation matches: the field defaults false (crates/dim-workflow/src/run_archive.rs:307, 340) and is set true only after every recorded stage Session is deleted (crates/dim-workflow/src/script_stage.rs:357-372); recovery returns terminal runs whose flag is false (crates/dim-workflow/src/script_owner.rs:903-905) and the owner runs that cleanup after registration and report recovery in a background task (script_owner.rs:662-668, 724-735); the crash-matrix row states the same behavior (contract:702). The sentence now agrees with the row and the code.
Prior findings
Round 8 P2 (the unreachable two-task wait) and the round-8 optional (8.3 step 3 said a refused delete only logs) are fixed. The round-7 Pause fix remains: Pause cancels only the pause token (crates/dim-workflow/src/script_engine.rs:130-132), stage_cancel is a child of the stop token (156-158), resolve abandons only on a cancelled stage token (1372-1379), and the held-launch fixture runs through Resume (crates/dim-workflow/tests/script_engine_flow.rs:969-1036). Earlier rounds' threads remain fixed. The one remaining optional is the Pause drain of calls already queued behind the concurrency limit (script_engine.rs:1275-1281, 966-974; contract:617; docs/design/plugins/Workflow.md:128-130), unchanged and not a blocker.
Cross-PR and base
The PR base is now f9957c0 (GitHub advanced it when main moved), and the head contains it through f2ce9eb. The main merge is clean by construction, and the auto-merge tree above equals the merge commit. Against the other open non-draft heads: #2530 conflicts in crates/dim-workflow/src/engine.rs (this PR deletes the file and #2530 edits it), #2322 in crates/dim-cli/src/projection.rs, #2421 in docs/design/appserver/sessions-service.md, and #2528 in crates/dim-app-server/src/agents/sessions/tests.rs; #2531, #2536, #2399, #2455 and #2449 merge cleanly. These are merge-order conflicts, not blockers for this PR.
Verified
- Head f2ce9eb; I read the round-8 to head delta: the two one-line fixes at db3b78d and the main merge at f2ce9eb, the merge tree check, the fixture and its failure path, the cleanup marker and retry code, the contract section, the crash-matrix row, and the existing reviews and threads.
- CI at f2ce9eb: changes, dependencies, macos-native, scripts and static-checks pass; verify (linux), web and windows-cli are in progress; acp-registry is skipped. At db3b78d verify (linux) was cancelled when the head moved, so the fixed fixture has not completed a Linux run yet. Not waited on.
- Not verified locally: the Linux PTY fixture was not run and the full workspace was not built. The test fix is verified from the fixture and the captured failure screen, not from a local execution.
Verdict: the two new commits fix the two round-8 items exactly, the cleanup sentence now matches the marker and the background retry, and the main merge is automatic. No new blocker; approve.
Opinions to withdraw: the round-8 P2 on the two-task wait and the round-8 optional on contract 8.3 step 3 are fixed.
zerob13
left a comment
There was a problem hiding this comment.
Approved on f2ce9eb14b98c2aaaf7cc8f746aeadcd48e0c917. The corrected PTY test passed end to end on this head. It opens /tasks after observing the one known command, verifies that the first Workflow status error blocks Stop All, then reopens the panel and stops both targets through their owning methods. The fixture also verifies that the leader still accepts a new submission while the Workflow stop reply is pending. Previous review · PTY assertions · Owner requests
The previously verified Pause/Resume and Stop paths are unchanged. The cleanup contract now describes the background retry after a refused deletion, and the merge from main only adds its ACP fixture change. Previous control verification · Cleanup contract
Linux and Windows CI were running at the last check. The independent current-head approval is on record, and required CI remains a merge gate. CI · Independent approval
zerob13
left a comment
There was a problem hiding this comment.
Requesting changes on f2ce9eb14. I found the following paths in the script-only Workflow implementation.
-
An accepted Stop can leave a paused run in
stoppinguntil restart. The engine writes its finalpausedrecord and releases the run lock before the owner removes the control fromruns. A Stop in that interval sees the control, writesstopping, and delegates the terminal write to a worker that has already finished settling. The worker then removes the control and ignores the paused outcome. Settle an accepted Stop and retire the worker under the same per-run lock. Exercise Stop after the paused write and before deregistration. Engine settlement · Worker exit · Stop -
The report worker can leave a pending report idle indefinitely. After the worker observes an empty queue and unlocks it, a producer can insert the only report and call
notify_waiters()before the worker createsnotified(). That notification is lost and the worker sleeps until another insertion or restart. There is one consumer, so usenotify_one()to retain a permit or register the waiter before inspecting the queue. Separately, once a report is dequeued, any error openingrun.jsonreturnsDelivery::Delivered. A temporary I/O failure therefore discards the retry even though the record still sayspending. ReturnRetryfor transient archive failures so the existing backoff runs. Queue and waiter · Archive read · Retry dispatch -
Recovered runs can change state without notifying their Session. Startup queues pending reports without calling
events.track. When delivery later succeeds,report_changedfinds no entry and returns. The same happens torun.changedwhen an operator stops a recovered paused run before its first Resume. Status shows the transition while an attached subscriber receives no notice. Restore tracking for recovered controllable runs and pending reports before their next transition. Recovery · Event routing · Run notices -
A status snapshot can undo a newer live event.
statusreads the run record, reads activities, then reads the current event sequence insidesummary. If completion occurs between those reads, the reply can containrunningstamped with the completion event's sequence. A client that already applied that event accepts the equal-sequence reply and puts the row back intorunning. This also affects Session-scoped recent summaries. Capture the sequence before reading the associated state, or retry when it changes during the read. Cover a completion interleaved with a status read. Status read · Sequence stamp · CLI acceptance -
Concurrent management writes can silently overwrite another caller's change. Two
workflow.enablecalls for different scripts with the sameexpected_revisioncan both read revision N, both report success at N+1, and leave only the last change on disk. Twoworkflow.savecalls for the same absent name withoverwrite=falsecan likewise both pass the existence check and replace one another's script. The management dispatcher spawns each call independently. Serialize each check and write in the owner, or use atomic create-if-absent for saves. Verify that exactly one caller succeeds in each collision. Dispatcher · Enable · Save
I also reproduced a merge conflict with main at 0497d1c43 using git merge-tree. Please preserve the shared SQLite/PostgreSQL launch-lifecycle coverage from #2528 and the new launch-fingerprint regression when resolving crates/dim-app-server/src/agents/sessions/tests.rs. I verified the code paths and merge conflict locally. I did not run the test suite.
|
Round-9 fixes at
Commands: dim-workflow 19+45+23+22, app-server session tests, clippy, workspace check and |
zerob13
left a comment
There was a problem hiding this comment.
Approved on 0179e65ad7a77f129a28577116931c89c15fcaf7. The five paths from the previous review are addressed. Worker retirement and Stop now share the run lock. The single report consumer retains early wakes, and unreadable records use retry. Recovery restores notification tracking for paused runs and pending reports. Both detail and Session-scoped recent reads capture their sequence before reading the run record. Concurrent saves and conditional enablement serialize the check and write, with one winner per collision. Previous review · Author follow-up
Focused tests passed for paused-worker retirement, recovered Stop and report routing, transient archive reads, the detail snapshot interleaving, and colliding management requests. The Sessions test resolution preserves #2528’s SQLite and PostgreSQL lifecycle cases and the Workflow launch-fingerprint coverage. Retirement · Snapshot reads · Sessions tests
Linux and Windows were still running at the last check. The earlier independent approval was on the previous head. Required CI and current-head approvals remain merge gates. CI · Previous independent approval
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
APPROVE
Round 10 of PR 2513 (make Workflow script-only, fixes #2510), reviewed at head 0179e65. The head adds 94fd336, which closes the report, stop and status races raised in the changes-requested review at f2ce9eb, and 0179e65, which serializes management writes and merges main 0497d1c with a manual conflict resolution in crates/dim-app-server/src/agents/sessions/tests.rs. All five raised paths now have code and test evidence, the merge keeps both sides, and I found no new blocker. The round-9 approval at f2ce9eb is superseded by this review.
The five fixes
- Stop after the paused write.
spawnretires the control after the engine returns (crates/dim-workflow/src/script_run.rs:195), andretiretakes the per-run lock, removes the control and, when the record is stillstopping, writesstopped(223-239). The Stop path re-checks the control after itsstoppingwrite and settles the record itself when the worker has already retired (373-392, check at 386-391).a_stop_after_the_paused_write_settles_as_stoppedcovers the gap (851). - Report wake and read failure.
scheduleandretry_laterwake the worker withnotify_one(crates/dim-workflow/src/script_report.rs:61-86, calls at 71 and 85), so a wake that arrives before the worker waits is retained rather than lost;a_wake_that_races_the_empty_check_is_not_lostreproduces that interleaving (335).read_for_deliverymaps a missing run to delivered and every other read error to retry (200-209), and the worker keeps a growing backoff throughretry_later(crates/dim-workflow/src/script_owner.rs:718).an_unreadable_record_retries_instead_of_dropping_its_reportcovers both branches (368). - Recovered tracking.
recover_archivenow takes the events registry and tracks every recovered paused run and pending report before its next transition (script_owner.rs:856, track at 910-914).startup_restores_tracking_for_recovered_runs_and_pending_reportsasserts the stop and delivery notices (crates/dim-workflow/tests/script_foundation.rs:906), anda_stop_of_a_recovered_paused_run_announces_itselfasserts thestoppingandstoppednotices through a Session (crates/dim-workflow/tests/script_owner_flow.rs:1459). - Status snapshot sequence.
statusand the Session-scopedrecentcapture the event sequence before reading the run record that supplies the state (script_run.rs:430-450 and 456-475), andsummarystamps that sequence intoevent_sequence(511-524). A completion that lands during the activity read can therefore no longer stamp older state with a newer sequence.a_status_read_never_stamps_older_state_with_a_newer_sequenceholds the activity read on a FIFO while the run completes and asserts the snapshot stays below the completion event (908). docs/design/plugins/Workflow.md:233-234 and 241 state the rule and the reconnect consequence. - Management collisions.
storage::management_lockserializes the check and the write (crates/dim-workflow/src/storage.rs:15-26);EnabledStore::setholds it across the read, the revision check and the write (crates/dim-workflow/src/script_definition.rs:548-561), andsave_scriptholds it across the existence check and the write (735-744).colliding_management_writes_leave_exactly_one_changeruns concurrent saves of one name and concurrent enables at one revision and asserts one winner, the expected loser error and an intact file (script_owner_flow.rs:899).
Merge resolution
The only conflict with main 0497d1c is crates/dim-app-server/src/agents/sessions/tests.rs: git merge-tree --write-tree 94fd3369 0497d1c4 reports a conflict there and its automatic tree (b4aedc14) differs from the merge tree (763bccd7). The resolution adapts main's launch-lifecycle test to the branch's request shape (tools: None, skills: None), keeps its incomplete-reservation assertion, and keeps the branch's a_launch_without_a_starter_is_read_only_unless_it_requests_a_policy; both tests pass at the head. The merge is not a pure conflict resolution: the management serialization in storage.rs and script_definition.rs and its collision test are in neither parent and are added by this commit. That is the fix for the fifth finding, it is covered by the test above, and the commit message names it.
Prior findings and options
- The five findings of the f2ce9eb CHANGES_REQUESTED review are fixed by the commits described above; that review is withdrawn. Our round-9 approval at f2ce9eb is superseded.
- Still open from earlier rounds, unchanged and optional: Pause drains calls already queued behind the concurrency limit before Resume can stop them (script_engine.rs:1275-1281 and 966-974; contract:617; Workflow.md:128-130).
- New optional, P3. A control reply is stamped with the event sequence read after the control returns (script_owner.rs:549-558) and the dispatch path does the same (1068-1073), while the summary carries the state the control wrote. If the worker publishes the
stoppedevent between that write and the sequence read, the reply carries thestoppingstate with thestoppedsequence; the CLI setsknown.appliedto it and applies the summary without the status guard (crates/dim-cli/src/session_host/workflow.rs:500-525), so a row that already showedstoppedcan briefly revert tostoppinguntil the next refresh. Stamping the reply with the sequence produced by the control write, or skipping a reply below the applied sequence, closes it. This is a narrow, self-healing path and does not change the verdict.
Cross-PR and base
Head 0179e65; base and origin/main are 0497d1c, which the head contains through the merge. Merge-tree against main is the head tree. Against the other open non-draft heads: #2530 conflicts only in crates/dim-workflow/src/engine.rs, the file this PR deletes and the alternative implementation edits, so it is the owner-selection duplicate rather than a code conflict; #2531 and #2322 merge cleanly. These are merge-order notes, not blockers for this PR.
Verified
- Head 0179e65. I read the two new commits, the combined first-parent diff, the manual resolution in sessions/tests.rs, the five fix paths and their tests, the documentation change, and the previous reviews and comments.
- Tests at the head with the real HOME, LC_ALL=en_US.UTF-8 and the installed 1.100.0 toolchain (the repo pins 1.100.1, which is not installed):
cargo test -p dim-workflow --lib --locked19 passed;--test script_engine_flow45 passed;--test script_foundation23 passed;--test script_owner_flow22 passed;cargo test -p dim-app-server --lib launch_id_is_idempotent_and_survives_deletion1 passed (PostgreSQL ignored);a_launch_without_a_starter_is_read_only_unless_it_requests_a_policy1 passed. No probes were left behind and no processes remain. - CI at 0179e65: changes, dependencies, macos-native, scripts, static-checks, web and windows-cli pass; verify (linux) is in progress; acp-registry is skipped. Not waited on; the new tests have not completed a Linux CI run yet.
- Not verified: the full workspace, the ignored PostgreSQL variants, and the Windows fallback.
Verdict: the five changed-state paths are fixed with tests, the merge resolution preserves both sides and both tests pass, and the remaining items are optional. Approve.
Opinions to withdraw: the f2ce9eb CHANGES_REQUESTED findings are fixed, and our round-9 approval at f2ce9eb is superseded by this review. The round-8 Pause-drain optional remains.
zerob13
left a comment
There was a problem hiding this comment.
Approved on 0179e65ad7a77f129a28577116931c89c15fcaf7. The five fixes and their verification still apply. Prior exact-head review · Independent exact-head review
Optional
A Stop reply can still carry stopping with the sequence of a newer stopped notice. The native CLI can briefly replace the terminal row with stopping or skip the matching notice if the reply arrives first. The next successful status refresh restores the stored terminal state. If status reads are already failing, reopening /tasks retries them. For a follow-up, capture the sequence associated with the control result and keep an older control reply from replacing a newer observed state. A client check for a strictly lower sequence alone would miss this equal-sequence case. Control reply · CLI reply adoption
Linux CI and the aggregate gate were pending at the last check. Both existing approvals are on this head, and required checks and branch protection still govern merge. CI
Fixes #2510.
What ships
.jsuser/project scripts and per-workspace enablement.
runs/index.json.workflow.stage,workflow.log,workflow.phase,stage options, input hashes, replay and pause/resume/stop.
workflowtoollist/start/submit/status/control, management methods,durable report delivery and
session.noticeevents.workflow-authoringSkill.dim.workflow/v1/v2, the old Settings source, oldruns.jsonstore, old tests and the TypeScript package owner.Compatibility
This is intentionally incompatible: old steps definitions, old
.yamlproject files and old
runs.jsonare not read, migrated or reinterpreted.Project scripts are
.jsand must be enabled per workspace.submituses theordinary Permission path;
FullAccessallows it without an extra prompt.Verification
cargo test -p dim-workflow --lockedcargo test -p dimcode --test cli_session_flow tui_workflow --lockedcargo test -p dim-agent-capabilities --test capabilities_flow -- --test-threads=1(772 passed, 5 ignored)cargo check --workspace --all-targets --lockedcargo clippy --workspace --all-targets --locked -- -D warningscargo run --locked -p xtask -- checknode --test scripts/*.test.mjscargo test --workspace --lockedwith default parallelism still aborts in theunrelated
dim-agent-capabilitieshost-health flow; the same target passes772/772 when run sequentially.
Design:
Workflow,
implementation contract.