Skip to content

fix(agent): stop stack overflow in agent_factory test under full features - #6711

Merged
bug-ops merged 1 commit into
mainfrom
fix/6699-agent-factory-stack-overflow
Jul 28, 2026
Merged

fix(agent): stop stack overflow in agent_factory test under full features#6711
bug-ops merged 1 commit into
mainfrom
fix/6699-agent-factory-stack-overflow

Conversation

@bug-ops

@bug-ops bug-ops commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • VigilGate::try_new (crates/zeph-core/src/agent/vigil.rs) recompiled the entire 14-pattern bundled injection bank via regex::Regex::new() on every Agent construction — the only one of 7 consumers of RAW_INJECTION_PATTERNS that didn't already cache the compile behind a LazyLock. Cached it behind a process-wide static, matching the six sibling call sites (zeph-sanitizer, zeph-mcp, zeph-skills). Independent perf fix, not itself sufficient to prevent the crash (nextest runs each test in its own process, so the cache is cold on first touch regardless).
  • Under --features full, one bundled pattern triggers regex_automata's SIMD Teddy-prefilter builder, whose frame overflowed the default 2 MiB test-thread stack when reached ~25 frames deep through serve::agent_factory::tests::build_agent_factory_gates_trust_state_independently_per_session's two-Agent construction chain (inflated further by full's unboxed AnyProvider::Candle/Gonka/Cocoon variants). Gave that test a dedicated 32 MiB-stack thread (named, with a resume_unwind panic passthrough), matching both MAIN_THREAD_STACK_SIZE (src/main.rs, zeph --daemon crashes with stack overflow on every invocation #5394) and the coverage job's existing RUST_MIN_STACK: "33554432" (added in 9a1efb89a for this exact test under instrumented coverage) — the explicit stack_size() would otherwise have silently overridden that CI protection down from 32 MiB to a smaller value.
  • Updated the coverage job's CI comment to reflect that this test now self-manages its stack, while keeping the env var (it still protects other, unnamed multi-agent tests).

Closes #6699

Test plan

  • cargo test -p zeph --bin zeph --features full serve::agent_factory::tests::build_agent_factory_gates_trust_state_independently_per_session -- --exact — passes (previously SIGABRT)
  • cargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler,testing" --lib --bins — 15258 passed, 0 failed
  • cargo +nightly fmt --check — clean
  • cargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warnings — clean
  • RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler" — clean
  • gitleaks protect --staged — no leaks

@github-actions github-actions Bot added bug Something isn't working size/M Medium PR (51-200 lines) documentation Improvements or additions to documentation rust Rust code changes core zeph-core crate ci CI/CD configuration labels Jul 28, 2026
@bug-ops
bug-ops enabled auto-merge (squash) July 28, 2026 19:01
@bug-ops
bug-ops force-pushed the fix/6699-agent-factory-stack-overflow branch from 25f778b to 7714806 Compare July 28, 2026 19:01
@bug-ops
bug-ops disabled auto-merge July 28, 2026 19:01
…ures

VigilGate::try_new recompiled the entire bundled injection-pattern bank
on every Agent construction instead of caching it like every other
consumer of RAW_INJECTION_PATTERNS. Under --features full, one bundled
pattern's regex_automata Teddy prefilter build overflowed the default
test-thread stack, reached ~25 frames deep through the two-agent
construction chain in build_agent_factory_gates_trust_state_independently_per_session.

Cache the bundled-pattern compile behind a process-wide LazyLock in
vigil.rs, matching the six existing sibling call sites, and give the
affected test a dedicated 32 MiB-stack thread matching both
MAIN_THREAD_STACK_SIZE and the coverage job's existing RUST_MIN_STACK
(added in 9a1efb8 for this same test under instrumented coverage).

Closes #6699
@bug-ops
bug-ops force-pushed the fix/6699-agent-factory-stack-overflow branch from 7714806 to 2f3ed71 Compare July 28, 2026 19:01
@bug-ops
bug-ops enabled auto-merge (squash) July 28, 2026 19:02
@bug-ops
bug-ops merged commit c293e61 into main Jul 28, 2026
43 checks passed
@bug-ops
bug-ops deleted the fix/6699-agent-factory-stack-overflow branch July 28, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci CI/CD configuration core zeph-core crate documentation Improvements or additions to documentation rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serve::agent_factory test overflows stack under --features full (not under CI's narrower feature set)

1 participant