Skip to content

feat(tools): add per-turn ExecutionContext to ShellExecutor#3589

Merged
bug-ops merged 3 commits intomainfrom
3572-per-turn-env-selection
May 4, 2026
Merged

feat(tools): add per-turn ExecutionContext to ShellExecutor#3589
bug-ops merged 3 commits intomainfrom
3572-per-turn-env-selection

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented May 4, 2026

Summary

  • Adds ExecutionContext (named environment, cwd, env_overrides, trusted flag) to ToolCall so each DAG subtask can target a different working directory and env set without restarting the session
  • ShellExecutor::resolve_context is the single dispatch chokepoint with explicit precedence: call-site > named registry > skill env > process default
  • Speculative cache HandleKey gains context_hash to prevent cross-environment result reuse in parallel subagent scenarios
  • validate_sandbox_with_cwd uses ancestor-walk for not-yet-created paths and rejects .. traversal without unsafe std::path::absolute fallback (security fix)
  • env_blocklist applied to final merged env for untrusted contexts (prefix-match, not exact-match)
  • New [execution] config section with [[execution.environments]] named registry
  • 18 unit tests covering resolution precedence, sandbox enforcement, blocklist, trust model

Breaking changes

  • AuditEntry::resolved_cwd changed from String to Option<String> with skip_serializing_if — non-shell tool producers now emit null instead of ""

Test plan

  • cargo +nightly fmt --check — clean
  • cargo clippy --all-targets --workspace -- -D warnings — clean
  • cargo nextest run --config-file .github/nextest.toml --workspace --lib --bins — 8719 passed
  • Security: path traversal test (allowed/../../etc/shadow rejected)
  • Trust: untrusted context cannot bypass blocklist via env_overrides or skill_env
  • Cache: parallel tool calls with different execution contexts get isolated cache keys
  • Live session: cargo run --features full -- --config .local/config/testing.toml (LLM serialization gate — required before merge per branching.md)

Closes #3572

@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes core zeph-core crate enhancement New feature or request size/XL Extra large PR (500+ lines) labels May 4, 2026
Add optional execution context (named environment, cwd, env overrides) to
ToolCall so orchestrator DAG nodes can target different working directories
and environment variable sets per turn without restarting a session.

Key changes:
- New ExecutionContext type (trusted/untrusted, name, cwd, env_overrides)
- ShellExecutor::resolve_context chokepoint with precedence:
  call-site > named registry > skill env > process default
- validate_sandbox_with_cwd: ancestor-walk for non-existent paths,
  rejects traversal without std::path::absolute fallback
- Speculative cache HandleKey gains context_hash to prevent cross-env
  result reuse in parallel subagent scenarios
- TaskNode::execution_environment wired through scheduler_loop to native
  tool dispatch
- Background path uses spawn_background_with_context with pre-resolved env
- AuditEntry::resolved_cwd changed to Option<String> (BREAKING)
- env_blocklist applied to final merged env for untrusted contexts
- Tracing spans: tools.shell.resolve_context, tool.shell.execute_block,
  tool.shell.execute_tool_call
- New [execution] config section with [[execution.environments]] registry
- 18 unit tests covering CWD resolution, sandbox, blocklist, trust model

Closes #3572
@bug-ops bug-ops force-pushed the 3572-per-turn-env-selection branch from fcc96c5 to 4fd2d47 Compare May 4, 2026 18:03
@bug-ops bug-ops enabled auto-merge (squash) May 4, 2026 18:04
bug-ops added 2 commits May 4, 2026 20:12
…nflicts

Both branches added fields to AuditEntry:
- #3572: execution_env, resolved_cwd
- #3588: scope_at_definition, scope_at_dispatch

Keep all four fields. Fix missing context: None in scope.rs test helper.
@bug-ops bug-ops merged commit 3414ff5 into main May 4, 2026
32 checks passed
@bug-ops bug-ops deleted the 3572-per-turn-env-selection branch May 4, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

research(orchestration): Codex CLI per-turn multi-environment selection — choose execution environment and working directory per agent turn

1 participant