Headless supervise-and-repair for Codex CLI: live log streaming + Playwright MCP (auto-fix, resume, zero-error stability)

Resolved 💬 0 comments Opened Sep 24, 2025 by hamzaydia Closed Sep 26, 2025

What feature would you like to see?

Summary

Add a non-interactive, headless “supervise & repair” mode to Codex CLI that continuously stabilizes a running app by orchestrating Playwright MCP to simulate real users, watching live logs, auto-diagnosing failures, applying fixes, and resuming the same user journey—repeating until a configurable zero-error stability goal is met (e.g., no critical errors for N minutes).

---

Problem

Long-running processes (dev servers, Docker) and evolving features often break user flows. Codex currently tends to act after a command finishes, which doesn’t work for never-ending tasks and delays remediation. We need an automatic, under-the-hood loop that observes the app while it runs, drives a real browser like a user, fixes issues the moment they appear, and continues without human intervention.

---

Desired Behavior

Start or attach to the app process and stream stdout/stderr incrementally (no wait for process exit).

Connect to Playwright MCP and execute live user flows (navigate, type, click, submit, validate).

On any runtime failure (console errors, unhandled exceptions, HTTP 5xx/4xx thresholds, Playwright selector/timeouts, health-check failures), Codex:

  1. Captures artifacts (logs, screenshot, trace, DOM snapshot, network/HAR).
  1. Drafts a root-cause and a minimal, safe code change.
  1. Applies the fix automatically (policy-gated, no prompts).
  1. Hot-reloads or restarts the affected service if needed.
  1. Resumes the exact flow at the failing step.
  1. Repeats until stability goals are met or bounded retry/backoff limits are reached.

---

Scope

Automation only: runs headless; no UI/TUI.

Playwright MCP as the browser driver; optional direct HTTP calls (via MCP tool) when UI interaction isn’t necessary.

Supports multiple supervised processes (e.g., web, API, worker).

---

Design Requirements

Live log ingestion: unbuffered, partial-line reads with lightweight summarization and debounced trigger evaluation.

Trigger model: regex patterns, severity/keyword thresholds, JSON-structured log queries, and MCP/Playwright events (timeouts, “not found,” navigation errors).

Repair policy: apply only minimal, reversible diffs; keep a rollback plan; bound changes per cycle (e.g., max lines changed/files touched).

Resume semantics: restart from the same Playwright step with state restoration (storage state, cookies, auth), or rerun the smallest stable sub-flow.

Retry/backoff: progressive delays, circuit-breaker after repeated failure modes, clear stop conditions.

Stability goals: configurable targets (e.g., “zero critical errors for 5 minutes,” “no console.error above allowlist,” “network-healthy: 0% 5xx and <N% 4xx during window”).

Non-interactive: never pause to ask; if a fix exceeds policy limits, halt with a concise remediation summary and artifact bundle.

---

Event Sources & Triggers (examples)

Dev/app/Docker logs; console.error; unhandled exceptions and stack traces.

Playwright events: selector not found, timeouts, navigation failures.

Network signals: HTTP 5xx, elevated 4xx, broken CORS/preflight, auth expiry.

Health-checks and readiness probes.

Custom allow/deny patterns per project.

---

Repair Workflow (automated)

  1. Snapshot: sliding window of logs; screenshot/video; DOM snapshot; network trace/HAR; key metrics.
  1. Root-cause draft: likely file/line, failing selector/route, minimal repro.
  1. Diff: smallest change to restore correctness (e.g., locator tweak, null-guard, missing import, mis-ordered await, route handler fix).
  1. Apply: write change, run formatter/linter, trigger rebuild/hot-reload or restart with backoff.
  1. Resume: continue same flow; on failure, retry with bounds, then escalate/halt.

---

Safety & Controls

Bounded blast radius: caps on lines changed, files touched, elapsed change time.

Rollback: atomic diffs and easy revert; keep a per-cycle artifact/diff trail.

Secrets & privacy: redact tokens, cookies, and auth headers by default; configurable scrub rules.

Rate limiting: protect external APIs during automated retries.

---

Observability (headless)

Structured logs describing: triggers fired, diffs applied, restart events, retry counts, and stability status.

Artifact bundle per cycle stored locally (screenshots, traces, HAR, logs, diffs).

---

Platform & MCP

Robust Playwright MCP session management (startup, health checks, retries) on macOS, Linux, and Windows/WSL.

Auto-detection of browsers/deps with clear remediation hints (text logs only).

---

Acceptance Criteria

Incremental log streaming and trigger detection while the app runs (no reliance on process exit).

Reliable Playwright MCP control with automatic resume at the failing step after each fix.

Convergence to a configurable stability goal (e.g., zero critical errors for N minutes) without human interaction.

Graceful handling of non-terminating processes (attach/detach, restart with backoff).

Per-cycle artifact and diff output suitable for review or CI follow-up.

---

Open Questions

Default allow/deny lists for console/network patterns across common stacks?

Heuristics for what qualifies as a safe, auto-applicable diff vs. a halt-and-report?

Optional CI mode that reuses the same non-interactive loop for pre-merge stabilization?

Are you interested in implementing this feature?

_No response_

Additional information

_No response_

View original on GitHub ↗