Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
772a115
Share SSH monitoring connections and persist host retry backoff
sox8502 Oct 22, 2026
ee67264
Fix explicit reconnect, growing logs, and long SSH setup
sox8502 Oct 22, 2026
97df5cd
Require idle SSH monitors before dev-slot data cleanup
sox8502 Oct 22, 2026
d2ee43a
Merge remote-tracking branch 'origin/main' into daniel/or-558-shared-ssh
sox8502 Oct 22, 2026
39cb2e4
Show SSH connection and run monitoring diagnostics
sox8502 Oct 22, 2026
aca6872
Preserve quoted SSH known-hosts filename lists
sox8502 Oct 22, 2026
b06a279
Merge remote-tracking branch 'origin/main' into daniel/or-558-shared-ssh
sox8502 Oct 22, 2026
6d046a0
Merge remote-tracking branch 'origin/main' into daniel/or-558-shared-ssh
sox8502 Oct 22, 2026
18157f6
Include shared SSH log files in run artifact cleanup
sox8502 Oct 22, 2026
575f8fa
Support Python 3.6 remote SSH helpers
sox8502 Oct 22, 2026
74d4901
Merge remote-tracking branch 'origin/main' into daniel/or-558-shared-ssh
sox8502 Oct 22, 2026
cc13526
Finish Slurm runs despite unavailable logs
sox8502 Oct 22, 2026
55af17d
Validate SSH log chunks during concurrent rewrites
sox8502 Oct 22, 2026
778114b
Merge origin/main and preserve shared SSH monitoring compatibility
sox8502 Oct 23, 2026
6025952
Detect full-prefix log rewrites and isolate legacy SSH monitors
sox8502 Oct 23, 2026
1e6c37d
Preserve whitespace in interactive SSH credentials
sox8502 Oct 23, 2026
21906b7
Reuse verified log digests and ignore unrelated obsolete SSH routes
sox8502 Oct 23, 2026
ca8fb01
Merge latest main and rebuild the reviewed dashboard
sox8502 Oct 23, 2026
99e8a39
Keep pinned SSH connections stable across unrelated config edits
sox8502 Oct 23, 2026
5cfb903
Merge current main and migrate saved SSH connection bindings
sox8502 Oct 23, 2026
cde56e5
Merge current main and isolate Slurm status read failures
sox8502 Oct 23, 2026
13b0bdf
Merge current main and close SSH retry and Slurm completion gaps
sox8502 Oct 23, 2026
6bee71f
Stream large SSH command input through bounded upload frames
sox8502 Oct 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Detect full-prefix log rewrites and isolate legacy SSH monitors
  • Loading branch information
sox8502 committed Oct 23, 2026
commit 602595221a02e668918ba08f06855b9d9cca6b68
18 changes: 18 additions & 0 deletions scripts/test_ssh_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ def test_log_bytes_partial_lines_and_replacement(self):
path.unlink()
self.assertTrue(self.rpc(op="log", dir=".orx/runs/test")["missing"])

def test_rewrite_with_unchanged_suffix_replaces_the_collected_prefix(self):
folder = Path(self.home.name) / ".orx/runs/test"
folder.mkdir(parents=True)
path = folder / "log"
original = b"a" * (256 * 1024) + b"z" * 64
path.write_bytes(original)
first = self.rpc(op="log", dir=str(folder))
second = self.rpc(op="log", dir=str(folder), offset=256 * 1024,
identity=first["identity"], boundary=first["boundary"])
for replacement in (b"b" * (256 * 1024) + b"z" * 64,
b"c" * (256 * 1024) + b"z" * 64 + b"appended"):
path.write_bytes(replacement)
changed = self.rpc(op="log", dir=str(folder), offset=len(original),
identity=second["identity"], boundary=second["boundary"])
self.assertTrue(changed["reset"])
self.assertEqual(changed["offset"], 0)
self.assertEqual(base64.b64decode(changed["data"]), replacement[:256 * 1024])

def test_large_logs_are_bounded_and_uploads_do_not_mix(self):
folder = Path(self.home.name) / ".orx/runs/test"
folder.mkdir(parents=True)
Expand Down
28 changes: 19 additions & 9 deletions src/jobs/ssh/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ def execute(command, source=None, timeout=None):
return {"code": child.returncode, "stdout": encode(result), "stderr": encode(error)}


def prefix_digest(file, length):
file.seek(0)
digest = hashlib.sha256()
while length:
chunk = file.read(min(CHUNK, length))
if not chunk:
raise RuntimeError("Remote log changed during collection; retrying.")
digest.update(chunk)
length -= len(chunk)
return digest


def log_chunk(request):
path = os.path.join(os.path.expanduser("~"), request["dir"], "log")
try:
Expand All @@ -80,22 +92,20 @@ def log_chunk(request):
identity = "%s:%s" % (stat.st_dev, stat.st_ino)
offset = request.get("offset", 0)
reset = request.get("identity") != identity or stat.st_size < offset
prefix = b""
digest = hashlib.sha256()
if not reset and offset:
file.seek(max(0, offset - 64))
prefix = file.read(min(64, offset))
reset = hashlib.sha256(prefix).hexdigest() != request.get("boundary")
digest = prefix_digest(file, offset)
Comment thread
sox8502 marked this conversation as resolved.
Resolved
reset = digest.hexdigest() != request.get("boundary")
if reset:
offset = 0
prefix = b""
digest = hashlib.sha256()
file.seek(offset)
data = file.read(CHUNK)
end = offset + len(data)
collected = prefix + data
file.seek(offset - len(prefix))
if file.read(len(collected)) != collected:
digest.update(data)
boundary = digest.hexdigest()
if prefix_digest(file, end).hexdigest() != boundary:
raise RuntimeError("Remote log changed during collection; retrying.")
boundary = hashlib.sha256(collected[-64:]).hexdigest()
return {"identity": identity, "reset": reset, "offset": offset,
"data": encode(data), "boundary": boundary, "size": stat.st_size, "eof": end >= os.fstat(file.fileno()).st_size}

Expand Down
14 changes: 13 additions & 1 deletion src/jobs/ssh/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,19 @@ impl Broker {
) && crate::commands::supervise::supervisor_running(&run.id)
&& !crate::commands::supervise::uses_shared_ssh(&run.id)
{
return Err(anyhow!("Run {} is monitored by an older OpenResearch process. Restart that monitor with the updated version before using shared SSH; its lock has not been taken over.", run.id));
let legacy_target = match descriptor.kind.as_str() {
"ssh_job" | "slurm_job" => {
descriptor.namespace.as_deref().map(SshTarget::alias)
}
"openresearch_job" => descriptor.openresearch_ssh_target(),
_ => None,
};
if let Some(legacy_target) = legacy_target {
let legacy = state::resolve(&legacy_target.for_run(&run.id)).await?;
if legacy.key == host.resolved.key {
return Err(anyhow!("Run {} is monitored by an older OpenResearch process. Restart that monitor with the updated version before using shared SSH; its lock has not been taken over.", run.id));
}
}
}
}
state::reserve_attempt(&host.resolved.key)?;
Expand Down
49 changes: 47 additions & 2 deletions tests/compute_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ esac
for case in [
"healthy",
"backoff",
"legacy_other",
"legacy_same",
"rejection",
"exit_zero",
"stop_failure",
Expand Down Expand Up @@ -431,8 +433,41 @@ esac
)
.unwrap();
}
let legacy = matches!(case, "legacy_other" | "legacy_same");
let mut legacy_lock = if legacy {
let output = sandbox
.command()
.env("ORX_DATA_DIR", &data)
.args(["projects", "--json"])
.output()
.unwrap();
assert!(output.status.success());
let db = rusqlite::Connection::open(data.join("orx.db")).unwrap();
let host = if case == "legacy_same" {
"lab"
} else {
"unrelated-host"
};
let backend = json!({"kind":"ssh_job", "namespace":host, "jobId":".orx/runs/legacy"});
db.execute("INSERT INTO local_experiments (id, project_id, slug, branch_name, run_command, created_at, updated_at) VALUES ('exp','project','exp','main','true',0,0)", []).unwrap();
db.execute("INSERT INTO runs (id, experiment_id, project_id, status, backend_json, created_at, updated_at) VALUES ('legacy','exp','project','running',?1,0,0)", [backend.to_string()]).unwrap();
std::fs::create_dir_all(data.join("run-logs")).unwrap();
Some(fd_lock::RwLock::new(
std::fs::File::create(data.join("run-logs/legacy.supervisor.lock")).unwrap(),
))
} else {
None
};
let _legacy_guard = legacy_lock.as_mut().map(|lock| lock.write().unwrap());
builder.env("ORX_DATA_DIR", &data);
builder.env("CASE", if case == "backoff" { "healthy" } else { case });
builder.env(
"CASE",
if case == "backoff" || legacy {
"healthy"
} else {
case
},
);
builder.args(["compute", "connect", "ssh", "--host", "lab"]);
let pair = native_pty_system().openpty(PtySize::default()).unwrap();
let mut child = pair.slave.spawn_command(builder).unwrap();
Expand All @@ -447,13 +482,23 @@ esac
let calls = std::fs::read_to_string(sandbox.0.join("calls")).unwrap();
let socket = PathBuf::from(std::fs::read_to_string(sandbox.0.join("socket-path")).unwrap());
let output = String::from_utf8_lossy(&output);
if legacy {
rusqlite::Connection::open(data.join("orx.db"))
.unwrap()
.execute("UPDATE runs SET status='cancelled' WHERE id='legacy'", [])
.unwrap();
}
match case {
"healthy" | "backoff" => {
"healthy" | "backoff" | "legacy_other" => {
assert!(status.success(), "{output}");
assert!(!calls.contains("-O stop"));
assert!(socket.exists());
assert!(output.contains("LOGIN"));
}
"legacy_same" => {
assert!(!status.success(), "{output}");
assert!(output.contains("older OpenResearch process"), "{output}");
}
"rejection" | "exit_zero" => {
assert!(status.success(), "{output}");
assert!(calls.find("-O stop").unwrap() < calls.find("-- lab true").unwrap());
Expand Down
Loading