{"record":{"id":"18fd4457fd300723","repo":"Hmbown/CodeWhale","slug":"reviewed-plugin-stage-changed-before-stdio-launch","errorCode":null,"errorMessage":"reviewed plugin stage changed before stdio launch","messagePattern":"reviewed plugin stage changed before stdio launch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp.rs","lineNumber":684,"sourceCode":"        server_name: &str,\n        command: &str,\n        args: &[String],\n        cwd: Option<&Path>,\n    ) -> Result<ReviewedStdioLaunch> {\n        self.validate_before_stdio_spawn(server_name)?;\n        let staged_root = self\n            .authority\n            .staged_manifest\n            .parent()\n            .context(\"reviewed plugin stage manifest has no parent\")?;\n        let validated = crate::plugins::manifest::PluginManifest::validate_from_path(\n            &self.authority.staged_manifest,\n        )\n        .map_err(|_| anyhow::anyhow!(\"reviewed plugin stage could not be opened for launch\"))?;\n        if validated.content_hash != self.authority.content_hash\n            || validated.capability_hash != self.authority.capability_hash\n        {\n            anyhow::bail!(\"reviewed plugin stage changed before stdio launch\");\n        }\n\n        let mut launch = ReviewedStdioLaunch {\n            command: std::ffi::OsString::from(command),\n            args: args.iter().map(std::ffi::OsString::from).collect(),\n            cwd: cwd.map(Path::to_path_buf),\n            opened_files: Vec::new(),\n            #[cfg(unix)]\n            cwd_fd: None,\n        };\n        if Path::new(command).is_absolute() {\n            launch.bind_command(staged_root, Path::new(command), &validated.file_hashes)?;\n        }\n        // Darwin descriptor paths lose Node's module filename, package.json\n        // context and relative-import directory (#5916). Keep the staged path\n        // for .js/.cjs and multi-file .mjs entries, after bind_file verifies\n        // their bytes. Node reopens these paths; this is not atomic descriptor\n        // execution. Sibling modules already use the reviewed staged paths.","sourceCodeStart":666,"sourceCodeEnd":702,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L666-L702","documentation":"Before launching a reviewed plugin over stdio, prepare_stdio_launch re-opens and validates the reviewed stage and compares its content and capability hashes against the hashes captured when the plugin was approved. If the staged files changed since review (drift), launch is refused to guarantee the reviewed code is the code that runs.","triggerScenarios":"The staged plugin directory was modified (or re-staged from changed sources) between the security review/approval and the stdio launch; concurrent re-staging by another process; a stale stage directory whose hashes no longer match the authority's recorded content_hash/capability_hash.","commonSituations":"Long-lived session where the plugin was updated on disk after approval; plugin auto-update overwriting the stage mid-session; interrupted staging leaving a partially rewritten stage; developer manually editing staged plugin files.","solutions":["Re-stage and re-review the plugin so the authority hashes match the current stage, then relaunch","Restart the session/workflow so the plugin is staged and approved fresh","Investigate what modified the stage directory (updater, another agent run) before retrying","Restore the stage to its originally approved content if it was changed accidentally"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before launch: recompute stage hashes and compare against approved authority\nconst current = hashStage(stageDir);\nif (current.content !== approved.contentHash || current.capability !== approved.capabilityHash) {\n  throw new Error(\"stage drift detected; re-review plugin before launch\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  launchStdioPlugin(plugin);\n} catch (e) {\n  if (String(e).includes(\"stage changed before stdio launch\")) {\n    // halt the plugin, trigger re-staging + re-review workflow, never retry blindly\n  }\n  throw e;\n}","preventionTips":["Treat the stage directory as immutable after approval; disable auto-updaters on it","Re-run review whenever plugin sources change","Monitor stage directory mtimes and alert on post-approval writes"],"tags":["mcp","security","plugin"],"backgroundTag":"checksum-mismatch","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}