Skip to main content

mj_controller/controller/
reviewer.rs

1//! Staging the second-opinion reviewer's profile onto a session's target.
2//!
3//! The reviewer runs a different configured profile in the primary session's
4//! own target. Its harness home is a fresh copy of that profile, placed inside
5//! the primary worker root, so the reviewer never reads or writes the
6//! primary's home and nothing outside the worker root has to be provisioned.
7//!
8//! Nothing here creates a session record, a target, a checkout, or any target
9//! lifecycle operation. Staging a reviewer is a file copy into a directory the
10//! session's worker already owns.
11
12use std::path::Path;
13
14use anyhow::{Context, Result, bail, ensure};
15
16use super::worker_binary::{bridge_launch, container_upload_ownership_args, stage_profile};
17use super::{Controller, execute_checked};
18use crate::targets::{self, CommandExecutor, CommandSpec, ProcessExecutor};
19use mj_core::worker_launch::{
20    REVIEWER_DIR, ReviewMcpDelivery, ReviewMcpServer, ReviewerLaunchConfig,
21    reviewer_staging_profile_home,
22};
23
24/// Build the capability used by client-side chat views to stage reviewers.
25/// The blocking filesystem and target work remains implemented by the
26/// controller and is invoked from chat's supervised blocking task.
27pub fn reviewer_stager() -> mj_client::session::ReviewerStager {
28    mj_client::session::ReviewerStager::new(ControllerReviewerStager)
29}
30
31struct ControllerReviewerStager;
32
33impl mj_client::session::ReviewerStagerBackend for ControllerReviewerStager {
34    fn stage(
35        &self,
36        _config: mj_core::config::Config,
37        session: mj_core::state::SessionRecord,
38        profile_id: String,
39        generation: u64,
40        cancelled: std::sync::Arc<std::sync::atomic::AtomicBool>,
41    ) -> Result<ReviewerLaunchConfig> {
42        let session_id = session.id.clone();
43        let controller = Controller::load()?;
44        let executor = crate::targets::CancellableProcessExecutor::new(cancelled)
45            .with_deadline(std::time::Duration::from_secs(90));
46        controller.stage_reviewer_profile_controlled(
47            &session_id,
48            &profile_id,
49            generation,
50            &[],
51            &executor,
52        )
53    }
54}
55
56impl Controller {
57    /// Copy `profile_id`'s home into the session worker's reviewer directory
58    /// and describe how the worker should launch it.
59    ///
60    /// `generation` distinguishes reviewer lifetimes: bumping it tells the
61    /// worker to start a new conversation instead of reloading the last one.
62    pub fn stage_reviewer_profile(
63        &self,
64        session_id: &str,
65        profile_id: &str,
66        generation: u64,
67    ) -> Result<ReviewerLaunchConfig> {
68        self.stage_reviewer_profile_controlled(
69            session_id,
70            profile_id,
71            generation,
72            &[],
73            &ProcessExecutor,
74        )
75    }
76
77    /// Stage a reviewer that also gets `mcp_servers`, which is how a turn
78    /// review attaches its analyzer tools.
79    ///
80    /// `dispatch_tool` adds the review supervisor's own tool, which is this
81    /// worker's binary in another mode. Only the controller knows where that
82    /// binary and its socket sit on the target, so it is built here rather
83    /// than by the caller.
84    pub fn stage_reviewer_profile_with_mcp(
85        &self,
86        session_id: &str,
87        profile_id: &str,
88        generation: u64,
89        mcp_servers: &[ReviewMcpServer],
90        dispatch_tool: bool,
91    ) -> Result<ReviewerLaunchConfig> {
92        let mut servers = mcp_servers.to_vec();
93        if dispatch_tool {
94            let (_, worker_root) = self.worker_placement(session_id)?;
95            servers.push(review_dispatch_server(&worker_root));
96        }
97        self.stage_reviewer_profile_controlled(
98            session_id,
99            profile_id,
100            generation,
101            &servers,
102            &ProcessExecutor,
103        )
104    }
105
106    pub fn stage_reviewer_profile_controlled(
107        &self,
108        session_id: &str,
109        profile_id: &str,
110        generation: u64,
111        mcp_servers: &[ReviewMcpServer],
112        executor: &impl CommandExecutor,
113    ) -> Result<ReviewerLaunchConfig> {
114        let profile = self
115            .config
116            .profiles
117            .get(profile_id)
118            .with_context(|| format!("unknown profile {profile_id:?}"))?;
119        ensure!(
120            profile.enabled,
121            "reviewer profile {profile_id:?} is disabled"
122        );
123        if !profile.kind.supports_injected_mcp() {
124            bail!(
125                "Muse Code cannot be a reviewer: muse-acp does not accept the required MCP tools. Select another reviewer profile."
126            );
127        }
128        let session = self
129            .state
130            .sessions
131            .get(session_id)
132            .with_context(|| format!("unknown session {session_id}"))?;
133        let target = session.target_runtime_settings(&self.config)?;
134        let execution_policy = profile
135            .kind
136            .effective_execution_policy(target.execution_policy);
137        let (backend, worker_root) = self.worker_placement(session_id)?;
138
139        let staging = tempfile::tempdir().context("create reviewer staging directory")?;
140        let local = staging.path().join("profile");
141        stage_profile(profile, &local).with_context(|| format!("stage profile {profile_id:?}"))?;
142        // Harnesses that ignore MCP servers offered over ACP read their own
143        // configuration instead, so the servers are written into the copy
144        // being staged, before it is uploaded.
145        if !mcp_servers.is_empty()
146            && ReviewMcpDelivery::for_harness(profile.kind) == ReviewMcpDelivery::HarnessProfile
147        {
148            configure_staged_review_mcp(profile.kind, &local, mcp_servers)
149                .with_context(|| format!("configure reviewer MCP servers for {profile_id:?}"))?;
150        }
151        upload_reviewer_profile(executor, &backend, &worker_root, generation, &local)?;
152
153        let (bridge_command, bridge_args) = bridge_launch(profile.kind, execution_policy);
154        let mut environment = profile.environment.clone();
155        // The worker sets the harness home from the directory it staged, so
156        // sending one here could only point the reviewer somewhere it must not
157        // read.
158        environment.remove(profile.home_env());
159        Ok(ReviewerLaunchConfig {
160            profile_id: profile_id.to_owned(),
161            harness: profile.kind,
162            bridge_command: bridge_command.into(),
163            bridge_args,
164            environment,
165            execution_policy,
166            model: None,
167            effort: None,
168            fast_mode: None,
169            generation,
170            // A harness that reads its servers from the staged profile must
171            // not also be offered them over ACP: it would either duplicate the
172            // server or reject the request.
173            mcp_servers: match ReviewMcpDelivery::for_harness(profile.kind) {
174                ReviewMcpDelivery::Acp => mcp_servers.to_vec(),
175                ReviewMcpDelivery::HarnessProfile => Vec::new(),
176            },
177        })
178    }
179}
180
181/// Writes `servers` into the staged profile of a harness that reads its MCP
182/// configuration from disk.
183///
184/// Claude Code reads `mcpServers` from `.claude.json` in its config directory;
185/// Kimi reads `mcpServers` from `mcp.json` in its home, and needs the runtime
186/// id its own schema carries. Both files are the reviewer's private copy, so
187/// nothing here can reach the user's own configuration.
188fn configure_staged_review_mcp(
189    harness: mj_core::config::HarnessKind,
190    profile_stage: &Path,
191    servers: &[ReviewMcpServer],
192) -> Result<()> {
193    let Some(file) = harness.mcp_config_file() else {
194        bail!("{harness:?} does not read MCP servers from its profile");
195    };
196    let kimi = harness == mj_core::config::HarnessKind::Kimi;
197    let path = profile_stage.join(file);
198    let mut document = match std::fs::read(&path) {
199        Ok(body) => serde_json::from_slice::<serde_json::Value>(&body)
200            .with_context(|| format!("parse staged reviewer configuration {}", path.display()))?,
201        Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
202            serde_json::Value::Object(serde_json::Map::new())
203        }
204        Err(error) => {
205            return Err(error)
206                .with_context(|| format!("read staged reviewer configuration {}", path.display()));
207        }
208    };
209    let root = document.as_object_mut().with_context(|| {
210        format!(
211            "staged reviewer configuration {} must contain a JSON object",
212            path.display()
213        )
214    })?;
215    let configured = root
216        .entry("mcpServers")
217        .or_insert_with(|| serde_json::Value::Object(serde_json::Map::new()))
218        .as_object_mut()
219        .with_context(|| {
220            format!(
221                "mcpServers in staged reviewer configuration {} must be a JSON object",
222                path.display()
223            )
224        })?;
225    for server in servers {
226        let mut entry = serde_json::json!({
227            "command": server.command,
228            "args": server.args,
229        });
230        if kimi {
231            let object = entry
232                .as_object_mut()
233                .expect("the server entry is a JSON object");
234            object.insert("transport".into(), "stdio".into());
235            object.insert("runtime_id".into(), "local".into());
236        } else {
237            let object = entry
238                .as_object_mut()
239                .expect("the server entry is a JSON object");
240            object.insert("type".into(), "stdio".into());
241        }
242        configured.insert(server.name.clone(), entry);
243    }
244    let mut body = serde_json::to_vec_pretty(&document)?;
245    body.push(b'\n');
246    mj_core::config::atomic_write(&path, &body)
247        .with_context(|| format!("write staged reviewer configuration {}", path.display()))
248}
249
250/// The review supervisor's dispatch tool, as it runs inside the container:
251/// this worker's own binary in `review-mcp` mode, talking to the socket the
252/// worker serves in its reviewer directory.
253fn review_dispatch_server(worker_root: &str) -> ReviewMcpServer {
254    let socket = format!(
255        "{worker_root}/{}/{}",
256        REVIEWER_DIR,
257        mj_core::review::mcp::REVIEW_DISPATCH_SOCKET
258    );
259    ReviewMcpServer {
260        name: mj_core::review::mcp::REVIEW_MCP_SERVER_NAME.to_owned(),
261        command: Path::new(worker_root).join("hel"),
262        args: vec![
263            "worker".to_owned(),
264            "review-mcp".to_owned(),
265            "--socket".to_owned(),
266            socket,
267        ],
268    }
269}
270
271/// Where one immutable reviewer profile snapshot lives on the target.
272///
273/// The worker copies this source into each role's private harness home before
274/// launch. Keeping generations in separate directories means staging a lane
275/// cannot replace the profile a running role is using.
276fn reviewer_profile_home(worker_root: &str, generation: u64) -> String {
277    reviewer_staging_profile_home(Path::new(worker_root), generation)
278        .to_string_lossy()
279        .into_owned()
280}
281
282/// Replace this generation's staged profile with a fresh copy of `local`.
283///
284/// The previous snapshot for this generation is removed first: a reviewer
285/// profile is a snapshot of the user's configured home, and merging a new copy
286/// over an old one would leave credentials and skills the source no longer has.
287fn upload_reviewer_profile(
288    executor: &impl CommandExecutor,
289    locator: &targets::TargetLocator,
290    worker_root: &str,
291    generation: u64,
292    local: &Path,
293) -> Result<()> {
294    let home = reviewer_profile_home(worker_root, generation);
295    match locator {
296        targets::TargetLocator::LocalBare { .. } => {
297            for command in [
298                CommandSpec::new("rm", ["-rf", "--", &home])
299                    .purpose("clear the local reviewer profile"),
300                CommandSpec::new("mkdir", ["-p", &home])
301                    .purpose("create the local reviewer profile directory"),
302                CommandSpec::new(
303                    "cp",
304                    [
305                        "-R".to_owned(),
306                        format!("{}/.", local.display()),
307                        home.clone(),
308                    ],
309                )
310                .purpose("install the local reviewer profile"),
311                CommandSpec::new("chmod", ["-R", "go-rwx", &home])
312                    .purpose("restrict local reviewer profile permissions"),
313            ] {
314                execute_checked(executor, command)?;
315            }
316        }
317        targets::TargetLocator::LocalPodman { container_id, .. }
318        | targets::TargetLocator::LocalDocker { container_id, .. }
319        | targets::TargetLocator::AppleContainer { container_id, .. } => {
320            let engine = match locator {
321                targets::TargetLocator::LocalPodman { .. } => "podman",
322                targets::TargetLocator::LocalDocker { .. } => "docker",
323                targets::TargetLocator::AppleContainer { .. } => "container",
324                _ => unreachable!("matched local container target"),
325            };
326            for arguments in [
327                vec![
328                    "exec".to_owned(),
329                    container_id.clone(),
330                    "rm".to_owned(),
331                    "-rf".to_owned(),
332                    "--".to_owned(),
333                    home.clone(),
334                ],
335                vec![
336                    "exec".to_owned(),
337                    container_id.clone(),
338                    "mkdir".to_owned(),
339                    "-p".to_owned(),
340                    home.clone(),
341                ],
342                vec![
343                    "cp".to_owned(),
344                    format!("{}/.", local.display()),
345                    format!("{container_id}:{home}"),
346                ],
347                container_upload_ownership_args(container_id, worker_root, &[&home]),
348                vec![
349                    "exec".to_owned(),
350                    container_id.clone(),
351                    "chmod".to_owned(),
352                    "-R".to_owned(),
353                    "go-rwx".to_owned(),
354                    home.clone(),
355                ],
356            ] {
357                execute_checked(
358                    executor,
359                    CommandSpec::new(engine, arguments).purpose("stage the reviewer profile"),
360                )?;
361            }
362        }
363        targets::TargetLocator::AwsEc2 { ssh, .. }
364        | targets::TargetLocator::SshBare { ssh, .. } => {
365            let incoming = format!("{home}.incoming");
366            execute_checked(
367                executor,
368                crate::targets::ssh_command(ssh, ["mkdir", "-p", worker_root])
369                    .purpose("create the reviewer directory"),
370            )?;
371            execute_checked(
372                executor,
373                crate::targets::ssh_command(ssh, ["rm", "-rf", "--", &incoming, &home])
374                    .purpose("clear the reviewer profile"),
375            )?;
376            execute_checked(
377                executor,
378                crate::targets::scp_upload(ssh, local, &incoming, true)
379                    .purpose("upload the reviewer profile"),
380            )?;
381            execute_checked(
382                executor,
383                crate::targets::ssh_command(ssh, ["mv", &incoming, &home])
384                    .purpose("install the reviewer profile"),
385            )?;
386            execute_checked(
387                executor,
388                crate::targets::ssh_command(ssh, ["chmod", "-R", "go-rwx", &home])
389                    .purpose("restrict reviewer profile permissions"),
390            )?;
391        }
392        targets::TargetLocator::SshPodman {
393            ssh, container_id, ..
394        }
395        | targets::TargetLocator::SshDocker {
396            ssh, container_id, ..
397        } => {
398            let engine = match locator {
399                targets::TargetLocator::SshPodman { .. } => "podman",
400                targets::TargetLocator::SshDocker { .. } => "docker",
401                _ => unreachable!("matched remote container target"),
402            };
403            let upload = format!("{worker_root}/.reviewer-upload-{generation}");
404            execute_checked(
405                executor,
406                crate::targets::ssh_command(ssh, ["rm", "-rf", "--", &upload])
407                    .purpose("clear remote reviewer staging"),
408            )?;
409            execute_checked(
410                executor,
411                crate::targets::scp_upload(ssh, local, &upload, true)
412                    .purpose("upload the remote reviewer profile"),
413            )?;
414            for arguments in [
415                vec![
416                    engine.to_owned(),
417                    "exec".to_owned(),
418                    container_id.clone(),
419                    "rm".to_owned(),
420                    "-rf".to_owned(),
421                    "--".to_owned(),
422                    home.clone(),
423                ],
424                vec![
425                    engine.to_owned(),
426                    "exec".to_owned(),
427                    container_id.clone(),
428                    "mkdir".to_owned(),
429                    "-p".to_owned(),
430                    home.clone(),
431                ],
432                vec![
433                    engine.to_owned(),
434                    "cp".to_owned(),
435                    format!("{upload}/."),
436                    format!("{container_id}:{home}"),
437                ],
438                std::iter::once(engine.to_owned())
439                    .chain(container_upload_ownership_args(
440                        container_id,
441                        worker_root,
442                        &[&home],
443                    ))
444                    .collect(),
445                vec![
446                    engine.to_owned(),
447                    "exec".to_owned(),
448                    container_id.clone(),
449                    "chmod".to_owned(),
450                    "-R".to_owned(),
451                    "go-rwx".to_owned(),
452                    home.clone(),
453                ],
454            ] {
455                execute_checked(
456                    executor,
457                    crate::targets::ssh_command(ssh, arguments)
458                        .purpose("stage the remote reviewer profile"),
459                )?;
460            }
461            execute_checked(
462                executor,
463                crate::targets::ssh_command(ssh, ["rm", "-rf", "--", &upload])
464                    .purpose("remove remote reviewer staging"),
465            )?;
466        }
467    }
468    if home.trim().is_empty() {
469        bail!("the reviewer profile home resolved to an empty path");
470    }
471    Ok(())
472}
473
474#[cfg(test)]
475mod tests {
476    use std::cell::RefCell;
477    use std::collections::BTreeMap;
478
479    use super::*;
480    use crate::controller::test_support::checkpoint_test_session;
481    use mj_core::config::{Config, HarnessKind, HarnessProfile, TargetTemplate};
482    use mj_core::state::{SessionState, State};
483
484    use crate::targets::CommandOutput;
485
486    struct RecordingExecutor {
487        commands: RefCell<Vec<CommandSpec>>,
488    }
489
490    impl RecordingExecutor {
491        fn new() -> Self {
492            Self {
493                commands: RefCell::new(Vec::new()),
494            }
495        }
496
497        /// Every command as one line, for order-sensitive assertions.
498        fn script(&self) -> Vec<String> {
499            self.commands
500                .borrow()
501                .iter()
502                .map(|command| format!("{} {}", command.program, command.args.join(" ")))
503                .collect()
504        }
505    }
506
507    impl CommandExecutor for RecordingExecutor {
508        fn execute(&self, command: &CommandSpec) -> Result<CommandOutput> {
509            self.commands.borrow_mut().push(command.clone());
510            Ok(CommandOutput {
511                status: 0,
512                stdout: Vec::new(),
513                stderr: Vec::new(),
514            })
515        }
516    }
517
518    /// A controller with one running session and two configured profiles: the
519    /// session's own and a second one to review with.
520    const SESSION_ID: &str = "0123456789abcdef0123456789abcdef";
521
522    fn fixture(directory: &Path, locator: mj_core::state::TargetLocator) -> (Controller, String) {
523        let session_id = SESSION_ID;
524        let mut session = checkpoint_test_session(session_id);
525        session.target_template_id = "local".into();
526        session.state = SessionState::Running;
527        let template = match &locator {
528            mj_core::state::TargetLocator::LocalPodman { .. } => {
529                serde_json::from_str(r#"{"kind":"local-podman","image":"test"}"#).unwrap()
530            }
531            mj_core::state::TargetLocator::LocalDocker { .. } => {
532                serde_json::from_str(r#"{"kind":"local-docker","image":"test"}"#).unwrap()
533            }
534            _ => TargetTemplate::LocalBare,
535        };
536        session.target = Some(locator);
537        let mut config = Config::default();
538        config.targets.insert("local".into(), template);
539        for (id, kind) in [
540            ("codex", HarnessKind::Codex),
541            ("claude", HarnessKind::Claude),
542        ] {
543            let home = directory.join(id);
544            std::fs::create_dir_all(&home).unwrap();
545            config.profiles.insert(
546                id.to_owned(),
547                HarnessProfile {
548                    enabled: true,
549                    kind,
550                    home,
551                    environment: BTreeMap::from([("EXTRA".into(), "1".into())]),
552                    context_window_bytes: None,
553                    guardian_review_model: None,
554                },
555            );
556        }
557        (
558            Controller {
559                config,
560                state: State {
561                    sessions: BTreeMap::from([(session_id.into(), session)]),
562                    ..State::default()
563                },
564            },
565            session_id.to_owned(),
566        )
567    }
568
569    #[test]
570    fn staging_copies_the_chosen_profile_into_the_worker_root() {
571        let directory = tempfile::tempdir().unwrap();
572        let worker_root = directory.path().join(SESSION_ID);
573        std::fs::create_dir_all(directory.path().join("claude")).unwrap();
574        // A file the allowlist copies, so the stage has something to move.
575        std::fs::write(directory.path().join("claude/CLAUDE.md"), b"reviewer").unwrap();
576        let (controller, session_id) = fixture(
577            directory.path(),
578            mj_core::state::TargetLocator::LocalBare {
579                worker_root: worker_root.clone(),
580            },
581        );
582        let executor = RecordingExecutor::new();
583
584        let config = controller
585            .stage_reviewer_profile_controlled(&session_id, "claude", 0, &[], &executor)
586            .unwrap();
587
588        assert_eq!(config.profile_id, "claude");
589        assert_eq!(config.harness, HarnessKind::Claude);
590        assert_eq!(config.generation, 0);
591        assert_eq!(config.model, None);
592        assert_eq!(config.effort, None);
593        // The worker owns the harness home, so the controller never sends one.
594        assert!(
595            !config
596                .environment
597                .contains_key(HarnessKind::Claude.home_env())
598        );
599        assert_eq!(
600            config.environment.get("EXTRA").map(String::as_str),
601            Some("1")
602        );
603
604        let home = format!("{}/reviewer/profile", worker_root.display());
605        let script = executor.script();
606        let cleared = script
607            .iter()
608            .position(|line| line.starts_with("rm ") && line.contains(&home))
609            .expect("the previous reviewer profile is cleared");
610        let copied = script
611            .iter()
612            .position(|line| line.starts_with("cp ") && line.ends_with(&home))
613            .expect("the staged profile is installed");
614        assert!(
615            cleared < copied,
616            "a stale profile must go before the new one lands: {script:?}"
617        );
618        assert!(
619            script
620                .iter()
621                .any(|line| line.contains("go-rwx") && line.contains(&home)),
622            "the reviewer profile must not be world readable: {script:?}"
623        );
624    }
625
626    #[test]
627    fn local_container_targets_stage_the_reviewer_through_their_engine() {
628        let directory = tempfile::tempdir().unwrap();
629        let container_id = crate::targets::resource_name(SESSION_ID).unwrap();
630        for (locator, engine) in [
631            (
632                mj_core::state::TargetLocator::LocalPodman {
633                    borrowed_from: None,
634                    container_id: container_id.clone(),
635                    workspace_storage: Default::default(),
636                },
637                "podman",
638            ),
639            (
640                mj_core::state::TargetLocator::LocalDocker {
641                    borrowed_from: None,
642                    container_id: container_id.clone(),
643                },
644                "docker",
645            ),
646        ] {
647            let (controller, session_id) = fixture(directory.path(), locator);
648            let executor = RecordingExecutor::new();
649
650            controller
651                .stage_reviewer_profile_controlled(&session_id, "codex", 3, &[], &executor)
652                .unwrap();
653
654            let script = executor.script();
655            assert!(
656                script
657                    .iter()
658                    .all(|line| line.starts_with(&format!("{engine} "))),
659                "a container target is reached only through its engine: {script:?}"
660            );
661            let home = script
662                .iter()
663                .find_map(|line| {
664                    line.split(' ')
665                        .find(|word| word.contains("/reviewer/profile"))
666                })
667                .expect("the reviewer profile is placed")
668                .to_owned();
669            assert!(
670                home.contains(&format!("/{session_id}")),
671                "the reviewer lives under this session's worker root: {home}"
672            );
673            // Nothing here provisions a target, a checkout, or another session.
674            assert!(
675                !script.iter().any(|line| {
676                    line.contains("run") || line.contains("git") || line.contains("create")
677                }),
678                "staging a reviewer provisions nothing: {script:?}"
679            );
680        }
681    }
682
683    #[test]
684    fn an_unknown_profile_is_refused_before_anything_is_copied() {
685        let directory = tempfile::tempdir().unwrap();
686        let (controller, session_id) = fixture(
687            directory.path(),
688            mj_core::state::TargetLocator::LocalBare {
689                worker_root: directory.path().join(SESSION_ID),
690            },
691        );
692        let executor = RecordingExecutor::new();
693
694        let error = controller
695            .stage_reviewer_profile_controlled(&session_id, "missing", 0, &[], &executor)
696            .unwrap_err();
697
698        assert!(format!("{error:#}").contains("unknown profile"));
699        assert!(executor.commands.borrow().is_empty());
700    }
701
702    #[test]
703    fn a_new_generation_travels_to_the_worker_so_it_starts_a_fresh_reviewer() {
704        let directory = tempfile::tempdir().unwrap();
705        let (controller, session_id) = fixture(
706            directory.path(),
707            mj_core::state::TargetLocator::LocalBare {
708                worker_root: directory.path().join(SESSION_ID),
709            },
710        );
711        let executor = RecordingExecutor::new();
712
713        let first = controller
714            .stage_reviewer_profile_controlled(&session_id, "codex", 0, &[], &executor)
715            .unwrap();
716        let second = controller
717            .stage_reviewer_profile_controlled(&session_id, "codex", 1, &[], &executor)
718            .unwrap();
719
720        assert!(first.reusable_for(&first));
721        assert!(
722            !first.reusable_for(&second),
723            "a new generation must not reload the old conversation"
724        );
725    }
726}