PM: merge F3 hardening: suspended Phpactor start, ConPTY in a job, completion cancel, syntax proptest
Some checks are pending
ci / ci (macos-15) (push) Waiting to run
ci / ci (ubuntu-24.04) (push) Waiting to run
ci / ci (windows-2025) (push) Waiting to run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-27 17:30:10 +01:00
commit d2c853c42f
17 changed files with 468 additions and 36 deletions

View file

@ -264,7 +264,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
`crates/syntax` (L1, depends on `lutra-text` only) parses PHP with tree-sitter (`tree-sitter` 0.26, `tree-sitter-php` 0.25, both MIT; the grammar variant that accepts inline HTML around `<?php` tags). It has no engine types; M2.7 wires it to buffers and M2.5 builds the index on it.
- **API:** `Parser::new()?`, `parser.parse(&str) -> Tree` (never fails), `parser.reparse(&Tree, &[lutra_text::Edit]) -> Result<Tree, SyntaxError>`, `outline(&Tree) -> Vec<OutlineItem>`, `folding(&Tree) -> Vec<Range>`. `Tree` carries the text it was parsed from (a `lutra_text::Buffer`, cheap to clone) plus `truncated()` and `has_errors()`; that is why `outline` takes no separate text argument (the contract sketch had `outline(tree, text)`): a tree and a mismatching text can't be combined.
- **Reparse:** the edit batch has `Buffer::apply` semantics (ranges against the old text, any order). It is mapped to one tree-sitter `InputEdit` covering the smallest start to the largest end, with points (row, byte column, rows by `\n` as tree-sitter counts them) computed from the old and new text. Proptests check that a reparse gives the same tree, outline and folding as a fresh parse whenever the edited text is error-free, and that an undo round trip ends at the original tree. On broken code tree-sitter's error recovery may legitimately differ between an incremental and a fresh parse; the engine can reparse from scratch when it wants a canonical tree (for example on save).
- **Reparse:** the edit batch has `Buffer::apply` semantics (ranges against the old text, any order). It is mapped to one tree-sitter `InputEdit` covering the smallest start to the largest end, with points (row, byte column, rows by `\n` as tree-sitter counts them) computed from the old and new text. Proptests check that a reparse gives the same leaf node kinds, outline and folding as a fresh parse whenever the edited text is error-free, and that an undo round trip ends at the original's. They compare leaves, not the whole S-expression (F3): an incremental reparse may keep a wrapper node a fresh parse does not build (tree-sitter-php 0.25.1, the newest release, keeps `(union_type (primitive_type))` for `array &$cache` after an undo where a fresh parse gives `(primitive_type)`), and nothing Lutra builds on the tree reads those wrappers. On broken code tree-sitter's error recovery may legitimately differ between an incremental and a fresh parse; the engine can reparse from scratch when it wants a canonical tree (for example on save).
- **Outline:** `OutlineItem {kind, name, detail, range, selection_range, children}`; `OutlineKind::as_str()` gives the contract names (`namespace`, `class`, …, `enumCase`). Braced and unbraced namespaces (an unbraced one owns everything up to the next namespace statement), promoted constructor parameters as properties after the constructor, enum cases with backing values, multi-element `const`/property declarations as one item each, attributes inside the declaration range. Anonymous classes are classes named `class@anonymous` (`OutlineItem::is_anonymous`, for the index to skip). Function, method and closure bodies are not searched; statements at file level are (`if (!function_exists(…)) { function … }`). Error nodes are transparent and nameless declarations are dropped. The search descends at most 96 levels.
- **Folding:** multi-line brace blocks (class-like bodies, function and control bodies, `switch`/`match`), arrays, comments, heredoc/nowdoc, `use A\{…}` groups and runs of two or more `use` statements; ranges include the delimiters. The walk is iterative and skips the inside of single-line nodes.
- **Positions:** 0-based line and UTF-16 column through `Buffer::offset_to_position` (about 1 µs per conversion on a 1 MB rope; the parse dominates).
@ -343,9 +343,11 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
- **Windows:** one job object per child with `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE` (`windows-sys`). Lutra holds the only handle, so dropping the `Child` or the end of Lutra's process (the kernel closes its handles) kills the child and everything it started. Jobs nest (Windows 8+), so this works when Lutra itself runs in a job (terminal, `cargo`, CI). `crates/proc/src/windows.rs` is the only module that allows `unsafe` (FFI).
- **Unix:** the child leads a new process group; a `/bin/sh` watchdog in its own group blocks on a pipe only Lutra holds and sends `SIGKILL` to the child's group when the pipe closes (drop, kill, quit, or a `SIGKILL` of Lutra). Left behind after a `SIGKILL` of Lutra: processes that left the group themselves (`setsid`/`setpgid`, daemons), and the child if Lutra dies between starting it and starting its watchdog. Compiled and tested by CI only (no Unix machine here).
- `Child` dereferences to `std::process::Child`. `Child::kill` replaces the standard `kill` and takes the whole group; `kill_and_wait` also reaps; `Drop` kills the group and reaps.
- A child runs for a moment before it joins its job (Windows) or before its watchdog exists (Unix); a grandchild started in those microseconds can escape.
- Tests: `crates/proc/tests/process_tree.rs` starts `lutra-proc-helper`, which starts a sleeping grandchild holding the test's pipe. A hard kill of the helper (`TerminateProcess` / `SIGKILL`, with and without the helper itself in a group), `Child::kill` and drop each end the tree; the pipe reaches end of file. Without `KILL_ON_JOB_CLOSE` the hard-kill tests fail.
- The integrated terminal (portable-pty) does not use it yet. On Unix portable-pty makes the shell a session leader, and closing the PTY master on Lutra's exit hangs it up. On Windows the ConPTY host ends its clients when its pipes break; joining the shell to a job needs an adopt-by-handle API (`portable_pty::Child::as_raw_handle`), a follow-up.
- A child of `spawn` runs for a moment before it joins its job (Windows) or before its watchdog exists (Unix); a grandchild started in those microseconds can escape. Short-lived tools (git, `php -l`, the `php -v` probe) keep this path: git starts hooks long after it is in its job.
- `lutra_proc::spawn_suspended` (F3) closes the window on Windows for long-lived children (Phpactor): `CREATE_SUSPENDED | CREATE_NO_WINDOW` (replacing the command's creation flags), assign to the job, then resume the primary thread. std keeps the thread handle to itself, so the thread is found with a Tool Help snapshot (`CreateToolhelp32Snapshot` + `Thread32First/Next`, `OpenThread` + `ResumeThread`). The snapshot covers every thread on the machine. Measured 2026-10-27, debug, 30× `cmd /c exit`, other builds running: std 35–38 ms, std + `CREATE_NO_WINDOW` 54–55 ms, `spawn` 55–65 ms (unchanged from H1), `spawn_suspended` 130–187 ms. That is why git does not use it. On Unix it is `spawn`.
- `lutra_proc::adopt(RawHandle) -> io::Result<Guard>` (Windows, F3) puts a process someone else started into a new kill-on-close job; dropping the `Guard` or `Guard::kill` ends the process and everything it started since.
- Tests: `crates/proc/tests/process_tree.rs` starts `lutra-proc-helper`, which starts a sleeping grandchild holding the test's pipe. A hard kill of the helper (`TerminateProcess` / `SIGKILL`, with and without the helper itself in a group), `Child::kill` and drop each end the tree; the pipe reaches end of file. Without `KILL_ON_JOB_CLOSE` the hard-kill tests fail. The same runs for `spawn_suspended`, and `adopt` is tested with a helper that starts its grandchild only after a line on stdin, i.e. after the adoption (9 tests).
- The integrated terminal (portable-pty): on Windows the ConPTY shell is adopted into a job right after it starts (`portable_pty::Child::as_raw_handle`, F3). `Session::kill` and drop kill the job, so processes the shell started (a dev server, `start /b`) end with the terminal tab or with Lutra, even after the shell itself exited. A process the shell starts in the microseconds before the adoption is not in the job; the ConPTY host still ends its console clients when its pipes break. On Unix portable-pty makes the shell a session leader, and closing the PTY master on Lutra's exit hangs it up.
### Terminal (M3.6)
@ -422,7 +424,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
- After an edit: 1.8 s and 2.7–2.9 s, including Phpactor's 1 s debounce.
- Without the adjustments: no diagnostics within 180 s.
- **Known gaps:**
- ~~A Phpactor process outlives Lutra when Lutra is killed.~~ Fixed by H1: Phpactor starts through `lutra_proc::spawn` (see Child processes).
- ~~A Phpactor process outlives Lutra when Lutra is killed.~~ Fixed by H1: Phpactor starts through `lutra_proc::spawn` (since F3 `spawn_suspended`; see Child processes).
- ~~`window/showMessage` and `logMessage` are dropped, and server-initiated progress is not shown.~~ Fixed by H3.
- **Tests:**
- `crates/engine/tests/lsp.rs` has 10 tests against `lutra-lsp-fake`: sync incl. UTF-16 and CRLF edits, diagnostics list/clear, reload resync, requests after edits, project close, restart, quit, missing server, crash and give-up, no server without a project, and a proptest of random edits. The ignored `real_phpactor_reports_diagnostics` runs with `LUTRA_PHPACTOR=<phar>`.
@ -466,6 +468,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
- Under the lock the command validates, runs the LSP pump once (so a buffer opened a moment ago is opened on the server first) and queues a closure with `lsp::submit`. That runs after every queued `didChange`.
- The closure sends the request with `request_with` (timeout 10 s). The reply callback converts the answer on the client thread, so a big list is never converted under the lock.
- It sends the result into the `Pending`'s channel. The host waits without the lock (wait 11 s + 1 s grace) and resolves.
- **Superseded completions (F3):** each `lsp.completion` cancels the previous completion request still pending on the same server (`Server::cancel`, which sends `$/cancelRequest`) before it sends its own; CodeMirror has dropped that answer anyway. The cancelled command resolves with the empty result, not an error. The latest request is one process-wide slot keyed by the server's address. Hover and signature help are not cancelled. Test: `a_new_completion_cancels_the_one_it_supersedes` (the fake server holds a completion while the text contains `SLOW`).
- The UI calls these commands with `runWaiting` (`engine_execute_waiting`, off the main thread).
- **Editor:**
- **Before a request,** the UI awaits the buffer sync's `idle()` and drops the request if the document changed meanwhile. Positions are lines and UTF-16 columns, which CodeMirror counts the same way within a line, so CRLF files need no conversion.
@ -651,6 +654,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
| Date | Change | Summary |
|---|---|---|
| 2026-10-27 | minor | F3: `lutra_proc::spawn_suspended` (Phpactor) and `adopt` (ConPTY shell in a job), cancel superseded completions, syntax proptests compare leaf kinds |
| 2026-10-27 | minor | C6 F1: remote branch checkout without a configured remote (`--no-track`), `git.lastMessage` and the Amend prefill, one shared git status store |
| 2026-10-27 | minor | F2: `ui.screenshot` through WebView2 `CapturePreview` without focus; region fallback elsewhere; `--control` windows open unfocused |
| 2026-10-26 | minor | M4.5: branches (status-bar item, popup, `vcs.branches`, `vcs.newBranch`, `vcs.checkout`) |

View file

@ -1,6 +1,6 @@
# Development
> **Status:** draft · **Last updated:** 2026-10-14
> **Status:** draft · **Last updated:** 2026-10-27
## Prerequisites
@ -18,7 +18,31 @@ cargo xtask ci # the full quality gate, run before every commit
cargo xtask fixtures # create Symfony and Laravel reference projects in target/fixtures/
```
A `--control PORT` instance keeps its settings, recovery journal and webview data in `<temp>/lutra-control/<port>/`, never in your own data directory; `--data-dir DIR` or `LUTRA_DATA_DIR=DIR` pick another directory. Delete the folder to start fresh. Its window opens without taking the foreground, and `ui.screenshot` never focuses it; only `app.focus` does. To check that on Windows, build with `--features bundled-ui` and run `LUTRA_DESKTOP_EXE=<target>/debug/lutra-desktop.exe LUTRA_CONTROL_PORT=<port> cargo test -p lutra-desktop --test screenshot_focus -- --ignored`.
## Data directories
A `--control PORT` instance keeps its settings, recovery journal and webview data in `<temp>/lutra-control/<port>/`, never in your own data directory, so a dev or agent instance cannot change your settings or restore your journal. `--data-dir DIR` or `LUTRA_DATA_DIR=DIR` pick another directory, for any instance:
```sh
cargo run -p lutra-desktop -- --control 7979 --data-dir target/lutra-data .
```
Delete the folder to start fresh. Its window opens without taking the foreground, and `ui.screenshot` never focuses it; only `app.focus` does. To check that on Windows, build with `--features bundled-ui` and run `LUTRA_DESKTOP_EXE=<target>/debug/lutra-desktop.exe LUTRA_CONTROL_PORT=<port> cargo test -p lutra-desktop --test screenshot_focus -- --ignored`.
## Build directories and parallel work
- Keep `CARGO_TARGET_DIR` inside the repository folder: the default `target/`, or `<worktree>/target` per git worktree (`/target/` is gitignored). Antivirus exclusions usually cover the checkout. On Windows, unsigned binaries built outside an excluded folder have taken about 26 s to start each child process (Phpactor, git, the test helpers) against 28 ms inside, which makes tests time out.
- Several builds in parallel (agents, worktrees): give each its own `CARGO_TARGET_DIR` and limit the jobs, e.g. `CARGO_BUILD_JOBS=4`. Delete a worktree's target directory once its work is merged; a full build takes about 10 GB.
## Deleting `ui/node_modules`
pnpm hardlinks packages from its shared store. Deleting `ui/node_modules` with Git Bash `rm -rf` on Windows breaks those links for other checkouts and makes their running Vitest fail with `EBUSY`. Delete it with either of:
```sh
cmd //c "rmdir /s /q ui\node_modules"
node -e "require('fs').rmSync('ui/node_modules',{recursive:true,force:true})"
```
Then run `pnpm --dir ui install` again.
## Robustness: Lutra never crashes
@ -32,6 +56,7 @@ No inline comments. Doc comment blocks above modules, functions, types and field
| Date | Change | Summary |
|---|---|---|
| 2026-10-27 | minor | F3: data directories, build directories inside the repository, parallel builds, deleting `ui/node_modules` |
| 2026-10-27 | minor | Unfocused `--control` windows and the screenshot focus check (F2) |
| 2026-10-25 | minor | Isolated data directory for `--control` instances (H6) |
| 2026-10-14 | minor | Node.js 22.12+ required by the frontend toolchain |

View file

@ -36,6 +36,8 @@ G11 progress: M1.7 added the crash-recovery journal: unsaved buffers are written
G11 progress (H6): development and live-check instances no longer share the user's data. `--data-dir PATH` / `LUTRA_DATA_DIR` move settings, the recovery journal, the rendezvous file and the WebView2 user data (local storage) into one directory; `--control PORT` without either uses `<temp>/lutra-control/<port>/`. The Phpactor cache stays shared from the user's data directory. An isolated instance never forwards to or registers as the user's main instance. A unit test drives an isolated `--control` engine through the control channel (`settings.set`, journal write) and checks the user directory is byte-for-byte unchanged.
G11 progress (F3): Phpactor starts suspended and joins its kill-on-close job before its first instruction (`lutra_proc::spawn_suspended`); git and `php -l` keep the cheaper `spawn` (the suspended start costs about 60 ms more per process). The terminal's ConPTY shell is adopted into a job, so a dev server started in the terminal ends with the tab or with Lutra. A superseded completion request is cancelled with `$/cancelRequest`. The syntax undo round-trip proptest no longer fails on a wrapper node tree-sitter keeps after an incremental reparse (it compares leaf kinds, outline and folding). Not verified with a hard kill of the running app (Daniel at the PC).
G14 progress: M1.11 moved every UI string in `ui/src` into the English catalog `ui/src/i18n/en.json` behind `t(key, params?)`, enforced by `vue/no-bare-strings-in-template` and a catalog test. Messages the engine sends (`EngineError.message`, the slogan from `app.about`) are still English text; they need message keys with params before a second language can cover them.
G5 progress: M2.3 landed the find-in-files backend: `crates/search` (parallel walk with the project's ignore rules, literal or regex, case, whole word, globs, binary and size skips, match cap, cancel) and the engine commands `search.find` / `search.cancel` with streamed `searchResults` and `searchDone` events; dirty buffers are searched in their buffer text. First result on a generated 20k-file tree 10–43 ms (release, measured). M2.4 added the Find tool window in a new bottom panel (options, globs, grouped and highlighted results, counts, cancel, truncated hint, keyboard navigation, `editor.reveal`, `find.open` `Mod+Alt+F` with prefill). M2.5 added the first symbol index (`crates/index`: every project file, PHP declarations from tree-sitter outlines, vendor as library, parallel build off the engine lock, incremental on disk and buffer changes, cancelled on project close) and the commands `index.status`, `goto.file`, `goto.class`, `goto.symbol` with `indexProgress`/`indexReady` events; a generated 20k-file project (88 MB of PHP) indexes in 3.9–4.2 s (release, measured, target 5 s), queries take 2–12 ms. M2.6 added the go-to popup (Files / Classes / Symbols tabs, `Mod+P`, `Mod+Alt+C`, `Mod+T`, live fuzzy results with marked characters, library rows labelled, indexing hint, `editor.reveal`). Open in G5: replace in files, scopes and history, go-to extras (recent files on an empty query, a non-project toggle, `:line`, file-type filter), an index that survives restarts, changes in directories the non-recursive watcher does not watch, usages.
@ -52,6 +54,7 @@ G6 progress: M3.2 landed the LSP client library in `crates/lsp`: JSON-RPC framin
| Date | Change | Summary |
|---|---|---|
| 2026-10-27 | minor | G11 note: suspended Phpactor start, terminal shell in a job, completion cancel, syntax proptest (F3) |
| 2026-10-27 | patch | G8: amend prefill, remote checkout fix, shared status store (C6 F1) |
| 2026-10-27 | minor | Screenshot item shrunk: webview capture without focus on Windows (F2) |
| 2026-10-26 | minor | G8 shrunk: branch widget and popup (M4.5) |