Skip to content

[Blazor] Add predictive state updates - #68335

Merged
dariatiurina merged 5 commits into
mainfrom
javiercn-components-ai-09-predictive-state
Sep 2, 2026
Merged

dariatiurina merged 5 commits into
mainfrom
javiercn-components-ai-09-predictive-state

Conversation

@javiercn

@javiercn javiercn commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Overview

Adds transactional predictive state to Microsoft.AspNetCore.Components.AI and demonstrates it in the document-edit dojo. Streamed edits are visible before confirmation, explicit acceptance commits them, and rejection or an unconfirmed terminal path restores the prior committed value.

This PR is position 9 in native stack #68340 and depends directly on #68334. The shipping API remains provider-neutral while the sample and E2E test continue through the real DojoClient to AG-UI HTTP and SSE boundary.

Design

StateMapperContext.SetPredictiveState marks mapped state as provisional. AgentState<T> captures one baseline for the predictive transaction, replaces only the visible candidate as snapshots arrive, and exposes explicit accept and reject operations.

AgentContext rejects pending predictive state on normal completion without confirmation, cancellation, failure, and disposal. Restore also rejects persisted predictive snapshots before committing restored state because the conversation thread does not currently record whether the user accepted them. Persistence of accepted predictive decisions is tracked in #68227.

The predictive API mapping expands document writes into incremental state snapshots and one confirmation action for the request. Multiple writes update the same latest predictive value and do not create competing confirmations.

Review updates

  • Makes the read-only document textbox keyboard-focusable and marks it as multiline.
  • Prevents concurrent confirmation responses and disables both controls while the first response runs.
  • Rejects restored predictive state so rejected or unconfirmed snapshots cannot return as pending.
  • Emits one confirmation for multiple document writes in the same predictive transaction.

No visual layout changes are included.

Validation

  • PredictiveStateTests passed with 6 of 6 tests.
  • PredictiveStateUpdatesScenarioTests passed with 1 of 1 tests through the dual-host AG-UI path.
  • The focused E2E project builds with zero warnings and zero errors.

@javiercn
javiercn requested a review from a team as a code owner August 11, 2026 02:02
@javiercn
javiercn force-pushed the javiercn-components-ai-09-predictive-state branch from 5b4151f to 8cc281f Compare August 11, 2026 07:28
@javiercn

Copy link
Copy Markdown
Member Author

/azp run aspnetcore-components-e2e

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI lite review requested due to automatic review settings August 12, 2026 13:24
@javiercn
javiercn force-pushed the javiercn-components-ai-09-predictive-state branch from 8cc281f to 90523c9 Compare August 12, 2026 13:24

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.

Pull request overview

Adds a provider-neutral “predictive state” transaction mechanism to Components.AI so streamed state updates can be displayed immediately, then explicitly accepted or rejected at a UI confirmation boundary. This is integrated into a new Dojo scenario (and API endpoint) that streams document edits via state snapshots, plus an E2E recording/test that still exercises the real dual-host HTTP/SSE boundary.

Changes:

  • Introduces predictive state mapping (StateMapperContext.SetPredictiveState) and transactional state operations on AgentState<T> (accept/reject + pending flag).
  • Ensures all non-accept termination paths (completion without confirmation, cancellation, failure, disposal) roll back pending predictive state (AgentContext + UIAgent<TState> dispatch).
  • Adds a new “Predictive State Updates” Dojo scenario + AGUIDojoApi endpoint, including deterministic replay support and an E2E test/recording.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Components/AI/testassets/DojoClient/Shared/DojoConversationThread.cs Renames/re-homes conversation thread type used by multiple scenarios.
src/Components/AI/testassets/DojoClient/Program.cs Registers keyed chat client for the new predictive scenario endpoint.
src/Components/AI/testassets/DojoClient/DojoScenarios.cs Adds the /predictive_state_updates scenario endpoint constant.
src/Components/AI/testassets/DojoClient/Components/Scenarios/SharedState/SharedStateScenario.razor Updates scenario to use the shared DojoConversationThread type.
src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/PredictiveStateUpdatesScenario.razor.css Styles for predictive document editor layout.
src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/PredictiveStateUpdatesScenario.razor New scenario wiring predictive state mapping + confirmation UI action.
src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentSuggestions.razor.css Styles for prompt suggestion buttons.
src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentSuggestions.razor UI for common prompts that drive the predictive editing flow.
src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentState.cs Scenario state model used by the client editor.
src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentPreview.razor.css Styles for editable/read-only document preview + diff highlights.
src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentPreview.razor Renders editable surface and read-only diff during predictive streaming.
src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/ConfirmChangesDialog.razor.css Styles for the confirmation dialog UI action.
src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/ConfirmChangesDialog.razor Implements the accept/reject UI action invocation UI.
src/Components/AI/testassets/DojoClient/Components/Pages/Home.razor Adds navigation entry for the new scenario.
src/Components/AI/testassets/DojoClient/Components/_Imports.razor Imports predictive scenario namespace for Razor compilation.
src/Components/AI/testassets/DojoClient.E2E.Tests/Tests/PredictiveStateUpdatesScenarioTests.cs New E2E test covering streaming + accept/reject flows.
src/Components/AI/testassets/DojoClient.E2E.Tests/ServiceOverrides/RecordedScript.cs Extends recorded frames to include predictive state snapshots.
src/Components/AI/testassets/DojoClient.E2E.Tests/ServiceOverrides/RecordedChatClient.cs Emits predictive state snapshots as DataContent with a custom media type.
src/Components/AI/testassets/DojoClient.E2E.Tests/ServiceOverrides/DojoModelOverrides.cs Adds deterministic model override wiring for predictive scenario.
src/Components/AI/testassets/DojoClient.E2E.Tests/Baselines/PredictiveStateUpdates.recording.json New recorded model script driving predictive scenario E2E.
src/Components/AI/testassets/AGUIDojoApi/ScriptedChatClient.cs Adds scripted behavior for confirmation-result messaging and predictive flow.
src/Components/AI/testassets/AGUIDojoApi/Program.cs Maps new /predictive_state_updates dojo endpoint with keyed chat client.
src/Components/AI/testassets/AGUIDojoApi/PredictiveStateUpdates/DocumentState.cs API-side document state model for snapshot serialization.
src/Components/AI/testassets/AGUIDojoApi/ChatClientAgentFactory.cs Adds predictive system prompt, tool set, and snapshot/confirmation stream mapping.
src/Components/AI/testassets/AGUIDojoApi/AGUIEndpoint.cs Adds keyed chat client resolution and “client tools as declarations” mode.
src/Components/AI/test/Engine/PredictiveStateTests.cs Adds runtime tests for accept/reject and rollback on cancellation/completion.
src/Components/AI/src/PublicAPI.Unshipped.txt Declares new public API surface for predictive state operations.
src/Components/AI/src/Pipeline/StateMapperContext.cs Adds predictive-state mapping flag and public SetPredictiveState.
src/Components/AI/src/Engine/UIAgentOfT.cs Routes predictive vs committed state updates and exposes rollback hook.
src/Components/AI/src/Engine/UIAgent.cs Adds virtual rollback hook used by AgentContext.
src/Components/AI/src/Engine/AgentState.cs Implements predictive transaction baseline + accept/reject APIs.
src/Components/AI/src/Engine/AgentContext.cs Ensures rollback on dispose, completion without accept, cancellation, and error.

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

@kotlarmilos
kotlarmilos force-pushed the javiercn-components-ai-09-predictive-state branch from 90523c9 to 6c0a11d Compare August 12, 2026 16:47
@javiercn
javiercn force-pushed the javiercn-components-ai-09-predictive-state branch from 6c0a11d to 5902fcc Compare August 13, 2026 10:06
@ilonatommy
ilonatommy force-pushed the javiercn-components-ai-09-predictive-state branch from 5902fcc to 142ec32 Compare August 14, 2026 12:37
@ilonatommy
ilonatommy force-pushed the javiercn-components-ai-09-predictive-state branch from 142ec32 to dca2ed2 Compare August 20, 2026 06:55
Base automatically changed from javiercn-components-ai-08-shared-state to main August 28, 2026 21:02
javiercn and others added 5 commits August 28, 2026 23:11
Rationale: let provider-neutral Components.AI applications render provisional state immediately while retaining a committed value that can survive rejection, cancellation, or an incomplete confirmation flow.

Implementation: add explicit predictive state mapping and observable accept/reject semantics, preserve the pre-prediction value across incremental updates, and roll unfinished predictions back when a turn is canceled, fails, is disposed, or completes without confirmation.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Rationale: demonstrate canonical Predictive State Updates across the real DojoClient to AGUIDojoApi HTTP/SSE boundary so a proposed document is visible before the user decides whether to keep it.

Implementation: add the /predictive_state_updates raw-model endpoint, translate write_document_local into incremental AG-UI state snapshots plus a synthetic confirm_changes call, and render an editable document diff whose predictive state can be accepted or rejected before continuation.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Rationale: protect provisional state from being committed accidentally and prove that confirmation, rejection, cancellation, and incomplete turns preserve the correct document across the real client-to-API transport.

Implementation: add focused engine tests for predictive transactions and rollback, extend API-side recorded replay with checkpointed state frames, and add a dual-host browser scenario that accepts one streamed document and rejects the next without replacing AGUIChatClient.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Rationale: make the predictive document browser scenario deterministic while retaining the real AG-UI request, HTTP/SSE response, and client-side confirmation flow.

Implementation: record four threaded model calls with incremental document-state checkpoints, final write calls, accepted and rejected continuation summaries, and the expected message, tool, and state inputs.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 107505be-e7f2-4460-a204-829ed9f8b231
@javiercn
javiercn force-pushed the javiercn-components-ai-09-predictive-state branch from dd8b97e to 489a976 Compare August 28, 2026 21:22

@dariatiurina dariatiurina 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.

I don't see anything of the note, except need to change dojo app, which has its own issue here: #68781

@dariatiurina
dariatiurina merged commit ca3abcd into main Sep 2, 2026
31 checks passed
@dariatiurina
dariatiurina deleted the javiercn-components-ai-09-predictive-state branch September 2, 2026 12:34
@kotlarmilos
kotlarmilos restored the javiercn-components-ai-09-predictive-state branch September 2, 2026 15:14
@kotlarmilos
kotlarmilos deleted the javiercn-components-ai-09-predictive-state branch September 2, 2026 15:14
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 3, 2026
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.

4 participants