Every tracked file that can carry a comment (880 of them) now opens with "Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with "Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com", in the file's own comment syntax. No behaviour change: the diff outside the version bump and changelogs is comment lines only. - tools/stamp_author.py: writes the lines; idempotent, `--check` lists what is missing. Headers go under a shebang and under Markdown front matter. - Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the LICENSE files (already carry the copyright line). - tools/linux_check.sh: --help reads its header from line 3, now that the author line sits under the shebang. - tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
549 lines
32 KiB
Markdown
549 lines
32 KiB
Markdown
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
|
|
|
# cancel-request
|
|
|
|
## Goal
|
|
|
|
`$/cancelRequest` is the client's way of saying "drop that one, the user has
|
|
moved on" — sent constantly by real editors, which cancel the completion,
|
|
hover and inlay-hint requests of the previous keystroke on every new one.
|
|
Until now the notification fell through `Server::notification`'s `_ => {}` arm
|
|
and the request was computed and answered anyway. This round answers a
|
|
cancelled request with the protocol's own `RequestCancelled` (-32800) instead
|
|
of computing it, whenever the cancel reaches the loop in time — which, on a
|
|
single-threaded server, means *while the request is still queued*. The gain is
|
|
not correctness (an ignored cancel is legal) but work not done: on a slow
|
|
rescan or a large-file format, the queue behind the busy handler is exactly
|
|
where a stale completion request sits, and answering it costs nothing (TODO.md
|
|
§9b, the last item of that section).
|
|
|
|
## What "in time" can mean on a one-message-at-a-time loop
|
|
|
|
Everything about this feature follows from one fact: **the client sends the
|
|
request and its cancel down one ordered channel**, and the server handles one
|
|
message at a time. Read strictly one message per iteration, a cancel is always
|
|
too late — by the time `C(R)` is dequeued, `R` was dequeued, computed and
|
|
answered an iteration ago. Cancellation only becomes reachable when the loop
|
|
looks at *more than one message at a time*: while a handler runs, the client
|
|
keeps sending, so the backlog waiting behind it can hold `[R1, C(R1), R2]` —
|
|
and R1 can be answered `RequestCancelled` for free.
|
|
|
|
So `run()` now works in bursts:
|
|
|
|
1. block for the next message, as before;
|
|
2. take everything already queued behind it, without blocking, into one FIFO
|
|
(the blocked-for message first);
|
|
3. scan that whole burst for `$/cancelRequest` notifications and collect the
|
|
ids that name a request **in the same burst**;
|
|
4. handle the burst strictly in arrival order — a cancelled request answered
|
|
`RequestCancelled` without dispatch, every other message exactly as before.
|
|
|
|
Step 3 is what keeps the cancelled set from being state: it is built per burst
|
|
and dropped with it.
|
|
|
|
### The transport does not queue — so we do
|
|
|
|
The first attempt used `connection.receiver.try_recv()` for step 2 and
|
|
cancelled **nothing** over a real pipe. The reason is worth writing down,
|
|
because it is invisible from the API:
|
|
|
|
> `lsp-server` 0.10's stdio transport wires its reader, writer and dropper
|
|
> threads with **`crossbeam_channel::bounded(0)`** — rendezvous channels with
|
|
> no capacity at all (`stdio.rs`). Its reader thread parks *inside* `send`
|
|
> holding one message until the loop takes it. A client's backlog therefore
|
|
> never sits on `connection.receiver`: it sits in the OS pipe, one message
|
|
> deep from where we stand, and `try_recv` right after a `recv` loses a
|
|
> microsecond-scale race with the reader thread essentially every time.
|
|
|
|
`Server::queue()` fixes this with the smallest thing that can: one forwarder
|
|
thread that blocks on `connection.receiver` and pushes onto an unbounded
|
|
`std::sync::mpsc` queue that `run()` owns. The backlog then accumulates where
|
|
we can see it, and step 2 is a plain `try_recv` loop. The thread touches no
|
|
server state, moves messages and nothing else, and is std-only — no new
|
|
dependency.
|
|
|
|
The forwarder **stops at the `shutdown` request and never reads past it**.
|
|
`Connection::handle_shutdown` answers the request and then reads the `exit`
|
|
notification off the *connection* itself; a forwarder that kept going would
|
|
take that `exit` first, and `handle_shutdown` would block for its full
|
|
thirty-second timeout and then return a protocol error. Stopping there also
|
|
means nothing after a shutdown is ever queued, which is exactly the protocol's
|
|
own rule.
|
|
|
|
## Assumptions
|
|
|
|
- **Cancellation is best-effort, and the spec says so.** LSP allows a server
|
|
to ignore a cancel it cannot honour; the only hard requirement is that every
|
|
request gets exactly one response. Both are held here: a cancel that misses
|
|
its window leaves the request answered normally.
|
|
- **A cancel arriving in a *later* burst than its request is dropped.** By
|
|
then the request has been answered — there is nothing left to cancel, and
|
|
remembering the id would be a set that grows for the life of the session.
|
|
This is the single rule that keeps this feature stateless.
|
|
- **A cancel in the same burst but dequeued *before* its request still
|
|
cancels it.** The burst is scanned as a whole before any of it runs, so
|
|
ordering within the burst does not matter. (A real client never sends the
|
|
cancel first; a transport is free to make it look that way.)
|
|
- **A cancel for a request the server never received is dropped** where it is
|
|
read, for the same reason.
|
|
- **Cancelling one request twice is harmless.** The id is removed from the
|
|
cancelled set as it is used, so a second cancel finds nothing — and it could
|
|
not touch a later request even if ids were reused, because the set never
|
|
outlives its burst.
|
|
- **`shutdown` is never cancellable.** `handle_shutdown` runs before the
|
|
cancelled set is consulted, so a cancel naming the shutdown id cannot stop
|
|
the server from shutting down. The spec's "a server should still answer a
|
|
cancelled request" reading is the safe one here: a client that cannot shut
|
|
its server down leaks a process.
|
|
- **Notifications are never cancelled.** They carry no id and get no
|
|
response; `$/cancelRequest` names request ids only. A `didChange` queued
|
|
ahead of a cancelled request is still applied — the state a *later* request
|
|
is answered against must not depend on which requests were dropped.
|
|
- **Order inside a burst is the invariant, not an implementation detail.**
|
|
A `didChange` the client sent before a completion request must be in effect
|
|
when that completion is answered, exactly as it would be one message at a
|
|
time. Pinned by
|
|
`a_notification_queued_ahead_of_a_request_is_applied_before_it_is_answered`.
|
|
- **Both id forms are read.** `CancelParams.id` is
|
|
`NumberOrString`; a numeric id becomes `RequestId::from(i32)` and a string
|
|
id `RequestId::from(String)`. The string `"8"` is not the number `8` —
|
|
`RequestId` keeps them apart and so does the cancel, which is the only
|
|
behaviour that can be right when a client uses both forms.
|
|
- **A cancel whose params do not parse is dropped**, on the same reasoning as
|
|
every other malformed notification: there is no id to act on and no id to
|
|
answer on.
|
|
- **The cancelled response carries a message.** `-32800` plus
|
|
`"lucisv: request cancelled by the client"`. Clients do not show it — the
|
|
code is what they read — but a log with the text in it is easier to read
|
|
than a log with a number in it.
|
|
- **Nothing already *running* is cancelled.** There is one thread; a format,
|
|
a rescan or a rename that has started runs to completion. The work-done
|
|
progress bar still advertises `cancellable: false`, which stays true.
|
|
- **The queue is unbounded.** Backpressure on the pipe used to be the reader
|
|
thread's rendezvous; now a burst is buffered in memory instead. For an LSP
|
|
client that is bounded by what an editor sends between two of our handler
|
|
calls — kilobytes. A client that floods a server faster than it can read
|
|
would grow this queue, and would equally have grown the pipe before.
|
|
|
|
## Handshakes
|
|
|
|
### `lucisv_server::server` (this feature's own module)
|
|
|
|
- `Server::run` no longer receives-and-dispatches inline. It builds the queue,
|
|
blocks on it, and hands each burst to `process_batch`. Behaviour for a
|
|
client that never cancels is identical, message for message.
|
|
- **New private items:** `Server::queue()` (the forwarder),
|
|
`Server::process_batch(Vec<Message>) -> Result<bool, …>` (the burst
|
|
handler; `true` means the client shut us down), and the free functions
|
|
`burst`, `is_shutdown`, `cancelled_in`, `cancelled_id`, `cancelled_response`.
|
|
- `Server::request`, `Server::notification` and `Server::response` are
|
|
**unchanged**. `$/cancelRequest` never reaches `notification()`; it is
|
|
consumed in the burst handler, which is the only place that can act on one.
|
|
- No field was added to `Server`. Cancellation state lives for the length of
|
|
one burst and no longer.
|
|
|
|
### `lsp-server`
|
|
|
|
- Consumed, not changed: `Connection.receiver` is now `clone()`d (crossbeam
|
|
receivers are `Clone`), and `handle_shutdown` is called exactly where it was
|
|
— the forwarder's stop rule is what keeps its `exit` read working.
|
|
- The rendezvous-channel finding above is a property of version `=0.10.0`,
|
|
which the workspace pins. A future bump should re-read `stdio.rs`: if the
|
|
transport ever queues, `Server::queue` becomes redundant rather than wrong.
|
|
|
|
### Every other crate, and `editors/vscode`
|
|
|
|
**Untouched.** No engine crate knows this happened, and no client capability
|
|
gates it — `$/cancelRequest` is unconditional in the protocol, advertised by
|
|
nobody and sent by everybody. `smoke.js` passes unchanged (run as a gate).
|
|
|
|
## Status / TODO
|
|
|
|
- [x] `run()` restructured into blocking receive → burst drain → burst handler
|
|
- [x] Forwarder thread so the backlog is observable at all (the rendezvous
|
|
finding), stopping at `shutdown` so `handle_shutdown` keeps its `exit`
|
|
- [x] Cancelled ids collected per burst, matched against that burst's own
|
|
requests, dropped otherwise
|
|
- [x] Cancelled requests answered `-32800` without dispatch; the cancels
|
|
themselves consumed
|
|
- [x] `shutdown` honoured before any cancel is consulted
|
|
- [x] Arrival order preserved across the whole burst (notifications included)
|
|
- [x] Numeric and string cancel ids; malformed cancels dropped
|
|
- [x] Tests: 10 unit in `server.rs` (through the `Session` harness, driving
|
|
the real `process_batch`), 1 e2e over the wire
|
|
- [x] TODO.md §9b checkbox; loop description in
|
|
`docs/features/lucisv-server/README.md`
|
|
- [ ] **Not done, deliberately:** no cancellation of work in flight. That
|
|
needs a worker pool and cancellation tokens threaded through the engine
|
|
— TODO.md §6's explicit non-goal for as long as per-file recompute stays
|
|
in the millisecond range.
|
|
- [ ] **Not done, deliberately:** no `ContentModified` (-32801) for requests
|
|
invalidated by a `didChange` queued behind them. It is the neighbouring
|
|
idea and a real option now that the loop can see a burst, but the spec
|
|
warns that an answer computed against slightly older text is usually
|
|
still useful — and the client, not the server, is the one that knows.
|
|
Filed here, not built.
|
|
|
|
## Work log
|
|
|
|
### 2026-08-26 — dev agent (§9b, `$/cancelRequest`)
|
|
|
|
- Read `CLAUDE.md`, `docs/features/lucisv-server/README.md`, TODO.md §9b and
|
|
the whole of `server.rs`'s loop before touching anything.
|
|
- **Verified the lead's design against the code, and found one thing that
|
|
invalidated its second step.** The plan said to drain `connection.receiver`
|
|
non-blockingly with `try_iter`/`try_recv`. Written that way, the e2e flood
|
|
cancelled **zero** of five requests, reproducibly. `lsp-server` 0.10's
|
|
`stdio.rs` uses `bounded(0)` rendezvous channels throughout: there is no
|
|
queue on that receiver to drain, ever. The rest of the design — burst FIFO,
|
|
batch-wide cancel scan, drop-if-not-in-batch, order preserved, shutdown
|
|
never cancellable — is unchanged and implemented as written.
|
|
- **Fix: one forwarder thread** (`Server::queue`) onto a `std::sync::mpsc`
|
|
queue, so the backlog accumulates somewhere observable. Std-only, no new
|
|
dependency, no shared state, ~12 lines. Considered and rejected: a timed
|
|
drain window (`recv_timeout(1ms)`), which would tax *every* message with a
|
|
millisecond of latency and still be a race; and handling shutdown ourselves
|
|
to free the forwarder, which would duplicate `handle_shutdown`'s protocol
|
|
for no gain.
|
|
- **The forwarder's stop-at-shutdown rule was found by reading
|
|
`handle_shutdown`, not by a failing test**: it reads `exit` off the
|
|
connection itself, so an eager forwarder would have stolen it and turned
|
|
every shutdown into a 30-second timeout followed by a protocol error. The
|
|
rule is asserted by `a_shutdown_is_honoured_however_it_is_cancelled` and by
|
|
the e2e session, which shuts down through the same flood.
|
|
- Tests: 10 unit tests in `server.rs`, driving the real `process_batch`
|
|
through a new `Session::batch` helper (the harness otherwise bypasses the
|
|
loop entirely), plus `Session::answers()` for reading responses off the
|
|
client end. One e2e test running the real binary and the real `run()`.
|
|
- **The e2e test asserts what is deterministic, and says why.** Three
|
|
iterations were needed to get there: with cheap requests, *how many* cancels
|
|
land in the same burst as their request is a scheduling race, and demanding
|
|
all five failed roughly one full-suite run in four (the suite runs 38
|
|
server processes in parallel). The final shape floods twenty
|
|
`textDocument/formatting` requests over a 300-line buffer — enough work per
|
|
message that the forwarder is never starved — and asserts the properties
|
|
that must hold on any schedule: exactly one response per request, `-32800`
|
|
only ever on an id the client actually cancelled, a correct formatted answer
|
|
on every other id, at least one honoured cancel (the wire path works), and
|
|
a clean shutdown. Measured under a deliberate 24-way overload: worst case
|
|
two of five honoured, never zero.
|
|
- Also corrected two now-stale comments about cancellation being absent
|
|
entirely — the module header of `server.rs`, `begin_indexing`'s note on
|
|
`cancellable: false`, and the matching line in the progress e2e test. The
|
|
bar's `false` stays correct: what has *started* still runs to completion.
|
|
- Gates, all clean: `cargo fmt --all -- --check`, `cargo clippy --all-targets`
|
|
(no warnings), `cargo test --workspace` (34 suites green; `lucisv_server`
|
|
702 unit + 38 e2e), `cargo build && node editors/vscode/smoke.js
|
|
target/debug/lucisv-server` → OK. The e2e suite was re-run ten consecutive
|
|
times looking for flake: ten passes.
|
|
|
|
## QA log
|
|
|
|
### 2026-08-26 — QA agent (§9b, `$/cancelRequest`)
|
|
|
|
**Verdict: committable as-is.** No corruption, no protocol violation, no
|
|
reproducible flake found. Four gaps in test coverage for the highest-risk
|
|
part of the change (the forwarder thread) were found and closed directly;
|
|
one theoretical (not reproduced) flake risk in the e2e flood is recorded
|
|
below with a reasoned trade-off, not "fixed," because the fixes available
|
|
would weaken the property the test exists to prove.
|
|
|
|
**Gates.** `cargo fmt --all -- --check` clean. `cargo clippy --all-targets`
|
|
clean, no warnings. `cargo test --workspace`: every suite green, including
|
|
`lucisv_server` at 706 unit (was 702 pre-QA; +4 added below) + 38 e2e.
|
|
`cargo build && node editors/vscode/smoke.js target/debug/lucisv-server` →
|
|
OK. `cargo test -p lucisv_server --test e2e` run five more times standalone,
|
|
before the QA-added tests and five more times after: **10/10 green**, no
|
|
flake observed in the flood test or anywhere else in the suite.
|
|
|
|
**1. Forwarder shutdown hand-off — verified clean, by reading
|
|
`lsp-server` 0.10's actual source, not the dev's summary.**
|
|
|
|
- Read `~/.cargo/registry/.../lsp-server-0.10.0/src/stdio.rs`,
|
|
`src/lib.rs` (`Connection::handle_shutdown`, `Connection::memory`) and
|
|
`src/msg.rs` (`Request::is_shutdown`, `Notification::is_exit`,
|
|
`Response`'s `#[serde(flatten)]` encoding). Confirms the README's claim:
|
|
the stdio reader thread parks inside a `bounded(0)` `send` until taken,
|
|
so a client's backlog really does live in the OS pipe and not on
|
|
`connection.receiver`.
|
|
- (a) **Method-name detection, and the notification case.** `is_shutdown`
|
|
(`crates/lucisv_server/src/server.rs:1119`) matches
|
|
`Message::Request { method == "shutdown" }` only — the same test
|
|
`lsp-server`'s own `Request::is_shutdown` (msg.rs:233) uses. A
|
|
**notification** shaped like `{"method":"shutdown"}` fails the match
|
|
(wrong enum variant), so the forwarder does not stop for it; it is
|
|
forwarded like any other message and falls through `notification()`'s
|
|
`_ => {}` arm, doing nothing. This was asserted by nothing before QA —
|
|
added `is_shutdown_matches_only_the_shutdown_request_never_a_notification_of_the_same_name`
|
|
(server.rs:3574). A malformed shutdown-*request* (e.g. non-null params)
|
|
is not a distinct case: neither `is_shutdown` nor `handle_shutdown`
|
|
parses params, only the method name, so there is nothing to be
|
|
malformed.
|
|
- (b) **The stolen-message / deadlock window.** Traced the forwarder
|
|
(`Server::queue`, server.rs:209-233): it checks `is_shutdown` on the
|
|
message **after** receiving it but **before** issuing its next `recv()`,
|
|
and breaks its loop without calling `recv()` again when that check is
|
|
true. `handle_shutdown` (lsp-server lib.rs:348) is only reached by
|
|
`process_batch` for a request already sitting in the batch Vec — i.e.
|
|
after the forwarder that produced it has already returned from its last
|
|
`sender.send`. Because the forwarder's own break happens strictly before
|
|
any further receive, there is no window where both the forwarder and
|
|
`handle_shutdown` are calling `recv`/`recv_timeout` on the same
|
|
crossbeam channel at once — no steal, no deadlock. Added
|
|
`the_forwarder_stops_at_shutdown_and_leaves_what_follows_for_handle_shutdown`
|
|
(server.rs:3632), which sends a real shutdown request + exit notification
|
|
through a `Connection::memory()` pair, calls the real `Server::queue()`,
|
|
and asserts (i) the shutdown is the last thing the forwarder ever
|
|
forwards even after 50ms of extra opportunity to misbehave, and (ii) the
|
|
`exit` is still sitting, unread, directly on `connection.receiver` —
|
|
exactly where `handle_shutdown` looks for it. This is the one test in
|
|
the whole suite that exercises the real `queue()` method without going
|
|
through a subprocess.
|
|
- (c) **Messages already forwarded ahead of a shutdown in the same
|
|
batch.** Because the forwarder always stops immediately after
|
|
forwarding the message it detects as shutdown, shutdown is provably
|
|
always the *last* message that forwarder instance ever produces — there
|
|
is no way for a message to be forwarded *after* shutdown by the same
|
|
producer, and there is only ever one producer (next point). So the
|
|
scenario "a request forwarded after shutdown gets silently dropped" is
|
|
not reachable through this code path. Nothing found here; the design
|
|
note in the feature README (lines 63-69) undersells this a little by
|
|
only mentioning the *thirty-second timeout* consequence of an eager
|
|
forwarder — the actual structural guarantee (shutdown is always last)
|
|
is worth knowing but the doc isn't wrong, just less complete than it
|
|
could be. Not fixed (doc-only, not a code finding, and rewriting
|
|
someone else's README section is not QA's job per CLAUDE.md).
|
|
|
|
**2. Message loss/reordering — verified clean.**
|
|
|
|
- Exactly one producer: `Server::queue` is called exactly once, from
|
|
`Server::run` (server.rs:185), which is itself called exactly once, from
|
|
`main.rs:76`. No respawn path exists.
|
|
- Single channel used throughout: `run`'s blocking head-of-burst read and
|
|
`burst`'s non-blocking drain (server.rs:1126) both operate on the same
|
|
`std::sync::mpsc::Receiver` returned by `queue()` — never a mix of the
|
|
mpsc and `connection.receiver` on the consuming side. (`connection.receiver`
|
|
itself is only ever touched by the forwarder's `source` handle and by
|
|
`handle_shutdown`, never by `run`/`burst`/`process_batch`.)
|
|
- Exactly-once processing: `burst` pushes the blocking-received `first`
|
|
plus everything `try_recv` drains, with no filtering or dedup step in
|
|
between — the FIFO in equals the FIFO out. Added
|
|
`burst_collects_everything_already_queued_in_arrival_order`
|
|
(server.rs:3602) directly against a fresh
|
|
`std::sync::mpsc` channel (no `Server` involved), pinning arrival order
|
|
for `[first, second, third]`. Previously `burst` had zero direct test
|
|
coverage — every existing cancel test drives `process_batch` through
|
|
`Session::batch`, bypassing `burst` entirely, so this was a real gap in
|
|
a change the assignment calls "the highest-risk this repo's server has
|
|
taken."
|
|
|
|
**3. `exit` handling / zombie-thread check — verified clean.**
|
|
|
|
- `talk()` (e2e.rs:66-79) and the progress-e2e session's own `finish()`
|
|
(e2e.rs:1978-1985) both call `child.wait()` and assert
|
|
`status.success()` — a hung forwarder or a process that doesn't
|
|
terminate would hang or fail these, and none did across 10 e2e runs.
|
|
This is a real check, not a rubber stamp: `child.wait()` blocks until
|
|
the OS reports the process gone, so a genuinely undead forwarder thread
|
|
(blocked on stdin, holding the process open) would show up as a test
|
|
timeout, not a silent pass.
|
|
- The forwarder thread is detached (`let _ = ... .spawn(...)`), never
|
|
joined. This is fine for process exit: after `shutdown`+`exit`, the
|
|
forwarder has *already* stopped itself (point 1b) well before `run()`
|
|
returns, so by the time `main()` returns there is no thread left
|
|
blocked on I/O that could hold the process open. In the one edge case
|
|
where a client disconnects without ever sending `shutdown` (broken
|
|
pipe), the forwarder's own `source.recv()` errors, it drops its `sender`
|
|
and exits, closing the mpsc and unblocking `run()`'s own `recv()` the
|
|
same way `self.connection.receiver.recv()` used to unblock pre-diff —
|
|
behaviorally identical to the old direct-receive loop for that case.
|
|
Not a new finding; equivalent to prior behavior.
|
|
|
|
**4. Cancellation semantics matrix — re-verified independently, assertions
|
|
read (not just names), all pass; one gap closed.**
|
|
|
|
Read every assertion, not just the test name, for: same-burst
|
|
cancel-after (`a_request_cancelled_in_the_same_burst_is_answered_cancelled`),
|
|
cancel-before (`a_cancel_dequeued_before_its_request_still_cancels_it`),
|
|
partial-batch cancel (`a_cancel_names_one_request_and_leaves_the_rest_of_the_burst_alone`),
|
|
orphan/late drop with the id-reuse proof
|
|
(`a_cancel_for_a_request_that_is_not_in_the_burst_is_dropped_on_the_spot`),
|
|
notification-ordering
|
|
(`a_notification_queued_ahead_of_a_request_is_applied_before_it_is_answered`),
|
|
notifications-uncancellable (`a_cancel_never_cancels_a_notification`),
|
|
shutdown-uncancellable (`a_shutdown_is_honoured_however_it_is_cancelled`),
|
|
double cancel (`cancelling_one_request_twice_answers_it_once`), int-vs-string
|
|
ids including the `"8"` vs `8` case (`a_cancel_id_may_be_a_number_or_a_string`),
|
|
and malformed params (`a_malformed_cancel_is_dropped_rather_than_guessed_at`).
|
|
Every one asserts what its name claims; none was a false-positive
|
|
(no-op) test. All pass, independently re-run.
|
|
|
|
**Gap found and closed:** no test covered a cancel naming a
|
|
**server-initiated** id (the `lucisv-0`/`lucisv-index-N`/`lucisv-watched-files-N`
|
|
namespace from `Server::send_request`, server.rs:949). Traced it: `cancelled_in`
|
|
(server.rs:1141) only ever matches a cancel against ids of `Message::Request`
|
|
entries *received in the same batch* — a server-initiated id only ever
|
|
appears on the wire as a `Message::Response` coming back from the client,
|
|
a different match arm in `process_batch` entirely, never consulted against
|
|
`cancelled`. So interference is not possible by construction. Added
|
|
`a_cancel_naming_a_server_initiated_id_does_not_touch_response_routing`
|
|
(server.rs:3682) to pin this rather than leave it as an inference:
|
|
it calls the real `send_request`, gets back `lucisv-0`, sends a cancel
|
|
naming it alongside an ordinary client request, asserts the client request
|
|
is untouched, and then answers the server-initiated request successfully
|
|
to prove routing was never disturbed.
|
|
|
|
**5. `-32800` on the wire — verified, one assertion added.**
|
|
|
|
`cancelled_response` (server.rs:1171) uses
|
|
`lsp_server::ErrorCode::RequestCanceled as i32`, which is `-32800` in
|
|
`msg.rs:128` — matches spec. `Response`'s `#[serde(flatten, with =
|
|
"ResponseResult")]` (lsp-server msg.rs:87-98) serializes to exactly one of
|
|
`result`/`error`, never both — confirmed by reading the encoding, and by
|
|
the e2e flood's existing `answer.get("result").is_none()` on a real wire
|
|
response (e2e.rs:3141). Id-type preservation (int in → int in response) is
|
|
implicitly covered by the flood test's own matching: it filters
|
|
`messages.iter().filter(|m| m["id"] == id)` against a Rust `u32`, which
|
|
would find nothing if the id had round-tripped as a string, and the test
|
|
asserts exactly one match per id. **Gap found and closed:** nothing
|
|
asserted that the error carried a non-empty `message` string, only that
|
|
`code` was right and `result` was absent. Added that assertion in-line at
|
|
e2e.rs (next to the `result`-absence check in
|
|
`a_flood_of_requests_and_cancels_is_answered_exactly_once_each`).
|
|
|
|
**6. The e2e flood's honesty — one theoretical, unreproduced flake risk,
|
|
documented rather than "fixed."**
|
|
|
|
Read the whole test (e2e.rs:3079-3168). The `honoured > 0` assertion
|
|
(e2e.rs:3160) is the one the
|
|
task flagged as suspicious, correctly. Reasoning:
|
|
|
|
- The forwarder thread and the main loop's request handling run
|
|
concurrently on real OS threads. While the main thread is inside a
|
|
synchronous `self.request(...)` call (formatting), the forwarder can
|
|
keep draining the reader thread's rendezvous handoffs into the mpsc
|
|
queue in parallel — this concurrency, not any timer, is what makes a
|
|
multi-message burst likely.
|
|
- It is **not mathematically impossible** for every burst to end up size
|
|
1: a scheduler that always preempts the forwarder thread and lets the
|
|
main thread fully drain-and-reblock before the next message is
|
|
forwarded would produce zero cancellations, every time, for any finite
|
|
request count. No such interleaving was produced in 10 standalone e2e
|
|
runs plus one full `cargo test --workspace` run (which itself runs the
|
|
e2e binary), so it is not a *practical* risk today, but "never observed"
|
|
is exactly the "≠ impossible" the task named.
|
|
- **Why not fixed:** the two available code fixes both make the test
|
|
worse. Relaxing `honoured > 0` to `honoured >= 0` (i.e., deleting the
|
|
assertion) would stop the test from ever proving the cancellation path
|
|
works over the real wire at all — the one thing this e2e test exists to
|
|
check per its own doc comment. Adding a synchronization point (e.g. a
|
|
test-only delay hook) to force a burst would add production-code
|
|
surface *purely for a test's benefit*, which the "simplicity first"
|
|
section of `CLAUDE.md` weighs against, for a risk that is theoretical
|
|
and has a fallback: a failure here is a flake in one non-gating-by-flake
|
|
test, not a correctness bug (the request would still be answered
|
|
correctly once instead of cancelled — see point 4's stateless-drop
|
|
behavior — so no invariant breaks, only the "never zero" assertion
|
|
would).
|
|
- **Recommendation:** accept the residual risk as-is. If it is ever
|
|
observed to flake in CI, the fix is almost certainly to widen the
|
|
buffer/request count further (the dev already tuned this once, from a
|
|
~1-in-4 flake rate with cheap requests down to zero observed in 10+ runs
|
|
with 300 lines / 20 requests) rather than to touch the assertion itself.
|
|
|
|
**7. CLAUDE.md compliance — verified clean.**
|
|
|
|
- No bare `std::thread::spawn` (which panics on OS resource exhaustion).
|
|
The forwarder uses `std::thread::Builder::new().spawn(...)`
|
|
(server.rs:215), which returns `io::Result`, and the error is
|
|
deliberately discarded with `let _ =` plus a comment explaining the
|
|
fallback (the mpsc sender is dropped, so `run()`'s `recv()` fails and
|
|
the loop ends cleanly instead of hanging) — no panic path introduced.
|
|
This is in `main`-path server setup, which CLAUDE.md's "Tests and
|
|
`main.rs` argument handling may use them" carve-out does not literally
|
|
name, but the *effect* is a `Result`-returning call whose error is
|
|
handled without panicking or unwrapping — no rule is broken; there is
|
|
no `unwrap`/`expect`/`panic!` in this path at all.
|
|
- All `.expect(...)`/`.unwrap()` calls introduced by the diff (checked
|
|
with `git diff | grep`) are inside `mod tests` (`Session::batch`,
|
|
`symbol_names`, `outcomes`, and the shutdown test's `sender.send(...)`)
|
|
— allowed.
|
|
- New free functions and the new `Server` methods all carry one-line-plus
|
|
doc comments explaining what/why, consistent with the surrounding file's
|
|
density; none of the new items are `pub`, so the strict "public items"
|
|
rule doesn't even apply, but the dev exceeded it anyway.
|
|
- `docs/features/cancel-request/README.md`: each of the seven required
|
|
sections (Goal, Assumptions, Handshakes, Status/TODO, Work log, QA log,
|
|
Review) appears **exactly once** (checked with `grep -n "^## "`); one
|
|
extra explanatory section between Goal and Assumptions is additional,
|
|
not a duplicate, and the template doesn't forbid it.
|
|
- `TODO.md`: the §9b item's original text
|
|
("**`$/cancelRequest`** — the loop handles requests sequentially and
|
|
ignores cancellation; at minimum answer already-cancelled queued
|
|
requests with `RequestCancelled`.") is byte-for-byte intact; only the
|
|
checkbox flipped and a `→`-prefixed summary line was appended below it,
|
|
which is the same pattern used by the 9 other completed items already
|
|
in the file (`grep -c` confirms 10 occurrences total including this
|
|
one) — not a one-off deviation.
|
|
- `docs/features/lucisv-server/README.md` was also touched by this
|
|
change. That file is the umbrella index every feature registers itself
|
|
in (the method-dispatch table and the Status/TODO checklist both list
|
|
every other feature the same way), so this is the expected cross-file
|
|
touch the Handshakes section describes, not scope creep.
|
|
|
|
**Tests added this round (4 unit + 1 e2e assertion, all in the files
|
|
already under review, no new files):**
|
|
`is_shutdown_matches_only_the_shutdown_request_never_a_notification_of_the_same_name`,
|
|
`burst_collects_everything_already_queued_in_arrival_order`,
|
|
`the_forwarder_stops_at_shutdown_and_leaves_what_follows_for_handle_shutdown`,
|
|
`a_cancel_naming_a_server_initiated_id_does_not_touch_response_routing`
|
|
(all in `crates/lucisv_server/src/server.rs`), plus a `message`-field
|
|
assertion added to
|
|
`a_flood_of_requests_and_cancels_is_answered_exactly_once_each` in
|
|
`crates/lucisv_server/tests/e2e.rs`. `lucisv_server` unit count moved from
|
|
702 to 706; e2e stayed at 38 (one test grew an assertion, none added).
|
|
|
|
**Fixes made:** none beyond the test additions above — no corruption, no
|
|
mishandled message, no dropped request found anywhere in the diff.
|
|
|
|
## Review
|
|
|
|
### 2026-08-26 — lead
|
|
|
|
Reviewed the diff, the work log and the QA log; re-ran all gates myself
|
|
plus two extra e2e passes (flood test green in every run I and QA made —
|
|
twelve consecutive between us), clean. The dev's deviation from my brief
|
|
was the right kind: my burst-drain design assumed a queue that lsp-server's
|
|
rendezvous channels do not provide, the dev proved that over a real pipe
|
|
(0/5 honoured) before changing anything, and the forwarder it added is
|
|
the minimal honest fix — one thread, no shared state, stopping at
|
|
shutdown for a reason it can cite from lsp-server's own source. QA then
|
|
re-derived the shutdown hand-off from the vendored code rather than the
|
|
work log, which is exactly the adversarial re-check this workflow exists
|
|
for, and closed the four real gaps (the shutdown-shaped notification,
|
|
bare `burst` coverage, the forwarder hand-off under a real Connection,
|
|
and the server-id-namespace cancel).
|
|
|
|
The stateless cancelled-set design — a cancel matters only beside its
|
|
request in one burst, everything else dropped on sight — is the reason
|
|
this feature cannot leak or misfire across sessions, and shutdown
|
|
sitting before the cancel check closes the one hole a hostile client
|
|
could poke. On the flood test's `honoured > 0` assertion: QA is right
|
|
that a pathological scheduler could in principle defeat it and right not
|
|
to weaken it; the property is the point of the test, the risk is
|
|
unreproduced in twelve runs, and if CI ever trips it the QA log already
|
|
contains the analysis. This completes §9b. Accepted as shipped.
|
|
|
|
### 2026-09-08 — the deferred set (perf5r-publication, lead)
|
|
|
|
A navigation request whose answer was empty while the startup scan was
|
|
still growing is put in `Server::deferred` and asked again at the next
|
|
publish (`docs/features/perf5r-publication/README.md`). Such a request is
|
|
in no burst, so the burst's own cancel rule (`cancelled_in`) cannot see
|
|
it; `Server::cancel_deferred` honours a `$/cancelRequest` naming it where
|
|
the cancel lands — answered `RequestCancelled` at once, removed, never
|
|
asked again. Every request still gets exactly one response. Found by QA;
|
|
pinned by `a_cancel_for_a_deferred_request_answers_it_cancelled_and_forgets_it`.
|
|
|
|
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|