Skip to content

Analysis: Spawn-per-Request vs. Long-running Daemon

This analysis compares the "Spawn-per-Request" (CGI Model) with the "Long-running Daemon" model for managing Zene's lifecycle in a web context.

1. How it works

  1. User Request: Web UI sends task to Backend.
  2. Spawn: Backend runs zene run "..." --session <id>.
  3. Pipe: Backend pipes Zene's stdout to the Web UI.
  4. Exit: Zene completes task and exits.

2. Advantages (The "Simple" Case)

  • Extreme Isolation: Fresh OS process per task.
  • Lower Complexity: No multi-threading or complex state management in the engine.
  • Stateless Backend: Simple management.

3. The Bottlenecks (The "Heavy" Reality)

TaskTime CostImpact
Model Load100ms - 500msLoading local embedding models (fastembed).
MCP Connect200ms - 1sHandshaking with sub-processes.
Context Index500ms - 2sParsing tree-sitter symbols.

Result: A "latency tax" of ~2 seconds before the Agent starts.

4. Compromise: The "Warm Worker" Pool

Instead of "Spawn-on-Demand," the outer app can maintain a Pool of Zene Daemons:

  • Backend keeps 5 Zene instances running in server mode.
  • Backend assigns idle Zene instance to session.
  • Once done, backend sends a session.clear command.

5. Security Comparison

FeatureSpawn-per-RequestLong-running Server
Zombie RiskLowHigh
Secret SafetyHighLow
Resource CapEasyHard

Conclusion

If your goal is simplicity and safety, the "Spawn-per-Request" model is the winner. If you need instant response, Zene needs to stay "Warm."

Released under the MIT License.