23 KiB
23 KiB
Server Ordering, Versioned Edits, and Startup Race Fixes (Round 1)
Goal
Close four ordering and protocol-soundness bugs identified in docs/topo.md (#53, #52, #61, #62):
- Topo #53 (Startup scan race for workspace-wide mutating requests): Hold
textDocument/rename,codeAction/resolve,workspace/executeCommand, andworkspace/willRenameFilesuntil an active background scan (self.scanning == true) finishes completely rather than letting them run mid-scan oncehead_owedclears, while preserving read-onlysame_filefast-action early answers and avoiding O(N) re-drain spinning across scan publishes. - Topo #52 (Versioned
DocumentChangesedits): Track client-announcedi32buffer versions acrossdidOpen,didChange, dirty flushes,didSave,didClose, and large-file reclassification; detectworkspace.workspaceEdit.documentChangesinClientAbilities; and emit deterministic, sortedDocumentChanges::Edits(OptionalVersionedTextDocumentIdentifier { uri, version }) inrename.rsandports.rs, falling back toWorkspaceEdit { changes: Some(...), .. }when unsupported or when no edited buffer carries a version. - Topo #61 (Stale
didChangeConfigurationreplay during staging): Whentake_the_answer_out_of_heldplucks a pulledPending::Configurationresponse during startup staging, drop any olderworkspace/didChangeConfigurationnotifications sitting earlier inself.heldso they cannot replay after staging ends and overwrite newer pulled settings, while retaining any pushes that arrived after the pull response. - Topo #62 (Exact state-index oracle in
fast_actions_bursts): Record the server's exactapplied_changescounter wheneveranswered_aheademits an early response and assert infast_actions_bursts.rsbothapplied >= required(no skipped affecting state change) ande == reference_at[applied]against the single-message reference stream.
Assumptions
- Read-only requests exempted via
same_file/viewport(answer_from_the_buffer) remain eligible mid-scan whenever their own preconditions hold; only whole-workspace mutating requests (textDocument/rename,codeAction/resolve,workspace/executeCommand,workspace/willRenameFiles) must wait forself.scanning == false. - Unopened on-disk files touched alongside an open versioned buffer in
DocumentChanges::EditscarryOptionalVersionedTextDocumentIdentifier { uri, version: None }, matching LSP 3.16+ semantics (and existingextract.rsconventions). When no edited file has an attached version (for instance, direct workspace unit tests or closed-file commands) or whendocument_changescapability is false,WorkspaceEdit::new(changes)is used.
Handshakes
crates/lucisv_server/src/server/index.rs(waiting_for_this_scan): Untouched per lane file ownership. Whole-scan mutators arriving duringself.scanning == trueare staged intoServer::after_scaninserver/mod.rs(checked alongsideheldinmust_wait,must_hold,ahead.rs::nothing_unapplied_for,ahead.rs::answer_ahead_mid_widen,Server::run, andserver/tests/scan_ordering.rs::settle) sowaiting_for_this_scandoes not re-drain and re-hold them on each intermediate scan file. A follow-up lane can foldafter_scanintoindex.rsif desired.crates/lucisv_server/src/server/probe.rs(went_ahead): Untouched per lane file ownership. Exactapplied_changesrecording atanswered_aheadlives in#[cfg(test)]server/ahead.rs::AHEAD_APPLIED(take_ahead_applied()) paired with#[cfg(test)] Server::applied_changesincremented inserver/mod.rs,server/startup.rs, andserver/notification.rs. A follow-up lane can foldAHEAD_APPLIEDintoprobe::Probe.crates/lucisv_server/src/state/buffers.rs/server/diagnostics.rs/server/large_file.rs: Untouched per lane file ownership. BecauseWorkspace::set_documentrebuildsDocumentwithout a version parameter,Server::versions: HashMap<Uri, i32>andServer::sync_document_versions()re-attach versions after dirty flushes,didSave(text),apply_settings, andtake_the_answer_out_of_held.- Remaining
WorkspaceEditproducers (imports.rs,instantiate.rs,extract.rs,inline_module.rs,code_action.rs,file_ops.rs): Untouched beyond lane ownership.rename.rsandports.rsnow shareports::encode_editand honorClientAbilities::document_changes; follow-up lanes can passself.abilities.document_changesand document versions toimports,instantiate,extract,inline_module,code_action, andfile_ops::will_rename. - Cross-lane handshake F2b (
crates/lucisv_server/src/same_file.rs+server/tests/fast_actions_differential.rs): Lane 1A fixed#53invlog_refactor::prepare_rename_hereto checkindex.units(enclosing_unit)for symbols inside a file-scope unit (Module/Interface/Package/Typedef/Class), not onlyscope == file_scope. Updatedsame_file::renamed_hereto walkSemanticsparent scopes up tofile_scopeand defer (false) whenever the symbol sits inside a file-scope unit, updatedsame_file/tests.rs, and added"dup_b.sv"tofast_actions_differential::early_answers_equal_settled_over_the_locality_shapes(passes both before and after Lane 1A merges).
Status / TODO
- Topo #53: Hold workspace-wide mutating requests across
self.scanningviaafter_scan+waits_for_whole_scan. - Topo #52: Track
Document::versionatomically, parseworkspace.workspaceEdit.documentChanges, and emitDocumentChanges::Editsinrename.rsandports.rsvia sharedports::encode_edit(including non-canonical client URIs and immediate version sync afterflush_dirty/flush_buffer). - Topo #61: Drain superseded
workspace/didChangeConfigurationnotifications preceding pluckedPending::Configurationanswers intake_the_answer_out_of_held. - Topo #62: Record exact
applied_changeson early answers and tightenfast_actions_bursts.rsoracle to exact state equality (e == reference_at[applied]andapplied >= required). - Cross-lane F2b: Align
same_file::renamed_herewithvlog_refactor::prepare_rename_herefor symbols enclosed by file-scope units and cover"dup_b.sv"infast_actions_differential.rs. - Add regression suite
crates/lucisv_server/src/server/tests/ordering_r1.rsplus unit tests inmain.rs,rename.rs, andports.rs.
Work log
- Added
AtomicI64bufferversionstorage (version(),set_version()) onDocumentincrates/lucisv_server/src/state/document.rswithout changingDocument: Syncor existing constructors. - Added
document_changes_supportincrates/lucisv_server/src/main.rsandClientAbilities::document_changesincrates/lucisv_server/src/server/mod.rs. - Added
Server::after_scan,Server::versions,must_wait_for,waits_for_whole_scan, andsync_document_versionsincrates/lucisv_server/src/server/mod.rs, updatingServer::run,process_batch,hold, andmust_hold. - Updated
crates/lucisv_server/src/server/startup.rs(take_the_answer_out_of_held) to drain olderDidChangeConfigurationnotifications prior to the last pluckedPending::Configurationresponse while keeping newer pushes intact; updatedcrates/lucisv_server/src/server/tests/fast_actions_precondition.rs::what_staging_held_behind_a_push_is_not_released_ahead_of_itso its testpush(1000)arrives aftersettings_answer(0)rather than relying on the pre-#61 stale-replay bug. - Updated
crates/lucisv_server/src/server/notification.rsandcrates/lucisv_server/src/server/dispatch.rsto record/sync document versions and dispatchdocument_changescapability torename::rename_traced_forandports::{code_actions_for, resolve_for, execute_for}. - Extracted shared
ports::encode_edithelper used by bothports.rsandrename.rs. - Tightened
crates/lucisv_server/src/server/tests/fast_actions_bursts.rswithahead::take_ahead_applied()andapplied >= required+ exact state equality, and added regression tests incrates/lucisv_server/src/server/tests/ordering_r1.rs,rename.rs,ports.rs, andmain.rs.
2026-11-26 — QA fix pass + F2b handshake
- QA F1 (
crates/lucisv_server/src/ports.rs::encode_edit): Matched open documents viaws.open_documents()(doc.path.as_deref() == Some(path)) instead of canonicalpath_to_uri(path)+ws.document(&target), preserving the client's open URI (file://localhost/..., lowercase percent-encoding, etc.) anddoc.version()across bothDocumentChanges::Editsand unversionedchangesmaps. Added unit and integration tests inports.rsandordering_r1.rs. - QA F2 (
crates/lucisv_server/src/server/{notification,ahead}.rs): Addedself.sync_document_versions()immediately afterself.flush_dirty()innotification.rsandself.flush_buffer(&uri)inahead.rssoDocument::version()remainsSome(v)immediately afterdidSave(text: None),didClose(other),didChangeWatchedFiles, or mid-scan buffer flushes. Added regression testqa_f2_document_version_survives_flush_dirty_and_flush_buffer_immediatelyinordering_r1.rs. - Cross-lane F2b (
crates/lucisv_server/src/same_file.rs,same_file/tests.rs,server/tests/fast_actions_differential.rs): Updatedsame_file::renamed_herewithenclosed_by_unitsotextDocument/prepareRenamedefers (false) for symbols inside file-scope units (Module,Interface,Package,Typedef,Class), updatedsame_file/tests.rs, and added"dup_b.sv"toearly_answers_equal_settled_over_the_locality_shapesinfast_actions_differential.rs.
QA log
2026-11-26 — QA agent (Round 1, Lane 1B)
Verdict: FAIL (two concrete Topo #52 bugs found; Topo #53, Topo #61, and Topo #62 passed all adversarial checks and live OpenTitan probing).
Ownership, hygiene, and size checks
- File ownership (
git status/git diff --stat): All DEV changes are inside the lane's allowed files (main.rs,ports.rs,rename.rs,server/{mod,startup,dispatch,notification,ahead}.rs,state/document.rs,server/tests/{mod,fast_actions_bursts,fast_actions_precondition,scan_ordering,ordering_r1}.rs,docs/features/server-ordering-r1/README.md). QA added 5 passing adversarial regression tests incrates/lucisv_server/src/server/tests/ordering_r1.rs(qa_topo_53_*,qa_topo_52_full_version_lifecycle_*,qa_topo_61_attack_burst_*). - Production line counts (non-blank, non-comment lines before
mod tests {): All modified production files are<= 600lines (dispatch.rs: 522,main.rs: 400,ports.rs: 367,server/mod.rs: 311,notification.rs: 261,ahead.rs: 250,startup.rs: 192,state/document.rs: 135,rename.rs: 88). - Safety / author stamps:
0occurrences ofunwrap(,expect(,panic!, orunsafein modified production code.python3 tools/stamp_author.py --checkexits0.
Verification & adversarial attacks
-
Topo #53 (
after_scan&waits_for_whole_scan) — PASS:- Inspected
Server::hold,must_wait,must_wait_for,must_hold,after_scandrain inServer::run,waiting_for_this_scan,nothing_unapplied_for, andanswer_ahead_mid_widen.heldandafter_scanremain mutually exclusive acrosshold,answer_ahead_mid_widen, andrun, preserving arrival order on nestedprocess_batchscans and avoiding O(N) re-drain spinning (handed_back <= 1). - Added and passed QA tests in
ordering_r1.rscovering:$/cancelRequestarriving in a later burst whilerenamesits inafter_scan;$/cancelRequestin the same burst asrenamewhilehead_owed == true(transitioningheld -> after_scan); incrementaldidChangebehindrenameinafter_scanfollowed by a second incrementaldidChangeand mid-scandidSave(rescan_wanted = true, two scanends beforeafter_scandrains). - Live OpenTitan 10-spawn probe (
./tools/guard.sh -m 6 -t 600 -- cargo build --release -p lucisv_server->target/release/lucisv-server --verboseagainst/Users/lucio/repo/opentitan,hw/top_englishbreakfast/ip/ast/rtl/adc.svline 81 col 42rst_adc_ni, workspace scope withpersist: falseand scratch/tmpstorage dirs): 5 startup-burst spawns + 5 mid-scan$/progressreportspawns (4044 files) all loggedtextDocument/rename HELD behind a rescan, answered strictly after$/progressend, exited0, and returned 10/10 identical deterministic refusal (code: -32803,"lucisv: `rst_adc_ni` is declared in more than one indexed file; lucisv will not guess which declaration this rename means.").git -C /Users/lucio/repo/opentitan status --porcelainremained empty.
- Inspected
-
Topo #52 (versioned
documentChanges) — FAIL (2 findings):- Passing lifecycle checks (
qa_topo_52_full_version_lifecycle_open_change_save_empty_change_rename_and_overlay+topo_52_session_tracks_versions_and_emits_versioned_document_changes):didOpen(v=1)->didChange(v=2)->didSave(None)->didChange(v=3, contentChanges=[])->watched(Document::refresh_overlay) ->rename(mixedSome(3)andNone,changesfallback whendocument_changes=false), eagercodeAction,codeAction/resolve,executeCommand(workspace/applyEdit),largeFile.thresholdreclassification, anddidCloseresetting version toNoneall pass for canonicalfile:///URIs. - Finding 1 (Medium/High — wire bug):
crates/lucisv_server/src/ports.rs:555-571(encode_edit) drops document versions and emits unversionedchanges(orversion: None) for valid non-canonicalfile:URIs.- At
ports.rs:555,ws.text_of(path)resolves open buffers viad.path.as_deref() == Some(path)(state/buffers.rs:103), whereasports.rs:570computestarget = path_to_uri(path)and looks upws.document(&target).and_then(Document::version). - Whenever the client opened the file with a valid
file:URI whose serialization differs frompath_to_uri(path)— e.g.file://localhost/...(explicitly supported byuri.rs:38), lowercase percent-encoding such ascaf%c3%a9.svvspath_to_uri's%C3%A9, or Windows VS Code'sfile:///c%3A/...vsfile:///C:/...—ws.document(&target)returnsNone, silently losing the buffer's version (Some(v)->None) and falling back to unversionedchanges(andtargetalso fails to echo the client's open URI). - Reproduction: Open
caf%c3%a9.sv(orfile://localhost/<tree>/sub.sv) atversion: 12withClientAbilities { document_changes: true, ..Default::default() }, then issuetextDocument/renameon it (or cross-file fromtop.sv).renamereturns{"changes": ...}(orversion: nullforsub.svin cross-filedocumentChanges) instead ofdocumentChangeswithversion: 12.
- At
- Finding 2 (Low/Medium — state invariant leak):
crates/lucisv_server/src/server/notification.rs:71(handle_notificationflush_dirty) andcrates/lucisv_server/src/server/ahead.rs:195(flush_buffer) rebuildDocumentwithout re-attachingself.versions.notification.rs:71runsself.flush_dirty()on non-didChangenotifications such asdidSavewithtext: None(the default becausemain.rs:221advertisesinclude_text: Some(false)),didCloseof another file, ordidChangeWatchedFiles.flush_dirty()callsset_document, replacing theDocumentwithversion = NO_VERSION(None). OnlydidSave(Some(text))(notification.rs:167) andapply_settings(notification.rs:366) callself.sync_document_versions(). Similarlyahead.rs:195(flush_buffer) does not sync versions.- Currently masked on LSP wire requests because
dispatch.rs:172(answer_request) callsself.sync_document_versions()beforeanswer_flushed, butDocument::version()onWorkspaceisNoneimmediately afterdidSave(None)until the next request or debounce timeout. - Reproduction:
didOpen(uri, v=1)->didChange(uri, v=2, text)->didSave(uri)(notextfield). Immediately inspectingsession.server.workspace.document(&uri).unwrap().version()returnsNoneinstead ofSome(2).
- Passing lifecycle checks (
-
Topo #61 (
take_the_answer_out_of_held) — PASS:- Tested attack burst
[didOpen, (optional lens), push(A: threshold=0), hover, settings_answer(B: threshold=100), push(C: threshold=4MiB)]inqa_topo_61_attack_burst_didopen_push_a_hover_answer_b_push_c:BbeatsA(hoversees threshold=100 ->Null),hoveris not dropped,CbeatsBoncehelddrains (threshold=4MiB), andapplied_changesmatches exact applied state transitions (2/3at staging end,+1afterpush(C)).
- Tested attack burst
-
Topo #62 (
fast_actions_bursts) — PASS:- Inspected
fast_actions_bursts.rs:403-511:ahead_appliedrecordsself.applied_changesatanswered_ahead(ahead.rs:237) and asserts bothapplied >= required(prior reachingcan_reachor config changes) ande == reference_at[applied]. - Ran
fast_actions_bursts(1448 requests, 384 answered ahead (0 from a later state), 1280 settled comparisons), 300-roundanswers_given_ahead_equal_a_one_message_at_a_time_server_long_run(seed 7: 1313 requests, 400 answered ahead (0 from a later state), 1200 settled comparisons, 0 differ), andordering_random(12 seeds × 10 rounds, pass). - Verified oracle sensitivity via temporary mutations (reverted immediately): subtracting 1 from
appliedfailed immediately atseed 1, round 0(6 answered at applied=1 ahead of reaching change 2), and skippingself.flush_buffer(&uri)inahead.rs:195failed atseed 2, round 5(28 went ahead at applied=4 (required >= 4) with wrong state).
- Inspected
Full crate gates (worktree, after final edits)
python3 tools/stamp_author.py --check-> exit 0cargo fmt -p lucisv_server -- --check-> exit 0./tools/guard.sh -m 6 -t 600 -- cargo clippy -p lucisv_server --all-targets -- -D warnings-> exit 0./tools/guard.sh -m 6 -t 600 -- cargo test -p lucisv_server --all-targets->2,043passed (47ignored) unit +106passed (3ignored) e2e +3grammar +1ifdef_folding +0passed (2ignored) opentitan_references;0failed
2026-11-26 — QA re-check (Round 1, Lane 1B)
Verdict: PASS (F1, F2, and cross-lane F2b all verified fixed; full crate gates green).
Ownership, hygiene, and size checks
- File ownership (
git status/git diff --stat): Only ownedcrates/lucisv_server/files (main.rs,ports.rs,rename.rs,same_file.rs,same_file/tests.rs,server/{mod,startup,dispatch,notification,ahead}.rs,state/document.rs,server/tests/{mod,fast_actions_bursts,fast_actions_differential,fast_actions_precondition,ordering_r1,scan_ordering}.rs) anddocs/features/server-ordering-r1/README.mdare modified or untracked. QA added 2 passing re-check regression tests (qa_r2_f1_*,qa_r2_f2_*) incrates/lucisv_server/src/server/tests/ordering_r1.rs. - Production line counts (non-blank, non-comment before inline
mod tests {): All modified production files remain<= 600lines (dispatch.rs: 522,main.rs: 400,ports.rs: 374,server/mod.rs: 311,notification.rs: 262,ahead.rs: 251,startup.rs: 192,state/document.rs: 134,same_file.rs: 126,rename.rs: 88). - Safety / author stamps:
0occurrences ofunwrap(,expect(,panic!, orunsafein modified production code.python3 tools/stamp_author.py --checkexits0.
Re-verification & adversarial attack results
-
Attack F1 (
ports.rs::encode_edit) — PASS:- Verified
ws.open_documents().find(|(_, doc)| doc.path.as_deref() == Some(path))preserves client non-canonical URIs (file://localhost/...and lowercase percent-encodedcaf%c3%a9.sv) anddoc.version(), while closed files fall back to canonicalpath_to_uri(path)withversion: None. - Verified
qa_f1_non_canonical_client_uris_preserve_uri_and_version_in_editsand QA-addedqa_r2_f1_multifile_rename_open_noncanonical_and_closed_doc_with_and_without_document_changespass: multi-filetextDocument/renametouching one open non-canonical URI (file://localhost/...orcaf%c3%a9.sv) plus one closed file (version: null) emitsdocumentChangeswhen enabled and uses the client's open URI as thechangesmap key whendocumentChangesis disabled.
- Verified
-
Attack F2 (
notification.rs/ahead.rsversion sync) — PASS:- Verified
qa_f2_document_version_survives_flush_dirty_and_flush_buffer_immediatelypasses. - Audited all
Documentreconstruction call sites acrossserver/andstate/: everyServer::set_document,flush_dirty,flush_buffer, andreclassify_large_bufferscaller (notification.rs,ahead.rs,dispatch.rs,server/mod.rs,startup.rs) immediately runsrecord_document_versionorsync_document_versions(). - Verified QA-added
qa_r2_f2_document_version_survives_reclassify_incremental_apply_changes_and_didsave_with_textpasses across incrementalapply_changes_at+ flush,didSave(text: Some(...)), andreclassify_large_buffers(normal -> large -> normal).
- Verified
-
Attack F2b (
same_file.rs::renamed_here+fast_actions_differential.rs) — PASS:- Verified
enclosed_by_unitmatchesvlog_semantic's 5 unit kinds (Module,Interface,Package,Typedef,Class) atfile_scopeand walks parent scopes so declarations/uses inside file-scope units wait for the index. - Confirmed
"dup_b.sv"runs infast_actions_differential::early_answers_equal_settled_over_the_locality_shapes(early=3378 waited=614 differed=0),same_file::tests::prepare_rename_waits_at_file_scope_inside_units_and_on_an_unresolved_usepasses, andfast_actions_bursts::answers_given_ahead_equal_a_one_message_at_a_time_serverpasses (1448 requests, 284 answered ahead (0 from a later state), 1280 settled comparisons).
- Verified
Full crate gates (worktree, after final edits)
python3 tools/stamp_author.py --check-> exit 0cargo fmt -p lucisv_server -- --check-> exit 0./tools/guard.sh -m 6 -t 600 -- cargo clippy -p lucisv_server --all-targets -- -D warnings-> exit 0./tools/guard.sh -m 6 -t 600 -- cargo test -p lucisv_server --all-targets->2,048passed (47ignored) unit +106passed (3ignored) e2e +3grammar +1ifdef_folding +0passed (2ignored) opentitan_references;0failed
Review
2026-11-26 — Lead review: PASS (merged with Lane 1A in Round 1)
- Inspected combined diff across
lucisv_serverand verifiedafter_scanexclusivity, non-canonical URI/version tracking inports::encode_edit, immediatesync_document_versionsafterflush_dirty/flush_buffer, staging push draining (#61), exactapplied_changesoracle (#62), andsame_file::renamed_hereparity (F2b) with Lane 1A's duplicate-unit check. - Live 10-spawn OpenTitan
adc.sv:81probe confirmed 10/10 deterministic refusal with/Users/lucio/repo/opentitanuntouched. - Handshakes closed in
docs/topo.md:#52,#53(server half),#61,#62. Fulltools/gates.shverified green on mergedmaster.