Skip to content

FE-1667: Run experiments from Petrinaut AI chat - #9678

Open
kube wants to merge 1 commit into
codex/fe-1666-experiment-hostfrom
codex/fe-1667-ai-experiment-chat
Open

FE-1667: Run experiments from Petrinaut AI chat#9678
kube wants to merge 1 commit into
codex/fe-1666-experiment-hostfrom
codex/fe-1667-ai-experiment-chat

Conversation

@kube

@kube kube commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Important

Experimental optimization
Optimization requires Parameter sweeps and In-browser optimization. Simulation is available without these flags.

Summary

Petrinaut AI can create experiments through the browser host and show their progress in the conversation. A compact card provides cancellation, the final metric, and a link to the experiment drawer.

The conversation stays mounted while the user inspects an experiment. Completion returns one captured tool result with the original call ID.

Experiments in chat

Links

Blocked by

Changes

  • Register createExperiment with its canonical schema and dispatch it from the AI panel
  • Show blue simulation cards and purple optimization cards with animated progress and reduced-motion support
  • Cancel owned requests when the chat stops, clears, changes conversation, or unmounts
  • Keep chat state across Edit, Simulate, and Notebook modes
  • Include core and React patch changesets and a chat flow diagram

Test coverage

After the 14 September rebase, affected package builds, unit tests, types, lint and architecture checks passed on the integrated stack. Browser recordings and manual checks listed below predate this rebase.

  • AI panel tests cover tool-call identity, progress, cancellation, conversation changes, and stale callbacks
  • Card tests cover progress, terminal states, and accessible controls
  • Editor tests cover keeping the conversation mounted across modes

Local package builds, unit tests, TypeScript, lint, architecture validation, and the docs site build pass.

How to test

  • Run yarn workspace @hashintel/petrinaut test:unit --run src/ui/views/Editor/panels/ai-assistant-panel.test.tsx src/ui/views/Editor/panels/ai-assistant-panel/ai-assistant-contents/experiment-card.test.tsx src/ui/views/Editor/editor-view.test.tsx
  • Use the integration demo to inspect live cards and open the experiment drawer

@kube kube self-assigned this Sep 11, 2026
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
hash Ready Ready Preview Sep 13, 2026 11:01pm UTC
petrinaut Ready Ready Preview Sep 13, 2026 11:01pm UTC
petrinaut-docs Ready Ready Preview Sep 13, 2026 11:01pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
hashdotdesign-tokens Ignored Ignored Preview Sep 13, 2026 11:01pm UTC

Request Review

@github-actions github-actions Bot added area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team type/eng > backend Owned by the @backend team labels Sep 11, 2026
@kube
kube added this pull request to stack #9679 September 11, 2026 14:48
@kube
kube marked this pull request as ready for review September 11, 2026 18:33
Copilot AI balanced review requested due to automatic review settings September 11, 2026 18:33
@cursor

cursor Bot commented Sep 11, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
New client-side experiment execution from chat affects long-running browser work and conversation lifecycle; mistakes could leak stale results or abort the wrong run, but changes are scoped to optional host-enabled tools with explicit cancellation and guards.

Overview
Adds createExperiment to Petrinaut’s AI tool surface in core and wires the assistant panel to the browser AiExperimentsContext host so chat can start simulations and optimizations with validated requests.

While a tool call runs, the UI shows a dedicated experiment card (blue simulation / purple optimization) with live progress, Cancel, View experiment navigation, and a single captured tool result when work finishes. Abort and stale-result guards cover stop, clear, conversation switches, and reused tool call IDs.

Editor layout keeps AiAssistantPanel mounted across Edit, Simulate, and Notebook so users can open experiment charts without tearing down an in-flight chat turn; panel offset now ignores the properties panel outside Edit mode. User and architecture docs, changesets, and unit tests cover the new flow.

Reviewed by Cursor Bugbot for commit 0755061. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

AI optimization currently bypasses the required Parameter sweeps feature flag.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds AI-driven Petrinaut experiments with live progress, cancellation, result cards, and persistent chat across editor modes.

Changes:

  • Registers and executes createExperiment.
  • Adds experiment cards, lifecycle handling, and tests.
  • Updates architecture docs, user guides, and changesets.
File summaries
File Description
libs/@local/petrinaut-arch-docs/content/experiments/ai-created-experiments.mdx Links browser-host and chat architecture.
libs/@local/petrinaut-arch-docs/content/diagrams/ai-experiment-chat.d2 Adds chat experiment flow diagram.
libs/@local/petrinaut-arch-docs/content/ai/experiment-chat.mdx Documents chat integration.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel/types.ts Adds experiment tool message types.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel/README.md Declares the AI panel architecture layer.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel/format-diagnostics-for-ai.ts Clarifies experiment compilation behavior.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel/format-diagnostics-for-ai.test.ts Updates diagnostics expectation.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel/ai-assistant-contents/get-message-render-items.ts Routes experiment parts to cards.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel/ai-assistant-contents/experiment-card.tsx Implements progress and result cards.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel/ai-assistant-contents/experiment-card.test.tsx Tests card states and progress.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel/ai-assistant-contents.tsx Renders experiment state and controls.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel.tsx Dispatches and manages experiment requests.
libs/@hashintel/petrinaut/src/ui/views/Editor/panels/ai-assistant-panel.test.tsx Tests experiment lifecycle integration.
libs/@hashintel/petrinaut/src/ui/views/Editor/editor-view.tsx Keeps chat mounted across modes.
libs/@hashintel/petrinaut/src/ui/views/Editor/editor-view.test.tsx Verifies persistent panel mounting.
libs/@hashintel/petrinaut/docs/experiments.md Documents assistant-created experiments.
libs/@hashintel/petrinaut/docs/ai-assistant.md Documents chat experiment workflows.
libs/@hashintel/petrinaut-core/src/index.ts Exports the experiment tool name.
libs/@hashintel/petrinaut-core/src/ai.ts Registers the canonical tool schema.
.changeset/small-experiments-chat.md Records the Petrinaut package change.
.changeset/experiment-ai-tool.md Records the core package change.
Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 1
  • Review effort level: Balanced (auto)

Note

Copilot is running an experiment and ran this review at Balanced.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

experimentControllersRef.current.get(toolCall.toolCallId) ===
controller;
try {
const result = await experimentHost.createExperiment(request, {

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0755061. Configure here.

for (const controller of experimentControllersRef.current.values())
controller.abort();
experimentControllersRef.current.clear();
setExperimentStates({});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aborted experiment stays pending

Medium Severity

Changing conversations aborts an in-flight experiment and clears experimentStates without writing a cancelled tool result onto that conversation. Returning to it leaves the card on Validating with a no-op Cancel, because the part is still input-available and the prior execution key is not run again.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0755061. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

2 participants