Astra: data safety (fencing, history, audit), AP 26D fixes, dry runs via the runner, client polish (56e055deeb3e)
5ce1088 verified |
Download docs/ARCHITECTURE.md from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 11.8 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/docs/ARCHITECTURE.md
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/docs/ARCHITECTURE.md
-
curl -L -o ARCHITECTURE.md https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/docs/ARCHITECTURE.md
11.8 kB
| # Architecture | |
| Astra is an AI QA co-worker that tests Oracle Fusion Cloud TEST pods. The running system is one container (a Hugging | |
| Face Space), a remote browser runner for Fusion pods, and a storage bucket that holds an encrypted snapshot of the data. | |
| ## Components | |
| ```mermaid | |
| flowchart LR | |
| U[Browser: consultant, QA approver, admin] -->|HTTPS, session cookie + CSRF header| API | |
| AS[Oracle Fusion AI Agent Studio<br/>workflows] -->|OAuth client: cycles, approval,<br/>pull of events| API | |
| subgraph Container [One Docker image, non-root, tini: the Hugging Face Space] | |
| API[FastAPI app<br/>coworker/api] --> RM[Run manager<br/>api/runner.py, run_jobs queue] | |
| RM --> G[LangGraph workflow<br/>coworker/graph] | |
| G --> PW[Playwright adapters<br/>adapters/playwright.py, adapters/remote_runner.py] | |
| G --> RR[QA rule C1-C6<br/>reports/generate_report.py, qa/audit.py] | |
| G --> TR[Triage<br/>triage/classifier.py] | |
| API --> DB[(SQLite: runs, events, users, sessions,<br/>pods, schedules, Agent Studio cycles, audit chain)] | |
| API --> V[(Vault: FPT_HOME/secrets/vault.json<br/>+ FPT_SECRET_* env)] | |
| SCH[Scheduler<br/>platform/scheduler.py] --> RM | |
| COU[Courier<br/>platform/agent_studio.py] --> RM | |
| SYNC[State sync<br/>platform/statesync.py] --> DB | |
| MOCK[Practice pod<br/>mock-app :3100] | |
| end | |
| G -->|EgressGate| LLM[AI model<br/>llm/router.py] | |
| G -->|EgressGate: REST, read-only| FUS[Oracle Fusion test pod] | |
| PW -->|EgressGate: HTTPS + runner token| RUN[Remote runner<br/>automation/remote_runner/server.py<br/>behind Caddy] | |
| RUN -->|browser| FUS | |
| PW -->|local browser| MOCK | |
| COU -->|EgressGate: signed callbacks, push mode| AS | |
| SYNC -->|EgressGate: encrypted snapshot| BKT[(Bucket: OCI Object Storage<br/>or Supabase Storage)] | |
| API -->|EgressGate| SB[Supabase: identity] | |
| ``` | |
| | Part | What it is | Code | | |
| |---|---|---| | |
| | API and web app | FastAPI serving the React app, the REST API, `/mcp`, `/a2a` and `/oauth/token` | `coworker/api` | | |
| | Run manager | One worker thread; queued jobs are kept in `run_jobs` | `coworker/api/runner.py` | | |
| | Workflow | LangGraph graph, one checkpoint per step (SQLite) | `coworker/graph` | | |
| | Remote runner | Runs the browsers of Fusion test attempts and screen reads, one job at a time ([REMOTE_RUNNER.md](REMOTE_RUNNER.md)) | `automation/remote_runner/server.py` | | |
| | Agent Studio API and courier | Fusion workflows start test cycles and approve them; the courier sends or queues the cycle events and runs the release watch ([AGENT_STUDIO.md](AGENT_STUDIO.md)) | `coworker/platform/agent_studio.py`, `coworker/api/routes/agent_studio.py` | | |
| | State sync | Saves an encrypted snapshot of `FPT_HOME` to the bucket and restores it at start | `coworker/platform/statesync.py`, `coworker/platform/ocistore.py` | | |
| ## A Fusion test cycle, step by step | |
| A cycle starts from the web app, a schedule, or Oracle AI Agent Studio (`POST /api/agent-studio/v1/cycles`; there the | |
| depth defaults to `regression`, which is depth `full`). Nodes are in `coworker/graph/nodes/`; the graph is in | |
| `coworker/graph/build.py`. | |
| | Step | Node | What happens | | |
| |---|---|---| | |
| | 1 | `scout` | Reads the pod; stops on a production pod. On a Fusion pod it finds which business areas the pod uses and samples their test data from the pod's own records (`platform/discovery.py`, [DISCOVERY.md](DISCOVERY.md)). Invoice lines are read from the business unit the tests use first, so the line account belongs to that unit's chart of accounts. | | |
| | 2 | `research_module`, `synthesizer` | Reads Oracle's What's New for the pod's release, per area (public data), and ranks the release changes into the coverage view. | | |
| | 3 | `test_generator` | Picks scenarios from the library (`tests/cases` and the approved ones in `FPT_HOME/library`; at depth `full`, every approved scenario of the areas). With an AI model configured it then designs new ones (`graph/nodes/ai_scenarios.py`), steps 3a to 3e. | | |
| | 3a | | **Screen reading** of the areas whose screens are missing (never read, read on another release, or files gone), inside the run, on the runner. Each area's key business tasks (`platform/fusion_catalog.py` `key_tasks`) are read first. Live runs only. | | |
| | 3b | | **AI scenarios** from the area's key screens, at most 3 per screen (`PER_SCREEN`). | | |
| | 3c | | **End-to-end flows**: at depth `full`, one per business process of each area (at most `FPT_FUSION_REGRESSION_FLOWS`, default 3); and cross-area flows (Procure-to-Pay, Order-to-Cash, Record-to-Report) when the run tests all their areas. | | |
| | 3d | | **Regression checks**: at depth `full`, one scenario per catalogue check (`fusion_catalog` `regression`) that no scenario covers yet, at most `FPT_FUSION_REGRESSION_CHECKS` (default 25) per area. | | |
| | 3e | | **Dry run** of the AI scenarios on the pod, only when `FPT_FUSION_AI_DRY_RUN=1` (off by default). With it off, nothing runs on the pod before a person approves. | | |
| | 4 | `approval_gate` | Pauses. A person approves or skips each scenario: in the app, or in Fusion for an Agent Studio cycle (`POST .../cycles/{id}/approval`). | | |
| | 5 | `data_planner`, `data_executor` | Plans test data; seeds it only where allowed (`SEED_ALLOWED=1`). | | |
| | 6 | `script_builder` | Turns the approved scenarios into Playwright specs. | | |
| | 7 | `executor` | **Pre-flight** first (`platform/preflight.py`): the runner answers and has its scenario files, the test user signs in, every area has test data (a warning only). A failed check stops the run before any browser starts. Then one Playwright run per test user: each area signs in as its own user (`FPT_FUSION_AREA_USERS`), on the remote runner when `FPT_REMOTE_RUNNER_URL` is set. A browser-level failure (nothing ran) is tried once more. | | |
| | 8 | `self_heal` | For a renamed control, proposes a new locator from the failure's ARIA snapshot and uses it for one retry only; the permanent fix needs a person. | | |
| | 9 | `triage` | Classifies failures (UI change, data, timing, real defect). | | |
| | 10 | `human_review`, `ticket` | A QA approver confirms real defects or waives them; confirmed defects become tickets. | | |
| | 11 | `reporter`, `learner` | Go / no-go by the QA rule; HTML and PDF report; test data clean-up summary. The Excel test script is built on download; Agent Studio events carry a signed link that opens it without a login for 7 days (`platform/links.py`). | | |
| | 12 | Courier | Sends each cycle's events (`scripts_ready`, `failures_need_review`, `results`, `stopped`, `patch_update`) by push (a signed POST, or straight to Fusion), or queues them for the Fusion workflow to pull. | | |
| On the practice pod the same graph runs with the practice scenarios and a local browser. | |
| The run manager keeps queued jobs (`run_jobs`), so a gate answer survives a restart. A run that was running when the | |
| server stopped is marked "interrupted" and is resumed by hand. LangGraph checkpoints (SQLite) let a paused run continue. | |
| The LangGraph path runs each attempt as one Playwright run (one per test user); it does not split it into chunks. | |
| **Temporal** (`FPT_ORCHESTRATOR=temporal`, the Compose shape) runs the same nodes as activities and splits execution | |
| into chunks of `exec_chunk_size` (10). Its execute activity (`coworker/workflows/activities.py`) supports the practice | |
| pod only: it starts the local practice pod (`ensure_mock`) and has no remote runner, no per-area test users and no | |
| pre-flight. **Fusion pods are not supported under Temporal today.** | |
| ## Boundaries that matter | |
| - **Egress gate** (`platform/egress.py`): the only module that makes HTTP calls. It checks the kill switch, writes an | |
| audit record per call, pins each call to the configured host, and allows writes to Fusion only for seeding test | |
| data (with `SEED_ALLOWED=1`) and cancelling it. Calls to the runner, the bucket and Agent Studio go through it too. | |
| Repeated status polls of the remote runner (attempt state, screen reads, live frames) are the one exception to a | |
| record per call: the first is audited as usual, the rest as one row a minute and one at the end, with a count and a | |
| digest over every answer; a non-2xx answer or a failed poll is audited on its own. | |
| - **Vault** (`platform/vault.py`): a plain JSON file, `FPT_HOME/secrets/vault.json` (file mode 600), plus | |
| `FPT_SECRET_<NAME>` environment overrides. It is **not encrypted on disk**; it is encrypted only inside the state | |
| snapshot. It holds `EVIDENCE_KEY`, the key of the evidence store. API answers never contain secrets; child processes | |
| get a scrubbed environment (`platform/procs.child_env`). | |
| - **LLM router** (`llm/router.py`): client data never goes to an external model. A request is public, or masked first: | |
| values that look like client data are replaced by placeholders before the call and put back in the answer | |
| (`platform/step_writer.py` `_call`, `platform/redaction.py`). A payload that still looks like client data is not sent | |
| to the external model; the local model or the built-in fallback answers instead. | |
| - **QA rule**: the decision is computed by `reports/generate_report.py`, never by the AI. | |
| ## Data | |
| SQLite at `$FPT_HOME/fpt.sqlite` and `checkpoints.sqlite`, migrations in `coworker/platform/migrations/*.sql` | |
| (forward-only, applied by `python -m coworker setup` at every start). Evidence (screenshots, videos, traces) is | |
| encrypted under `$FPT_HOME/evidence`, with retention. | |
| The Space has no persistent disk. `platform/statesync.py` saves an encrypted snapshot (Fernet, `FPT_STATE_KEY`) of the | |
| two databases and the `secrets`, `runs`, `evidence`, `tickets`, `screens` and `library` folders to a bucket, and | |
| restores it at start when the data folder is empty. | |
| | Store | Set by | Notes | | |
| |---|---|---| | |
| | OCI Object Storage | `OCI_STATE_PAR_URL`: a pre-authenticated request URL on one private bucket (`platform/ocistore.py`) | Used when set. | | |
| | Supabase Storage | `SUPABASE_URL`, `SUPABASE_SERVICE_KEY`, `SUPABASE_BUCKET` | Used when no OCI URL is set. | | |
| When a save happens: | |
| - **Periodically**, when the databases changed: checked every `FPT_STATE_SYNC_INTERVAL` seconds (default 60; at least | |
| 300 on OCI, to stay inside the bucket's request budget; at least 10 on Supabase). | |
| - **At once** on key events (`save_soon`): a screen read finished, a run waits for a person, a run ended, a run was | |
| cancelled. | |
| - **On shutdown**: a forced save, after the run worker has stopped (a running run stops between two steps and is | |
| queued to continue after the restart; the wait is bounded by `FPT_SHUTDOWN_RUN_WAIT_S`, default 20 s). | |
| - **On request**: `POST /api/storage/save` (administrator). Call it before every restart or deploy. | |
| At start, a screen read that the snapshot shows as running is marked interrupted (`PodRegistry.recover_screens`). | |
| The snapshot serves one instance, but a Hugging Face rebuild keeps the old container running while the new one starts. | |
| So `state/meta.json` carries a generation number and the id of the instance that wrote it: each start takes the next | |
| generation after its restore, every save reads `meta.json` first (one GET), and an instance that finds the bucket | |
| moved on by another one stops saving (`.state-fenced`, `paused_reason: "fenced"`, audit `state.fenced`) instead of | |
| overwriting it. Each save also keeps a copy as `state/history/<time>.bin`; the newest `FPT_STATE_HISTORY` (default 5) | |
| are kept, older ones deleted at most once an hour (RUNBOOK "Going back to an earlier save"). | |
| ## Web app | |
| React 18, Mantine 7, TanStack Query, React Router; typed API client generated from the backend's OpenAPI | |
| (`npm run gen:api`). Less-used pages are loaded on demand. Errors are mapped to plain language in | |
| `web/src/api/errors.ts`; a screen that crashes shows a recovery page (`components/ErrorPages.tsx`). | |