From 57c9eae7137e363da60df6eaaf357c3b47bde097 Mon Sep 17 00:00:00 2001 From: James Chapman Date: Tue, 17 Nov 2026 16:40:47 +0000 Subject: [PATCH 1/4] test: time chat-turn cancellation from the cancel, not the turn start a_streamed_text_turn_cancelled_mid_stream_is_recorded_as_cancelled failed once on a windows-2025 runner with "cancellation took 5.9s" against the 5-second CANCEL_BOUND. The five cancellation tests in chat_turn.rs started their clock before calling the turn, so the bound also covered reading settings and the synced journal appends made before the request, whose duration depends on the host's storage. Evidence: - In the failing job the chat_turn suite took 27.2 s (about 3 s in four earlier Windows runs), and two omgcode-app unit tests that only open a DesktopService on a temporary directory took 4 to 5 s each (the whole unit binary takes 0.06 s on a normal run). The runner's storage was slow; no network or cancellation is involved in those tests. - Local timing probes in the adapter and turn put cancel-to-return under 1 ms, also with the host at 100% CPU and under disk-flush contention, where the pre-request journal phases grew up to twentyfold. - A temporary 6-second delay before the response head reproduced the failure ("cancellation took 6.02s") with cancel-to-return at 1.0 ms. It passes with the new timing. - A temporary slow cancellation (6-second poll, no fast-path check) still fails the new check with "cancellation took 6.009s". The tests now take the instant at the cancel (in the stream hook or the canceller thread) and assert that the turn or compaction returned within CANCEL_BOUND of it, as the desktop cancellation tests already do. The bound, the other assertions, and the adapter are unchanged. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 14 +++++ crates/omgcode-app/tests/chat_turn.rs | 75 ++++++++++++++++++--------- docs/provider-authentication.md | 6 ++- docs/testing-standards.md | 6 ++- 4 files changed, 74 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d48dfee..a412406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -888,6 +888,20 @@ Changes are recorded here before a release version is assigned. ### Fixed +- The five cancellation tests in `crates/omgcode-app/tests/chat_turn.rs` now + time the interval from the moment the token is cancelled until the turn or + compaction returns, as the desktop cancellation tests already did. They + timed the whole turn, which also covers reading settings and the synced + journal appends made before the request. On a slow Windows runner, + `a_streamed_text_turn_cancelled_mid_stream_is_recorded_as_cancelled` + failed with "cancellation took 5.9s". In the same job, two `omgcode-app` + unit tests that only open a service on a temporary directory took 4 to 5 + seconds each, against milliseconds on other runs. Local timing probes put + the cancel-to-return step under 1 ms, also under full CPU load and under + disk-flush contention. A 6-second delay before the response head + reproduced the failure with the old timing and passes with the new one. A + slowed-down cancellation (a 6-second poll) still fails the new check. The + 5-second bound and the adapter are unchanged. - Findings from the first Sonar analysis of the desktop frontend: - Both workflows now install the frontend's dependencies with `npm ci --ignore-scripts`. `ui/.npmrc` already set this; the flag makes diff --git a/crates/omgcode-app/tests/chat_turn.rs b/crates/omgcode-app/tests/chat_turn.rs index 9dc0a3a..62f4241 100644 --- a/crates/omgcode-app/tests/chat_turn.rs +++ b/crates/omgcode-app/tests/chat_turn.rs @@ -4,7 +4,7 @@ //! an ephemeral port. No process is spawned on Unix; on Windows the private //! data root is prepared with `icacls`, which holds no store handle. -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; use std::fs; use std::io::{Read, Write}; use std::net::{TcpListener, TcpStream}; @@ -876,7 +876,14 @@ fn a_turn_without_a_stream_hook_sends_stream_false() { // ---- Cancelling a streamed turn (ADR-0050) ---- -/// The slowest acceptable cancellation. The request deadline is 30 seconds. +/// The slowest acceptable cancellation, timed from the moment the token is +/// cancelled until the turn or compaction returns. The request deadline is 30 +/// seconds. +/// +/// The interval starts at the cancel, as in the desktop cancellation tests. +/// Before it, a turn reads its settings and makes several synced journal +/// appends. Their duration depends on the host's storage, not on cancellation: +/// on a loaded Windows runner they once took 5.9 seconds. const CANCEL_BOUND: Duration = Duration::from_secs(5); /// What a streamed turn did when its token was cancelled by the first piece. @@ -884,7 +891,8 @@ struct CancelledTurn { error: omgcode_app::AppError, log: Vec, handed: usize, - elapsed: Duration, + /// From the stream hook's cancel until the turn returned. + after_cancel: Duration, served: usize, has_active_turn: bool, events: Vec, @@ -903,6 +911,7 @@ fn cancel_after_the_first_piece(tools_enabled: bool) -> CancelledTurn { common::sse_text(&["second-piece "]), )]); let slot: RefCell> = RefCell::new(None); + let cancelled_at: Cell> = Cell::new(None); let mut handed = 0_usize; let mut log = Vec::new(); let mut on_cancel_token = |token: CancelToken| { @@ -914,12 +923,15 @@ fn cancel_after_the_first_piece(tools_enabled: bool) -> CancelledTurn { ChatStreamEvent::Text(text) => { log.push(format!("text:{text}")); if let Some(token) = slot.borrow().as_ref() { + // The first cancel starts the measured interval. + if cancelled_at.get().is_none() { + cancelled_at.set(Some(Instant::now())); + } token.cancel(); } } }; - let started = Instant::now(); let result = turn( &mut journal, &fixture.data, @@ -932,7 +944,12 @@ fn cancel_after_the_first_piece(tools_enabled: bool) -> CancelledTurn { on_stream: Some(&mut on_stream), }, ); - let elapsed = started.elapsed(); + let returned = Instant::now(); + let after_cancel = returned.saturating_duration_since( + cancelled_at + .get() + .expect("the stream hook cancelled the turn's token"), + ); // Let the server finish; it never saw the rest of its body read. drop(release); let served = server.finish(); @@ -941,7 +958,7 @@ fn cancel_after_the_first_piece(tools_enabled: bool) -> CancelledTurn { error: result.expect_err("the cancelled turn fails"), log, handed, - elapsed, + after_cancel, served, has_active_turn, events: close_and_read(journal), @@ -968,9 +985,9 @@ fn a_streamed_text_turn_cancelled_mid_stream_is_recorded_as_cancelled() { assert_eq!(ended.handed, 1); assert_eq!(ended.log, ["request_started", "text:one "]); assert!( - ended.elapsed < CANCEL_BOUND, + ended.after_cancel < CANCEL_BOUND, "cancellation took {:?}", - ended.elapsed + ended.after_cancel ); // And the journal holds a cancelled failure, no reply, and no open turn. @@ -996,9 +1013,9 @@ fn a_streamed_tool_turn_cancelled_in_its_first_request_runs_no_tool() { assert_eq!(ended.log, ["request_started", "text:one "]); assert_eq!(ended.served, 1); assert!( - ended.elapsed < CANCEL_BOUND, + ended.after_cancel < CANCEL_BOUND, "cancellation took {:?}", - ended.elapsed + ended.after_cancel ); assert_eq!( last_failure_code(&ended.events).as_deref(), @@ -1110,7 +1127,8 @@ fn a_cancel_seen_only_after_the_reply_arrived_still_ends_the_turn_as_cancelled() /// reply of its first request. struct HeldTurn { error: omgcode_app::AppError, - elapsed: Duration, + /// From the helper thread's cancel until the turn returned. + after_cancel: Duration, served: usize, has_active_turn: bool, events_before: usize, @@ -1142,10 +1160,11 @@ fn cancel_while_a_reply_is_held( let cancel = cancel.clone(); thread::spawn(move || { common::wait_arrived(&arrival); + let cancelled_at = Instant::now(); cancel.cancel(); + cancelled_at }) }; - let started = Instant::now(); let result = turn( &mut journal, &fixture.data, @@ -1158,15 +1177,16 @@ fn cancel_while_a_reply_is_held( on_stream: None, }, ); - let elapsed = started.elapsed(); - canceller.join().expect("canceller thread"); + let returned = Instant::now(); + let cancelled_at = canceller.join().expect("canceller thread"); + let after_cancel = returned.saturating_duration_since(cancelled_at); // Let the server finish; its held reply finds the connection closed. drop(release); let served = server.finish(); let has_active_turn = journal.snapshot().active_turn.is_some(); HeldTurn { error: result.expect_err("the cancelled turn fails"), - elapsed, + after_cancel, served, has_active_turn, events_before, @@ -1185,9 +1205,9 @@ fn a_non_streamed_text_turn_cancelled_while_waiting_is_recorded_as_cancelled() { assert_eq!(ended.error.code(), "cancelled"); assert_eq!(ended.error.message(), "turn was cancelled"); assert!( - ended.elapsed < CANCEL_BOUND, + ended.after_cancel < CANCEL_BOUND, "cancellation took {:?}", - ended.elapsed + ended.after_cancel ); assert_eq!(ended.served, 1); assert_eq!( @@ -1209,9 +1229,9 @@ fn a_non_streamed_tool_turn_cancelled_while_waiting_runs_no_tool() { assert_eq!(ended.error.code(), "cancelled"); assert_eq!(ended.error.message(), "turn was cancelled"); assert!( - ended.elapsed < CANCEL_BOUND, + ended.after_cancel < CANCEL_BOUND, "cancellation took {:?}", - ended.elapsed + ended.after_cancel ); assert_eq!( last_failure_code(&ended.events).as_deref(), @@ -1265,9 +1285,9 @@ fn cancelling_the_compaction_before_a_turn_records_nothing() { "Compaction was cancelled; nothing was recorded" ); assert!( - ended.elapsed < CANCEL_BOUND, + ended.after_cancel < CANCEL_BOUND, "cancellation took {:?}", - ended.elapsed + ended.after_cancel ); assert_eq!(ended.served, 1); assert!(!ended.has_active_turn); @@ -1344,12 +1364,13 @@ fn a_cancelled_compaction_through_the_command_path_records_nothing() { let cancel = cancel.clone(); thread::spawn(move || { common::wait_arrived(&arrival); + let cancelled_at = Instant::now(); cancel.cancel(); + cancelled_at }) }; // When the token is cancelled while the summarizer request waits. - let started = Instant::now(); let error = compact_journal( &mut journal, &fixture.data, @@ -1363,14 +1384,18 @@ fn a_cancelled_compaction_through_the_command_path_records_nothing() { &cancel, ) .expect_err("the cancelled compaction fails"); - let elapsed = started.elapsed(); - canceller.join().expect("canceller thread"); + let returned = Instant::now(); + let cancelled_at = canceller.join().expect("canceller thread"); + let after_cancel = returned.saturating_duration_since(cancelled_at); drop(release); server.finish(); // Then it is cancelled promptly and no compaction was recorded. assert_eq!(error.code(), "cancelled"); - assert!(elapsed < CANCEL_BOUND, "cancellation took {elapsed:?}"); + assert!( + after_cancel < CANCEL_BOUND, + "cancellation took {after_cancel:?}" + ); assert!(journal.snapshot().compaction.is_none()); assert!( close_and_read(journal) diff --git a/docs/provider-authentication.md b/docs/provider-authentication.md index 295ed08..fb11393 100644 --- a/docs/provider-authentication.md +++ b/docs/provider-authentication.md @@ -441,7 +441,11 @@ applies the cancel rule above to every request. - **Still not interruptible.** A read, list, or edit tool call already in progress. A command tool call is cancelled through its run. - **Limits.** Checked against local fixtures only. No live LM Studio server - was used, and the CLI interrupt was delivered by a test only on Linux. + was used, and the CLI interrupt was delivered by a test only on Linux. The + fixtures bound the time from the cancel until the turn or compaction + returns, recording included, at five seconds. They do not bound the work + before the cancel: reading settings and the synced journal appends depend + on the host's storage. LM Studio documents the request fields in [Chat Completions](https://lmstudio.ai/docs/developer/openai-compat/chat-completions) diff --git a/docs/testing-standards.md b/docs/testing-standards.md index ed4e4bf..655e153 100644 --- a/docs/testing-standards.md +++ b/docs/testing-standards.md @@ -225,7 +225,11 @@ and tool turns, of the compaction before a turn, and of `compact_journal`; a token set before a turn; the desktop cancel of a non-streamed turn and the shutdown grace with a turn held in an event sink; and, on Linux only, `SIGINT` delivered to the CLI during `chat` and `session compact`. The platform -interrupt test also covers `watch_interrupt`. The adapter requires the +interrupt test also covers `watch_interrupt`. Each cancellation test, in the +turn tests as in the desktop tests, times the interval from the cancel to the +return or the `finished` event against a five-second bound. Work before the +cancel, such as synced journal appends, is not timed: a slow Windows runner +once spent 5.9 seconds there. The adapter requires the compiled base prompt and accepts only a literal loopback HTTP endpoint. The adapter is not a permission boundary: the CLI selects tool mode from the live `model_tools` preference, and the runtime rechecks that preference before each From e61beec2d8751259c3b67f397749d0556bb220e3 Mon Sep 17 00:00:00 2001 From: James Chapman Date: Tue, 17 Nov 2026 16:41:29 +0000 Subject: [PATCH 2/4] docs: count six chat-turn cancellation tests, not five Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a412406..76c6cd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -888,7 +888,7 @@ Changes are recorded here before a release version is assigned. ### Fixed -- The five cancellation tests in `crates/omgcode-app/tests/chat_turn.rs` now +- The six cancellation tests in `crates/omgcode-app/tests/chat_turn.rs` now time the interval from the moment the token is cancelled until the turn or compaction returns, as the desktop cancellation tests already did. They timed the whole turn, which also covers reading settings and the synced From 633c34fbf2bd2fc7f19008a8d66bde7155ae6821 Mon Sep 17 00:00:00 2001 From: James Chapman Date: Tue, 17 Nov 2026 16:51:39 +0000 Subject: [PATCH 3/4] docs: name the timed cancellation tests instead of claiming all are timed Co-Authored-By: Claude Opus 5.5 --- docs/testing-standards.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/testing-standards.md b/docs/testing-standards.md index 655e153..be68d4e 100644 --- a/docs/testing-standards.md +++ b/docs/testing-standards.md @@ -225,11 +225,13 @@ and tool turns, of the compaction before a turn, and of `compact_journal`; a token set before a turn; the desktop cancel of a non-streamed turn and the shutdown grace with a turn held in an event sink; and, on Linux only, `SIGINT` delivered to the CLI during `chat` and `session compact`. The platform -interrupt test also covers `watch_interrupt`. Each cancellation test, in the -turn tests as in the desktop tests, times the interval from the cancel to the -return or the `finished` event against a five-second bound. Work before the -cancel, such as synced journal appends, is not timed: a slow Windows runner -once spent 5.9 seconds there. The adapter requires the +interrupt test also covers `watch_interrupt`. The timed cancellation tests +start the clock at the cancel or shutdown request and require the turn or +compaction to end within five seconds: six tests in `chat_turn.rs`, the +desktop non-streamed cancel in `desktop_chat.rs`, and the streamed cancel and +shutdown in `desktop_events.rs`. The other cancellation tests are not timed. +Work before the cancel, such as synced journal appends, is never timed: a slow +Windows runner once spent 5.9 seconds there. The adapter requires the compiled base prompt and accepts only a literal loopback HTTP endpoint. The adapter is not a permission boundary: the CLI selects tool mode from the live `model_tools` preference, and the runtime rechecks that preference before each From ce2fa7e4dc719912eb16bdeebde5c1cfea4363be Mon Sep 17 00:00:00 2001 From: James Chapman Date: Tue, 17 Nov 2026 16:59:00 +0000 Subject: [PATCH 4/4] docs: limit the cancellation timing statement to the omgcode-app tests Co-Authored-By: Claude Opus 5.5 --- docs/testing-standards.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/testing-standards.md b/docs/testing-standards.md index be68d4e..96cd1a1 100644 --- a/docs/testing-standards.md +++ b/docs/testing-standards.md @@ -225,13 +225,15 @@ and tool turns, of the compaction before a turn, and of `compact_journal`; a token set before a turn; the desktop cancel of a non-streamed turn and the shutdown grace with a turn held in an event sink; and, on Linux only, `SIGINT` delivered to the CLI during `chat` and `session compact`. The platform -interrupt test also covers `watch_interrupt`. The timed cancellation tests -start the clock at the cancel or shutdown request and require the turn or -compaction to end within five seconds: six tests in `chat_turn.rs`, the -desktop non-streamed cancel in `desktop_chat.rs`, and the streamed cancel and -shutdown in `desktop_events.rs`. The other cancellation tests are not timed. -Work before the cancel, such as synced journal appends, is never timed: a slow -Windows runner once spent 5.9 seconds there. The adapter requires the +interrupt test also covers `watch_interrupt`. In `omgcode-app`, these turn and +desktop tests start the clock at the cancel or shutdown request and require +the turn or compaction to end within five seconds: six tests in +`chat_turn.rs`, the non-streamed cancel in `desktop_chat.rs`, and the streamed +cancel and shutdown in `desktop_events.rs`. The other `omgcode-app` +cancellation tests are not timed, and the `omgcode-core` adapter tests keep +their own bounds. In the listed tests, work before the cancel, such as synced +journal appends, is not timed: a slow Windows runner once spent 5.9 seconds +there. The adapter requires the compiled base prompt and accepts only a literal loopback HTTP endpoint. The adapter is not a permission boundary: the CLI selects tool mode from the live `model_tools` preference, and the runtime rechecks that preference before each