Skip to content

perf(web): a web start builds its plan once - #127

Merged
404SecNotFound merged 1 commit into
mainfrom
claude/sweet-meitner-uo27fc
Oct 20, 2026
Merged

404SecNotFound merged 1 commit into
mainfrom
claude/sweet-meitner-uo27fc

Conversation

@404SecNotFound

Copy link
Copy Markdown
Owner

Summary

This closes the last open engineering item in tasks/todo.md, "Plan-twice cost in the web start path". POST /api/runs built the plan to price its pacing, then the worker's Orchestrator.run built the same plan again before emitting it. That is about 1.6 s of CPU on the start path for REP-004 at high intensity.

Now _preview builds the plan once and hands it to RunManager.start(plan=...), and the worker emits it through a new keyword Orchestrator.run(plan=...). Building is pure and seeded and nothing mutates a plan during a run (_mark copies the extension dict), so the emitted events do not change. The CLI and menu never built twice and are untouched. Two plan or build checks became plan is None, because ScenarioPlan defines __len__ and an empty plan is falsy.

Verification

  • New guard tests/test_web_single_plan_build.py counts Orchestrator.build_plan calls across a real start that runs to done. It is parametrized over fortigate (the configured default) and paloalto (the per-vendor orchestrator path). Positive control: against the unfixed orchestrator.py, runner.py and server.py, both cases fail with the plan was built 2 times for one start. With the fix, both pass.
  • A parity test checks that the reused plan is the one the run records: the /api/plan priced count equals the run's event_count and the manifest's planned_event_count (REP-004 low, seed 7). This test is not a guard of the fix; it passes on both trees.
  • test_web_api.py's busy stub mirrors RunManager.start's signature, so it gained plan=None.
  • Full Python suite with this change (Python 3.13.16): 3505 passed, 3 skipped. black, ruff and mypy replicant tools experiments/typesafe/run.py are clean.

Documentation impact

  • Maintained documentation changed alongside the behavior, or unaffected surfaces are explained above. (tasks/todo.md item struck through with a dated note. No operator, API, safety or runbook contract describes the internal build count, and the HTTP API is unchanged.)
  • CHANGELOG.md records the change.
  • Historical decision records were preserved or received a dated addendum.
  • Documentation claims were checked against the implemented behavior.

Scope boundary

This change moves no request or response field, no manifest field and no pacing, and it does not touch the send path, the eps cap or the send lock. I did not measure wall-clock savings; the claim is the build count.


Generated by Claude Code

POST /api/runs built the plan to price its pacing, then the worker's
Orchestrator built the same plan again before emitting it, about 1.6 s
of wasted CPU for REP-004 at high intensity. The preview's plan is now
handed to the worker through RunManager.start(plan=...) and
Orchestrator.run(plan=...). Building is pure and seeded, so the
emitted events are unchanged.

tests/test_web_single_plan_build.py counts build_plan calls across a
real start; against the unfixed code it counted 2 for the default
vendor and for a non-default one, and 1 with the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HbjsVBv8HQSQkAds6W5Y1v
@404SecNotFound
404SecNotFound merged commit 8ae06db into main Oct 20, 2026
13 checks passed
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