Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix: export the session artifact dir as the kernel's local harness store (#3564)

Sebastian Müller33da15a2c15c
diff --git a/crates/pa-core/src/session_engine/runtime_wiring.rs b/crates/pa-core/src/session_engine/runtime_wiring.rs
index 5d2f6f3ccf..31165418e0 100644
--- a/crates/pa-core/src/session_engine/runtime_wiring.rs
+++ b/crates/pa-core/src/session_engine/runtime_wiring.rs
@@ -209,7 +209,9 @@ pub fn kernel_python_skills(skills: &[Skill]) -> Vec<KernelPythonSkill> {
/// Build the kernel provisioner for a session: host handlers for the goal/heartbeat bridge
/// plus the pre-imported skills. The session's agent dir is propagated into the kernel env
/// (`PRIME_AGENT_CODING_AGENT_DIR`): an embedding host whose ambient env differs must not
-/// leak its own paths into the kernel (#109). `cwd` is the SESSION's working directory.
+/// leak its own paths into the kernel (#109). A persistent session's artifact dir is
+/// likewise propagated (`RLM_SESSION_DIR` + `RLM_HARNESS_STATE_DIR`), so kernel-side
+/// harness writes land in the session-local store. `cwd` is the SESSION's working directory.
/// `shell_path` is the session-start-resolved kernel shell: an invalid `shellPath` fails
/// `create_session`, not the kernel boot.
#[allow(clippy::too_many_arguments)] // one wiring funnel, same style as AgentSession::from_session_arc
@@ -221,17 +223,28 @@ pub fn kernel_provisioner(
cwd: std::path::PathBuf,
agent_dir: &std::path::Path,
shell_path: Option<std::path::PathBuf>,
- snapshot_dir: Option<std::path::PathBuf>,
+ session_artifact_dir: Option<std::path::PathBuf>,
on_restore: Option<crate::kernel::provisioner::RestoreCallback>,
on_background_work_settled: Option<crate::kernel::shared::BackgroundWorkSettledCallback>,
on_unavailable_skills: Option<crate::kernel::provisioner::UnavailableSkillsCallback>,
on_bootstrap_result: Option<crate::kernel::provisioner::KernelBootstrapResultHandler>,
) -> Arc<KernelProvisioner> {
- let mut env = HashMap::with_capacity(1);
+ let mut env = HashMap::with_capacity(3);
env.insert(
"PRIME_AGENT_CODING_AGENT_DIR".to_string(),
agent_dir.to_string_lossy().to_string(),
);
+ for (key, value) in [
+ ("RLM_SESSION_DIR", session_artifact_dir.clone()),
+ (
+ "RLM_HARNESS_STATE_DIR",
+ crate::refinement::get_local_harness_state_dir(session_artifact_dir.as_deref()),
+ ),
+ ] {
+ if let Some(value) = value {
+ env.insert(key.to_string(), value.to_string_lossy().to_string());
+ }
+ }
Arc::new(KernelProvisioner::new(
cwd,
IpythonKernelProvisionerOptions {
@@ -244,7 +257,7 @@ pub fn kernel_provisioner(
python_skills,
// Only persistent sessions (which have an artifact dir) get
// a revivable snapshot (TS `snapshotDir`).
- snapshot_dir,
+ snapshot_dir: session_artifact_dir,
ready_gate: None,
on_restore,
on_background_work_settled,
diff --git a/crates/pa-daemon/tests/kernel_harness_env_e2e.rs b/crates/pa-daemon/tests/kernel_harness_env_e2e.rs
new file mode 100644
index 0000000000..b0f91618a0
--- /dev/null
+++ b/crates/pa-daemon/tests/kernel_harness_env_e2e.rs
@@ -0,0 +1,304 @@
+//! Kernel harness-env e2e: a persisted session's kernel must carry the session's RLM
+//! session + local-harness dirs in its env (TS `_rlmKernelEnv`), so kernel-side
+//! `rlm.harness` writes land in the session-local store. Skips (with a note)
+//! without a live kernel install.
+#![cfg(unix)]
+
+use std::io::{BufRead, BufReader, Write};
+use std::os::unix::net::UnixStream;
+use std::path::{Path, PathBuf};
+use std::process::{Child, Command, Stdio};
+use std::time::{Duration, Instant};
+
+use serde_json::{json, Value};
+
+/// The kernel Python with prime-agent-runtime installed; set
+/// `PA_E2E_KERNEL_PYTHON` to point at an explicit interpreter instead.
+fn kernel_python() -> Option<PathBuf> {
+ if let Some(explicit) = std::env::var_os("PA_E2E_KERNEL_PYTHON") {
+ let explicit = PathBuf::from(explicit);
+ assert!(
+ explicit.exists(),
+ "PA_E2E_KERNEL_PYTHON {} not found",
+ explicit.display()
+ );
+ return Some(explicit);
+ }
+ let candidate = PathBuf::from(std::env::var("HOME").map_or_else(
+ |_| "/home/ubuntu/.prime/agent/kernel-venv/bin/python".to_string(),
+ |home| format!("{home}/.prime/agent/kernel-venv/bin/python"),
+ ));
+ if candidate.exists() {
+ return Some(candidate);
+ }
+ eprintln!(
+ "kernel python {} not found; skipping live kernel-harness-env e2e",
+ candidate.display()
+ );
+ None
+}
+
+struct Daemon {
+ child: Child,
+}
+
+impl Drop for Daemon {
+ fn drop(&mut self) {
+ let _ = self.child.kill();
+ let _ = self.child.wait();
+ }
+}
+
+#[allow(clippy::zombie_processes)]
+fn spawn_supervisor(socket: &Path, agent_dir: &Path, kernel_python: &Path) -> Daemon {
+ std::fs::create_dir_all(agent_dir).expect("agent dir");
+ let child = Command::new(env!("CARGO_BIN_EXE_pa-daemon"))
+ .arg("supervisor")
+ .arg("--socket")
+ .arg(socket)
+ .arg("--agent-dir")
+ .arg(agent_dir)
+ .env("PRIME_AGENT_KERNEL_PYTHON", kernel_python)
+ // Hermetic agent dir: point every fallback at the test sandbox.
+ .env("PRIME_AGENT_CODING_AGENT_DIR", agent_dir)
+ // Hermetic harness resolution: ambient session/harness dirs would
+ // mask a missing kernel-env export (the regression this test guards).
+ .env_remove("RLM_SESSION_DIR")
+ .env_remove("RLM_HARNESS_STATE_DIR")
+ .env_remove("RLM_GLOBAL_HARNESS_STATE_DIR")
+ .stdout(Stdio::null())
+ .stderr(Stdio::null())
+ .env(
+ pa_daemon::worker::WORKER_SUPERVISOR_LOST_EXIT_MS_ENV,
+ "15000",
+ )
+ .spawn()
+ .expect("spawn pa-daemon supervisor");
+ Daemon { child }
+}
+
+fn wait_socket_ready(socket: &Path) {
+ let deadline = Instant::now() + Duration::from_secs(15);
+ loop {
+ if UnixStream::connect(socket).is_ok() {
+ return;
+ }
+ assert!(Instant::now() < deadline, "supervisor socket never came up");
+ std::thread::sleep(Duration::from_millis(20));
+ }
+}
+
+/// JSONL supervisor client (command envelopes, id-matched responses).
+struct Client {
+ reader: BufReader<UnixStream>,
+ writer: UnixStream,
+}
+
+impl Client {
+ fn connect(socket: &Path) -> (Self, Value) {
+ let stream = UnixStream::connect(socket).expect("connect supervisor");
+ let writer = stream.try_clone().expect("clone socket");
+ let mut client = Client {
+ reader: BufReader::new(stream),
+ writer,
+ };
+ let hello = client.read_line();
+ (client, hello)
+ }
+
+ fn send_command(&mut self, id: &str, command: &Value) {
+ self.write_line(&json!({
+ "type": "command",
+ "id": id,
+ "protocol": { "name": "prime-agent.daemon", "version": 7 },
+ "command": command,
+ }));
+ }
+
+ fn write_line(&mut self, value: &Value) {
+ let mut line = serde_json::to_string(value).expect("serialize line");
+ line.push('\n');
+ self.writer.write_all(line.as_bytes()).expect("send");
+ self.writer.flush().expect("flush");
+ }
+
+ fn read_line(&mut self) -> Value {
+ let mut line = String::new();
+ let deadline = Instant::now() + Duration::from_mins(2);
+ self.reader
+ .get_mut()
+ .set_read_timeout(Some(Duration::from_millis(100)))
+ .expect("set timeout");
+ loop {
+ match self.reader.read_line(&mut line) {
+ Ok(0) => panic!("supervisor closed the connection"),
+ Ok(_) if line.trim().is_empty() => line.clear(),
+ Ok(_) => return serde_json::from_str(line.trim()).expect("parse line"),
+ Err(error) => {
+ assert!(
+ Instant::now() < deadline,
+ "timed out waiting for supervisor line: {error}"
+ );
+ }
+ }
+ }
+ }
+
+ fn read_response(&mut self, id: &str) -> Value {
+ let deadline = Instant::now() + Duration::from_mins(4);
+ loop {
+ assert!(Instant::now() < deadline, "no response for id {id}");
+ let line = self.read_line();
+ if line.get("id").and_then(Value::as_str) == Some(id) {
+ return line;
+ }
+ }
+ }
+}
+
+/// The one scripted cell: create + read back a session-local memory and a global
+/// one, recording success or the failure traceback in a receipt.
+fn harness_cell(receipt: &Path) -> String {
+ format!(
+ "import json, traceback\nreceipt = {{\"ok\": False, \"error\": \"\"}}\ntry:\n rlm.harness.create_memory(title=\"kernel session-local memory\", content=\"persisted from the session kernel\", id=\"kernel-local-memory\")\n rlm.get_harness_state().entries[\"memory\"][\"kernel-local-memory\"]\n rlm.harness.create_memory(title=\"kernel global memory\", content=\"persisted from the session kernel\", id=\"kernel-global-memory\", global_=True)\n receipt = {{\"ok\": True, \"error\": \"\"}}\nexcept Exception:\n receipt = {{\"ok\": False, \"error\": traceback.format_exc()}}\nopen({receipt_path:?}, \"w\").write(json.dumps(receipt))\n",
+ receipt_path = receipt.to_string_lossy(),
+ )
+}
+
+fn write_faux_script(dir: &Path, cell: &str) -> PathBuf {
+ let script = dir.join("faux.json");
+ std::fs::write(
+ &script,
+ json!({
+ "engine": "faux",
+ "responses": [
+ { "content": [
+ { "type": "toolCall", "name": "python_repl", "arguments": {
+ "code": cell,
+ } },
+ ] },
+ { "text": "done" },
+ ],
+ })
+ .to_string(),
+ )
+ .expect("write faux script");
+ script
+}
+
+/// The stored entry equals the one the cell created, apart from its timestamps.
+fn assert_stored_memory(state: &Value, id: &str, title: &str, content: &str, scope: &str) {
+ let mut entry = state["entries"]["memory"][id].clone();
+ assert!(entry.is_object(), "memory entry {id} missing: {state}");
+ entry["created_at"] = json!("<timestamp>");
+ entry["updated_at"] = json!("<timestamp>");
+ assert_eq!(
+ entry,
+ json!({
+ "id": id,
+ "kind": "memory",
+ "title": title,
+ "content": content,
+ "path": "general",
+ "scope": scope,
+ "reference": {},
+ "arguments": {},
+ "metadata": {},
+ "source": "agent",
+ "version": 1,
+ "created_at": "<timestamp>",
+ "updated_at": "<timestamp>",
+ }),
+ "the stored {scope} memory entry diverged"
+ );
+}
+
+fn read_state(path: &Path) -> Value {
+ let content = std::fs::read_to_string(path).expect("read harness state");
+ serde_json::from_str(&content).expect("parse harness state")
+}
+
+#[test]
+fn persistent_session_kernel_writes_the_session_local_harness_store() {
+ let Some(kernel_python) = kernel_python() else {
+ return;
+ };
+ let dir = tempfile::TempDir::new().expect("temp dir");
+ let agent_dir = dir.path().join("agent");
+ let socket = dir.path().join("supervisor.sock");
+ let receipts_dir = dir.path().join("receipts");
+ std::fs::create_dir_all(&receipts_dir).expect("receipts dir");
+ let receipt = receipts_dir.join("harness.json");
+ let script = write_faux_script(dir.path(), &harness_cell(&receipt));
+
+ let _daemon = spawn_supervisor(&socket, &agent_dir, &kernel_python);
+ wait_socket_ready(&socket);
+ let (mut client, hello) = Client::connect(&socket);
+ assert_eq!(hello["type"], "daemon_hello");
+
+ // A persisted session: its artifact dir is `dirname(sessionDir)/session-artifacts/<id>`
+ // (the same rule the session manager applies).
+ let sessions_dir = dir.path().join("sessions");
+ std::fs::create_dir_all(&sessions_dir).expect("sessions dir");
+ client.send_command(
+ "c1",
+ &json!({
+ "type": "create",
+ "config": {
+ "cwd": dir.path().to_string_lossy(),
+ "sessionDir": sessions_dir.to_string_lossy(),
+ "script": script.to_string_lossy(),
+ },
+ }),
+ );
+ let created = client.read_response("c1");
+ assert_eq!(created["success"], true, "create failed: {created}");
+ let session_id = created["data"]["sessionId"].as_str().expect("session id");
+
+ client.send_command(
+ "t1",
+ &json!({ "type": "prompt", "activeSessionId": session_id, "message": "run the cell" }),
+ );
+ let prompted = client.read_response("t1");
+ assert_eq!(prompted["success"], true, "prompt failed: {prompted}");
+ client.send_command(
+ "t1-idle",
+ &json!({ "type": "wait_for_idle", "activeSessionId": session_id }),
+ );
+ let idle = client.read_response("t1-idle");
+ assert_eq!(idle["success"], true, "wait_for_idle failed: {idle}");
+
+ // The turn ended, so the cell's receipt is written: a `false` ok carries the
+ // kernel-side failure (the instructive error when the env vars are missing).
+ let cell_receipt = std::fs::read_to_string(&receipt)
+ .unwrap_or_else(|error| panic!("kernel cell receipt missing: {error}"));
+ let cell_receipt: Value =
+ serde_json::from_str(&cell_receipt).expect("parse kernel cell receipt");
+ assert_eq!(
+ cell_receipt["ok"],
+ true,
+ "the kernel cell failed: {}",
+ cell_receipt["error"].as_str().unwrap_or_default()
+ );
+
+ // The session-local store is the artifact dir's harness file.
+ let artifact_dir = dir.path().join("session-artifacts").join(session_id);
+ let local_state_file = artifact_dir.join("harness").join("harness_state.json");
+ assert_stored_memory(
+ &read_state(&local_state_file),
+ "kernel-local-memory",
+ "kernel session-local memory",
+ "persisted from the session kernel",
+ "local",
+ );
+
+ // The global store stays the agent dir's harness file.
+ let global_state_file = agent_dir.join("harness").join("harness_state.json");
+ assert_stored_memory(
+ &read_state(&global_state_file),
+ "kernel-global-memory",
+ "kernel global memory",
+ "persisted from the session kernel",
+ "global",
+ );
+}
diff --git a/scripts/review_local_harness_parity.py b/scripts/review_local_harness_parity.py
new file mode 100644
index 0000000000..eb2872f792
--- /dev/null
+++ b/scripts/review_local_harness_parity.py
@@ -0,0 +1,235 @@
+#!/usr/bin/env python3
+"""Drive real TS/Rust REPLs through session-local/global memory CRUD and isolation.
+
+Uses the restore-notice verifier's loopback-provider protocol and subprocess
+isolation. Compares actual tool results and persisted files, not source strings.
+Only volatile timestamps, fixture roots and generated session IDs are normalized.
+Tool names (legacy ipython/python_repl) are selected from each binary's offer.
+"""
+import argparse
+import http.server
+import json
+import os
+from pathlib import Path
+import sys
+import tempfile
+import threading
+
+from review_restore_notice_parity import invoke, texts, Server, sha256, TS_ARCHIVE_SHA256
+
+MARKER = 'LOCAL_HARNESS_PARITY='
+READ = """import os, json, dataclasses
+state = rlm.get_harness_state()
+def entry(value):
+ if value is None:
+ return None
+ row = dataclasses.asdict(value)
+ for key in ('created_at', 'updated_at'):
+ row[key] = '<timestamp>'
+ return row
+result = {
+ 'env': {key: os.environ.get(key) for key in ('RLM_SESSION_DIR', 'RLM_HARNESS_STATE_DIR', 'RLM_GLOBAL_HARNESS_STATE_DIR')},
+ 'local': entry(state.get('memory', 'parity-local')),
+ 'global': entry(state.get('memory', 'parity-global', global_=True)),
+ 'deleted': entry(state.get('memory', 'parity-delete')),
+ 'local_ids': sorted(item.id for item in state.list('memory')),
+ 'global_ids': sorted(item.id for item in state.list('memory', global_=True)),
+}
+print('LOCAL_HARNESS_PARITY=' + json.dumps(result))"""
+SETUP = """rlm.harness.create_memory(title='local initial', content='local initial body', id='parity-local')
+rlm.harness.update_memory(id='parity-local', title='local updated', content='local updated body')
+rlm.harness.create_memory(title='global initial', content='global initial body', id='parity-global', global_=True)
+rlm.harness.update_memory(id='parity-global', title='global updated', content='global updated body', global_=True)
+rlm.harness.create_memory(title='delete me', content='temporary', id='parity-delete')
+assert rlm.harness.delete_memory('parity-delete') is True
+rlm.harness.create_memory(title='delete global', content='temporary', id='parity-delete-global', global_=True)
+assert rlm.harness.delete_memory('parity-delete-global', global_=True) is True
+""" + READ
+
+
+class Handler(http.server.BaseHTTPRequestHandler):
+ def log_message(self, *_args):
+ pass
+
+ def do_POST(self):
+ if self.path != '/v1/chat/completions':
+ self.send_error(404)
+ return
+ body = json.loads(self.rfile.read(int(self.headers['Content-Length'])))
+ requests = self.server.requests[self.server.phase]
+ requests.append(body)
+ if len(requests) == 1:
+ offered = {tool.get('function', {}).get('name') for tool in body.get('tools', [])}
+ name = next((name for name in ('python_repl', 'ipython') if name in offered), None)
+ if name is None:
+ self.send_error(422, 'No supported Python REPL tool offered')
+ return
+ self.server.tool_names[self.server.phase] = name
+ delta = {'tool_calls': [{'index': 0, 'id': 'call_' + self.server.phase,
+ 'type': 'function', 'function': {'name': name, 'arguments': json.dumps({
+ 'code': SETUP if self.server.phase == 'setup' else READ})}}]}
+ finish = 'tool_calls'
+ else:
+ delta, finish = {'content': 'Fixture complete.'}, 'stop'
+ def chunk(delta, reason=None):
+ return {'id': 'harness-parity', 'object': 'chat.completion.chunk', 'created': 1,
+ 'model': 'harness-fixture', 'choices': [{'index': 0, 'delta': delta,
+ 'finish_reason': reason}]}
+ wire = ''.join('data: ' + json.dumps(item) + '\n\n' for item in (
+ chunk({'role': 'assistant', **delta}), chunk({}, finish))) + 'data: [DONE]\n\n'
+ self.send_response(200)
+ self.send_header('Content-Type', 'text/event-stream')
+ self.send_header('Content-Length', str(len(wire.encode())))
+ self.end_headers()
+ self.wfile.write(wire.encode())
+
+
+def current_probe(requests, phase):
+ """Read only this phase's completed tool call, never historical results."""
+ assert requests, 'missing provider requests'
+ tool_id = 'call_' + phase
+ messages = requests[-1].get('messages', [])
+ calls = [call for message in messages if message.get('role') == 'assistant'
+ for call in message.get('tool_calls', []) if call.get('id') == tool_id]
+ assert len(calls) == 1, 'missing or duplicate current phase tool call ' + tool_id
+ results = [message for message in messages if message.get('role') == 'tool'
+ and message.get('tool_call_id') == tool_id]
+ assert len(results) == 1, 'missing or duplicate current phase tool result ' + tool_id
+ probes = [json.loads(line[len(MARKER):]) for text in texts(results[0].get('content'))
+ for line in text.splitlines() if line.startswith(MARKER)]
+ assert len(probes) == 1, 'missing or duplicate current phase probe ' + tool_id
+ return probes[0]
+
+
+def stored(path):
+ state = json.loads(path.read_text())
+ rows = state['entries']['memory']
+ for row in rows.values():
+ for key in ('created_at', 'updated_at'):
+ row[key] = '<timestamp>'
+ return rows
+
+
+def run_case(binary, label, root, observation):
+ for name in ('home', 'agent', 'sessions', 'work', 'tmp'):
+ (root / name).mkdir(parents=True)
+ cwd, agent, sessions = root / 'work', root / 'agent', root / 'sessions'
+ env = {key: os.environ[key] for key in ('PATH', 'LANG', 'LC_ALL', 'TZ',
+ 'PRIME_AGENT_KERNEL_PYTHON', 'PA_E2E_KERNEL_PYTHON', 'PYTHONPATH') if key in os.environ}
+ library = Path(os.environ['PI_PACKAGE_DIR'])
+ if label == 'ts':
+ env['PI_PACKAGE_DIR'] = str(library)
+ env.update(HOME=str(root / 'home'), TMPDIR=str(root / 'tmp'), DO_NOT_TRACK='1',
+ PI_OFFLINE='1', PI_CODING_AGENT_DIR=str(agent), PRIME_AGENT_CODING_AGENT_DIR=str(agent),
+ PI_SESSION_DIR=str(sessions), PRIME_AGENT_SESSION_DIR=str(sessions),
+ XDG_CONFIG_HOME=str(root / 'config'), XDG_CACHE_HOME=str(root / 'cache'),
+ XDG_DATA_HOME=str(root / 'data'))
+ # Common skill imports only; never inject RLM_* harness paths, which would
+ # mask the missing runtime exports this PR repairs.
+ env['PYTHONPATH'] = os.pathsep.join(sorted(str(p) for p in (library / 'skills').glob('*/src')
+ if p.is_dir()) + [env.get('PYTHONPATH', '')])
+ server = Server(root)
+ server.RequestHandlerClass = Handler
+ server.requests['other'] = []
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
+ thread.start()
+ (agent / 'models.json').write_text(json.dumps({'providers': {'fixture': {
+ 'api': 'openai-completions', 'apiKey': 'fixture-only',
+ 'baseUrl': 'http://127.0.0.1:%s/v1' % server.server_address[1],
+ 'models': [{'id': 'harness-fixture', 'name': 'Harness fixture', 'reasoning': False,
+ 'contextWindow': 128000, 'maxTokens': 4096}]}}}))
+ (agent / 'settings.json').write_text(json.dumps({'defaultProvider': 'fixture',
+ 'defaultModel': 'harness-fixture', 'prewarmPythonKernel': False}))
+ command = [str(binary), '--mode', 'json', '--provider', 'fixture', '--model',
+ 'harness-fixture', '--session-dir', str(sessions)]
+ try:
+ observation['version'] = invoke([str(binary), '--version'], cwd, env)['stdout'].strip()
+ probes = {}
+ original = None
+ for phase in ('setup', 'resume', 'other'):
+ server.phase = phase
+ args = ['--resume', str(original)] if phase == 'resume' else []
+ observation[phase] = invoke(command + args + ['Run the harness parity cell.'], cwd, env)
+ observation[phase]['requests'] = server.requests[phase]
+ probe = current_probe(server.requests[phase], phase)
+ assert len(server.requests[phase]) == 2, 'unexpected provider request sequence'
+
+ files = [p for p in sessions.rglob('*.jsonl')
+ if json.loads(p.read_text().splitlines()[0]).get('type') == 'session']
+ if phase == 'setup':
+ assert len(files) == 1, files
+ original = files[0]
+ current = original if phase != 'other' else next(p for p in files if p != original)
+ session_id = json.loads(current.read_text().splitlines()[0])['id']
+ artifact = root / 'session-artifacts' / session_id
+ assert probe['env']['RLM_SESSION_DIR'] == str(artifact), probe['env']
+ assert probe['env']['RLM_HARNESS_STATE_DIR'] == str(artifact / 'harness'), probe['env']
+ # The effective global destination is checked on disk below; record
+ # any optional explicit global env export difference without hiding it.
+ expected_global_env = str(agent / 'harness') if label == 'ts' else None
+ assert probe['env']['RLM_GLOBAL_HARNESS_STATE_DIR'] == expected_global_env, probe['env']
+ observation[phase]['kernel_env'] = probe.pop('env')
+ assert probe['local_ids'] == ([] if phase == 'other' else ['parity-local']), probe
+ assert probe['global_ids'] == ['parity-global'], probe
+ assert probe['deleted'] is None, probe
+ assert (probe['local'] is None) == (phase == 'other'), probe
+ if phase != 'other':
+ assert stored(artifact / 'harness' / 'harness_state.json') == {'parity-local': probe['local']}
+ assert stored(agent / 'harness' / 'harness_state.json') == {'parity-global': probe['global']}
+ for scope in ('local', 'global'):
+ row = probe[scope]
+ if row is not None:
+ assert row['scope'] == scope and row['id'] == 'parity-' + scope, row
+ assert row['title'] == scope + ' updated' and row['content'] == scope + ' updated body', row
+ probes[phase] = probe
+ assert probes['setup'] == probes['resume'], 'local/global CRUD did not survive resume'
+ observation.update(probes=probes, offered_repl_tool_names=server.tool_names)
+ finally:
+ server.shutdown()
+ server.server_close()
+ thread.join(timeout=2)
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--receipt', type=Path, required=True)
+ args = parser.parse_args()
+ result = {'verified': False, 'runs': {}, 'normalization': [
+ 'Volatile created_at/updated_at timestamps only in HarnessEntry objects.',
+ 'Fixture roots/session IDs checked exactly within each run, then excluded from cross-run entry comparison.',
+ 'Select offered python_repl or legacy ipython; identical cell code.'],
+ 'scope': 'Actual REPL results and local/global files: CRUD, resume durability, fresh-session isolation. No TUI frame or daemon-wire parity claim.'}
+ try:
+ assert sys.platform == 'linux', 'requires Linux hosted CI binaries'
+ result['ts_release_archive_sha256'] = sha256(os.environ['PA_TS_ARCHIVE'])
+ assert result['ts_release_archive_sha256'] == TS_ARCHIVE_SHA256, 'TS archive hash mismatch'
+ with tempfile.TemporaryDirectory(prefix='local-harness-parity-') as temp:
+ for label in ('ts', 'rust'):
+ binary = Path(os.environ['PA_' + label.upper() + '_BINARY']).resolve()
+ observation = {'binary': str(binary), 'binary_sha256': sha256(binary)}
+ result['runs'][label] = observation
+ try:
+ run_case(binary, label, Path(temp) / label, observation)
+ except Exception as error:
+ observation['error'] = str(error)
+ errors = {label: run['error'] for label, run in result['runs'].items() if 'error' in run}
+ assert not errors, errors
+ ts, rust = result['runs']['ts'], result['runs']['rust']
+ assert ts['probes'] == rust['probes'], 'TS/Rust memory behavior differs'
+ result['global_env_exports'] = {label: {phase: run[phase]['kernel_env']['RLM_GLOBAL_HARNESS_STATE_DIR']
+ for phase in ('setup', 'resume', 'other')} for label, run in result['runs'].items()}
+ result['global_env_scope'] = ('Known provisioning difference: TS explicitly exports its agent/harness directory; '
+ 'Rust leaves RLM_GLOBAL_HARNESS_STATE_DIR unset and the common runtime resolves '
+ 'PRIME_AGENT_CODING_AGENT_DIR/harness. Both exact environments are asserted, '
+ 'and the effective global files and complete entries must match.')
+ result['verified'] = True
+ except Exception as error:
+ result['error'] = str(error)
+ args.receipt.parent.mkdir(parents=True, exist_ok=True)
+ args.receipt.write_text(json.dumps(result, indent=2) + '\n')
+ print(json.dumps({'receipt': str(args.receipt), 'verified': result['verified'], 'error': result.get('error')}))
+ return 0 if result['verified'] else 1
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/scripts/test_review_local_harness_parity.py b/scripts/test_review_local_harness_parity.py
new file mode 100644
index 0000000000..6bd05e7258
--- /dev/null
+++ b/scripts/test_review_local_harness_parity.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+"""Guard the binary verifier against historical tool-result false positives."""
+import json
+import unittest
+
+from review_local_harness_parity import current_probe, MARKER
+
+
+def request(current_content=None):
+ messages = [
+ {'role': 'assistant', 'tool_calls': [{'id': 'call_setup'}]},
+ {'role': 'tool', 'tool_call_id': 'call_setup', 'content': MARKER + json.dumps({'old': True})},
+ {'role': 'assistant', 'tool_calls': [{'id': 'call_resume'}]},
+ ]
+ if current_content is not None:
+ messages.append({'role': 'tool', 'tool_call_id': 'call_resume', 'content': current_content})
+ return [{'messages': messages}]
+
+
+class CurrentProbeTests(unittest.TestCase):
+ def test_resume_returns_new_marker_with_old_marker_in_history(self):
+ self.assertEqual(current_probe(request(MARKER + json.dumps({'new': True})), 'resume'),
+ {'new': True})
+
+ def test_failing_current_cell_cannot_pass_using_old_marker(self):
+ with self.assertRaisesRegex(AssertionError, 'current phase probe'):
+ current_probe(request('Traceback: current resume cell failed'), 'resume')
+
+ def test_missing_current_result_cannot_pass_using_old_marker(self):
+ with self.assertRaisesRegex(AssertionError, 'current phase tool result'):
+ current_probe(request(), 'resume')
+
+
+if __name__ == '__main__':
+ unittest.main()