← Commit history

Merge PR #536: status only reads the run: no turn, no dashboard tab, no clip guard (fix/status-read-only -> main) merge

Colby Knox ·350a937cd3 · ·parents d042494, a8efcd0

Showing changes introduced by the merge (against its first parent).

2 files changed +88−5
crates/adom-aiflow/src/main.rs+8−5
@@ -367,7 +367,7 @@ enum Cmd {     #[arg(long)] off_page: bool },     /// The comparison page: a sub-README for this run and another (`compose --with` first), the side-by-side video first, then the numbers from both ledgers, the AIs' drawings side by side and the links to both run pages; --push puts it on the page under docs/comparisons/<a>-vs-<b>/     Compare { #[arg(long)] with: PathBuf, #[arg(long)] page: Option<String>, #[arg(long)] push: bool, #[arg(long)] refresh: bool },-    /// Where the run stands+    /// Where the run stands. It only reads: no turn in the run's ledger, no dashboard tab, no clip guard, so any thread may read any run with it     Status,     /// A new human prompt on this run (a follow-up: "add the walkthroughs", "recut the video"): the AI's time for it counts from here to its `done`. --at is the paste time when you start late.     Prompt { #[arg(long)] text: String, #[arg(long)] at: Option<String>,@@ -719,8 +719,9 @@ fn run_dir(cli: &Cli) -> PathBuf { fn load_run(cli: &Cli) -> Run {     let d = run_dir(cli);     if let Some(mut r) = Run::open(&d) {-        // issue #170: the media worker's results come into the run here (every command but the stop hook)-        if !matches!(cli.cmd, Cmd::FinishGuard { .. } | Cmd::MediaWorker) && media_dir(&d).join("done").is_dir() { media_reconcile(&mut r); }+        // issue #170: the media worker's results come into the run here (every command but the stop hook+        // and `status`, which only read the run)+        if !matches!(cli.cmd, Cmd::FinishGuard { .. } | Cmd::MediaWorker | Cmd::Status) && media_dir(&d).join("done").is_dir() { media_reconcile(&mut r); }         if let Some(b) = r.data["remoteBoard"].as_str() { aiflow_bridge::eda::set_run_board(b); }         // the run's desktop is where a remote KiCad runs, unless the human named another         if let (Some(t), Err(_)) = (r.data["target"].as_str(), std::env::var("KICAD_REMOTE_TARGET")) { std::env::set_var("KICAD_REMOTE_TARGET", t); }@@ -3645,13 +3646,15 @@ fn main() {         }     }     // All engines share the same default. Server/write children must never open tabs recursively.-    if !matches!(cli.cmd, Cmd::Timeline { .. } | Cmd::Demo { .. }) {+    // `status` reads a run, often another thread's (an audit, a director): it opens no tab, records no+    // turn and leaves the run's clips alone, so the run's own files are byte for byte what they were.+    if !matches!(cli.cmd, Cmd::Timeline { .. } | Cmd::Demo { .. } | Cmd::Status) {         let ai_thread = cli.ai_thread.clone().or_else(|| Run::open(&dir).and_then(|r|r.data["aiThread"].as_str().map(str::to_owned))).unwrap_or_else(|| "adom-aiflow".into());         let _ = DASHBOARD.set((dir.clone(), ai_thread.clone()));         ensure_dashboard(&dir, &ai_thread, matches!(cli.cmd, Cmd::Prompt { .. }));     }     // every command is a turn in the run's ledger; the gap before it is the AI's thinking time-    if !matches!(cli.cmd, Cmd::Start { .. } | Cmd::Intake { .. } | Cmd::Demo { .. }) && !matches!(&cli.cmd, Cmd::Timeline { action, .. } if action == "serve" || action == "list" || action == "close") {+    if !matches!(cli.cmd, Cmd::Start { .. } | Cmd::Intake { .. } | Cmd::Demo { .. } | Cmd::Status) && !matches!(&cli.cmd, Cmd::Timeline { action, .. } if action == "serve" || action == "list" || action == "close") {         if let Some(mut r) = Run::open(&dir) {             let idx = r.turn_begin(&command_line());             // the thread that last drove the run: the dashboard header and the tab registry name it
tests/status-readonly-workflow.pyadded+80
@@ -0,0 +1,80 @@+"""`status` only reads the run: an audit or a director reading another thread's run with it changes+nothing in that run and touches nothing outside it.++The run has an open clip that is hours past its budget (so any other command's clip guard stops it+through Adom Bridge), a media worker outbox (`media/done`) and no AIFLOW_DASHBOARD=off. `status`+must leave every file under the run byte for byte as it was (run.json, run.jsonl, timeline, media),+call neither adom-bridge nor adom-cli (no dashboard tab), and still print where the run stands. A+control command afterwards shows the harness sees writes and bridge calls when they happen.++adom-bridge and adom-cli are fakes on PATH that record every call. No CAD, desktop or dashboard.++  python3 tests/status-readonly-workflow.py <adom-aiflow binary>+"""+import hashlib, json, os, pathlib, subprocess, sys, tempfile+binary = str(pathlib.Path(sys.argv[1]).resolve())++FAKE = r'''#!/usr/bin/env python3+import json, os, sys+open(os.environ["FAKE_LOG"], "a").write(json.dumps({"tool": os.path.basename(sys.argv[0]), "args": sys.argv[1:]}) + "\n")+print(json.dumps({"success": False, "errorCode": "fake", "error": "test fake"}))+'''+++def snapshot(root):+    out = {}+    for d, _, files in os.walk(root):+        for f in files:+            q = os.path.join(d, f)+            out[os.path.relpath(q, root)] = hashlib.sha256(open(q, 'rb').read()).hexdigest()+    return out+++with tempfile.TemporaryDirectory(prefix='aiflow-status-') as td:+    p = pathlib.Path(td)+    b = p / 'bin'; b.mkdir()+    for tool in ['adom-bridge', 'adom-cli']:+        (b / tool).write_text(FAKE); (b / tool).chmod(0o755)+    log = p / 'calls.jsonl'+    base = dict(os.environ, PATH=f"{b}:{os.environ['PATH']}", FAKE_LOG=str(log))+    quiet = dict(base, AIFLOW_DASHBOARD='off')+    base.pop('AIFLOW_DASHBOARD', None)++    def call(env, run, *args):+        return subprocess.run([binary, '--run', str(run), '--ai-thread', 'status-reader', *args], env=env, capture_output=True, text=True, timeout=120)++    def calls():+        return [json.loads(l) for l in log.read_text().splitlines()] if log.exists() else []++    run = p / 'run'+    r = call(quiet, run, 'intake', '--prompt-time', '2026-11-19T01:00:00Z', '--engine', 'test', '--target', 'Some-Desktop')+    assert r.returncode == 0, r.stdout + r.stderr+    assert call(quiet, run, 'step', 'rules').returncode == 0+    # an open clip started long ago (the guard stops anything past an hour) and a media worker outbox+    d = json.loads((run / 'run.json').read_text())+    d['captures'] = [{'recordingId': 'rec-1', 'step': 'rules', 'visit': 1, 'start': '2026-11-19T01:00:00Z'}]+    (run / 'run.json').write_text(json.dumps(d))+    (run / 'media' / 'done').mkdir(parents=True)+    if log.exists(): log.unlink()++    before = snapshot(run)+    r = call(base, run, 'status'); out = r.stdout + r.stderr+    assert r.returncode == 0 and out.startswith('OK: run ') and 'stages (min)' in out, out+    after = snapshot(run)+    changed = sorted(k for k in set(before) | set(after) if before.get(k) != after.get(k))+    assert changed == [], f'status wrote into the run it read: {changed}'+    assert calls() == [], f'status called out: {calls()}'+    assert 'clip guard' not in out and 'Dashboard' not in out, out++    # without --ai-thread too (a quick look)+    r = subprocess.run([binary, '--run', str(run), 'status'], env=base, capture_output=True, text=True, timeout=120)+    assert r.returncode == 0, r.stdout + r.stderr+    assert snapshot(run) == before and calls() == []++    # control: any other command records its turn, and its clip guard stops the stale clip+    r = call(quiet, run, 'step', 'test-plan'); out = r.stdout + r.stderr+    assert r.returncode == 0, out+    changed = sorted(k for k in set(before) | set(snapshot(run)) if before.get(k) != snapshot(run).get(k))+    assert 'run.json' in changed and 'run.jsonl' in changed, changed+    assert any(c['tool'] == 'adom-bridge' for c in calls()), calls()+print('PASS: status leaves every file of the run unchanged (no turn, no media fold-in, no clip guard), calls neither adom-bridge nor adom-cli and still reports the run; a control step records its turn and its guard reaches the bridge')