Skip to content

Commit 1ced355

Browse files
committed
fix: move workspace to /home/agent/sessions, fix node_modules permissions, improve agent code error handling
- Change DEFAULT_WORKSPACE_BASE from /tmp/sessions to /home/agent/sessions to avoid noexec mount issues - Add chmod +x on node_modules/.bin/ after npm install to fix vitest Permission denied - Bail with clear error when agent.py/main.py not found instead of silent fallback - Fix submit_tasks auth: return 503 when whitelist not ready instead of bypassing auth
1 parent 737ab1f commit 1ced355

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ RUN useradd -m -s /bin/bash agent \
5454
&& chown -R agent:agent /home/agent
5555

5656
COPY --from=builder /build/target/release/term-executor /usr/local/bin/
57-
RUN mkdir -p /tmp/sessions && chown agent:agent /tmp/sessions
57+
RUN mkdir -p /home/agent/sessions && chown agent:agent /home/agent/sessions
5858

5959
USER agent
6060
ENV HOME=/home/agent

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const DEFAULT_CLONE_TIMEOUT: u64 = 600;
77
const DEFAULT_AGENT_TIMEOUT: u64 = 600;
88
const DEFAULT_TEST_TIMEOUT: u64 = 300;
99
const DEFAULT_MAX_ARCHIVE_BYTES: usize = 500 * 1024 * 1024;
10-
const DEFAULT_WORKSPACE_BASE: &str = "/tmp/sessions";
10+
const DEFAULT_WORKSPACE_BASE: &str = "/home/agent/sessions";
1111
const DEFAULT_MAX_PENDING_CONSENSUS: usize = 100;
1212
const DEFAULT_BITTENSOR_NETUID: u16 = 100;
1313
const DEFAULT_MIN_VALIDATOR_STAKE_TAO: f64 = 10_000.0;

src/executor.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,19 @@ async fn run_task_pipeline(
546546
}
547547
}
548548

549+
// Ensure node_modules/.bin binaries are executable (fixes "Permission denied" with vitest etc.)
550+
let node_bin_dir = repo_dir.join("node_modules/.bin");
551+
if node_bin_dir.exists() {
552+
debug!("[{}] Fixing node_modules/.bin permissions", task.id);
553+
let _ = run_shell(
554+
"chmod -R +x node_modules/.bin/ 2>/dev/null || true",
555+
&repo_dir,
556+
Duration::from_secs(30),
557+
None,
558+
)
559+
.await;
560+
}
561+
549562
if *cancel_rx.borrow() {
550563
anyhow::bail!("Cancelled");
551564
}
@@ -1094,13 +1107,29 @@ async fn run_agent(
10941107
}
10951108
}
10961109

1110+
// Log extracted agent directory structure for debugging
1111+
debug!(
1112+
"Agent directory resolved to: {}",
1113+
agent_dir.display()
1114+
);
1115+
if let Ok(mut entries) = tokio::fs::read_dir(&agent_dir).await {
1116+
let mut files = Vec::new();
1117+
while let Ok(Some(entry)) = entries.next_entry().await {
1118+
files.push(entry.file_name().to_string_lossy().to_string());
1119+
}
1120+
debug!("Agent directory contents: {:?}", files);
1121+
}
1122+
10971123
// Determine entry point (use absolute path so we can run from repo_dir)
10981124
let entry_file = if agent_dir.join("agent.py").exists() {
10991125
agent_dir.join("agent.py")
11001126
} else if agent_dir.join("main.py").exists() {
11011127
agent_dir.join("main.py")
11021128
} else {
1103-
agent_dir.join("agent.py")
1129+
anyhow::bail!(
1130+
"Agent code not found: neither agent.py nor main.py exists in {}",
1131+
agent_dir.display()
1132+
);
11041133
};
11051134

11061135
let mut argv = vec![

src/handlers.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,20 +1066,28 @@ async fn submit_tasks(
10661066
)
10671067
})?;
10681068

1069-
if state.validator_whitelist.validator_count() > 0 {
1070-
if let Err(e) = auth::verify_request(
1071-
&auth_headers,
1072-
&state.nonce_store,
1073-
&state.validator_whitelist,
1074-
) {
1075-
return Err((
1076-
StatusCode::UNAUTHORIZED,
1077-
Json(serde_json::json!({
1078-
"error": e.code(),
1079-
"message": e.message(),
1080-
})),
1081-
));
1082-
}
1069+
if state.validator_whitelist.validator_count() == 0 {
1070+
return Err((
1071+
StatusCode::SERVICE_UNAVAILABLE,
1072+
Json(serde_json::json!({
1073+
"error": "whitelist_not_ready",
1074+
"message": "Validator whitelist not yet initialized. Please retry shortly."
1075+
})),
1076+
));
1077+
}
1078+
1079+
if let Err(e) = auth::verify_request(
1080+
&auth_headers,
1081+
&state.nonce_store,
1082+
&state.validator_whitelist,
1083+
) {
1084+
return Err((
1085+
StatusCode::UNAUTHORIZED,
1086+
Json(serde_json::json!({
1087+
"error": e.code(),
1088+
"message": e.message(),
1089+
})),
1090+
));
10831091
}
10841092

10851093
// Parse multipart: expect "task_ids" (JSON) and "archive" (file)

0 commit comments

Comments
 (0)