Repository navigation
Capture a single rename-based text edit in the Linux sandbox - #110
daniel-furman wants to merge 5 commits into
Conversation
Assisted-by: Replit
Assisted-by: Replit
Assisted-by: Replit
Mayank808
left a comment
There was a problem hiding this comment.
Approach makes sense to me. One correctness thing on the touched check I'd fix before release, the rest are questions / a simplification.
| if !self | ||
| .touched | ||
| .iter() | ||
| .all(|path| *path == edit.source_path || *path == edit.destination_path) |
There was a problem hiding this comment.
I think this lets an earlier write to the destination through. echo x >> f && sed -i s/a/b/ f: the append lands in touched as f, which passes here, and before is read at rename time so it already has the append. The diff would show only the sed change. Can we taint on any non-rename write to the destination, and add that script to it_reports_nothing_for_unattributable_commands? (Read from the code, I haven't run it.)
| rules: sandbox_opts | ||
| .rules | ||
| (opts.sandbox.is_some() || edit_sender.is_some()).then(|| sandbox::Options { | ||
| observe_only: opts.sandbox.is_none(), |
There was a problem hiding this comment.
This turns the tracer on for shells that had no rules before (conversation agents). Repl-bound shells already run traced because of the git guard, so it's probably fine, but could you time one syscall-heavy command with and without capture, and check sudo / strace still behave in the Ubuntu sandbox? Worth a line in the description.
| let Some(path) = edit.destination_path.to_str() else { | ||
| return; | ||
| }; | ||
| let json = format!( |
There was a problem hiding this comment.
Simplification: snapshots are already NUL-free and a path can't contain NUL, so we could send path\0before\0after. That drops json_string, the 208 KiB buffer, and the JSON.parse + schema check on the pid2 side.
| /// Called at syscall exit with the syscall's return value. | ||
| pub(crate) fn exit(&mut self, pid: Pid, result: i64) { | ||
| if self.terminal_opens.remove(&pid) && result >= 0 { | ||
| // Bash opens /dev/tty for job control. With a filesystem-root workspace, |
There was a problem hiding this comment.
Is a workspace rooted at / a real setup? With that root, > /dev/null or anything writing to /tmp also lands in touched and kills the capture, so the /dev/tty exemption may not buy much. If it's not real we can drop terminal_opens entirely.
The before snapshot is read at rename time, so an earlier append or overwrite of the destination was folded into it and left out of the diff. Assisted-by: Replit
A path check misses writes that reach the file through '..' from outside the workspace, a symlink, or /proc/self/cwd. Record the inode behind every descriptor opened for writing and skip the report if the replaced file was one of them. truncate(2) now also skips the report. Assisted-by: Replit
Adds opt-in
verifiedEditRooton Linux. A successful command can report a single small rename replacement without parsing shell source or standard output. This works with or without path rules; configured rules still apply.The tracer sends before and after text on a private socket instead of a result file. Call
takeVerifiedEdit()after exit. Files must be single-link UTF-8 under the supplied root, contain no NUL bytes, and be at most 16 KiB. Unverified, unchanged or ambiguous edits produce no record.Draft for API and attribution review, not a release. Tested a rename followed by a read-only check. All 12 library tests passed with one test thread. The existing descriptor test was flaky with the parallel runner.
~ written by ⠕ Replit