Repository navigation
fix(sandbox): review follow-ups from #60 — launch failure, resume confinement, param honesty #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -637,9 +637,12 @@ impl StreamJsonSession { | |
| let mut args = resolved.args.clone(); | ||
| args.extend(dialect.launch_args(&config, resume)); | ||
|
|
||
| let transport = resolved | ||
| .spawn_ndjson(&args, &HashMap::new(), &config) | ||
| .await?; | ||
| // `[backends.X].env` reaches the child like every other backend's | ||
| // (it used to be dropped here, which silently disabled the override | ||
| // — and, worse for the sandbox, left the policy binding an | ||
| // `CLAUDE_CONFIG_DIR` the process never saw). | ||
| let env: HashMap<String, String> = resolved.env.iter().cloned().collect(); | ||
| let transport = resolved.spawn_ndjson(&args, &env, &config).await?; | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
Comment on lines
+644
to
+645
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 별도 설정 디렉터리의 Claude 세션이 가져오기 목록에서 누락됨 백엔드에 Learn more세션을 시작하거나 재개할 때 Claude는 백엔드 환경에 지정된 Example: Recommended fix: Claude의 세션 목록 구현에 실제 실행과 같은 설정 루트를 전달하세요. 백엔드 환경의 오버라이드, 상속 환경, 기본 경로의 우선순위를 실행과 검색에서 일치시키고, 커스텀 설정 루트에만 세션 파일이 있는 경우를 테스트하세요. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| let session = Arc::new(Self { | ||
| transport: transport.clone(), | ||
|
|
@@ -962,10 +965,8 @@ impl AgentSession for OneShotSession { | |
| args.extend(self.dialect.launch_args(&config, resume.as_deref())); | ||
| args.extend(self.dialect.prompt_args(&prompt)?); | ||
|
|
||
| let transport = self | ||
| .resolved | ||
| .spawn_ndjson(&args, &HashMap::new(), &config) | ||
| .await?; | ||
| let env: HashMap<String, String> = self.resolved.env.iter().cloned().collect(); | ||
| let transport = self.resolved.spawn_ndjson(&args, &env, &config).await?; | ||
| *self.active.lock().await = Some(transport.clone()); | ||
|
|
||
| let turn_id = uuid::Uuid::new_v4().to_string(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
|
|
||
| use std::path::Path; | ||
| use std::process::{Command, Stdio}; | ||
| use std::sync::OnceLock; | ||
| use std::sync::{Mutex, OnceLock}; | ||
| use std::time::{Duration, Instant}; | ||
|
|
||
| use anyhow::{Result, bail}; | ||
|
|
@@ -31,9 +31,14 @@ use super::{ | |
| }; | ||
|
|
||
| /// How long the availability probe may take before it counts as unusable. | ||
| /// A working bwrap answers in milliseconds; a hung one must not stall | ||
| /// `doctor` or the first session. | ||
| const PROBE_TIMEOUT: Duration = Duration::from_secs(10); | ||
| /// A working bwrap answers in milliseconds. The probe runs inline on a | ||
| /// tokio worker (the decision is sync), so the cap is short: a hung bwrap | ||
| /// must not hold a worker for a session start. | ||
| const PROBE_TIMEOUT: Duration = Duration::from_secs(3); | ||
|
|
||
| /// How long a probe answer is trusted before the next `auto` resolution | ||
| /// re-checks (see `Bwrap::status`). | ||
| const STATUS_TTL: Duration = Duration::from_secs(30); | ||
|
|
||
| pub struct Bwrap; | ||
|
|
||
|
|
@@ -43,8 +48,23 @@ impl SandboxDriver for Bwrap { | |
| } | ||
|
|
||
| fn status(&self) -> DriverStatus { | ||
| static STATUS: OnceLock<DriverStatus> = OnceLock::new(); | ||
| STATUS.get_or_init(probe).clone() | ||
| // Re-probed after a short while: `auto` reads this on every session | ||
| // start, and a driver installed (or a sysctl flipped) while the | ||
| // daemon runs must take effect without a restart — a forever-cached | ||
| // "not usable" would leave a resident daemon unconfined with no way | ||
| // to tell. The probe is one short-lived process, so the window keeps | ||
| // session starts cheap without pinning the answer. | ||
| static CACHE: OnceLock<Mutex<Option<(Instant, DriverStatus)>>> = OnceLock::new(); | ||
| let cache = CACHE.get_or_init(|| Mutex::new(None)); | ||
| let mut guard = cache.lock().unwrap_or_else(|e| e.into_inner()); | ||
| if let Some((at, status)) = guard.as_ref() | ||
| && at.elapsed() < STATUS_TTL | ||
| { | ||
| return status.clone(); | ||
| } | ||
| let status = probe(); | ||
| *guard = Some((Instant::now(), status.clone())); | ||
|
Comment on lines
+57
to
+66
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 주기적 드라이버 검사가 비동기 워커를 점유함 캐시가 만료되면 백엔드 실행이 Tokio 워커에서 드라이버 프로세스를 동기적으로 기다린다. 완료할 때까지 캐시 잠금도 유지하므로, 재검사를 블로킹 전용 작업으로 분리할지 검토할 만하다. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| status | ||
| } | ||
|
|
||
| fn wrap( | ||
|
|
@@ -60,10 +80,15 @@ impl SandboxDriver for Bwrap { | |
| } | ||
| } | ||
|
|
||
| /// The launcher binary name. Resolved through PATH by the spawn, which is | ||
| /// also how the probe found it. | ||
| /// The launcher to exec: resolved to an absolute path against the daemon's | ||
| /// PATH, so the launch does not depend on the *child's* environment — a | ||
| /// `[backends.X].env` PATH (a custom bin dir, a cleanup helper) would | ||
| /// otherwise leave `bwrap` unresolvable and the session unable to start. | ||
| /// It also guarantees the binary the probe validated is the one used. | ||
| fn launcher() -> String { | ||
| "bwrap".to_string() | ||
| crate::backend::registry::which("bwrap") | ||
| .map(|p| p.to_string_lossy().into_owned()) | ||
| .unwrap_or_else(|| "bwrap".to_string()) | ||
|
Comment on lines
+89
to
+91
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟥 작업공간의 파일이 샌드박스 런처로 실행됨 데몬의 Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| } | ||
|
|
||
| /// Policy + command → the full `bwrap` argument list (everything after the | ||
|
|
@@ -184,6 +209,10 @@ fn probe() -> DriverStatus { | |
| "/dev", | ||
| "--proc", | ||
| "/proc", | ||
| // The recipe's own scratch mount, so a host where /tmp cannot be | ||
| // masked fails here rather than at the first session. | ||
| "--tmpfs", | ||
| "/tmp", | ||
| "--unshare-all", | ||
| "--die-with-parent", | ||
| "--new-session", | ||
|
|
@@ -460,7 +489,12 @@ mod tests { | |
| policy: Box::new(policy(NetworkPolicy::Allow)), | ||
| }; | ||
| let cmd = confined.confine("claude", &[]).unwrap(); | ||
| assert_eq!(cmd.program, "bwrap"); | ||
| // Absolute when bwrap is on the daemon's PATH, bare otherwise. | ||
| assert!( | ||
| cmd.program == "bwrap" || cmd.program.ends_with("/bwrap"), | ||
| "{}", | ||
| cmd.program | ||
| ); | ||
| assert_eq!(cmd.args.last().unwrap(), "claude"); | ||
| } | ||
|
|
||
|
|
@@ -475,6 +509,7 @@ mod tests { | |
| network: NetworkPolicy::Backend, | ||
| cwd: Path::new("/tmp"), | ||
| extra_writable: &[], | ||
| launch_env: &[], | ||
| }; | ||
| let decision = decide(&spec).unwrap(); | ||
| assert!(matches!( | ||
|
|
@@ -486,9 +521,18 @@ mod tests { | |
| request: SandboxRequest::Bwrap, | ||
| ..spec | ||
| }; | ||
| let err = decide(&spec).unwrap_err().to_string(); | ||
| assert!(err.contains("opencode"), "{err}"); | ||
| assert!(err.contains("sandbox = \"none\""), "{err}"); | ||
| let err = decide(&spec).unwrap_err(); | ||
| let msg = err.to_string(); | ||
| assert!(msg.contains("opencode"), "{msg}"); | ||
| assert!(msg.contains("sandbox = \"none\""), "{msg}"); | ||
| // Typed, so the wire answers `not_supported` rather than a daemon | ||
| // bug (see rpc::error_payload). | ||
| assert!( | ||
| err.chain().any(|c| c | ||
| .downcast_ref::<crate::sandbox::SandboxUnsupported>() | ||
| .is_some()), | ||
| "the refusal must stay typed: {msg}" | ||
| ); | ||
| } | ||
|
|
||
| /// An explicit opt-out is honored everywhere, serve mode included. | ||
|
|
@@ -501,6 +545,7 @@ mod tests { | |
| network: NetworkPolicy::Backend, | ||
| cwd: Path::new("/tmp"), | ||
| extra_writable: &[], | ||
| launch_env: &[], | ||
| }; | ||
| assert_eq!( | ||
| decide(&spec).unwrap(), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.