Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions src/Covenant.Ui/Components/RequestComposer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
</span>
@if (ready.SwitchToProfile is { } alt)
{
<button type="button" class="btn sm" disabled="@Pg.Running" @onclick="() => Pg.SelectProfile(alt)">Switch to @(ComposerRules.Profile(Ws.Profiles, alt)?.Name ?? alt)</button>
<button type="button" class="btn sm" disabled="@Pg.Running" @onclick="() => Pg.SelectProfileAndPreviewAsync(alt)">Switch to @(ComposerRules.Profile(Ws.Profiles, alt)?.Name ?? alt)</button>
}
}
else
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Covenant.Ui/Components/RoutePreviewPanel.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
5 changes: 5 additions & 0 deletions src/Covenant.Ui/Logic/RoutePreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>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).</summary>
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);
Expand Down
23 changes: 19 additions & 4 deletions src/Covenant.Ui/Services/PlaygroundState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -277,6 +283,15 @@ public bool SelectProfile(string? profileId)
return ok;
}

/// <summary>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.</summary>
public async Task SelectProfileAndPreviewAsync(string? profileId)
{
if (!SelectProfile(profileId)) return;
if (RoutePreview.CanPreview(Form)) await PreviewRouteAsync();
}

/// <summary>After a manual edit: a preset-specific note is dropped once the form no longer holds that preset.</summary>
public void NotifyFormChanged()
{
Expand Down
22 changes: 22 additions & 0 deletions tests/Covenant.Tests/PreviewFreshnessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
Loading