Skip to content

Capture a single rename-based text edit in the Linux sandbox - #110

Open
daniel-furman wants to merge 5 commits into
mainfrom
capture-rename-edits
Open

daniel-furman wants to merge 5 commits into
mainfrom
capture-rename-edits

Conversation

@daniel-furman

@daniel-furman daniel-furman commented Nov 24, 2026 •

Copy link
Copy Markdown

Adds opt-in verifiedEditRoot on 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.

Chat about this change

~ written by ⠕ Replit

@daniel-furman
daniel-furman marked this pull request as ready for review November 24, 2026 19:45

@Mayank808 Mayank808 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach makes sense to me. One correctness thing on the touched check I'd fix before release, the rest are questions / a simplification.

Comment thread src/edit_snapshot.rs
if !self
.touched
.iter()
.all(|path| *path == edit.source_path || *path == edit.destination_path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

Comment thread src/lib.rs
rules: sandbox_opts
.rules
(opts.sandbox.is_some() || edit_sender.is_some()).then(|| sandbox::Options {
observe_only: opts.sandbox.is_none(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/edit_snapshot.rs
let Some(path) = edit.destination_path.to_str() else {
return;
};
let json = format!(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/edit_snapshot.rs
/// 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants