Skip to content

OPEX AI researches in the background from Entry approval - #62

Merged
sa-anyan merged 1 commit into
mainfrom
e1/opex-background-ai
Nov 13, 2026
Merged

sa-anyan merged 1 commit into
mainfrom
e1/opex-background-ai

Conversation

@sa-anyan

Copy link
Copy Markdown
Owner

Stacked on #61 (reference defaults). Merge #61 first and this PR retargets to main.

What changes

  • The AI starts researching OPEX as soon as Entry is approved. It runs in the background, outside the stage lock, so the user never waits for it. It also starts on a stage run, or when a study approved earlier is opened with AI on.
  • What it proposes: labour roles and headcounts, utilities, materials and Garrett factors. Python still does all the arithmetic.
  • Results are saved only between stages. A background save can never invalidate a calculation that is running.
  • How results are merged:
    • empty fields are filled, marked as AI proposals;
    • reference defaults may be refined, but an AI factor is kept only inside the printed Garrett range;
    • user values, documented overrides, earlier AI values and locked OPEX are never replaced;
    • questions the AI has answered (for example labour) are removed.
  • OPEX page:
    • shows "AI is researching…" while it runs, then "AI added N proposals";
    • AI rows appear in the review list with Accept / Edit / Exclude (labour headcount is editable);
    • Python recalculates by itself when the user arrives and OPEX is out of date;
    • unsaved edits are no longer discarded when a new saved revision arrives.
  • If the AI fails or is switched off: the page says so, offers "Try again", and the reference defaults still apply.

Checked live (AI on, copy of the PEM study)

After What the page showed
2 s "AI is researching…"
8 s 17 AI proposals added: 2 labour roles, an electricity line with a 0.07/kWh tariff (marked unverified), and 14 factors
12 s Recalculated by itself to 12 of 18 categories priced, 3.85m, up from 7 of 18 and 2.15m

The feed price question stays open: the AI declined to invent an RO-permeate price.

Tests

  • Backend pytest (Python 3.12.10): 4,655 passed, 3 skipped, 0 failures.
  • The new file test_opex_brainstorm.py (8 tests) covers:
    • merge rules (fill, refine, out-of-range rejection, user and earlier-AI values kept);
    • the job starts on approval and saves into the gaps;
    • no repeat AI call for the same data;
    • an AI failure is recorded and changes nothing;
    • no job when AI is off;
    • locked OPEX is never touched;
    • live status while the job runs;
    • a page read taken just before the save still reports "running".
  • Frontend: tsc OK, node tests 60/60, next build OK.

Known limits

  • Edits sent outside the stage lock (a plan PATCH) can, rarely, hit "Assessment changed; reload" if the AI save lands at the same moment. The page refreshes every 4 s while the AI runs, which keeps that window small.
  • One AI call per approved study, with usage charges. It runs again only when the approved data changes.

🤖 Generated with Claude Code

- New background brainstorm (backend/blocks/opex/brainstorm.py): starts when
  engineering data is approved (and on stage runs or page open if missing),
  off the stage lock; the AI proposes labour roles/headcounts, utilities,
  materials and factors. Results are written only between stages.
- Merge fills gaps and refines reference defaults only; AI factors kept only
  inside the printed Garrett range; user, override, earlier-AI and locked
  values are never replaced. Answered questions are dropped.
- OPEX page: "AI is researching..." notice, AI proposals in the review list
  (labour headcount editable), and Python recalculates on arrival when OPEX
  is stale. Unsaved draft edits are kept when a new revision arrives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
flowvalue-ai Ready Ready Preview Nov 13, 2026 3:15pm UTC

@sa-anyan
sa-anyan changed the base branch from e1/opex-reference-defaults to main November 13, 2026 15:21
@sa-anyan
sa-anyan merged commit d5b63c3 into main Nov 13, 2026
4 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.

1 participant