mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-07 08:27:12 +00:00
parent
0b6b0a56b1
commit
08bc24eb51
5 changed files with 218 additions and 13 deletions
|
|
@ -1,12 +1,14 @@
|
|||
{
|
||||
"timestamp": "2026-03-16T05:39:23.800410Z",
|
||||
"current_node": "solve",
|
||||
"timestamp": "2026-03-16T05:39:25.665535Z",
|
||||
"current_node": "extract_patch",
|
||||
"completed_nodes": [
|
||||
"start",
|
||||
"setup",
|
||||
"solve"
|
||||
"solve",
|
||||
"extract_patch"
|
||||
],
|
||||
"node_retries": {
|
||||
"extract_patch": 1,
|
||||
"solve": 1,
|
||||
"start": 1,
|
||||
"setup": 1
|
||||
|
|
@ -14,27 +16,42 @@
|
|||
"context_values": {
|
||||
"last_response": "Perfect! Let me review the complete flow of the fix:\n\n1. A setup command like `git clone https://github.com/django/django.git . && git checkout 466920f && python -m pip install -e .` is executed\n2. If",
|
||||
"response.solve": "Perfect! Let me review the complete flow of the fix:\n\n1. A setup command like `git clone https://github.com/django/django.git . && git checkout 466920f && python -m pip install -e .` is executed\n2. If it fails with an exit code != 0 AND the stderr contains \"not an empty directory\" or \"already exists and is not an empty\" AND the command contains \"git clone\"\n3. We call `construct_git_clone_fallback()` to create a modified command\n4. The modified command `git init && git remote add origin https://github.com/django/django.git && git fetch origin && git checkout 466920f && python -m pip install -e .` is executed\n5. If this succeeds, the setup continues; if not, we report the error\n\nThis is exactly what we need! The fix handles the \"directory not empty\" error gracefully by using an alternative git initialization approach.\n\nNow let me write a summary of the changes made:\n\n## Summary of Changes\n\nI've implemented a fix for the issue where setup commands that include `git clone` into the current directory (`.`) fail when the directory already contains files (e.g., workflow configuration files, initialization files, etc.).\n\n### Changes Made:\n\n1. **Added `construct_git_clone_fallback()` function** in `/home/daytona/workspace/lib/crates/fabro-workflows/src/cli/run.rs`:\n - Parses git clone commands to extract the repository URL and destination directory\n - Converts `git clone <url> .` into `git init && git remote add origin <url> && git fetch origin`\n - Preserves any additional commands in compound commands (e.g., `&& git checkout <commit>`)\n - Only applies the fallback when cloning into the current directory\n\n2. **Added `quote_shell_arg()` helper function** to properly quote shell arguments using the existing `shell_quote` utility\n\n3. **Enhanced setup command execution** in `run_command()`:\n - When a setup command fails with the \"directory not empty\" error from git clone\n - Automatically retries using the fallback approach instead of reporting failure\n - Logs the retry attempt for debugging\n\n4. **Added comprehensive tests** to verify:\n - Simple git clone commands are converted correctly\n - Compound commands with additional git/python operations are preserved\n - Commands cloning to non-current directories are not affected\n - Non-git-clone commands are not affected\n\n### How it works:\n\nWhen a workflow setup command tries to clone a repository into a non-empty directory:\n1. **Original command fails**: `git clone https://github.com/django/django.git . && git checkout 466920f && python -m pip install -e .`\n - Error: \"fatal: destination path '.' already exists and is not an empty directory.\"\n\n2. **Fallback command executes**: `git init && git remote add origin https://github.com/django/django.git && git fetch origin && git checkout 466920f && python -m pip install -e .`\n - Initializes a new git repository in the current directory\n - Adds the remote origin\n - Fetches all branches and commits\n - Continues with the original checkout and setup commands\n\nThis approach matches the pattern already used in the SSH and exe.dev sandboxes, ensuring consistency across all sandbox providers.",
|
||||
"command.output": "fatal: destination path '.' already exists and is not an empty directory.\n",
|
||||
"command.output": "",
|
||||
"thread.solve.current_node": "extract_patch",
|
||||
"internal.node_visit_count": 1,
|
||||
"internal.fidelity": "compact",
|
||||
"last_stage": "solve",
|
||||
"internal.retry_count.start": 1,
|
||||
"graph.rankdir": "LR",
|
||||
"internal.retry_count.extract_patch": 1,
|
||||
"failure_signature": "",
|
||||
"command.stderr": "",
|
||||
"internal.retry_count.setup": 1,
|
||||
"current_node": "solve",
|
||||
"current_node": "extract_patch",
|
||||
"internal.run_id": "01KKTJA7N831P0AH7DPCMNXPR1",
|
||||
"current.preamble": "Goal: \n\n## Completed stages\n- **setup**: fail\n - Script: `git clone https://github.com/django/django.git . && git checkout 466920f6d726eee90d5566e0a9948e92b33a122e && python -m pip install -e .`\n - Stdout:\n ```\n fatal: destination path '.' already exists and is not an empty directory.\n ```\n - Stderr: (empty)\n\n## Context\n- failure_class: deterministic\n- failure_signature: setup|deterministic|script failed with exit code: <n> ## stdout fatal: destination path '.' already exists and is not an empty directory.\n",
|
||||
"current.preamble": "Goal: \n\n## Completed stages\n- **setup**: fail\n - Script: `git clone https://github.com/django/django.git . && git checkout 466920f6d726eee90d5566e0a9948e92b33a122e && python -m pip install -e .`\n - Stdout:\n ```\n fatal: destination path '.' already exists and is not an empty directory.\n ```\n - Stderr: (empty)\n- **solve**: success\n - Model: claude-haiku-4-5, 60.1k tokens in / 18.2k out\n - Files: /home/daytona/workspace/lib/crates/fabro-workflows/src/cli/run.rs\n",
|
||||
"outcome": "success",
|
||||
"thread.setup.current_node": "solve",
|
||||
"thread.start.current_node": "setup",
|
||||
"internal.retry_count.solve": 1,
|
||||
"failure_class": "",
|
||||
"internal.thread_id": "setup"
|
||||
"internal.thread_id": "solve"
|
||||
},
|
||||
"logs": [],
|
||||
"node_outcomes": {
|
||||
"start": {
|
||||
"status": "success",
|
||||
"duration_ms": 0
|
||||
},
|
||||
"extract_patch": {
|
||||
"status": "success",
|
||||
"context_updates": {
|
||||
"command.output": "",
|
||||
"command.stderr": ""
|
||||
},
|
||||
"notes": "Script completed: git diff",
|
||||
"duration_ms": 22
|
||||
},
|
||||
"solve": {
|
||||
"status": "success",
|
||||
"context_updates": {
|
||||
|
|
@ -67,19 +84,16 @@
|
|||
"failure_class": "deterministic"
|
||||
},
|
||||
"duration_ms": 18
|
||||
},
|
||||
"start": {
|
||||
"status": "success",
|
||||
"duration_ms": 0
|
||||
}
|
||||
},
|
||||
"next_node_id": "extract_patch",
|
||||
"next_node_id": "exit",
|
||||
"loop_failure_signatures": {
|
||||
"setup|deterministic|script failed with exit code: <n> ## stdout fatal: destination path '.' already exists and is not an empty directory.": 1
|
||||
},
|
||||
"node_visits": {
|
||||
"start": 1,
|
||||
"solve": 1,
|
||||
"setup": 1,
|
||||
"solve": 1
|
||||
"extract_patch": 1
|
||||
}
|
||||
}
|
||||
5
nodes/extract_patch/script_invocation.json
Normal file
5
nodes/extract_patch/script_invocation.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"command": "git diff",
|
||||
"language": "shell",
|
||||
"timeout_ms": null
|
||||
}
|
||||
5
nodes/extract_patch/script_timing.json
Normal file
5
nodes/extract_patch/script_timing.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"duration_ms": 21,
|
||||
"exit_code": 0,
|
||||
"timed_out": false
|
||||
}
|
||||
6
nodes/extract_patch/status.json
Normal file
6
nodes/extract_patch/status.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"status": "success",
|
||||
"notes": "Script completed: git diff",
|
||||
"failure_reason": null,
|
||||
"timestamp": "2026-03-16T05:39:25.665322+00:00"
|
||||
}
|
||||
175
nodes/solve/diff.patch
Normal file
175
nodes/solve/diff.patch
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
diff --git a/lib/crates/fabro-workflows/src/cli/run.rs b/lib/crates/fabro-workflows/src/cli/run.rs
|
||||
index 749f888..0ff968a 100644
|
||||
--- a/lib/crates/fabro-workflows/src/cli/run.rs
|
||||
+++ b/lib/crates/fabro-workflows/src/cli/run.rs
|
||||
@@ -7,6 +7,7 @@ use std::time::Instant;
|
||||
use anyhow::{bail, Context};
|
||||
use chrono::{Local, Utc};
|
||||
use fabro_agent::{DockerSandbox, DockerSandboxConfig, LocalSandbox, Sandbox};
|
||||
+use fabro_util::shell::shell_quote;
|
||||
use fabro_util::terminal::Styles;
|
||||
use tracing::debug;
|
||||
|
||||
@@ -313,6 +314,84 @@ struct CostAccumulator {
|
||||
has_pricing: bool,
|
||||
}
|
||||
|
||||
+/// Constructs a fallback git clone command when the target directory is not empty.
|
||||
+/// Converts `git clone <url> .` to `git init && git remote add origin <url> && git fetch origin && git checkout [branch]`
|
||||
+/// Returns None if the command doesn't match a git clone pattern that can be handled.
|
||||
+fn construct_git_clone_fallback(cmd: &str) -> Option<String> {
|
||||
+ // Try to extract git clone parameters from the command
|
||||
+ // Pattern: git clone [options] <url> [<directory>] [&& other commands]
|
||||
+
|
||||
+ // Split by && to handle compound commands
|
||||
+ let parts: Vec<&str> = cmd.split("&&").collect();
|
||||
+ let clone_part = parts.first()?.trim();
|
||||
+
|
||||
+ if !clone_part.starts_with("git clone") {
|
||||
+ return None;
|
||||
+ }
|
||||
+
|
||||
+ // Simple regex-like parsing for: git clone [options] <url> [<path>] [&& ...]
|
||||
+ let tokens: Vec<&str> = clone_part.split_whitespace().collect();
|
||||
+ if tokens.len() < 3 {
|
||||
+ return None;
|
||||
+ }
|
||||
+
|
||||
+ // Find the URL and destination (skip 'git clone' and any leading options)
|
||||
+ let mut url_idx = 2;
|
||||
+ let mut url = None;
|
||||
+ let mut dest = ".";
|
||||
+
|
||||
+ // Skip options (starting with -)
|
||||
+ while url_idx < tokens.len() && tokens[url_idx].starts_with('-') {
|
||||
+ // Skip option and its value if it takes one
|
||||
+ url_idx += 1;
|
||||
+ if url_idx < tokens.len() && tokens[url_idx - 1].contains('=') == false {
|
||||
+ // Options like --branch take a value
|
||||
+ if matches!(tokens.get(url_idx - 1), Some(&opt) if opt.ends_with("branch")) {
|
||||
+ url_idx += 1;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // Next token should be the URL
|
||||
+ if url_idx < tokens.len() {
|
||||
+ url = Some(tokens[url_idx]);
|
||||
+ url_idx += 1;
|
||||
+ }
|
||||
+
|
||||
+ // Next token might be destination path
|
||||
+ if url_idx < tokens.len() && !tokens[url_idx].contains("://") {
|
||||
+ dest = tokens[url_idx];
|
||||
+ }
|
||||
+
|
||||
+ let url = url?;
|
||||
+
|
||||
+ // Only apply fallback if cloning into current directory
|
||||
+ if dest != "." {
|
||||
+ return None;
|
||||
+ }
|
||||
+
|
||||
+ // Construct fallback command: git init && git remote add origin <url> && git fetch origin
|
||||
+ // The original command's remaining parts (like git checkout) will handle branch/commit selection
|
||||
+ let mut fallback_cmd = format!(
|
||||
+ "git init && git remote add origin {} && git fetch origin",
|
||||
+ quote_shell_arg(url),
|
||||
+ );
|
||||
+
|
||||
+ // Append any remaining commands from the original compound command
|
||||
+ if parts.len() > 1 {
|
||||
+ let remaining = parts[1..].join("&&");
|
||||
+ fallback_cmd.push_str(" && ");
|
||||
+ fallback_cmd.push_str(remaining.trim());
|
||||
+ }
|
||||
+
|
||||
+ Some(fallback_cmd)
|
||||
+}
|
||||
+
|
||||
+/// Helper function to properly quote shell arguments
|
||||
+fn quote_shell_arg(s: &str) -> String {
|
||||
+ shell_quote(s).unwrap_or_else(|_| format!("'{}'", s))
|
||||
+}
|
||||
+
|
||||
/// Execute a full workflow run.
|
||||
///
|
||||
/// # Errors
|
||||
@@ -1040,10 +1119,28 @@ pub async fn run_command(
|
||||
index,
|
||||
});
|
||||
let cmd_start = Instant::now();
|
||||
- let result = sandbox
|
||||
+ let mut result = sandbox
|
||||
.exec_command(cmd, 300_000, None, None, None)
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Setup command failed: {e}"))?;
|
||||
+
|
||||
+ // If command failed with git clone "directory not empty" error, retry with fallback
|
||||
+ if result.exit_code != 0
|
||||
+ && (result.stderr.contains("not an empty directory")
|
||||
+ || result.stderr.contains("already exists and is not an empty"))
|
||||
+ && cmd.contains("git clone")
|
||||
+ {
|
||||
+ // Try to extract the repository URL and branch from the command
|
||||
+ // Pattern: git clone <url> <path> or just git clone <url>
|
||||
+ if let Some(retry_cmd) = construct_git_clone_fallback(cmd) {
|
||||
+ tracing::info!(original = cmd, fallback = &retry_cmd, "Retrying git clone with fallback");
|
||||
+ result = sandbox
|
||||
+ .exec_command(&retry_cmd, 300_000, None, None, None)
|
||||
+ .await
|
||||
+ .map_err(|e| anyhow::anyhow!("Setup command failed: {e}"))?;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
let cmd_duration = crate::millis_u64(cmd_start.elapsed());
|
||||
if result.exit_code != 0 {
|
||||
emitter.emit(&crate::event::WorkflowRunEvent::SetupFailed {
|
||||
@@ -3150,4 +3247,45 @@ mod tests {
|
||||
"third field must be event, got: {fields:?}"
|
||||
);
|
||||
}
|
||||
-}
|
||||
+
|
||||
+ #[test]
|
||||
+ fn git_clone_fallback_simple_django() {
|
||||
+ let cmd = "git clone https://github.com/django/django.git .";
|
||||
+ let result = construct_git_clone_fallback(cmd);
|
||||
+ assert!(result.is_some());
|
||||
+ let fallback = result.unwrap();
|
||||
+ assert!(fallback.contains("git init"));
|
||||
+ assert!(fallback.contains("git remote add origin"));
|
||||
+ assert!(fallback.contains("git fetch origin"));
|
||||
+ assert!(!fallback.contains("git clone"));
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn git_clone_fallback_with_compound_commands() {
|
||||
+ let cmd = "git clone https://github.com/django/django.git . && git checkout 466920f && python -m pip install -e .";
|
||||
+ let result = construct_git_clone_fallback(cmd);
|
||||
+ assert!(result.is_some());
|
||||
+ let fallback = result.unwrap();
|
||||
+ assert!(fallback.contains("git init"));
|
||||
+ assert!(fallback.contains("git remote add origin"));
|
||||
+ assert!(fallback.contains("git fetch origin"));
|
||||
+ assert!(fallback.contains("git checkout 466920f"));
|
||||
+ assert!(fallback.contains("python -m pip install -e ."));
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn git_clone_fallback_not_current_dir() {
|
||||
+ let cmd = "git clone https://github.com/django/django.git /tmp/django";
|
||||
+ let result = construct_git_clone_fallback(cmd);
|
||||
+ // Should not apply fallback since not cloning to current directory
|
||||
+ assert!(result.is_none());
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn git_clone_fallback_not_git_clone() {
|
||||
+ let cmd = "git init && git remote add origin https://github.com/django/django.git";
|
||||
+ let result = construct_git_clone_fallback(cmd);
|
||||
+ // Should not apply fallback since it's not a git clone command
|
||||
+ assert!(result.is_none());
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
Loading…
Add table
Reference in a new issue