Skip to content

Add HTTP server API and run resumption support#1

Open
htyredc wants to merge 6 commits into
mainfrom
claude/latest-code-branches-sgazrg
Open

Add HTTP server API and run resumption support#1
htyredc wants to merge 6 commits into
mainfrom
claude/latest-code-branches-sgazrg

Conversation

@htyredc

@htyredc htyredc commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds a complete HTTP server API for managing Webwright exploration runs and introduces support for resuming prior runs with follow-up instructions. The server exposes run lifecycle management, execution of parameterized functions, and live progress streaming over Server-Sent Events.

Key Changes

Server API (src/webwright/server/)

  • app.py: FastAPI application exposing HTTP endpoints for run management, follow-ups, script execution, and health checks
  • run_manager.py: Single-active-operation manager ensuring only one run/follow-up/execution can be live at a time; handles process lifecycle, reconciliation after server crashes, and re-attachment to orphaned workers
  • worker.py: Subprocess entrypoint for exploration runs and follow-ups; runs outside asyncio event loop to avoid nested-loop conflicts
  • replay_worker.py: Subprocess entrypoint for executing parameterized functions or replaying recorded steps against a live browser session
  • artifacts.py: Read-only helpers for accessing per-run artifact directories (trajectory.json, debug steps, final_function.py, etc.)
  • schemas.py: Pydantic models for HTTP request/response validation
  • sse.py: Server-Sent Events stream for live run progress by polling filesystem artifacts
  • config_presets.py: Built-in YAML config preset enumeration and server defaults
  • doctor_api.py: JSON adapter over environment health checks

Run Resumption

  • src/webwright/utils/trajectory.py: Utilities to load trajectory.json, extract resume state, and resolve trajectory paths
  • src/webwright/run/cli.py: Extended run_one() to accept resume_from and followup parameters; integrates resume state into agent initialization
  • src/webwright/agents/default.py: Added resume() method to agents for continuing from prior state; drops exit messages and appends follow-up instructions

Environment Updates

  • src/webwright/environments/local_browser.py: Added target-finding helpers (_find_cdp_target_by_id, _find_cdp_target_by_url, _find_new_cdp_target) and resume configuration options (resume_existing_output, resume_existing_page)
  • src/webwright/environments/local_workspace.py: Added resume_existing_output config option

Configuration

  • src/webwright/config/crafted_browser_fn.yaml: New config preset for authoring reusable parameterized browser functions (mirrors crafted_cli.yaml for live browser context)
  • src/webwright/config/model_claude.yaml: Updated model endpoint configuration

Testing

  • tests/unit/test_server_run_manager.py: Tests for run manager state, operation queueing, and process lifecycle
  • tests/unit/test_server_app.py: Tests for HTTP API endpoints and run CRUD operations
  • tests/unit/test_server_artifacts.py: Tests for artifact parsing (params spec extraction, trajectory info)
  • tests/unit/test_resume_flow.py: Tests for trajectory loading, resume state building, and agent resumption
  • tests/unit/test_model_json_parsing.py: Tests for JSON output parsing with various formatting styles

Documentation & Dependencies

  • README.md: Updated installation and usage instructions to use uv package manager; added resume workflow examples
  • pyproject.toml: Added [server] optional dependency group (fastapi, uvicorn); added dev dependencies for testing
  • src/webwright/run/doctor.py: Generalized API key check to support multiple model backends (OpenAI, Anthropic, OpenRouter)

Notable Implementation Details

  • Process Management: Worker processes run in separate process groups to enable unconditional cancellation via SIGTERM; re-attachment after server restart is supported via PID liveness checks
  • Filesystem-Based IPC: Server and workers communicate through JSON files (server_meta.json, server_request.json) rather than pipes, enabling clean

https://claude.ai/code/session_01S3APtC5izAUzVHk2W3qsdE

xlinliu and others added 6 commits July 3, 2026 17:00
Wraps the CLI exploration loop in a FastAPI service (webwright-server,
[server] extra) so a web UI can start runs, stream step-by-step code and
progress over SSE, continue a run with follow-ups (reusing the same
local_cdp browser tab), and re-execute the generated artifact with
different parameters.

- src/webwright/server/: app (routes), run_manager (single-active-
  operation lock, subprocess-per-run, SIGINT cancellation, restart
  reconciliation from server_meta.json), worker (run_one adapter),
  replay_worker (parameterized re-execution: final_function.py via the
  LocalBrowserEnvironment primitive against the original tab, step
  replay fallback, final_script.py subprocess mode), artifacts
  (read-only run-directory readers), sse, schemas, config_presets,
  doctor_api.
- src/webwright/config/crafted_browser_fn.yaml: prompt-only modifier
  porting crafted_cli.yaml's reusable-parameterized-function contract to
  the headed local_browser mode; the deliverable is final_function.py
  with PARAMS_SPEC + async run(page, context, browser, params).
- No changes to the core agent/environment code: progress is read from
  the artifacts the loop already writes every step, and runs execute in
  child processes to satisfy run_async()'s no-nested-event-loop guard.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S3APtC5izAUzVHk2W3qsdE
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S3APtC5izAUzVHk2W3qsdE
The doctor/health key check now passes when either provider key is set,
matching the model_openai.yaml / model_claude.yaml config options.
check_openai_key remains as an alias for backwards compatibility.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S3APtC5izAUzVHk2W3qsdE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants