runs: reconcile uncertain browser launches with a persistent intent key

This commit is contained in:
2026-10-20 15:40:43 +01:00
parent f06281db08
commit 44834e91f0
8 changed files with 146 additions and 9 deletions
+39 -6
View File
@@ -27,6 +27,8 @@ import {
import { PIPELINE_GRAPH_EMPTY, layoutGraph, mount as mountGraph } from "../graph.js";
import { statusIcon } from "../statusIcon.js";
import { writeGraphExpanded } from "../graphPrefs.js";
import { pendingRun, createRunIntent, saveRunIntent, clearRunIntent } from "../runIntent.js";
import { ProtocolError } from "../client.js";
export function createPipelinesView(rt) {
const { state, repo, modal } = rt;
@@ -391,6 +393,13 @@ async function openRunDialog(pipeline) {
sending: false,
error: "",
};
start.intent = pendingRun(globalThis.sessionStorage, state.url, start.pipelineId, start.version);
if (start.intent) {
start.prompt = start.intent.prompt;
start.workspace = start.intent.workspace;
start.notifyMode = start.intent.notifyMode;
start.error = "A previous launch has an unknown result. Check/retry reconciles that same request; it will not start a duplicate.";
}
state.runStart = start;
renderContent();
try {
@@ -428,9 +437,9 @@ async function startRun() {
}
start.sending = true;
start.error = "";
renderContent();
try {
const run = await repo.runPipeline({
const recovering = start.intent != null;
if (!start.intent) {
start.intent = createRunIntent({
pipelineId: start.pipelineId,
version: start.version,
prompt,
@@ -438,12 +447,34 @@ async function startRun() {
notifyMode: start.notifyMode,
title: "",
});
}
saveRunIntent(globalThis.sessionStorage, state.url, start.intent);
renderContent();
try {
const existing = recovering ? await repo.runByRequestKey(start.intent.requestKey) : null;
const run = existing ?? await repo.runPipeline(start.intent);
clearRunIntent(globalThis.sessionStorage, state.url, start.intent);
state.runStart = null;
await applyRoute({ kind: "run", id: run.id });
} catch (error) {
if (state.runStart !== start) return;
// A confirmed refusal can be corrected, but only after a read proves no
// run was admitted. A generic transport failure remains uncertain.
if (error instanceof ProtocolError) {
try {
const existing = await repo.runByRequestKey(start.intent.requestKey);
if (existing) {
clearRunIntent(globalThis.sessionStorage, state.url, start.intent);
state.runStart = null;
await applyRoute({ kind: "run", id: existing.id });
return;
}
clearRunIntent(globalThis.sessionStorage, state.url, start.intent);
start.intent = null;
} catch { /* Keep the launch immutable until admission can be checked. */ }
}
start.sending = false;
start.error = describeError(error);
start.error = describeError(error) + (start.intent ? ". Admission may be unknown. Check/retry uses the same request key." : "");
renderContent();
}
}
@@ -470,6 +501,7 @@ function renderRunStartDialog() {
rows: "5",
placeholder: "What should this run do?",
spellcheck: "false",
disabled: start.intent != null,
oninput: (event) => { start.prompt = event.target.value; },
});
prompt.value = start.prompt;
@@ -486,6 +518,7 @@ function renderRunStartDialog() {
type: "text",
list: listId,
value: start.workspace,
disabled: start.intent != null,
spellcheck: "false",
autocomplete: "off",
placeholder: "/absolute/path/on/the/server",
@@ -497,7 +530,7 @@ function renderRunStartDialog() {
const notifyField = h("label", { class: "run-start-field", for: "runNotify" });
notifyField.append(h("span", { class: "run-start-label", text: "Notifications for this run" }));
const notify = h("select", { id: "runNotify", onchange: (event) => { start.notifyMode = event.target.value; } });
const notify = h("select", { id: "runNotify", disabled: start.intent != null, onchange: (event) => { start.notifyMode = event.target.value; } });
for (const [value, label] of [
["auto", "Pipeline default"],
["on", "Notify me"],
@@ -525,7 +558,7 @@ function renderRunStartDialog() {
h("button", {
class: "primary run-start-confirm",
type: "button",
text: start.sending ? "Starting…" : "Run",
text: start.sending ? "Starting…" : start.intent ? "Check / retry" : "Run",
disabled: start.sending,
onclick: startRun,
}),