Skip to content

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

Rust

pa-daemon: share the ledger replay and look edges up by key in edge_is_live (#3603)

Sebastian Müllerb9b2ce83ccb7
diff --git a/crates/pa-daemon/src/rlm_ledger.rs b/crates/pa-daemon/src/rlm_ledger.rs
index a58bd778e0..7f8d8edce3 100644
--- a/crates/pa-daemon/src/rlm_ledger.rs
+++ b/crates/pa-daemon/src/rlm_ledger.rs
@@ -20,7 +20,7 @@ use std::fs::{self, File, OpenOptions};
use std::io::{Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
-use std::sync::Mutex;
+use std::sync::{Arc, Mutex};
use anyhow::{bail, Context, Result};
use serde::{Deserialize, Serialize};
@@ -681,16 +681,26 @@ impl RlmSpawnLedger {
/// snapshotted counts as live. An unreadable (oversized) ledger reads
/// as not-live.
pub fn edge_is_live(&self, child_id: &str, child: &str) -> bool {
- let child = canonical_session_path(Path::new(child));
+ let canonical_child = canonical_session_path(Path::new(child));
self.seed_once().is_ok()
&& self.replay_cached().is_ok_and(|state| {
- state.edges.iter().any(|edge| {
+ let is_live = |edge: &RlmLedgerEdge| {
edge.child_id == child_id
&& edge.deleted.is_none()
- && canonical_session_path(Path::new(&edge.child)) == child
+ && canonical_session_path(Path::new(&edge.child)) == canonical_child
&& is_file(Path::new(&edge.child))
&& is_file(Path::new(&edge.parent))
- })
+ };
+ // Most reads prove liveness through the index. Its keys
+ // were canonicalized at replay, though: a file replaced
+ // by a symlink does not change the ledger's stat identity.
+ // A stale key or tombstoned alias cannot prove absence;
+ // preserve the original read-time path comparison then.
+ state
+ .index
+ .get(&edge_key(child_id, child))
+ .is_some_and(|&at| is_live(&state.edges[at]))
+ || state.edges.iter().any(is_live)
})
}
@@ -711,19 +721,19 @@ impl RlmSpawnLedger {
/// Replay behind the stat guard: a file whose identity snapshot is
/// unchanged reuses the cached edges. A missing file replays empty.
- fn replay_cached(&self) -> Result<ReplayState> {
+ fn replay_cached(&self) -> Result<Arc<ReplayState>> {
let identity = file_identity(&self.path)?;
let mut cache = self.cache.lock().expect("ledger cache lock");
if let (Some(identity), Some(cached)) = (&identity, cache.as_ref()) {
if *identity == cached.identity {
- return Ok(cached.state.clone());
+ return Ok(Arc::clone(&cached.state));
}
}
- let state = self.replay()?;
+ let state = Arc::new(self.replay()?);
if let Some(identity) = identity {
*cache = Some(ReplaySnapshot {
identity,
- state: state.clone(),
+ state: Arc::clone(&state),
});
}
Ok(state)
diff --git a/crates/pa-daemon/src/rlm_ledger/replay.rs b/crates/pa-daemon/src/rlm_ledger/replay.rs
index ecd6f97e08..0a66622d66 100644
--- a/crates/pa-daemon/src/rlm_ledger/replay.rs
+++ b/crates/pa-daemon/src/rlm_ledger/replay.rs
@@ -5,8 +5,8 @@
use anyhow::Context as _;
use super::{
- bail, canonical_session_path, fs, json, HashMap, Path, PathBuf, Result, RlmLedgerDeleteReason,
- RlmLedgerEdge, Value,
+ bail, canonical_session_path, fs, json, Arc, HashMap, Path, PathBuf, Result,
+ RlmLedgerDeleteReason, RlmLedgerEdge, Value,
};
/// One replayed ledger record (`meta` records carry no edge and are skipped).
@@ -152,7 +152,7 @@ pub(super) fn parse_ledger_line(line: &str, index: usize) -> Result<Option<Ledge
}
/// The replayed edge set: replay order plus a key index for record joins.
-#[derive(Debug, Default, Clone)]
+#[derive(Debug, Default)]
pub(super) struct ReplayState {
pub(super) edges: Vec<RlmLedgerEdge>,
pub(super) index: HashMap<String, usize>,
@@ -249,7 +249,7 @@ fn artifact_session_index(agent_dir: &Path) -> HashMap<String, PathBuf> {
#[derive(Debug)]
pub(super) struct ReplaySnapshot {
pub(super) identity: FileIdentity,
- pub(super) state: ReplayState,
+ pub(super) state: Arc<ReplayState>,
}
#[derive(Debug, PartialEq, Eq, Clone)]
diff --git a/crates/pa-daemon/src/rlm_ledger/tests.rs b/crates/pa-daemon/src/rlm_ledger/tests.rs
index e889e084fb..da3c2199f0 100644
--- a/crates/pa-daemon/src/rlm_ledger/tests.rs
+++ b/crates/pa-daemon/src/rlm_ledger/tests.rs
@@ -171,6 +171,108 @@ fn edge_is_live_reflects_tombstones_and_files() {
assert!(!ledger.edge_is_live("sub-none", &child_path));
}
+// File changes do not invalidate the ledger's stat-identity cache. A
+// canonical path recorded at spawn can later become a symlink, so the
+// replay index alone cannot establish that no live edge matches a path.
+#[cfg(unix)]
+#[test]
+fn edge_is_live_revalidates_paths_without_a_ledger_append() {
+ use std::os::unix::fs::symlink;
+
+ let dir = temp_dir("liveness-retarget");
+ let ledger = ledger_for(&dir);
+ let parent = dir.join("p.jsonl");
+ let child = dir.join("a.jsonl");
+ let target = dir.join("b.jsonl");
+ for path in [&parent, &child, &target] {
+ fs::write(path, "{}").unwrap();
+ }
+ for path in [&child, &target] {
+ ledger
+ .append_spawn(&RlmSpawnInput {
+ child_id: "sub-1".into(),
+ parent: parent.to_string_lossy().into_owned(),
+ child: path.to_string_lossy().into_owned(),
+ depth: 1,
+ name: "child".into(),
+ })
+ .unwrap();
+ }
+ ledger
+ .append_delete(
+ "sub-1",
+ &target.to_string_lossy(),
+ RlmLedgerDeleteReason::User,
+ )
+ .unwrap();
+ let child_path = child.to_string_lossy();
+ let target_path = target.to_string_lossy();
+ assert!(ledger.edge_is_live("sub-1", &child_path));
+ assert!(!ledger.edge_is_live("sub-1", &target_path));
+ let cached = ledger.replay_cached().unwrap();
+ let identity = file_identity(&ledger.path).unwrap();
+
+ fs::remove_file(&child).unwrap();
+ symlink(&target, &child).unwrap();
+ assert_eq!(file_identity(&ledger.path).unwrap(), identity);
+ assert!(Arc::ptr_eq(&cached, &ledger.replay_cached().unwrap()));
+ // The query now hits the target's tombstoned index entry, but the
+ // original live edge resolves to the same path and must still count.
+ assert!(ledger.edge_is_live("sub-1", &child_path));
+ assert!(ledger.edge_is_live("sub-1", &target_path));
+
+ let unindexed = dir.join("c.jsonl");
+ fs::write(&unindexed, "{}").unwrap();
+ fs::remove_file(&child).unwrap();
+ symlink(&unindexed, &child).unwrap();
+ assert_eq!(file_identity(&ledger.path).unwrap(), identity);
+ assert!(Arc::ptr_eq(&cached, &ledger.replay_cached().unwrap()));
+ // This query misses the index entirely after the second retarget.
+ assert!(ledger.edge_is_live("sub-1", &child_path));
+ assert!(ledger.edge_is_live("sub-1", &unindexed.to_string_lossy()));
+ assert!(!ledger.edge_is_live("sub-1", &target_path));
+
+ fs::remove_file(&unindexed).unwrap();
+ assert!(!ledger.edge_is_live("sub-1", &child_path));
+ assert!(!ledger.edge_is_live("sub-1", &target_path));
+}
+
+/// A respawned child id: the tombstoned edge at the old path stays dead,
+/// the new path's edge is live, and a later respawn on the old path's key
+/// re-lives that edge in place (the fold keeps one edge per key).
+#[test]
+fn a_respawned_child_id_on_a_new_path_is_live_and_the_old_one_is_not() {
+ let dir = temp_dir("respawn");
+ let ledger = ledger_for(&dir);
+ let parent = dir.join("p.jsonl");
+ let a = dir.join("a.jsonl");
+ let b = dir.join("b.jsonl");
+ fs::write(&parent, "{}").unwrap();
+ fs::write(&a, "{}").unwrap();
+ fs::write(&b, "{}").unwrap();
+ let spawn = |child: &Path, name: &str| {
+ ledger
+ .append_spawn(&RlmSpawnInput {
+ child_id: "sub-1".into(),
+ parent: parent.to_string_lossy().into_owned(),
+ child: child.to_string_lossy().into_owned(),
+ depth: 1,
+ name: name.into(),
+ })
+ .unwrap();
+ };
+ spawn(&a, "first");
+ ledger
+ .append_delete("sub-1", &a.to_string_lossy(), RlmLedgerDeleteReason::User)
+ .unwrap();
+ spawn(&b, "second");
+ assert!(!ledger.edge_is_live("sub-1", &a.to_string_lossy()));
+ assert!(ledger.edge_is_live("sub-1", &b.to_string_lossy()));
+ spawn(&a, "third");
+ assert!(ledger.edge_is_live("sub-1", &a.to_string_lossy()));
+ assert!(ledger.edge_is_live("sub-1", &b.to_string_lossy()));
+}
+
#[test]
fn dead_child_or_parent_drops_from_live_edges() {
let dir = temp_dir("live");
diff --git a/scripts/review_ledger_liveness_parity.py b/scripts/review_ledger_liveness_parity.py
new file mode 100644
index 0000000000..f9493e6a76
--- /dev/null
+++ b/scripts/review_ledger_liveness_parity.py
@@ -0,0 +1,283 @@
+#!/usr/bin/env python3
+"""Hosted actual TS/Rust RLM spawn, durable ledger and warm-list liveness comparison.
+
+A real parent kernel admits a child with rlm.spawn. The synthetic provider holds
+that child's turn while both daemons answer repeated list/roster reads. This is
+live-family baseline parity, not a TS proof of external symlink retargeting or
+passivation/registration timing; those boundaries are recorded as out of scope.
+"""
+import argparse
+import http.server
+import json
+import os
+import signal
+from pathlib import Path
+import subprocess
+import sys
+import tempfile
+import threading
+import time
+
+from review_agent_bounce_parity import Client, LIMIT
+from review_draft_disconnect_parity import digest, env_for, stop, TS_ARCHIVE_SHA256
+from review_restore_notice_parity import texts
+
+PARENT = 'Create the ledger liveness fixture child.'
+CHILD = 'LEDGER_LIVENESS_CHILD_HOLD'
+NAME = 'ledger-fixture-child'
+MARKER = 'LEDGER_LIVENESS_ADMITTED='
+CODE = """import json
+ledger_handle = await rlm.spawn('LEDGER_LIVENESS_CHILD_HOLD', name='ledger-fixture-child')
+print('LEDGER_LIVENESS_ADMITTED=' + json.dumps({'child_id': ledger_handle.rlm_child_id}))"""
+
+
+def admitted_probe(body):
+ rows = [row for row in body.get('messages', [])
+ if row.get('role') == 'tool' and row.get('tool_call_id') == 'ledger_spawn']
+ assert len(rows) == 1, 'expected exactly one current ledger_spawn tool result'
+ probes = [json.loads(line[len(MARKER):]) for row in rows
+ for text in texts(row.get('content')) for line in text.splitlines()
+ if line.startswith(MARKER)]
+ assert len(probes) == 1 and probes[0].get('child_id'), 'expected one nonempty admission probe'
+ return probes[0]
+
+
+def owned_processes(root):
+ expected = {('PI_CODING_AGENT_DIR=' + str(root / 'agent')).encode(),
+ ('PRIME_AGENT_CODING_AGENT_DIR=' + str(root / 'agent')).encode()}
+ found = {}
+ for path in Path('/proc').iterdir():
+ if not path.name.isdigit():
+ continue
+ try:
+ environment = set((path / 'environ').read_bytes().split(b'\0'))
+ if expected.isdisjoint(environment):
+ continue
+ start = (path / 'stat').read_text().rsplit(')', 1)[1].split()[19]
+ found[int(path.name)] = start
+ except (OSError, IndexError):
+ continue
+ return found
+
+
+def confirm_cleanup(root, observed):
+ deadline = time.monotonic() + 10
+ remaining = owned_processes(root)
+ while remaining and time.monotonic() < deadline:
+ threading.Event().wait(0.025)
+ remaining = owned_processes(root)
+ observed['remaining_owned_processes'] = remaining
+ # Failure stays red, even when fixture-owned fallback cleanup succeeds.
+ if remaining:
+ for sig in (signal.SIGTERM, signal.SIGKILL):
+ for pid, start in remaining.items():
+ if owned_processes(root).get(pid) == start:
+ try:
+ os.kill(pid, sig)
+ except ProcessLookupError:
+ pass
+ deadline = time.monotonic() + 5
+ while owned_processes(root) and time.monotonic() < deadline:
+ threading.Event().wait(0.025)
+ observed['remaining_after_fallback'] = owned_processes(root)
+ assert not remaining, 'owned detached processes survived normal shutdown'
+ assert 'shutdown_error' not in observed, observed.get('shutdown_error')
+
+
+class Provider(http.server.ThreadingHTTPServer):
+ daemon_threads = True
+
+ def __init__(self):
+ super().__init__(('127.0.0.1', 0), Handler)
+ self.arrived = threading.Condition()
+ self.requests = []
+ self.release = threading.Event()
+ self.probe = None
+ self.parent_calls = 0
+ self.child_arrived = False
+
+ def ready(self):
+ with self.arrived:
+ assert self.arrived.wait_for(lambda: self.probe is not None and self.child_arrived,
+ timeout=LIMIT * 2), 'actual spawn/tool result/child request never arrived'
+ return self.probe
+
+
+class Handler(http.server.BaseHTTPRequestHandler):
+ def log_message(self, *_args):
+ pass
+
+ def do_POST(self):
+ body = json.loads(self.rfile.read(int(self.headers['Content-Length'])))
+ user_texts = [text for row in body.get('messages', []) if row.get('role') == 'user'
+ for text in texts(row.get('content'))]
+ is_child = any(CHILD in text for text in user_texts)
+ with self.server.arrived:
+ self.server.requests.append(body)
+ if is_child:
+ self.server.child_arrived = True
+ delta, finish = {'content': 'Child fixture released.'}, 'stop'
+ else:
+ self.server.parent_calls += 1
+ if self.server.parent_calls == 1:
+ offered = {tool.get('function', {}).get('name') for tool in body.get('tools', [])}
+ tool = next((name for name in ('python_repl', 'ipython') if name in offered), None)
+ if tool is None:
+ self.send_error(422, 'No real REPL tool offered')
+ return
+ delta = {'tool_calls': [{'index': 0, 'id': 'ledger_spawn', 'type': 'function',
+ 'function': {'name': tool, 'arguments': json.dumps({'code': CODE})}}]}
+ finish = 'tool_calls'
+ else:
+ self.server.probe = admitted_probe(body)
+ delta, finish = {'content': 'Parent fixture completed.'}, 'stop'
+ self.server.arrived.notify_all()
+ if is_child:
+ self.server.release.wait(LIMIT * 4)
+ def chunk(delta, reason=None):
+ return {'id': 'ledger-fixture', 'object': 'chat.completion.chunk', 'created': 1,
+ 'model': 'parity-1', 'choices': [{'index': 0, 'delta': delta, 'finish_reason': reason}]}
+ wire = ''.join('data: ' + json.dumps(row) + '\n\n' for row in (
+ chunk({'role': 'assistant', **delta}), chunk({}, finish))) + 'data: [DONE]\n\n'
+ encoded = wire.encode()
+ try:
+ self.send_response(200)
+ self.send_header('Content-Type', 'text/event-stream')
+ self.send_header('Content-Length', str(len(encoded)))
+ self.end_headers()
+ self.wfile.write(encoded)
+ except (BrokenPipeError, ConnectionResetError):
+ pass
+
+
+def family_contract(rows, child_id, parent_active):
+ selected = [row for row in rows if row.get('rlmChildId') == child_id]
+ assert len(selected) == 1, 'expected one actual admitted child, got ' + repr(selected)
+ row = selected[0]
+ assert row.get('sessionName') == NAME, row
+ assert row.get('rlmDepth') == 1, row
+ assert row.get('parentActiveSessionId') == parent_active, row
+ assert row.get('sessionFile') and Path(row['sessionFile']).is_file(), row
+ # Only generated identities/paths are replaced, preserving relational facts.
+ return {'name': row['sessionName'], 'depth': row['rlmDepth'], 'child': '<admitted-child>',
+ 'parent': '<resident-parent>', 'transcript_exists': True}
+
+
+def run_case(binary, kind, root, observed):
+ env = env_for(root, kind)
+ library = Path(os.environ['PI_PACKAGE_DIR']) / 'skills'
+ env['PYTHONPATH'] = os.pathsep.join(sorted(str(path) for path in library.glob('*/src') if path.is_dir()))
+ provider = Provider()
+ thread = threading.Thread(target=provider.serve_forever, daemon=True)
+ thread.start()
+ models = {'providers': {'parity-local': {'api': 'openai-completions', 'apiKey': 'fixture-only',
+ 'baseUrl': 'http://127.0.0.1:%s/v1' % provider.server_port,
+ 'models': [{'id': 'parity-1', 'name': 'Parity 1', 'reasoning': False,
+ 'contextWindow': 128000, 'maxTokens': 4096}]}}}
+ (root / 'agent/models.json').write_text(json.dumps(models))
+ (root / 'agent/settings.json').write_text(json.dumps({'prewarmPythonKernel': False,
+ 'defaultProvider': 'parity-local', 'defaultModel': 'parity-1',
+ 'onboardingCompleted': True, 'telemetry': {'noticeShown': True}}))
+ process, client = None, None
+ log_path = root / 'daemon.log'
+ try:
+ with log_path.open('wb') as log:
+ path = root / 'd.sock'
+ process = subprocess.Popen([str(binary), '--mode', 'daemon', '--daemon-socket', str(path)],
+ cwd=root, env=env, stdout=log, stderr=subprocess.STDOUT, start_new_session=True)
+ client = Client(path, process)
+ config = {'cwd': str(root), 'agentDir': str(root / 'agent'), 'provider': 'parity-local',
+ 'model': 'parity-1', 'noExtensions': True, 'noContextFiles': True,
+ 'telemetryDisabled': True}
+ created = client.call('create', name='ledger-fixture-parent', config=config)
+ observed['created'] = created
+ active = created.get('activeSessionId') or created.get('id')
+ assert active and created.get('sessionFile'), created
+ client.call('attach', activeSessionId=active)
+ client.call('prompt', activeSessionId=active, message=PARENT)
+ probe = provider.ready()
+ child_id = probe['child_id']
+ observed['admitted_tool_result'] = probe
+ # Reads are immediate after observed admission and provider readiness,
+ # never delayed to hide a liveness failure or retried until green.
+ observed['lists'] = [client.call('list', all=True) for _ in range(2)]
+ contracts = [family_contract(view['sessions'], child_id, active)
+ for view in observed['lists']]
+ assert contracts[0] == contracts[1], 'warm list lost or changed child'
+ roster = client.call('roster_subscribe')
+ observed['roster'] = roster
+ summaries = [entry.get('summary', {}) for entry in roster['roster']]
+ roster_contract = family_contract(summaries, child_id, active)
+ ledgers = list((root / 'agent/rlm-ledger').glob('*.jsonl'))
+ ledger_rows = [json.loads(line) for path in ledgers for line in path.read_text().splitlines()]
+ observed['ledger_rows'] = ledger_rows
+ spawns = [row for row in ledger_rows if row.get('op') == 'spawn' and row.get('childId') == child_id]
+ assert len(spawns) == 1, 'actual spawn did not produce one durable ledger edge'
+ assert spawns[0]['depth'] == 1 and spawns[0]['name'] == NAME, spawns
+ assert Path(spawns[0]['parent']).resolve() == Path(created['sessionFile']).resolve(), spawns
+ listed = [row for row in observed['lists'][0]['sessions'] if row.get('rlmChildId') == child_id]
+ assert Path(spawns[0]['child']).resolve() == Path(listed[0]['sessionFile']).resolve(), spawns
+ assert Path(spawns[0]['child']).is_file(), spawns
+ return {'list': contracts, 'roster': roster_contract,
+ 'durable_spawn': {'name': NAME, 'depth': 1, 'count': 1,
+ 'parent_matches_created_session': True, 'child_transcript_exists': True}}
+ finally:
+ observed['owned_before_shutdown'] = owned_processes(root)
+ provider.release.set()
+ if process and process.poll() is None and client:
+ try:
+ client.call('shutdown', force=True)
+ observed['wire'] = client.wire
+ client.close()
+ process.wait(timeout=15)
+ observed['shutdown'] = 'owned supervisor and workers stopped'
+ except Exception as error:
+ observed['shutdown_error'] = str(error)
+ if process:
+ stop(process)
+ if client:
+ observed['wire'] = client.wire
+ client.close()
+ observed['provider_requests'] = provider.requests
+ if log_path.exists():
+ observed['daemon_log'] = log_path.read_text(errors='replace')[-10000:]
+ provider.shutdown()
+ provider.server_close()
+ thread.join(timeout=5)
+ confirm_cleanup(root, observed)
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--receipt', type=Path, required=True)
+ args = parser.parse_args()
+ result = {'verified': False, 'scope': __doc__, 'runs': {},
+ 'not_compared': ['external symlink retarget on an active transcript',
+ 'nonresident-child passivation/registration timing',
+ 'whole wire equality: full raw responses preserved; compare declared family contract']}
+ try:
+ assert sys.platform == 'linux', 'hosted Linux CI only'
+ assert digest(os.environ['PA_TS_ARCHIVE']) == TS_ARCHIVE_SHA256, 'TS archive hash mismatch'
+ result['ts_archive_sha256'] = TS_ARCHIVE_SHA256
+ with tempfile.TemporaryDirectory(prefix='pa-ledger-', dir='/tmp') as temporary:
+ for kind in ('ts', 'rust'):
+ binary = Path(os.environ['PA_' + kind.upper() + '_BINARY']).resolve()
+ observed = result['runs'][kind] = {'binary_sha256': digest(binary)}
+ try:
+ observed['contract'] = run_case(binary, kind, Path(temporary) / kind, observed)
+ except Exception as error:
+ observed['error'] = str(error)
+ errors = {kind: run['error'] for kind, run in result['runs'].items() if 'error' in run}
+ assert not errors, errors
+ assert result['runs']['ts']['contract'] == result['runs']['rust']['contract'], 'family contract mismatch'
+ 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_ledger_liveness_parity.py b/scripts/test_review_ledger_liveness_parity.py
new file mode 100644
index 0000000000..268a7abc23
--- /dev/null
+++ b/scripts/test_review_ledger_liveness_parity.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+"""Guard the real-wire family receipt against duplicate or unrelated children."""
+import tempfile
+from unittest.mock import patch
+from pathlib import Path
+import unittest
+
+from review_ledger_liveness_parity import NAME, MARKER, admitted_probe, confirm_cleanup, family_contract
+
+
+class FamilyReceiptTests(unittest.TestCase):
+ def test_duplicate_current_probes_fail(self):
+ text = MARKER + '{"child_id":"child"}'
+ with self.assertRaises(AssertionError):
+ admitted_probe({'messages': [{'role': 'tool', 'tool_call_id': 'ledger_spawn',
+ 'content': text + '\n' + text}]})
+
+ def test_duplicate_current_tool_results_fail(self):
+ row = {'role': 'tool', 'tool_call_id': 'ledger_spawn',
+ 'content': MARKER + '{"child_id":"child"}'}
+ with self.assertRaises(AssertionError):
+ admitted_probe({'messages': [row, row]})
+
+ def test_shutdown_failure_cannot_be_a_green_receipt(self):
+ with patch('review_ledger_liveness_parity.owned_processes', return_value={}):
+ with self.assertRaises(AssertionError):
+ confirm_cleanup(Path('/unused'), {'shutdown_error': 'shutdown refused'})
+
+ def test_duplicates_do_not_prove_one_child(self):
+ with tempfile.TemporaryDirectory() as directory:
+ path = Path(directory) / 'child.jsonl'
+ path.write_text('{}')
+ row = {'rlmChildId': 'child', 'sessionName': NAME, 'rlmDepth': 1,
+ 'parentActiveSessionId': 'parent', 'sessionFile': str(path)}
+ with self.assertRaises(AssertionError):
+ family_contract([row, row], 'child', 'parent')
+
+ def test_unrelated_parent_is_not_normalized_away(self):
+ row = {'rlmChildId': 'child', 'sessionName': NAME, 'rlmDepth': 1,
+ 'parentActiveSessionId': 'different-parent', 'sessionFile': '/unused'}
+ with self.assertRaises(AssertionError):
+ family_contract([row], 'child', 'parent')
+
+ def test_generated_paths_only_normalize_after_real_file_check(self):
+ with tempfile.TemporaryDirectory() as directory:
+ path = Path(directory) / 'child.jsonl'
+ row = {'rlmChildId': 'child', 'sessionName': NAME, 'rlmDepth': 1,
+ 'parentActiveSessionId': 'parent', 'sessionFile': str(path)}
+ with self.assertRaises(AssertionError):
+ family_contract([row], 'child', 'parent')
+ path.write_text('{}')
+ self.assertTrue(family_contract([row], 'child', 'parent')['transcript_exists'])
+
+
+if __name__ == '__main__':
+ unittest.main()