fix(missions): let the server and the agent share one git checkout
Mission 019fc437 lost both phases' work to:
git add → exit 128: insufficient permission for adding an object
to repository database .git/objects
cm-api runs as uid 65532; the mission runtime container runs as root;
they share one bind-mounted checkout. Git's .git/objects/xx/ fan-out
directories inherit the ownership of whoever creates them, so an agent
that writes objects first locks the server out of those directories.
The failure is intermittent, which is why the previous run looked clean.
Mission 019fc42b's agents committed their own work, so the blobs already
existed and the server's `git add` never had to write one. Same template,
different agent behaviour, opposite outcome.
`core.sharedRepository` is git's own mechanism for this: objects and refs
are created group- and world-writable, and both parties read the setting
from the shared .git/config. It grants the agent nothing — it is already
root over the whole checkout — and unblocks the server, which was the
party being refused. Applied on clone and on checkout reuse.
Two supporting changes. The artifact now records `commit_error`: this
failure surfaced as `branch: null, push_error: null`, indistinguishable
from a phase that never had work to commit, with the reason only in host
stderr. And the test seeder now calls the production setup function
instead of reimplementing it — building the checkout by hand is what let
a clone-path defect stay invisible to fourteen tests.
Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
8bad869248
commit
5b53705c97
@@ -67,6 +67,9 @@ pub async fn ensure_checkout(
|
||||
|
||||
let auth_url = with_ambient_auth(clone_url);
|
||||
if path.join(".git").exists() {
|
||||
// Checkouts cloned before this setting existed get it on reuse. It
|
||||
// governs objects created from now on, which is what delivery needs.
|
||||
share_repository_across_uids(&path);
|
||||
fetch_and_reset(&path, default_branch, &auth_url).await?;
|
||||
} else {
|
||||
clone(&path, &auth_url).await?;
|
||||
@@ -119,12 +122,68 @@ async fn clone(path: &std::path::Path, url: &str) -> Result<(), String> {
|
||||
.collect::<String>()
|
||||
));
|
||||
}
|
||||
share_repository_across_uids(path);
|
||||
scrub_remote_credentials(path, url);
|
||||
ignore_agent_scaffolding(path);
|
||||
record_base_commit(path);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Let the server and the agent container both write to this checkout.
|
||||
///
|
||||
/// The checkout is one directory bind-mounted into two processes running as
|
||||
/// different users: cm-api is uid 65532, the mission runtime container is
|
||||
/// root. Git creates `.git/objects/xx/` fan-out directories on first write and
|
||||
/// they inherit the writer's ownership, so whichever party commits first locks
|
||||
/// the other out of that directory:
|
||||
///
|
||||
/// ```text
|
||||
/// git add → exit 128: insufficient permission for adding an object
|
||||
/// to repository database .git/objects
|
||||
/// ```
|
||||
///
|
||||
/// The failure is intermittent, which is what makes it dangerous. Mission
|
||||
/// `019fc42b` delivered cleanly because its agents committed their own work,
|
||||
/// so the blobs already existed and the server's `git add` never had to write
|
||||
/// one. Mission `019fc437` ran the same template, its agents left the work
|
||||
/// uncommitted, and delivery lost both phases.
|
||||
///
|
||||
/// `core.sharedRepository` is git's own answer to a repository shared between
|
||||
/// users: it makes git create objects and refs group- and world-writable. Both
|
||||
/// parties read this config from the shared `.git/config`, so it governs the
|
||||
/// agent's commits as much as ours.
|
||||
///
|
||||
/// This grants the agent no access it lacks. It is already root inside a
|
||||
/// container with the entire checkout bind-mounted read-write, and could
|
||||
/// rewrite any of it. The party actually gaining something is the server,
|
||||
/// which is currently the one being locked out.
|
||||
pub fn share_repository_across_uids(path: &std::path::Path) {
|
||||
let out = std::process::Command::new("git")
|
||||
.args([
|
||||
"-C",
|
||||
&path.display().to_string(),
|
||||
"-c",
|
||||
&format!("safe.directory={}", path.display()),
|
||||
"config",
|
||||
"core.sharedRepository",
|
||||
"0777",
|
||||
])
|
||||
.output();
|
||||
match out {
|
||||
Ok(o) if o.status.success() => {}
|
||||
Ok(o) => eprintln!(
|
||||
"mission_workspace: could not set core.sharedRepository on {} ({}) — delivery \
|
||||
may fail to commit if the agent writes git objects first",
|
||||
path.display(),
|
||||
String::from_utf8_lossy(&o.stderr).trim()
|
||||
),
|
||||
Err(e) => eprintln!(
|
||||
"mission_workspace: could not set core.sharedRepository on {} ({e})",
|
||||
path.display()
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Remember the commit the mission started from.
|
||||
///
|
||||
/// Delivery needs to answer "what did this mission change", and the obvious
|
||||
|
||||
Reference in New Issue
Block a user