From f4d7a62d5e3bc4f9af5235109cccceede859e81c Mon Sep 17 00:00:00 2001 From: Alex Kaziuka Date: Tue, 10 Nov 2026 23:03:14 -0500 Subject: [PATCH] feat(console): workload switch re-previews the expected route Switching the workload in the Playground kept the prompt but left the Expected route as "Stale / Unknown until previewed" until Preview route was pressed, so the switch appeared to do nothing. The switch now runs the Host dry run for the new workload at once when the form has a sender and a prompt. The same request then shows its new outcome in the route scheme (for example Internal: served locally; Public: rejected at Classify). Nothing is sent to a model and nothing runs until Run. A newer dry run now wins over an older one that completes late, so two quick switches cannot leave the previous workload's route on screen. Co-Authored-By: Claude Fable 5.2 --- docs/user-guide.md | 4 +++- .../Components/RequestComposer.razor | 4 ++-- .../Components/RoutePreviewPanel.razor | 5 +--- src/Covenant.Ui/Logic/RoutePreview.cs | 5 ++++ src/Covenant.Ui/Services/PlaygroundState.cs | 23 +++++++++++++++---- tests/Covenant.Tests/PreviewFreshnessTests.cs | 22 ++++++++++++++++++ 6 files changed, 52 insertions(+), 11 deletions(-) diff --git a/docs/user-guide.md b/docs/user-guide.md index edbf265..d6bc1cb 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -44,7 +44,9 @@ send externally. If inspection cannot finish within its bounds, the request is r ## Reading a result Before Run, **Expected route** shows three boxes: **Sender → Covenant → Destination**. It comes only from the server's -current preview. When you change the inputs or the configuration, it says *stale* instead of showing an old answer. A +current preview. Switching the workload keeps the prompt and previews again at once, so the scheme shows the new +workload's outcome for the same request. When you change other inputs or the configuration, it says *stale* instead of +showing an old answer. A blocked preview says the destination would not be contacted. Web search adds a separate *external retrieval (Tavily)* badge, even when inference is local. diff --git a/src/Covenant.Ui/Components/RequestComposer.razor b/src/Covenant.Ui/Components/RequestComposer.razor index 6cc7d27..8696da0 100644 --- a/src/Covenant.Ui/Components/RequestComposer.razor +++ b/src/Covenant.Ui/Components/RequestComposer.razor @@ -155,7 +155,7 @@ @if (ready.SwitchToProfile is { } alt) { - + } } else @@ -334,7 +334,7 @@ private void OnProfile(ChangeEventArgs e) => Pg.SelectProfile(e.Value?.ToString()); - private void OnWorkload(string? profileId) => Pg.SelectProfile(profileId); + private Task OnWorkload(string? profileId) => Pg.SelectProfileAndPreviewAsync(profileId); private void OnCatalogModel(ChangeEventArgs e) { diff --git a/src/Covenant.Ui/Components/RoutePreviewPanel.razor b/src/Covenant.Ui/Components/RoutePreviewPanel.razor index 8747cdb..e214ee4 100644 --- a/src/Covenant.Ui/Components/RoutePreviewPanel.razor +++ b/src/Covenant.Ui/Components/RoutePreviewPanel.razor @@ -85,10 +85,7 @@ private void OnChanged() => _ = InvokeAsync(StateHasChanged); - private async Task SwitchAndPreviewAsync(string profileId) - { - if (Pg.SelectProfile(profileId)) await Pg.PreviewRouteAsync(); - } + private Task SwitchAndPreviewAsync(string profileId) => Pg.SelectProfileAndPreviewAsync(profileId); public void Dispose() { diff --git a/src/Covenant.Ui/Logic/RoutePreview.cs b/src/Covenant.Ui/Logic/RoutePreview.cs index aeb3c4e..27dc266 100644 --- a/src/Covenant.Ui/Logic/RoutePreview.cs +++ b/src/Covenant.Ui/Logic/RoutePreview.cs @@ -9,6 +9,11 @@ public sealed record RoutePreview(string Key, SimulateResponseDto? Result, strin public static string KeyOf(PlaygroundForm f) => string.Join("\u001f", f.ApplicationId ?? "", f.ProfileId ?? "", f.RequestedModel ?? "", f.Prompt); + /// The form holds enough for a Host dry run: a sender and a prompt. The workload switch uses this to decide + /// whether the Expected route can follow it at once (dry run only — no model call, no record, no spend). + public static bool CanPreview(PlaygroundForm f) + => !string.IsNullOrWhiteSpace(f.ApplicationId) && !string.IsNullOrWhiteSpace(f.Prompt); + public bool IsCurrent(PlaygroundForm f, int? activeVersion = null) => string.Equals(Key, KeyOf(f), StringComparison.Ordinal) && (activeVersion is null || Result?.ConfigVersion == activeVersion); diff --git a/src/Covenant.Ui/Services/PlaygroundState.cs b/src/Covenant.Ui/Services/PlaygroundState.cs index 180ecd9..f3ff38f 100644 --- a/src/Covenant.Ui/Services/PlaygroundState.cs +++ b/src/Covenant.Ui/Services/PlaygroundState.cs @@ -170,22 +170,28 @@ public async Task ApplyExampleAsync(ExampleResolution resolution) public async Task PreviewRouteAsync() { - if (Running || string.IsNullOrWhiteSpace(Form.ApplicationId) || string.IsNullOrWhiteSpace(Form.Prompt)) return; + if (Running || !RoutePreview.CanPreview(Form)) return; var key = RoutePreview.KeyOf(Form); - Preview = new RoutePreview(key, null, null, Loading: true); + var pending = new RoutePreview(key, null, null, Loading: true); + Preview = pending; Notify(); + RoutePreview done; try { var result = await _admin.SimulateAsync(new SimulateRequestDto { ApplicationId = Form.ApplicationId!, ProfileId = Form.ProfileId, Prompt = Form.Prompt, Model = Form.RequestedModel, }); - Preview = new RoutePreview(key, result, null, Loading: false); + done = new RoutePreview(key, result, null, Loading: false); } catch (Exception ex) { - Preview = new RoutePreview(key, null, "Route preview unavailable: " + ex.Message, Loading: false); + done = new RoutePreview(key, null, "Route preview unavailable: " + ex.Message, Loading: false); } + // Latest request wins: a quick second workload switch starts a newer dry run, and this older answer must not + // replace it (it would show the previous workload's route as "stale"). + if (!ReferenceEquals(Preview, pending)) return; + Preview = done; Notify(); } public bool CanRun => !Running && Problem is null; @@ -277,6 +283,15 @@ public bool SelectProfile(string? profileId) return ok; } + /// The composer's workload switch: the prompt is kept and the Expected route follows the switch at once, so the + /// same request visibly changes outcome (e.g. Internal → served locally, Public → rejected at Classify). The preview is + /// the Host's dry run for the NEW workload — nothing is sent to a model and nothing runs until Run. + public async Task SelectProfileAndPreviewAsync(string? profileId) + { + if (!SelectProfile(profileId)) return; + if (RoutePreview.CanPreview(Form)) await PreviewRouteAsync(); + } + /// After a manual edit: a preset-specific note is dropped once the form no longer holds that preset. public void NotifyFormChanged() { diff --git a/tests/Covenant.Tests/PreviewFreshnessTests.cs b/tests/Covenant.Tests/PreviewFreshnessTests.cs index d5a0123..dd6b62f 100644 --- a/tests/Covenant.Tests/PreviewFreshnessTests.cs +++ b/tests/Covenant.Tests/PreviewFreshnessTests.cs @@ -16,4 +16,26 @@ public void Changing_policy_configuration_invalidates_preview_even_when_prompt_i form.Prompt = "Different request"; Assert.False(preview.IsCurrent(form, 3)); } + + [Fact] + public void Switching_workload_makes_the_old_preview_stale_and_the_form_still_previewable_with_the_same_prompt() + { + // The Internal/Public comparison: the prompt is kept, only the workload changes. The old dry run no longer + // describes the form, and the form still holds everything a new dry run needs — so the switch re-previews. + var form = new PlaygroundForm { ApplicationId = "demo-app", ProfileId = "internal-default", Prompt = "SSN on file: 000-12-3456" }; + var preview = new RoutePreview(RoutePreview.KeyOf(form), new SimulateResponseDto { ConfigVersion = 4 }, null, false); + form.ProfileId = "public-demo"; + Assert.False(preview.IsCurrent(form, 4)); + Assert.True(RoutePreview.CanPreview(form)); + Assert.Equal("SSN on file: 000-12-3456", form.Prompt); + } + + [Theory] + [InlineData(null, "Hello", false)] + [InlineData("", "Hello", false)] + [InlineData("demo-app", "", false)] + [InlineData("demo-app", " ", false)] + [InlineData("demo-app", "Hello", true)] + public void A_dry_run_needs_a_sender_and_a_prompt(string? application, string prompt, bool expected) + => Assert.Equal(expected, RoutePreview.CanPreview(new PlaygroundForm { ApplicationId = application, Prompt = prompt })); }