diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 04:21:37 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 04:36:28 -0300 |
| commit | e1a47cef599070e3ea268255ef4c1164e4a3169b (patch) | |
| tree | e8f31d971181f1e988bea94f5ab112333c566b2d /core/ninep | |
| parent | 6e8735895d04c0073eb28cc1a2f431a2ba587e9d (diff) | |
| download | pardes-e1a47cef599070e3ea268255ef4c1164e4a3169b.tar.gz pardes-e1a47cef599070e3ea268255ef4c1164e4a3169b.zip | |
ninep: a client attached while a script's pty/run runs in a shell replays it as its session does: the open's handle is the session's 9P server's answer (tape.authority), not the client's first free open record, which a client joined since (holding none of the opens made before its join) chose otherwise, so its write named no record and its run never went (the base, the attach agent's probe: 6 of 6 runs a client diverged, "the core called prompt where the tape has a done"); and a run's step reads the shell's marks through the tape's prompt site (pty.marksOf, as the greeting and the run's answer did), not the emulator here, which on a client of screen-state terminals is the last delta's and comes a frame after the unit that replays the output (with the handle alone 3 of 6 still diverged: sent_command's count and the busy check read marks behind the session's); Pane.noteCommand takes the count from its caller; a client whose rejoin lands as its session ends goes as at a hang-up, in the same words ("let this client go"), never "could not join again: the session hung up before the dump was whole" (replica.ended: hung up, nothing answers, no such session); tests: a client joined from a dump with a listing open held across the join takes a run as the session does (failed on the base: its digest), the same with screen-state terminals and their deltas after each unit (failed with the handle fix alone: "the core did not make the host call the tape has, in output"), and the rejoin test says a session gone and one hung up mid-dump are its end; the tape's results list Term.Prompt, so the semantics word moves: 7a610621b2f37456 -> 92963bab2e4436fb; probe (exitclient.py, 6 runs): 0 of 6 diverge, 0 of 3 with a digest every unit (PARDES_REPLICA_TRACE); a pty/data-only variant diverged 0 of 2 on this build too; tui core-test 856/1009 (153 skipped: the two new tests need a shell), shell-test 1049/1052 (load 15-20)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/ninep')
| -rw-r--r-- | core/ninep/pty.zig | 14 | ||||
| -rw-r--r-- | core/ninep/tree.zig | 15 |
2 files changed, 23 insertions, 6 deletions
diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig index 26bb7661..e2b5e842 100644 --- a/core/ninep/pty.zig +++ b/core/ninep/pty.zig @@ -220,7 +220,7 @@ pub fn writeRun(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { for (line) |c| if (c < ' ' and c != '\t') return tree.failText(req.tag, E.INVAL, e_bad_line); const pf = &pane.fs; if (pane.terminal == null) return tree.failText(req.tag, E.INVAL, e_bad_line); - const marks = pardes.Term.prompt(pane.terminal); + const marks = marksOf(pane); if (pane.shell_failed) { // Its shell never started: no prompt is coming to wait for. answer(p, slot, "error shell gone", .{}); @@ -288,7 +288,7 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { if (pane.terminal == null) return; const pf = &pane.fs; const slot = waitingRun(p, pane) orelse return; - const marks = pardes.Term.prompt(pane.terminal); + const marks = marksOf(pane); if (slot.phase == .waiting) { if (pf.unmarked) { answer(p, slot, "error no prompt marks", .{}); @@ -305,7 +305,7 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { if (pardes.Term.modes(pane.terminal).alternate) pane.feedOutput(p, "\x1b[?1049l"); p.emitWrite(id, slot.line); p.emitWrite(id, "\r"); - pane.noteCommand(slot.line); + pane.noteCommand(slot.line, marks.started); // The run is the shell's first command: a greeting `ls` typed at the // same prompt would run after it, and its C would be taken for ours. pane.greet = false; @@ -360,6 +360,14 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { finish(p, slot, pane, done.status); } +/// The shell's marks as the session's emulator has them (taped), as a +/// run's step reads them: a screen-state replica's emulator is the last +/// delta's, which comes at a frame and can be a unit behind the one it +/// replays. +fn marksOf(pane: *const Pane) pardes.Term.Prompt { + return pardes.tape.value(.prompt, pardes.Term.prompt, .{pane.terminal}); +} + /// Answers a run whose command ended with `status`: the header and the /// output it printed. fn finish(p: *Pardes, slot: *Run, pane: *Pane, status_code: ?i32) void { diff --git a/core/ninep/tree.zig b/core/ninep/tree.zig index 46a4e3d2..1eaaa8cb 100644 --- a/core/ninep/tree.zig +++ b/core/ninep/tree.zig @@ -928,9 +928,11 @@ fn open(p: *Pardes, req: Req, target: Target) Reply { }; }, }; - const i = for (p.fs.opens, 0..) |o, i| { - if (o.node == 0) break i; - } else return Reply.fail(req.tag, E.NFILE); + // The handle every later request of this open names: the session's 9P + // server's, told to a replica as the answer it was. A client joined + // since holds none of the opens made before it, and its first free + // record would be another than the session's. + const i = p.tape.authority(freeOpen, .{p}) orelse return Reply.fail(req.tag, E.NFILE); const o = &p.fs.opens[i]; o.* = .{ .node = req.node, .what = what }; if (resultsFile(target)) { @@ -969,6 +971,13 @@ fn open(p: *Pardes, req: Req, target: Target) Reply { return .{ .tag = req.tag, .handle = @intCast(i + 1) }; } +/// The first open record free. +fn freeOpen(p: *Pardes) ?u64 { + return for (p.fs.opens, 0..) |o, i| { + if (o.node == 0) break i; + } else null; +} + /// Tremove closes a pane. Nothing else in the tree can be removed, and this /// is also where an ORCLOSE open lands, so every node is checked here. fn remove(p: *Pardes, req: Req) Reply { |
