Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(git_operations): report a config refusal as a refusal, not "not a repository"\n\nWith the layout gate green, `Rust Core Coverage` runs for the first time and\nfails: 3160 passed, 7 failed, all of them the #5494 repository-config\nhardening tests. That lane is gated behind `Rust Quality`, which fails on\n`main` at the layout step, so the lane has been reporting `skipped` and these\ntests have not executed on any branch. They fail identically on an unmodified\n`main` checkout — this PR did not break them, it revealed them.\n\nThe bug is an ordering inversion. `execute_in_context` decides whether it is\nin a repository by probing through `run_git_command_in`:\n\n let is_worktree = self\n .run_git_command_in(&effective_dir, &["rev-parse", "--is-inside-work-tree"])\n .await\n .is_ok_and(|output| output.trim() == "true");\n\nBut `run_git_command_in` refuses up front when the repository config carries a\ndisallowed key, bailing with the message that names it. `is_ok_and` discards\nthat error, so a repository setting `core.fsmonitor`, `credential.helper`,\n`core.worktree`, a worktree-scoped `core.hooksPath` or an LFS `filter.*` was\nreported to the user as **"Not in a git repository"** — false, and stripped of\nthe only text explaining which key caused it.\n\n`first_disallowed_repo_config_key` documents the ordering this restores: it\nsays the caller "has already confirmed `dir` — or one of its parents —\ncontains a `.git`". No such check exists in the file; the probe that stands in\nfor it routes back through the guard, which is circular.\n\nThe security property was never at risk — the command is refused and never\nexecutes, and every one of these tests asserts that separately. What was lost\nwas the diagnostic.\n\nTwo changes:\n\n- The probe runs `hardened_git` directly instead of `run_git_command_in`. Safe\n unguarded: `hardened_git` already neutralises every config key that names a\n command, so the probe cannot be turned into an execution primitive, and the\n real command still goes through the full allow-list check.\n\n- A failed probe no longer means "no repository". It can fail *because* the\n repository is misconfigured — a `core.worktree` redirect git cannot follow,\n or a config it cannot read — so the guard is consulted before concluding:\n a disallowed key yields the refusal naming it, an unreadable config yields\n "could not inspect its repository config", and only a genuinely clean\n non-repository yields "Not in a git repository".\n\n`disallowed_config_refusal` is extracted so the two paths that now produce\nthat refusal cannot word it differently.\n\n`cargo test --lib git_operations`: 42 passed, 0 failed (was 35/7).\n\nClaude-Session: https://claude.ai/code/session_014U1r9R4iFTNoq9vwyrLe7h\n

Shanu39a3cbd2bff2
diff --git a/src/openhuman/tools/impl/filesystem/git_operations.rs b/src/openhuman/tools/impl/filesystem/git_operations.rs
index ae718eedda..0186ce495e 100644
--- a/src/openhuman/tools/impl/filesystem/git_operations.rs
+++ b/src/openhuman/tools/impl/filesystem/git_operations.rs
@@ -6,7 +6,9 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use tinytools::ToolRunContext;
-use super::git_operations_config::{first_disallowed_repo_config_key, hardened_git};
+use super::git_operations_config::{
+ disallowed_config_refusal, first_disallowed_repo_config_key, hardened_git,
+};
use super::git_operations_render::{
render_branch_markdown, render_log_markdown, render_status_markdown,
};
@@ -100,14 +102,7 @@ impl GitOperationsTool {
"[git_operations] refusing to run git: dir={}, disallowed_config_key={key}",
cwd.display()
);
- anyhow::bail!(
- "refusing to run git in {}: its repository config sets `{key}`, which is \
- not on the allowlist of configuration this tool will run under. \
- Several git config keys name a command git then executes, and this \
- directory is agent-writable, so unrecognised configuration is treated \
- as untrusted rather than honoured.",
- cwd.display()
- )
+ anyhow::bail!("{}", disallowed_config_refusal(cwd, &key))
}
let output = hardened_git(cwd).args(args).output().await?;
@@ -553,12 +548,44 @@ impl GitOperationsTool {
// Validate the repository instead of trusting the presence of a `.git`
// path. This handles linked-worktree gitfiles and rejects malformed
// ancestor markers that Git itself cannot open.
- let is_worktree = self
- .run_git_command_in(&effective_dir, &["rev-parse", "--is-inside-work-tree"])
+ //
+ // Probed with `hardened_git` directly rather than through
+ // `run_git_command_in`. That helper refuses up front when the
+ // repository config carries a disallowed key, and routing the probe
+ // through it made the refusal indistinguishable from "there is no
+ // repository here": `is_ok_and` discarded the error, so a repo setting
+ // `core.fsmonitor` / `credential.helper` / `core.worktree` was reported
+ // as **not a git repository** and the message naming the key was lost
+ // (#5494). `first_disallowed_repo_config_key` even documents the
+ // ordering this restores — it expects the caller to have established
+ // that `dir` is a repository before it runs.
+ //
+ // Safe to probe unguarded: `hardened_git` already neutralises every
+ // config key that names a command, so this invocation cannot be turned
+ // into an execution primitive, and the real command below still goes
+ // through the full allow-list check in `run_git_command_in`.
+ let is_worktree = hardened_git(&effective_dir)
+ .args(["rev-parse", "--is-inside-work-tree"])
+ .output()
.await
- .is_ok_and(|output| output.trim() == "true");
+ .is_ok_and(|output| {
+ output.status.success() && String::from_utf8_lossy(&output.stdout).trim() == "true"
+ });
if !is_worktree {
- return Ok(ToolResult::error("Not in a git repository"));
+ // The probe can fail *because* the repository is misconfigured: a
+ // `core.worktree` redirect git cannot follow, or a config file it
+ // cannot read. Ask the guard before concluding there is nothing
+ // here, so a refusal is reported as a refusal — "Not in a git
+ // repository" is both false and un-actionable for those (#5494).
+ return Ok(
+ match first_disallowed_repo_config_key(&effective_dir).await {
+ Ok(Some(key)) => {
+ ToolResult::error(disallowed_config_refusal(&effective_dir, &key))
+ }
+ Err(error) => ToolResult::error(error.to_string()),
+ Ok(None) => ToolResult::error("Not in a git repository"),
+ },
+ );
}
// Check autonomy level for write operations
diff --git a/src/openhuman/tools/impl/filesystem/git_operations_config.rs b/src/openhuman/tools/impl/filesystem/git_operations_config.rs
index bc2b6ded6e..d4143a1b9a 100644
--- a/src/openhuman/tools/impl/filesystem/git_operations_config.rs
+++ b/src/openhuman/tools/impl/filesystem/git_operations_config.rs
@@ -253,6 +253,23 @@ pub(super) fn normalise_config_key(key: &str) -> String {
/// `git config --list` failing means the config could not be read, not that
/// there is none. Proceeding to run the real command against config this step
/// never actually inspected would defeat the point of inspecting it first.
+/// The refusal text for a repository whose config carries `key`.
+///
+/// Lives here so the two paths that produce it — the guard inside
+/// `run_git_command_in` and the repository probe in `execute_in_context`,
+/// which reaches this conclusion without ever getting as far as the guard —
+/// cannot word the same refusal differently.
+pub(super) fn disallowed_config_refusal(dir: &Path, key: &str) -> String {
+ format!(
+ "refusing to run git in {}: its repository config sets `{key}`, which is \
+ not on the allowlist of configuration this tool will run under. \
+ Several git config keys name a command git then executes, and this \
+ directory is agent-writable, so unrecognised configuration is treated \
+ as untrusted rather than honoured.",
+ dir.display()
+ )
+}
+
pub(super) async fn first_disallowed_repo_config_key(dir: &Path) -> anyhow::Result<Option<String>> {
let mut cmd = tokio::process::Command::new("git");
suppress_ambient_git_config(&mut cmd).current_dir(dir);