Notícias
Notícias
5 min de leitura
22 de setembro de 2026

Seu agent funcionava em staging (morreu em produção)

Agent funciona em staging. Quebra em produção. Customer vê erro. Churn. Como fazer staging = produção (preview env).

Equipe OpenClaw

Equipe OpenClaw · Time de Engenharia & Produto

A Equipe OpenClaw é formada por engenheiros, designers e especialistas em IA dedicados a construir a melhor plataforma de agentes conversacionais para negócios brasileiros. Combinamos expertise…


Seu agent funcionava em staging (morreu em produção).

Você é founder de SaaS.

Você tem agent em produção.

Agent está rodando bem.

Você decide: "Vou melhorar o agent. Adicionar novo feature."

Your process:

Step 1: Clone agent (staging environment) ├─ Isolada: Sim ├─ Dados: Dados de teste (fake) ├─ Usuários: Ninguém (staging) ├─ Performance: Não importa (empty database) │ Step 2: Fazer mudança ├─ Adicionar lógica nova ├─ Testar em staging ├─ Result: Funciona! ✓ │ Step 3: Deploy em produção ├─ Copiar código para produção ├─ Restart agent ├─ Result: Quebra! ✗ │ Step 4: Debug problema ├─ "Mas funcionava em staging!" ├─ "Por que quebrou aqui?" ├─ Customers vendo erro ├─ Support inundado ├─ Churn iniciando │ Step 5: Rollback (revert mudança) ├─ Deploy version anterior ├─ Damage: Já feito (customers viram erro) ├─ Trust: Abalado ├─ Reputação: Danificada │ Step 6: Post-mortem (investigação) ├─ "Staging não era igual à produção" ├─ Razões: Dados diferentes, volume diferente, latência diferente, config diferente ├─ Prometido: "Vamos fazer staging = produção" ├─ Reality: Never happens

Your nightmare:

Agent estava bom.

Você fez mudança (que parecia segura).

Mudança quebrou produção.

Customers viu erro.

Churn aconteceu.

The problem:

Stagging ≠ Produção.

Staging é lie.

Stagging está vazio, limpo, rápido.

Produção é cheio, sujo, lento.

When staging looks good but production explodes:

Reason 1: Data volume ├─ Staging: 100 registros (agent rápido) ├─ Produção: 10M registros (agent lento → timeout) ├─ Result: Mudança funciona em staging, timeout em produção │ Reason 2: Concurrency ├─ Staging: 1 requisição (sequencial) ├─ Produção: 1000 requisições simultâneas (race conditions) ├─ Result: Mudança funciona em staging, race condition em produção │ Reason 3: Dependencies/integrations ├─ Staging: Mock API (sempre retorna success) ├─ Produção: Real API (pode falhar, timeouts, rate limits) ├─ Result: Mudança funciona em staging, falha em produção │ Reason 4: Configuration ├─ Staging: Dev config (logging, retries, timeouts diferente) ├─ Produção: Prod config (menos logging, strict timeouts) ├─ Result: Mudança funciona em staging, erro em produção │ Reason 5: State/Context ├─ Staging: Fresh start (zero state) ├─ Produção: Years of accumulated state (old data) ├─ Result: Mudança funciona em staging, breaks old data in production │ Reason 6: Infrastructure ├─ Staging: Single server (simple) ├─ Produção: Distributed (load balancer, multiple servers) ├─ Result: Mudança funciona em staging, network issues in production │

The harsh truth:

You can't prevent staging→production disasters with just staging environment.

You need production-like preview environment.


O problema: Staging é mentira

Staging environment ≠ Production environment

=== STAGING VS PRODUCTION ===

                | Staging      | Production

────────────────────┼──────────────┼───────────────── Data volume | 100 rows | 10M+ rows Users active | 0 | 1000s Request volume | 10/min | 10k/min Concurrency | 1 | 100s parallel Network latency | <10ms | 50-500ms Database size | 1GB | 1TB+ Cache state | Empty | Months of data External APIs | Mocked | Real (unreliable) SSL certificates | Test certs | Real certs Middleware | Minimal | Full security stack Monitoring | None | Full observability Error rates | 0% | 0.1-1% (real traffic) │ === WHAT BREAKS IN PRODUCTION (NOT IN STAGING) ===

N+1 query problem: ├─ Staging: 100 rows → 1 query = fast ├─ Produção: 10M rows → 1 query per row = 10M queries → timeout │ Memory leak: ├─ Staging: 1-hour test → no memory issue ├─ Production: 30-day uptime → memory leak kills agent │ Race condition: ├─ Staging: 1 user testing → no race condition ├─ Production: 1000s users → race condition crashes agent │ Rate limit: ├─ Staging: 10 requests/min → no rate limit ├─ Production: 10k requests/min → rate limited by external API │ Time-based bug: ├─ Staging: Test at 10am → no timezone issues ├─ Production: Runs 24/7 across timezones → timezone bug surfaces │ Cache invalidation: ├─ Staging: Fresh cache → always works ├─ Production: 1-month-old cache → stale data bugs surface │


A solução: Worker Previews (Staging dentro de Produção)

Production-like preview environment para cada mudança

=== WHAT IS WORKER PREVIEW? ===

Definition: ├─ Isolated environment that's IDENTICAL to production ├─ Includes: Real data (subset), real traffic patterns, real latency ├─ Works for: Testing agent changes BEFORE full deployment ├─ Goal: Catch production bugs BEFORE customers see them │ === HOW WORKER PREVIEW WORKS ===

Traditional deployment: ├─ Write code in local ├─ Deploy to staging ├─ Test in staging (looks good) ├─ Deploy to production ├─ Production explodes (too late) │ Worker Preview deployment: ├─ Write code in local ├─ Deploy to production (but to isolated worker) ├─ Preview gets: Production data, production traffic, production config ├─ Test in preview (as if it's production) ├─ Result: If it works in preview, it works in production ├─ Deploy to full production (safe) │ === TECHNICAL ARCHITECTURE ===

Worker preview is: ├─ Isolated process (doesn't affect other workers) ├─ Full production environment (same data, config, dependencies) ├─ Real-time traffic replication (sees actual customer requests) ├─ Instant rollback (if preview breaks, rollback is instant) ├─ Side-by-side comparison (preview results vs production results) │ Result: ├─ Preview sees: Real data, real volume, real latency ├─ Preview can be tested: With real production traffic ├─ Preview failures: Only affects preview (not customers) ├─ Preview deploy: One-click switch to full production │ === EXAMPLE: AGENT CHANGE TEST ===

Scenario: You want to add smart routing to support agent ├─ Change: "Route complex questions to human (don't try to handle)" │ Step 1: Deploy to preview ├─ Create new worker (isolated) ├─ Copy production code to worker ├─ Add your routing logic ├─ Worker is live, isolated (customers don't see it) │ Step 2: Replicate real traffic to preview ├─ Send 1% of real customer questions to preview ├─ Preview processes with new routing logic ├─ You monitor: Do results match expectations? ├─ Example: "90% of simple questions handled by agent, 10% routed to human?" │ Step 3: Monitor preview results ├─ Compare: Preview results vs Production results ├─ Example metrics: │ ├─ Avg response time: Preview 1.2s, Production 1.0s (acceptable) │ ├─ Error rate: Preview 0.05%, Production 0.03% (slightly higher, investigate) │ ├─ Routing accuracy: Preview routing 87% correct (good) │ ├─ Human handoff rate: Preview 12%, Production 8% (expected increase) │ Step 4: Debug in production (not in staging) ├─ If preview shows error: Fix in real production environment ├─ Why: Production has real data, real traffic, real latency ├─ Debug time: 10x faster (no more "works in staging but not prod") │ Step 5: Deploy preview to full production ├─ Flip switch: Route 100% of traffic to preview worker ├─ Rollback: If anything breaks, flip back to old version (instant) ├─ Monitoring: Full metrics (not just guesses) │ Result: ├─ Zero staging→production surprises ├─ Zero customer-facing errors from this change ├─ Instant rollback if needed ├─ Full confidence in change │


Por que isso é crítico para agents

Agents tem mais attack surface que regular code

=== WHY AGENTS ARE RISKIER THAN NORMAL CODE ===

Normal code risk: ├─ Input: Known types (string, number, boolean) ├─ Output: Deterministic (same input → same output) ├─ Testing: Can cover most paths (10k test cases cover 90%) ├─ Failure mode: Crashes cleanly (exception, error message) │ Agent risk: ├─ Input: Arbitrary natural language (unpredictable) ├─ Output: Probabilistic (same input → different output) ├─ Testing: Can't cover most paths (10k test cases cover 5%) ├─ Failure mode: Subtle hallucinations (sounds right, wrong answer) │ === AGENT FAILURE MODES (PRODUCTION SPECIFIC) ===

Hallucination at scale: ├─ Staging: 100 test questions → agent answers 98 correctly ├─ Production: 10k real questions → agent hallucinates on 5% (500 wrong answers) ├─ Why: Production has edge cases staging doesn't cover │ Latency-triggered failures: ├─ Staging: Response time 500ms ├─ Production: Response time 2s (due to load) ├─ Agent behavior: Different (timeout → worse answers) │ RateLimiting: ├─ Staging: Calls external API, no rate limit ├─ Production: Calls external API 1000x more → rate limited ├─ Agent behavior: Different (retry logic, fallback logic breaks) │ Concurrency bugs: ├─ Staging: 1 user at a time ├─ Production: 1000 users simultaneously ├─ Agent behavior: Race conditions, state corruption │ State accumulation: ├─ Staging: Fresh start every test ├─ Production: Agent runs 24/7 for months ├─ Agent behavior: Memory leaks, state rot (old data affecting new answers) │


Como implementar Agent Preview (3 estratégias)

Build safe agent deployment pipeline

=== STRATEGY 1: CLOUDFLARE WORKER PREVIEWS (EASIEST) ===

If your agent runs on Cloudflare Workers: ├─ Use: Cloudflare Worker Previews (built-in) ├─ How: │ ├─ Deploy change to preview worker │ ├─ Route X% of traffic to preview │ ├─ Monitor results │ ├─ Flip to 100% when safe │ Advantages: ├─ No setup needed (built into Cloudflare) ├─ Zero latency (same infrastructure) ├─ Real data (production data) ├─ Instant rollback (one-click) │ Disadvantages: ├─ Only works on Cloudflare (vendor lock-in) ├─ Limited to Cloudflare's ecosystem │ Who should use: ├─ Anyone already on Cloudflare Workers ├─ Want simplest possible solution │ === STRATEGY 2: CANARY DEPLOYMENT (MEDIUM) ===

If your agent runs on your own infrastructure: ├─ Use: Gradual rollout (1% → 10% → 50% → 100%) ├─ How: │ ├─ Deploy new version to canary servers (1% traffic) │ ├─ Monitor canary: Error rate, latency, quality │ ├─ Gradually increase traffic (1% → 5% → 25% → 100%) │ ├─ At any point, rollback to old version │ Advantages: ├─ Works on any infrastructure ├─ Gradual risk increase (not all-or-nothing) ├─ Real production data + traffic │ Disadvantages: ├─ Slower (need to monitor each stage) ├─ More complex to implement │ Who should use: ├─ Running agents on AWS/GCP/Azure ├─ Want production-safe deployment │ === STRATEGY 3: SHADOW DEPLOYMENT (BEST) ===

If you want maximum safety: ├─ Use: Shadow mode + canary + full preview ├─ How: │ ├─ Step 1: Shadow mode │ │ ├─ Run new agent alongside old agent │ │ ├─ Send 100% of requests to both │ │ ├─ Compare results (new vs old) │ │ ├─ Log differences (don't use new results) │ │ ├─ Duration: 1-7 days │ │ │ ├─ Step 2: Canary │ │ ├─ Start routing 1% of traffic to new agent │ │ ├─ Monitor: Error rate, quality, latency │ │ ├─ Gradually increase: 1% → 5% → 25% → 50% → 100% │ │ ├─ Duration: 1-7 days per stage │ │ │ ├─ Step 3: Full deployment │ │ ├─ Route 100% to new agent │ │ ├─ Keep old agent as rollback for 7 days │ │ ├─ If errors, instant rollback │ Advantages: ├─ Maximum safety (shadow + canary + rollback) ├─ Works on any infrastructure ├─ Real production data + traffic throughout ├─ Can rollback at any stage │ Disadvantages: ├─ Slower (shadow takes time) ├─ More operational overhead │ Who should use: ├─ Enterprise SaaS (high customer expectations) ├─ Healthcare/Finance/Legal agents (high risk of failure) ├─ Critical business process (can't afford downtime) │ === COMPARISON ===

                | Worker Preview | Canary  | Shadow

────────────────────┼────────────────┼─────────┼────────── Setup ease | Easiest | Medium | Hard Safety level | High | High | Maximum Deployment speed | Instant | 1-7 days| 3-14 days Rollback speed | <1 second | 5 min | 5 min Data representat. | 100% real | 100% real| 100% real Recommended for | Startups | Growing | Enterprise │


Conclusão

Simple verdade:

Staging ≠ Production (this is why agents break after deploy).

Worker Previews = Production-like test environment (safe deployment).

You can't prevent staging→production disasters with staging alone.

3 fatos:

  1. Most agent failures happen in production (not staging)
  2. Staging looks safe because it's not real data/traffic
  3. Worker Previews solve this (test in production-like env, rollback if needed)

Your choice:

  • Keep deploying to staging then production → Agent breaks → Customer churn → Bad
  • Use canary deployment → Catch issues early → No customer impact → Good
  • Use shadow + canary + rollback → Maximum safety → Zero risk → Best

Timeline:

  • Today: You're using staging (risky)
  • Week 1: Implement canary (safer)
  • Week 2: Implement shadow mode (safest)
  • Result: Zero production surprises (agents just work)

Próximos passos

Na OpenClaw, ajudamos SaaS builders implementar safe agent deployment:

  • Staging vs Production Audit: Onde seu pipeline é vulnerável? (diagnostic)
  • Worker Preview Setup: Como usar Cloudflare previews? (if applicable)
  • Canary Deployment: Como implementar gradual rollout? (implementation)
  • Shadow Mode: Como rodar new + old agent em paralelo? (advanced)
  • Monitoring Strategy: Quais métricas monitorar durante deployment? (observability)
  • Rollback Automation: Como fazer instant rollback se algo quebra? (safety)
  • Load Testing: Como testar agent com production-like volume? (testing)
  • Error Budget: Quanto erro é aceitável durante canary? (policy)
  • Deployment Checklist: O que validar antes de full rollout? (process)
  • Incident Response: Como responder rápido se preview shows issues? (ops)

Agent Deployment | CI/CD | Production Safety | Preview Testing →


Publicado em 22 de setembro de 2026

Leia também