summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 06:14:26 -0300
committerGabriel Schneider <[email protected]>2026-11-26 06:44:31 -0300
commit849542a05f7be03f37a0e6444e0eb70fb4dbea0c (patch)
treeee03796248038d92be42330fb1435fe69b133c1a /core
parent02b64ff90ae2f82fb83a604f6d4ded3459a84620 (diff)
downloadpardes-849542a05f7be03f37a0e6444e0eb70fb4dbea0c.tar.gz
pardes-849542a05f7be03f37a0e6444e0eb70fb4dbea0c.zip
ninep/ctl, Pick, Names: a key written to 9P's kbdin (and a mouse line to mousein) takes the keyboard's path: the write is answered once its keys are handled, and what they start runs on a worker as the keyboard's does, its rows after (agent W78's find, rqouyxqp's description: a scripted `SPC f g` over V8's 18,441 files held the session until the 9P client timed out; and W6's: kbdin's Symbols picker over a text of more than 64 KB listed nothing); THE CAUSE: writeKbdin and writeMousein ran their keys inside serveFs with `p.fs.serving` set, which these places read as "a script's write, answered with its result": Pick.start and filter (Find's listing and Grep's search stepped on the loop, `.now`), Query (a query pane's), Stream.step (runHere, not the worker), Stream.parseFor (no worker: a text over 64 KB never parsed), paintAhead and paintRows, builtins' search (a miss said to the write), look (a tty pane's click searched), edit_cmd (the write held for an Edit's filters), panes (a Save's question to /log) and lsp/Ask (the write waits for the server's answer); `fs.typed` made Pick.asked alone take the keys as the user's; THE FIX: writeKbdin and writeMousein run their keys with `serving` off and put it back after, so every one of those places takes the keyboard's path for typed keys and keeps the script's for a script's write; `fs.typed` has no reader and goes (FsState, its replica list); A CRASH IT UNCOVERED: with the parse on a worker, Pick.declsArrived scored the declarations that came by typing the picker's own query again, `names.typed(gpa, names.queryText())`, and Names.typed copied the query onto itself with @memcpy, `@memcpy arguments alias`, a panic in a safe build (the installed ReleaseSafe's): a keyboard's `SPC s s` whose query was typed before its file's parse landed (a big file) killed the session; Names.typed copies with copyForwards; ACCEPTED (the coordinator): a kbdin `gd` no longer waits for the server's answer, nor a kbdin `SPC f f` for its rows: a script reads them after, as a keyboard user sees them a frame later (docs/typ/reference.typ's kbdin says so; a script that wants the answer in its write writes the word to a pane's ctl, `Def`, `Find x`, which still waits); RUN (TEST FIRST): process/other_files.zig "kbdin's SPC f f over a work tree of 20,000 files is answered before the listing, which a worker runs as the keyboard's, its rows after" (a detached session, a tree of 200 directories of 100 files with a `.git`, `SPC f f zzlast` in one kbdin write timed, then /screen read until zzlast.txt's row shows): on T2 the write took 46-47 ms and the row was there at 62-63 ms (the listing ran in the write), now the write takes 3 ms and the row comes at 58-60 ms (three runs); "kbdin's SPC s s lists the declarations of a file over 64 KB, parsed on a worker as the keyboard's are" (4,001 two-line functions, 80 KB, `SPC s s zzlast`): on T2 nothing in 20 s, with the fix alone the session died at Pick.declsArrived (the probe, .scratch/walkui/T23/symprobe.sh: `panic: @memcpy arguments alias` at Names.zig typed), now its row in under a second; Names.zig "Names takes its own query typed again: ..." types a query, adds two names and types its own query again: panics before (`@memcpy arguments alias`), one hit now; behaviour tests that read a picker's rows in the write that typed its keys read them a frame later (Session.tick): other_files.zig's SPC f f, and addons.zig's two `SPC f f ...` then Enter, now the query, a tick, then Enter (Enter typed before the rows came picks none, for a keyboard too); a user hit the stall with any script driving a session's keys over a big tree, and the crash with `SPC s s` typed ahead of a big file's parse; NEW HOT PATHS: none (a write of keys saves and puts back one flag); GATES: core-test 1131/1305 (174 skipped: +1), shell-test 1353/1356 (3 skipped: +1), pane-test 183/184, behaviour-test 286/286 and --replay 20 seeds of 70 steps, 0 failures, process-test 0 of 149 failed (3 skipped: +2), term-test 17/17, kitty-test 45/45, the gui unit-test (Debug, this change over T2's mlvruznk) 1962/1966 (4 skipped: T2's lsp_client test and this change's Names test among the new; its perf check's BaselineHarnessMismatch, every base's); no dump change (`typed` was a field of the server's own, out of the digest: fs.zig's authority list) and no wire change (FsState is not on the tape), so no fuzz or soak; Stream.parseFor keeps its `!p.fs.serving` for a script's write, whose answer holds its rows (a script's `Symbols` word over a text past 64 KB still lists nothing: not this change's); no frame or perf gate (the user's rule of 2026-11-26); load 1.2 to 2.6
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
-rw-r--r--core/Names.zig16
-rw-r--r--core/Pick.zig8
-rw-r--r--core/fs.zig10
-rw-r--r--core/ninep/ctl.zig18
4 files changed, 36 insertions, 16 deletions
diff --git a/core/Names.zig b/core/Names.zig
index d063bd17..01dbecf0 100644
--- a/core/Names.zig
+++ b/core/Names.zig
@@ -128,7 +128,9 @@ pub fn typed(n: *Names, gpa: std.mem.Allocator, text: []const u8) void {
// only those are scored again (and then the ones not yet scored).
const grew = n.query_len > 0 and std.mem.startsWith(u8, q, n.queryText()) and std.mem.indexOfScalar(u8, q[n.query_len..], ' ') == null;
n.query_len = @intCast(q.len);
- @memcpy(n.query_buf[0..q.len], q);
+ // Its own query typed again, to score names that came after it
+ // (Pick.declsArrived), is the buffer itself.
+ std.mem.copyForwards(u8, n.query_buf[0..q.len], q);
n.reach = max_rows;
if (grew) {
const pending = n.pending.items[n.pending_at..];
@@ -435,3 +437,15 @@ test "Names keeps its best `reach` hits first in a full sort's order, the rest a
n.reachTo(max_rows + 500);
try std.testing.expectEqualSlices(Hit, all[0 .. max_rows + 500], n.hits.items[0 .. max_rows + 500]);
}
+
+test "Names takes its own query typed again: names added after it (a Symbols picker's declarations from a worker, Pick.declsArrived) are scored against it" {
+ const gpa = std.testing.allocator;
+ var n: Names = .{};
+ defer n.deinit(gpa);
+ n.typed(gpa, "zzlast");
+ for ([_][]const u8{ "fn f0001() void {", "fn zzlastfn() void {" }) |cand| try n.add(gpa, cand, 0, cand.len, 0, 0);
+ n.typed(gpa, n.queryText());
+ while (n.busy()) n.rescore(gpa);
+ try std.testing.expectEqualStrings("zzlast", n.queryText());
+ try std.testing.expectEqual(@as(usize, 1), n.hits.items.len);
+}
diff --git a/core/Pick.zig b/core/Pick.zig
index 9a9d0cde..5951f925 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -182,11 +182,11 @@ pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void {
/// Whether a search a builtin asks for from pane `id` is a picker in the
/// tag (SPEC ยง14.3 phase 4): in a session whose jumps walk, from the
-/// keyboard or a click (kbdin's and mousein's too), never a script's word
-/// (a 9P exec's: the query pane, whose rows it reads back, and whose `not
-/// found` it hears).
+/// keyboard or a click (kbdin's and mousein's too, which run as theirs:
+/// ninep/ctl.zig writeKbdin), never a script's word (a 9P exec's: the query
+/// pane, whose rows it reads back, and whose `not found` it hears).
pub fn asked(p: *const Pardes) bool {
- return p.settings.jumps == .walk and (!p.fs.serving or p.fs.typed);
+ return p.settings.jumps == .walk and !p.fs.serving;
}
/// Picker `id`, kept or live.
diff --git a/core/fs.zig b/core/fs.zig
index 594c89cf..c5eb432d 100644
--- a/core/fs.zig
+++ b/core/fs.zig
@@ -868,7 +868,7 @@ pub const Namespace = struct {
.authority = .{
"socket_path", "tcp_address", "mounts", "node_name", "os_paths", "out",
"listeners", "origin", "no_prompt", "session_write", "unlogged", "capturing",
- "serving", "typed", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len",
+ "serving", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len",
"said", "said_len", "said_at", "late_failure", "late_failure_len",
"lsp_answer_at", "edit_started", "edit_hold", "edit_said", "lsp_result", "write_room",
"write_waits", "log_full_hash", "pages", "closed_lines", "ran_at", "refilled",
@@ -908,12 +908,10 @@ pub const Namespace = struct {
/// which also refuses prompts, which a click may open).
capturing: bool = false,
/// A 9P request is being served (Pardes.serveFs): a prompt it opens is
- /// a question for the log (`ask`), answered with `answer`.
+ /// a question for the log (`ask`), answered with `answer`. Not while
+ /// the keys or the mouse written to `kbdin` or `mousein` run: they are
+ /// the user's own (ninep/ctl.zig writeKbdin).
serving: bool = false,
- /// The request is keys or a mouse written to `kbdin` or `mousein`:
- /// the user's own, so a builtin they reach routes as typed
- /// (Pick.asked), though their write is served as any other.
- typed: bool = false,
refused: bool = false,
failure: [256]u8 = undefined,
failure_len: u16 = 0,
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig
index 2411b20f..17f58e7f 100644
--- a/core/ninep/ctl.zig
+++ b/core/ninep/ctl.zig
@@ -882,7 +882,10 @@ const e_no_pane = "no such pane";
/// rio's kbdin (windows/rio/xfid.c:515): each rune written is a key typed
/// at the pane with the keyboard, the user's own, each done before the next
-/// and all before the write is answered. Control runes are Ctrl and a
+/// and all before the write is answered. They run as the keyboard's, not as
+/// a script's write: what they start on a worker (a picker's listing or
+/// search, a parse, a language server's answer) comes after the answer, as
+/// a keyboard's comes a frame later. Control runes are Ctrl and a
/// letter, but for Plan 9's keys (include/ALL/keyboard.h): \n or \r Enter,
/// \t Tab, \b Backspace, 0x7f Delete, 0x1b Esc, and the arrows, Home, End,
/// Page Up and Down, Insert and F1-F12 at its private-use runes. Its
@@ -890,8 +893,11 @@ const e_no_pane = "no such pane";
/// or Ctrl to the key after them.
pub fn writeKbdin(p: *Pardes, req: Req) Reply {
const view = std.unicode.Utf8View.init(req.data) catch return tree.failText(req.tag, E.INVAL, "invalid UTF-8");
- p.fs.typed = true;
- defer p.fs.typed = false;
+ // The keyboard's path, not a script's write's: nothing waits on the
+ // loop for a picker's source or an answer (Pick.asked, Stream.step).
+ const serving = p.fs.serving;
+ p.fs.serving = false;
+ defer p.fs.serving = serving;
var it = view.iterator();
var mods: pardes.Key = .{ .cp = 0 };
while (it.nextCodepointSlice()) |rune| {
@@ -946,8 +952,10 @@ fn kbdKey(rune: []const u8) pardes.Key {
/// changed since the last line is pressed or released there, in that order
/// of buttons; a move with one held drags, with none moves.
pub fn writeMousein(p: *Pardes, req: Req) Reply {
- p.fs.typed = true;
- defer p.fs.typed = false;
+ // The mouse's path, as kbdin's keys take the keyboard's.
+ const serving = p.fs.serving;
+ p.fs.serving = false;
+ defer p.fs.serving = serving;
var lines = std.mem.tokenizeScalar(u8, req.data, '\n');
while (lines.next()) |line| {
var words = std.mem.tokenizeAny(u8, line, " \t\r");