fix: add Code Queue steer confirmation
This commit is contained in:
+1
-1
@@ -67,7 +67,7 @@ function displayCommandName(parts: string[]): string {
|
||||
}
|
||||
if (parts[0] === "codex" && parts[1] === "steer" && parts[2] !== undefined) {
|
||||
const shown = ["codex", "steer", parts[2]];
|
||||
const shownValueOptions = new Set(["--prompt-file", "--file", "--retry-attempts", "--retry-delay-ms"]);
|
||||
const shownValueOptions = new Set(["--prompt-file", "--file", "--retry-attempts", "--retry-delay-ms", "--steer-id", "--steerId"]);
|
||||
const hasPromptFile = parts.includes("--prompt-file") || parts.includes("--file");
|
||||
const hasPromptStdin = parts.includes("--prompt-stdin") || parts.includes("--stdin");
|
||||
const hasHelp = parts.slice(3).some(isHelpToken);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
|
||||
import { writeFileSync, unlinkSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { codexSteerTaskForTest } from "./src/code-queue";
|
||||
import { codexSteerTaskForTest, codexSteerTraceConfirmForTest } from "./src/code-queue";
|
||||
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
|
||||
@@ -45,6 +45,10 @@ function stringArray(value: unknown): string[] {
|
||||
return Array.isArray(value) ? value.map((item) => String(item)) : [];
|
||||
}
|
||||
|
||||
function deterministicSteerId(taskId: string, prompt: string): string {
|
||||
return `steer_${Bun.SHA256.hash(`unidesk-code-queue-steer:v1\0${taskId}\0${prompt}`, "hex").slice(0, 24)}`;
|
||||
}
|
||||
|
||||
function assertDryRunPrompt(response: JsonRecord, expectedText: string): void {
|
||||
assertCondition(response.ok === true, "CLI dry-run should succeed", response);
|
||||
const data = nestedRecord(response.data, []);
|
||||
@@ -57,10 +61,13 @@ function assertDryRunPrompt(response: JsonRecord, expectedText: string): void {
|
||||
assertCondition(prompt.text === expectedText, "dry-run prompt text mismatch", prompt);
|
||||
assertCondition(prompt.chars === expectedText.length, "dry-run prompt char count mismatch", prompt);
|
||||
assertCondition(prompt.truncated === false, "dry-run prompt must not truncate", prompt);
|
||||
assertCondition(String(request.steerId || "").startsWith("steer_"), "dry-run should expose deterministic steerId", request);
|
||||
const bodySummary = nestedRecord(response.data, ["request", "bodySummary"]);
|
||||
assertCondition(bodySummary.promptChars === expectedText.length, "dry-run should expose body prompt char count", bodySummary);
|
||||
assertCondition(bodySummary.steerId === request.steerId, "dry-run body summary should repeat steerId", { bodySummary, request });
|
||||
const commands = nestedRecord(response.data, ["commands"]);
|
||||
assertCondition(String(commands.rawProxy || "").includes("microservice proxy code-queue /api/tasks/codex_test_task/steer --method POST"), "dry-run should expose raw proxy equivalent", commands);
|
||||
assertCondition(String(commands.traceConfirm || "").includes(`--steer-id ${String(request.steerId)}`), "dry-run should expose trace confirmation command", commands);
|
||||
}
|
||||
|
||||
function assertReason(result: unknown, reason: string, status: number | null): void {
|
||||
@@ -124,15 +131,30 @@ export function runCodeQueueCliSteerContract(): JsonRecord {
|
||||
let fetchPath = "";
|
||||
let fetchMethod = "";
|
||||
let fetchPrompt = "";
|
||||
let fetchSteerId = "";
|
||||
const success = codexSteerTaskForTest("direct_task", ["send this"], (path, init) => {
|
||||
fetchPath = path;
|
||||
fetchMethod = String(init?.method || "");
|
||||
fetchPrompt = String((init?.body as JsonRecord | undefined)?.prompt || "");
|
||||
fetchSteerId = String((init?.body as JsonRecord | undefined)?.steerId || "");
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
body: {
|
||||
ok: true,
|
||||
accepted: true,
|
||||
deliveryState: "accepted",
|
||||
steerId: fetchSteerId,
|
||||
traceConfirmation: {
|
||||
taskId: "direct_task",
|
||||
steerId: fetchSteerId,
|
||||
found: true,
|
||||
accepted: true,
|
||||
deliveryState: "accepted",
|
||||
matchCount: 1,
|
||||
trace: { seq: 5, at: "2026-05-23T00:00:00.000Z", method: "turn/steer", steerId: fetchSteerId, promptChars: 9, promptHash: "hash", promptOmitted: true, source: "promptHistory" },
|
||||
duplicateSuppressionKey: fetchSteerId,
|
||||
},
|
||||
task: { id: "direct_task", status: "running", prompt: "p" },
|
||||
queue: { activeTaskIds: ["direct_task"] },
|
||||
},
|
||||
@@ -141,7 +163,12 @@ export function runCodeQueueCliSteerContract(): JsonRecord {
|
||||
assertCondition(fetchPath === "/api/microservices/code-queue/proxy/api/tasks/direct_task/steer", "non-dry-run should use stable proxy path", { fetchPath });
|
||||
assertCondition(fetchMethod === "POST", "non-dry-run should POST", { fetchMethod });
|
||||
assertCondition(fetchPrompt === "send this", "non-dry-run should send raw prompt in body", { fetchPrompt });
|
||||
assertCondition(fetchSteerId === deterministicSteerId("direct_task", "send this"), "non-dry-run should send deterministic steerId", { fetchSteerId });
|
||||
assertCondition(nestedRecord(success, ["steer"]).accepted === true, "successful steer should report accepted=true", success);
|
||||
assertCondition(nestedRecord(success, ["steer"]).steerId === fetchSteerId, "successful steer should report steerId", success);
|
||||
assertCondition(nestedRecord(success, ["steer"]).deliveryState === "accepted", "successful steer should report delivery state", success);
|
||||
assertCondition(nestedRecord(success, ["traceConfirmation"]).accepted === true, "successful steer should expose bounded trace confirmation", success);
|
||||
assertCondition(String(nestedRecord(success, ["commands"]).traceConfirm || "").includes(`--steer-id ${fetchSteerId}`), "successful steer should expose trace confirmation command", success);
|
||||
const successJson = JSON.stringify(success);
|
||||
assertCondition(nestedRecord(success, ["steer"]).promptOmitted === true, "successful steer should mark prompt omitted", success);
|
||||
assertCondition(!successJson.includes("send this"), "successful steer must not echo prompt text", success);
|
||||
@@ -166,38 +193,82 @@ export function runCodeQueueCliSteerContract(): JsonRecord {
|
||||
attempts: [{ attempt: 1, ok: false, durationMs: 30003, timeoutMs: 30000, result: { ok: false, error: "The operation was aborted" } }],
|
||||
};
|
||||
let retryCalls = 0;
|
||||
const retryThenSuccess = codexSteerTaskForTest("direct_task", ["transient correction", "--retry-delay-ms", "0"], () => {
|
||||
const retrySteerIds: string[] = [];
|
||||
const retryThenSuccess = codexSteerTaskForTest("direct_task", ["transient correction", "--retry-delay-ms", "0"], (_path, init) => {
|
||||
retryCalls += 1;
|
||||
retrySteerIds.push(String((init?.body as JsonRecord | undefined)?.steerId || ""));
|
||||
if (retryCalls === 1) return { ok: false, status: 502, body: abortedTunnelBody };
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
body: {
|
||||
ok: true,
|
||||
accepted: true,
|
||||
deliveryState: "accepted",
|
||||
steerId: retrySteerIds[0],
|
||||
traceConfirmation: {
|
||||
taskId: "direct_task",
|
||||
steerId: retrySteerIds[0],
|
||||
found: true,
|
||||
accepted: true,
|
||||
deliveryState: "accepted",
|
||||
matchCount: 1,
|
||||
trace: { seq: 6, at: "2026-05-23T00:00:02.000Z", method: "turn/steer", steerId: retrySteerIds[0], promptChars: 20, promptHash: "hash2", promptOmitted: true, source: "output" },
|
||||
duplicateSuppressionKey: retrySteerIds[0],
|
||||
},
|
||||
task: { id: "direct_task", status: "running", prompt: "hidden" },
|
||||
queue: { activeTaskIds: ["direct_task"] },
|
||||
},
|
||||
};
|
||||
}) as JsonRecord;
|
||||
assertCondition(retryCalls === 2, "retryable 502 tunnel abort should be retried once by default", { retryCalls, retryThenSuccess });
|
||||
assertCondition(retrySteerIds.length === 2 && retrySteerIds[0] === retrySteerIds[1] && retrySteerIds[0] === deterministicSteerId("direct_task", "transient correction"), "retry should reuse a single steerId", { retrySteerIds });
|
||||
assertCondition(nestedRecord(retryThenSuccess, ["steer"]).accepted === true, "retry success should accept steer", retryThenSuccess);
|
||||
assertCondition(nestedRecord(retryThenSuccess, ["steer"]).steerId === retrySteerIds[0], "retry success should report reused steerId", retryThenSuccess);
|
||||
const retrySuccessAttempts = nestedRecord(retryThenSuccess, ["steer"]).attempts;
|
||||
assertCondition(Array.isArray(retrySuccessAttempts) && retrySuccessAttempts.length === 2, "retry success should expose both attempts", retryThenSuccess);
|
||||
assertCondition(String(JSON.stringify(retryThenSuccess)).includes("The operation was aborted"), "retry attempts should preserve aborted tunnel evidence", retryThenSuccess);
|
||||
assertCondition(!String(JSON.stringify(retryThenSuccess)).includes("transient correction"), "retry success must not echo steer prompt", retryThenSuccess);
|
||||
|
||||
let exhaustedCalls = 0;
|
||||
const exhausted = codexSteerTaskForTest("direct_task", ["final correction", "--retry-attempts", "2", "--retry-delay-ms", "0"], () => {
|
||||
const exhaustedSteerIds: string[] = [];
|
||||
const exhausted = codexSteerTaskForTest("direct_task", ["final correction", "--retry-attempts", "2", "--retry-delay-ms", "0"], (path, init) => {
|
||||
exhaustedCalls += 1;
|
||||
exhaustedSteerIds.push(String((init?.body as JsonRecord | undefined)?.steerId || ""));
|
||||
if (path.includes("/steer-confirmation")) {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
body: {
|
||||
ok: true,
|
||||
confirmation: {
|
||||
taskId: "direct_task",
|
||||
steerId: exhaustedSteerIds[0],
|
||||
found: false,
|
||||
accepted: false,
|
||||
deliveryState: "unknown",
|
||||
matchCount: 0,
|
||||
trace: null,
|
||||
duplicateSuppressionKey: exhaustedSteerIds[0],
|
||||
promptOmitted: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
return { ok: false, status: 502, body: abortedTunnelBody };
|
||||
}) as JsonRecord;
|
||||
assertCondition(exhaustedCalls === 2, "retryable 502 tunnel abort should honor retry-attempts", { exhaustedCalls, exhausted });
|
||||
assertCondition(exhaustedCalls === 3, "retryable 502 tunnel abort should honor retry-attempts and run confirmation lookup", { exhaustedCalls, exhausted });
|
||||
assertCondition(exhaustedSteerIds[0] === exhaustedSteerIds[1], "exhausted retry should reuse steerId", { exhaustedSteerIds });
|
||||
assertReason(exhausted, "stable-proxy-failed", 502);
|
||||
assertCondition(nestedRecord(exhausted, ["steer"]).status === "unknown", "unconfirmed transport failure should report unknown status", exhausted);
|
||||
assertCondition(nestedRecord(exhausted, ["steer"]).steerId === exhaustedSteerIds[0], "exhausted failure should expose steerId", exhausted);
|
||||
assertCondition(nestedRecord(exhausted, ["traceConfirmation"]).deliveryState === "unknown", "exhausted failure should include trace confirmation lookup", exhausted);
|
||||
const exhaustedDiagnostics = nestedRecord(exhausted, ["diagnostics"]);
|
||||
const exhaustedAttempts = exhaustedDiagnostics.attempts;
|
||||
assertCondition(Array.isArray(exhaustedAttempts) && exhaustedAttempts.length === 2, "exhausted retry diagnostics should expose attempts", exhaustedDiagnostics);
|
||||
assertCondition(String(exhaustedDiagnostics.message || "").includes("The operation was aborted"), "diagnostics should include provider abort message", exhaustedDiagnostics);
|
||||
assertCondition(nestedRecord(exhaustedDiagnostics, ["operatorGuidance"]).rawProxyEquivalentIsFallback === false, "raw proxy equivalent should be diagnostic, not fallback", exhaustedDiagnostics);
|
||||
assertCondition(String(nestedRecord(exhausted, ["commands"]).traceConfirm || "").includes(`--steer-id ${exhaustedSteerIds[0]}`), "failure should expose bounded trace confirmation command", exhausted);
|
||||
assertCondition(String(nestedRecord(exhausted, ["commands"]).rawProxy || "").includes("microservice proxy code-queue /api/tasks/direct_task/steer"), "failure should still expose raw proxy diagnostic command", exhausted);
|
||||
assertCondition(nestedRecord(exhausted, ["steer"]).promptOmitted === true, "failed steer should omit prompt by default", exhausted);
|
||||
assertCondition(!("request" in exhausted), "failed steer should omit request by default", exhausted);
|
||||
@@ -218,6 +289,96 @@ export function runCodeQueueCliSteerContract(): JsonRecord {
|
||||
}) as JsonRecord;
|
||||
assertCondition("rawFailure" in exhaustedRaw, "--raw failed steer should expose raw response", exhaustedRaw);
|
||||
|
||||
const timeoutAcceptedSteerId = deterministicSteerId("direct_task", "accepted but timed out");
|
||||
let timeoutAcceptedCalls = 0;
|
||||
const timeoutAccepted = codexSteerTaskForTest("direct_task", ["accepted but timed out", "--retry-attempts", "1", "--retry-delay-ms", "0"], (path) => {
|
||||
timeoutAcceptedCalls += 1;
|
||||
if (path.includes("/steer-confirmation")) {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
body: {
|
||||
ok: true,
|
||||
confirmation: {
|
||||
taskId: "direct_task",
|
||||
steerId: timeoutAcceptedSteerId,
|
||||
found: true,
|
||||
accepted: true,
|
||||
deliveryState: "accepted",
|
||||
matchCount: 1,
|
||||
trace: { seq: 77, at: "2026-05-23T00:00:03.000Z", method: "turn/steer", steerId: timeoutAcceptedSteerId, promptChars: 22, promptHash: "hash3", promptOmitted: true, source: "promptHistory" },
|
||||
duplicateSuppressionKey: timeoutAcceptedSteerId,
|
||||
promptOmitted: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
return { ok: false, status: 502, body: abortedTunnelBody };
|
||||
}) as JsonRecord;
|
||||
assertCondition(timeoutAcceptedCalls === 2, "timeout accepted contract should perform one send and one confirmation lookup", { timeoutAcceptedCalls });
|
||||
assertCondition(timeoutAccepted.ok === true, "trace-confirmed timeout should be treated as accepted", timeoutAccepted);
|
||||
assertCondition(nestedRecord(timeoutAccepted, ["steer"]).status === "accepted_response_timeout", "trace-confirmed timeout should expose accepted_response_timeout", timeoutAccepted);
|
||||
assertCondition(nestedRecord(timeoutAccepted, ["steer"]).deliveryUnconfirmed === false, "trace-confirmed timeout should not remain deliveryUnconfirmed", timeoutAccepted);
|
||||
assertCondition(nestedRecord(timeoutAccepted, ["traceConfirmation"]).accepted === true, "trace-confirmed timeout should include confirmation", timeoutAccepted);
|
||||
|
||||
const explicitSteerId = "steer_manual_12345";
|
||||
const duplicateSuppressed = codexSteerTaskForTest("direct_task", ["same prompt", "--steer-id", explicitSteerId], (_path, init) => {
|
||||
const body = init?.body as JsonRecord | undefined;
|
||||
assertCondition(body?.steerId === explicitSteerId, "explicit steerId should be sent unchanged", body ?? {});
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
body: {
|
||||
ok: true,
|
||||
accepted: true,
|
||||
duplicateSuppressed: true,
|
||||
deliveryState: "accepted",
|
||||
steerId: explicitSteerId,
|
||||
traceConfirmation: {
|
||||
taskId: "direct_task",
|
||||
steerId: explicitSteerId,
|
||||
found: true,
|
||||
accepted: true,
|
||||
deliveryState: "accepted",
|
||||
matchCount: 1,
|
||||
trace: { seq: 88, at: "2026-05-23T00:00:04.000Z", method: "turn/steer", steerId: explicitSteerId, promptChars: 11, promptHash: "hash4", promptOmitted: true, source: "promptHistory" },
|
||||
duplicateSuppressionKey: explicitSteerId,
|
||||
},
|
||||
task: { id: "direct_task", status: "running", prompt: "hidden" },
|
||||
queue: { activeTaskIds: ["direct_task"] },
|
||||
},
|
||||
};
|
||||
}) as JsonRecord;
|
||||
assertCondition(nestedRecord(duplicateSuppressed, ["steer"]).duplicateSuppressed === true, "duplicate suppression should be visible", duplicateSuppressed);
|
||||
assertCondition(nestedRecord(duplicateSuppressed, ["steer"]).steerId === explicitSteerId, "duplicate suppression should preserve steerId", duplicateSuppressed);
|
||||
|
||||
const confirmLookup = codexSteerTraceConfirmForTest("direct_task", ["--steer-id", explicitSteerId], (path) => {
|
||||
assertCondition(path.includes("/api/microservices/code-queue/proxy/api/tasks/direct_task/steer-confirmation"), "confirm lookup should use proxy confirmation endpoint", { path });
|
||||
assertCondition(path.includes(`steerId=${encodeURIComponent(explicitSteerId)}`), "confirm lookup should include steerId query", { path });
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
body: {
|
||||
ok: true,
|
||||
confirmation: {
|
||||
taskId: "direct_task",
|
||||
steerId: explicitSteerId,
|
||||
found: true,
|
||||
accepted: true,
|
||||
deliveryState: "accepted",
|
||||
matchCount: 1,
|
||||
trace: { seq: 88, at: "2026-05-23T00:00:04.000Z", method: "turn/steer", steerId: explicitSteerId, promptChars: 11, promptHash: "hash4", promptOmitted: true, source: "promptHistory" },
|
||||
duplicateSuppressionKey: explicitSteerId,
|
||||
promptOmitted: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}) as JsonRecord;
|
||||
assertCondition(confirmLookup.ok === true, "trace confirmation lookup should succeed when accepted", confirmLookup);
|
||||
assertCondition(nestedRecord(confirmLookup, ["delivery"]).status === "accepted", "trace confirmation output should expose accepted status", confirmLookup);
|
||||
assertCondition(nestedRecord(confirmLookup, ["traceConfirmation", "trace"]).seq === 88, "trace confirmation output should expose bounded trace seq", confirmLookup);
|
||||
assertCondition(!JSON.stringify(confirmLookup).includes("same prompt"), "trace confirmation lookup must not echo prompt", confirmLookup);
|
||||
|
||||
const terminalPrompt = `${"do not leak ".repeat(40)}tail-secret-marker`;
|
||||
const terminalRejection = codexSteerTaskForTest("completed_task", [terminalPrompt], () => ({
|
||||
ok: false,
|
||||
@@ -241,7 +402,10 @@ export function runCodeQueueCliSteerContract(): JsonRecord {
|
||||
const terminalSteer = nestedRecord(terminalRejection, ["steer"]);
|
||||
assertCondition(terminalRejection.ok === false, "terminal steer rejection should fail", terminalRejection);
|
||||
assertCondition(terminalSteer.reason === "task-already-terminal", "terminal steer rejection should use compact terminal reason", terminalSteer);
|
||||
assertCondition(terminalSteer.status === "succeeded", "terminal steer rejection should expose task status", terminalSteer);
|
||||
assertCondition(terminalSteer.deliveryState === "not_accepted", "terminal steer rejection should expose not_accepted delivery state", terminalSteer);
|
||||
assertCondition(String(terminalSteer.steerId || "").startsWith("steer_"), "terminal steer rejection should expose steerId", terminalSteer);
|
||||
assertCondition(terminalSteer.status === "not_accepted", "terminal steer rejection should expose not_accepted status", terminalSteer);
|
||||
assertCondition(terminalSteer.taskStatus === "succeeded", "terminal steer rejection should expose task status", terminalSteer);
|
||||
assertCondition(terminalSteer.terminalStatus === "completed", "terminal steer rejection should expose terminal status", terminalSteer);
|
||||
assertCondition(terminalSteer.lastUpdate === "2026-05-22T00:00:00.000Z", "terminal steer rejection should expose last update", terminalSteer);
|
||||
assertCondition(terminalSteer.updatedAt === "2026-05-22T00:00:00.000Z", "terminal steer rejection should expose last update time", terminalSteer);
|
||||
@@ -308,6 +472,8 @@ export function runCodeQueueCliSteerContract(): JsonRecord {
|
||||
"successful steer confirms write without echoing prompt",
|
||||
"steer failure classification is JSON-consumable",
|
||||
"retryable tunnel aborts are retried with bounded diagnostics",
|
||||
"retry reuses steerId and trace confirmation distinguishes accepted_response_timeout from unknown",
|
||||
"duplicate suppression and trace confirmation lookup expose bounded output shape",
|
||||
"terminal steer rejection is compact and actionable",
|
||||
"terminal steer rejection full/raw disclosure is explicit",
|
||||
],
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import { findSteerTraceConfirmation, steerDuplicateDecision, steerTraceText } from "../src/components/microservices/code-queue/src/steer-confirmation";
|
||||
import type { QueueTask } from "../src/components/microservices/code-queue/src/types";
|
||||
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
|
||||
function assertCondition(condition: unknown, message: string, detail: JsonRecord = {}): void {
|
||||
if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`);
|
||||
}
|
||||
|
||||
function fixtureTask(): QueueTask {
|
||||
const at = "2026-05-23T00:00:00.000Z";
|
||||
return {
|
||||
id: "codex_steer_confirm_fixture",
|
||||
queueId: "default",
|
||||
queueEnteredAt: at,
|
||||
prompt: "base",
|
||||
basePrompt: "base",
|
||||
referenceTaskIds: [],
|
||||
referenceInjection: null,
|
||||
providerId: "D601",
|
||||
cwd: "/workspace",
|
||||
model: "gpt-5.5",
|
||||
reasoningEffort: null,
|
||||
executionMode: "default",
|
||||
maxAttempts: 99,
|
||||
status: "running",
|
||||
createdAt: at,
|
||||
updatedAt: at,
|
||||
startedAt: at,
|
||||
finishedAt: null,
|
||||
readAt: null,
|
||||
currentAttempt: 1,
|
||||
currentMode: "initial",
|
||||
codexThreadId: "thread_fixture",
|
||||
activeTurnId: "turn_fixture",
|
||||
finalResponse: "",
|
||||
lastError: null,
|
||||
lastJudge: null,
|
||||
judgeFailCount: 0,
|
||||
promptHistory: [],
|
||||
output: [],
|
||||
events: [],
|
||||
attempts: [],
|
||||
cancelRequested: false,
|
||||
nextPrompt: null,
|
||||
nextMode: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function runCodeQueueSteerConfirmationContract(): JsonRecord {
|
||||
const task = fixtureTask();
|
||||
const steerId = "steer_contract_12345";
|
||||
const prompt = "correct this running task";
|
||||
task.output.push({ seq: 7, at: "2026-05-23T00:00:07.000Z", channel: "user", method: "turn/steer", itemId: steerId, text: steerTraceText(steerId, prompt) });
|
||||
task.promptHistory.push({ seq: 7, at: "2026-05-23T00:00:07.000Z", method: "turn/steer", text: prompt, steerId });
|
||||
|
||||
const confirmation = findSteerTraceConfirmation(task, steerId);
|
||||
assertCondition(confirmation.found === true && confirmation.accepted === true, "confirmation should find steer trace by steerId", confirmation as unknown as JsonRecord);
|
||||
assertCondition(confirmation.matches.length === 1, "confirmation should coalesce promptHistory/output duplicates by seq", confirmation as unknown as JsonRecord);
|
||||
assertCondition(confirmation.trace?.promptChars === prompt.length, "confirmation should expose prompt chars without prompt text", (confirmation.trace ?? {}) as unknown as JsonRecord);
|
||||
assertCondition(JSON.stringify(confirmation).includes(prompt) === false, "confirmation must not echo prompt text", confirmation as unknown as JsonRecord);
|
||||
|
||||
const duplicate = steerDuplicateDecision(task, steerId, prompt);
|
||||
assertCondition(duplicate.duplicate === true && duplicate.conflict === false, "same steerId and prompt should be duplicate-suppressed", duplicate as unknown as JsonRecord);
|
||||
|
||||
const conflict = steerDuplicateDecision(task, steerId, "different prompt");
|
||||
assertCondition(conflict.duplicate === false && conflict.conflict === true, "same steerId with different prompt should be rejected as conflict", conflict as unknown as JsonRecord);
|
||||
|
||||
const missing = findSteerTraceConfirmation(task, "steer_missing_12345");
|
||||
assertCondition(missing.found === false && missing.deliveryState === "unknown", "missing steerId should remain unknown", missing as unknown as JsonRecord);
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
checks: [
|
||||
"trace confirmation finds steer by steerId",
|
||||
"promptHistory/output duplicate seq is coalesced",
|
||||
"duplicate suppression requires same prompt hash",
|
||||
"steerId conflict is detectable",
|
||||
"missing steerId returns unknown",
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
process.stdout.write(`${JSON.stringify(runCodeQueueSteerConfirmationContract(), null, 2)}\n`);
|
||||
}
|
||||
@@ -36,6 +36,7 @@ const syntaxFiles = [
|
||||
"scripts/code-queue-cli-disclosure-contract-test.ts",
|
||||
"scripts/code-queue-prompt-lint-contract-test.ts",
|
||||
"scripts/code-queue-cli-steer-test.ts",
|
||||
"scripts/code-queue-steer-confirmation-contract-test.ts",
|
||||
"scripts/code-queue-cli-submit-prompt-contract-test.ts",
|
||||
"scripts/code-queue-submit-execution-mode-contract-test.ts",
|
||||
"scripts/code-queue-submit-summary-contract-test.ts",
|
||||
@@ -321,6 +322,7 @@ export function runChecks(config: UniDeskConfig, options: CheckOptions = default
|
||||
fileItem("scripts/code-queue-cli-disclosure-contract-test.ts"),
|
||||
fileItem("scripts/code-queue-prompt-lint-contract-test.ts"),
|
||||
fileItem("scripts/code-queue-cli-steer-test.ts"),
|
||||
fileItem("scripts/code-queue-steer-confirmation-contract-test.ts"),
|
||||
fileItem("scripts/code-queue-cli-read-terminal-contract-test.ts"),
|
||||
fileItem("scripts/code-queue-cli-submit-prompt-contract-test.ts"),
|
||||
fileItem("scripts/code-queue-submit-summary-contract-test.ts"),
|
||||
@@ -367,6 +369,7 @@ export function runChecks(config: UniDeskConfig, options: CheckOptions = default
|
||||
items.push(commandItem("code-queue:cli-disclosure-contract", ["bun", "scripts/code-queue-cli-disclosure-contract-test.ts"], 30_000));
|
||||
items.push(commandItem("code-queue:prompt-lint-contract", ["bun", "scripts/code-queue-prompt-lint-contract-test.ts"], 30_000));
|
||||
items.push(commandItem("code-queue:cli-steer-contract", ["bun", "scripts/code-queue-cli-steer-test.ts"], 30_000));
|
||||
items.push(commandItem("code-queue:steer-confirmation-contract", ["bun", "scripts/code-queue-steer-confirmation-contract-test.ts"], 30_000));
|
||||
items.push(commandItem("code-queue:read-terminal-contract", ["bun", "scripts/code-queue-cli-read-terminal-contract-test.ts"], 30_000));
|
||||
items.push(commandItem("code-queue:submit-prompt-contract", ["bun", "scripts/code-queue-cli-submit-prompt-contract-test.ts"], 30_000));
|
||||
items.push(commandItem("code-queue:submit-execution-mode-contract", ["bun", "scripts/code-queue-submit-execution-mode-contract-test.ts"], 30_000));
|
||||
@@ -403,6 +406,7 @@ export function runChecks(config: UniDeskConfig, options: CheckOptions = default
|
||||
items.push(skippedItem("code-queue:cli-disclosure-contract", "Code Queue CLI disclosure/noise contract is opt-in with script checks", "--scripts-typecheck or --full"));
|
||||
items.push(skippedItem("code-queue:prompt-lint-contract", "Code Queue prompt live-authorization lint contract is opt-in with script checks", "--scripts-typecheck or --full"));
|
||||
items.push(skippedItem("code-queue:cli-steer-contract", "Code Queue steer CLI contract is opt-in with script checks", "--scripts-typecheck or --full"));
|
||||
items.push(skippedItem("code-queue:steer-confirmation-contract", "Code Queue steer delivery confirmation contract is opt-in with script checks", "--scripts-typecheck or --full"));
|
||||
items.push(skippedItem("code-queue:read-terminal-contract", "Code Queue terminal read contract is opt-in with script checks", "--scripts-typecheck or --full"));
|
||||
items.push(skippedItem("code-queue:submit-prompt-contract", "Code Queue submit prompt contract is opt-in with script checks", "--scripts-typecheck or --full"));
|
||||
items.push(skippedItem("code-queue:submit-execution-mode-contract", "Code Queue submit execution-mode contract is opt-in with script checks", "--scripts-typecheck or --full"));
|
||||
|
||||
+198
-25
@@ -3,6 +3,7 @@ import { runCommand } from "./command";
|
||||
import { type UniDeskConfig, repoRoot, rootPath } from "./config";
|
||||
import { coreInternalFetch } from "./microservices";
|
||||
import { previewJson } from "./preview";
|
||||
import { createSteerId, type SteerDeliveryState } from "../../src/components/microservices/code-queue/src/steer-confirmation";
|
||||
import {
|
||||
codeAgentPortForModel,
|
||||
codeExecutionModes,
|
||||
@@ -220,6 +221,7 @@ interface SubmitRoutingRecommendation {
|
||||
|
||||
interface CodexSteerOptions {
|
||||
prompt: string;
|
||||
steerId: string | undefined;
|
||||
dryRun: boolean;
|
||||
retryAttempts: number;
|
||||
retryDelayMs: number;
|
||||
@@ -227,6 +229,11 @@ interface CodexSteerOptions {
|
||||
raw: boolean;
|
||||
}
|
||||
|
||||
interface CodexSteerConfirmOptions {
|
||||
steerId: string;
|
||||
raw: boolean;
|
||||
}
|
||||
|
||||
type CodexSteerFailureReason =
|
||||
| "backend-core-unreachable"
|
||||
| "code-queue-microservice-unregistered"
|
||||
@@ -237,6 +244,8 @@ type CodexSteerFailureReason =
|
||||
| "stable-proxy-failed"
|
||||
| "invalid-proxy-response";
|
||||
|
||||
type CodexSteerAcceptanceStatus = "accepted" | "not_accepted" | "accepted_response_timeout" | "unknown";
|
||||
|
||||
interface ClassifiedCodexSteerError {
|
||||
reason: CodexSteerFailureReason;
|
||||
scope: "backend-core" | "stable-proxy" | "code-queue-runtime" | "unknown";
|
||||
@@ -261,8 +270,12 @@ interface CodexSteerAttemptSummary {
|
||||
scope: ClassifiedCodexSteerError["scope"] | null;
|
||||
retryable: boolean;
|
||||
message: string | null;
|
||||
deliveryState?: CodexSteerDeliveryState | null;
|
||||
steerId?: string | null;
|
||||
}
|
||||
|
||||
type CodexSteerDeliveryState = SteerDeliveryState;
|
||||
|
||||
interface CompactTaskMutationResponseOptions {
|
||||
fullPrompt?: boolean;
|
||||
}
|
||||
@@ -443,6 +456,18 @@ function codeQueueProxyEquivalentCommand(targetPath: string, bodyJson: string):
|
||||
return `bun scripts/cli.ts microservice proxy code-queue ${targetPath} --method POST --body-json '${bodyJson}'`;
|
||||
}
|
||||
|
||||
function steerConfirmationPath(taskId: string, steerId: string): string {
|
||||
return `/api/tasks/${encodeURIComponent(taskId)}/steer-confirmation${queryString({ steerId })}`;
|
||||
}
|
||||
|
||||
function steerConfirmationCommand(taskId: string, steerId: string): string {
|
||||
return `bun scripts/cli.ts codex steer-confirm ${taskId} --steer-id ${steerId}`;
|
||||
}
|
||||
|
||||
function rawSteerConfirmationCommand(taskId: string, steerId: string): string {
|
||||
return `bun scripts/cli.ts microservice proxy code-queue ${steerConfirmationPath(taskId, steerId)} --raw`;
|
||||
}
|
||||
|
||||
function nonNegativeIntegerEnv(name: string, fallback: number): number {
|
||||
const raw = process.env[name];
|
||||
if (raw === undefined || raw.trim().length === 0) return fallback;
|
||||
@@ -745,6 +770,57 @@ function compactSteerFailureDiagnostics(diagnostics: ClassifiedCodexSteerError,
|
||||
};
|
||||
}
|
||||
|
||||
function compactSteerTraceConfirmation(value: unknown, taskId: string, steerId: string): Record<string, unknown> {
|
||||
const record = asRecord(value) ?? {};
|
||||
const confirmation = asRecord(record.confirmation) ?? record;
|
||||
const trace = asRecord(confirmation.trace);
|
||||
return {
|
||||
taskId: asString(confirmation.taskId) || taskId,
|
||||
steerId: asString(confirmation.steerId) || steerId,
|
||||
found: confirmation.found === true,
|
||||
accepted: confirmation.accepted === true,
|
||||
deliveryState: asString(confirmation.deliveryState) || (confirmation.found === true ? "accepted" : "unknown"),
|
||||
matchCount: asNumber(confirmation.matchCount, 0),
|
||||
trace: trace === null ? null : {
|
||||
seq: trace.seq ?? null,
|
||||
at: trace.at ?? null,
|
||||
method: trace.method ?? null,
|
||||
steerId: trace.steerId ?? steerId,
|
||||
promptChars: trace.promptChars ?? null,
|
||||
promptHash: trace.promptHash ?? null,
|
||||
promptOmitted: true,
|
||||
source: trace.source ?? null,
|
||||
},
|
||||
duplicateSuppressionKey: confirmation.duplicateSuppressionKey ?? steerId,
|
||||
promptOmitted: true,
|
||||
};
|
||||
}
|
||||
|
||||
function fetchSteerTraceConfirmation(taskId: string, steerId: string, fetcher: CodexResponseFetcher): Record<string, unknown> {
|
||||
const response = unwrapCodexResponse(fetcher(codeQueueProxyPath(steerConfirmationPath(taskId, steerId))));
|
||||
return compactSteerTraceConfirmation(response.body, taskId, steerId);
|
||||
}
|
||||
|
||||
function safeFetchSteerTraceConfirmation(taskId: string, steerId: string, fetcher: CodexResponseFetcher): Record<string, unknown> {
|
||||
try {
|
||||
return fetchSteerTraceConfirmation(taskId, steerId, fetcher);
|
||||
} catch (error) {
|
||||
return {
|
||||
taskId,
|
||||
steerId,
|
||||
found: false,
|
||||
accepted: false,
|
||||
deliveryState: "unknown",
|
||||
promptOmitted: true,
|
||||
lookupError: error instanceof Error ? error.message : String(error),
|
||||
commands: {
|
||||
retryLookup: steerConfirmationCommand(taskId, steerId),
|
||||
rawLookup: rawSteerConfirmationCommand(taskId, steerId),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function unwrapSteerResponse(response: unknown, targetPath: string, stableProxyPath: string, rawProxyEquivalent: string): { ok: true; upstream: { ok: unknown; status: unknown }; body: Record<string, unknown> } | { ok: false; diagnostics: ClassifiedCodexSteerError; rawResponse: unknown } {
|
||||
const record = asRecord(response);
|
||||
const body = responseBody(record);
|
||||
@@ -763,7 +839,7 @@ function terminalStatusFromTask(task: Record<string, unknown> | null): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
function compactTerminalSteerRejection(taskId: string, response: unknown): Record<string, unknown> | null {
|
||||
function compactTerminalSteerRejection(taskId: string, steerId: string, response: unknown): Record<string, unknown> | null {
|
||||
const record = asRecord(response);
|
||||
const body = responseBody(record);
|
||||
const task = asRecord(body?.task);
|
||||
@@ -775,9 +851,12 @@ function compactTerminalSteerRejection(taskId: string, response: unknown): Recor
|
||||
ok: false,
|
||||
steer: {
|
||||
accepted: false,
|
||||
status: "not_accepted",
|
||||
deliveryState: "not_accepted",
|
||||
steerId,
|
||||
reason: "task-already-terminal",
|
||||
taskId,
|
||||
status,
|
||||
taskStatus: status,
|
||||
terminalStatus: terminalStatus || null,
|
||||
lastUpdate,
|
||||
updatedAt: task?.updatedAt ?? null,
|
||||
@@ -833,7 +912,7 @@ function attachSteerDisclosure(
|
||||
return result;
|
||||
}
|
||||
|
||||
function steerSuccessAttempt(attempt: number, durationMs: number, upstream: { ok: unknown; status: unknown }): CodexSteerAttemptSummary {
|
||||
function steerSuccessAttempt(attempt: number, durationMs: number, upstream: { ok: unknown; status: unknown }, steerId?: string, deliveryState: CodexSteerDeliveryState = "accepted"): CodexSteerAttemptSummary {
|
||||
const status = typeof upstream.status === "number" && Number.isFinite(upstream.status) ? upstream.status : null;
|
||||
return {
|
||||
attempt,
|
||||
@@ -845,6 +924,8 @@ function steerSuccessAttempt(attempt: number, durationMs: number, upstream: { ok
|
||||
scope: null,
|
||||
retryable: false,
|
||||
message: "steer accepted by Code Queue",
|
||||
deliveryState,
|
||||
steerId: steerId ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -859,6 +940,8 @@ function steerFailureAttempt(attempt: number, durationMs: number, diagnostics: C
|
||||
scope: diagnostics.scope,
|
||||
retryable: diagnostics.retryable,
|
||||
message: diagnostics.message,
|
||||
deliveryState: null,
|
||||
steerId: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2512,6 +2595,10 @@ export function codexSteerTaskForTest(taskId: string, optionArgs: string[], fetc
|
||||
return codexSteerTask(taskId, optionArgs, fetcher);
|
||||
}
|
||||
|
||||
export function codexSteerTraceConfirmForTest(taskId: string, optionArgs: string[], fetcher: CodexResponseFetcher): unknown {
|
||||
return codexSteerTraceConfirm(taskId, optionArgs, fetcher);
|
||||
}
|
||||
|
||||
function isTerminalTaskStatus(status: unknown): boolean {
|
||||
return status === "succeeded" || status === "failed" || status === "canceled";
|
||||
}
|
||||
@@ -3980,6 +4067,8 @@ const steerPromptValueOptions = new Set([
|
||||
"--file",
|
||||
"--retry-attempts",
|
||||
"--retry-delay-ms",
|
||||
"--steer-id",
|
||||
"--steerId",
|
||||
]);
|
||||
|
||||
function referenceTaskIdsFromOptions(args: string[]): string[] {
|
||||
@@ -4089,13 +4178,16 @@ function parseSubmitOptions(args: string[]): CodexSubmitOptions {
|
||||
function parseSteerOptions(args: string[]): CodexSteerOptions {
|
||||
assertKnownOptions(args, {
|
||||
flags: ["--prompt-stdin", "--stdin", "--dry-run", "--no-retry", "--full", "--raw"],
|
||||
valueOptions: ["--prompt-file", "--file", "--retry-attempts", "--retry-delay-ms"],
|
||||
valueOptions: ["--prompt-file", "--file", "--retry-attempts", "--retry-delay-ms", "--steer-id", "--steerId"],
|
||||
}, "codex steer");
|
||||
const retryAttempts = hasFlag(args, "--no-retry")
|
||||
? 1
|
||||
: positiveIntegerOption(args, ["--retry-attempts"], defaultSteerRetryAttempts, maxSteerRetryAttempts);
|
||||
const steerId = optionValue(args, ["--steer-id", "--steerId"]);
|
||||
if (steerId !== undefined && !/^[A-Za-z0-9._:-]{8,128}$/u.test(steerId)) throw new Error("--steer-id must be 8-128 chars using letters, numbers, dot, underscore, colon, or dash");
|
||||
return {
|
||||
prompt: promptFromArgs(args, "codex steer", steerPromptValueOptions),
|
||||
steerId,
|
||||
dryRun: hasFlag(args, "--dry-run"),
|
||||
retryAttempts,
|
||||
retryDelayMs: nonNegativeIntegerOption(args, ["--retry-delay-ms"], defaultSteerRetryDelayMs, maxSteerRetryDelayMs),
|
||||
@@ -4104,6 +4196,17 @@ function parseSteerOptions(args: string[]): CodexSteerOptions {
|
||||
};
|
||||
}
|
||||
|
||||
function parseSteerConfirmOptions(args: string[]): CodexSteerConfirmOptions {
|
||||
assertKnownOptions(args, {
|
||||
flags: ["--raw"],
|
||||
valueOptions: ["--steer-id", "--steerId"],
|
||||
}, "codex steer-confirm");
|
||||
const steerId = optionValue(args, ["--steer-id", "--steerId"]);
|
||||
if (steerId === undefined) throw new Error("codex steer-confirm requires --steer-id <id>");
|
||||
if (!/^[A-Za-z0-9._:-]{8,128}$/u.test(steerId)) throw new Error("--steer-id must be 8-128 chars using letters, numbers, dot, underscore, colon, or dash");
|
||||
return { steerId, raw: hasFlag(args, "--raw") };
|
||||
}
|
||||
|
||||
function parsePromptLintOptions(args: string[]): CodexPromptLintOptions {
|
||||
assertKnownOptions(args, {
|
||||
flags: ["--prompt-stdin", "--stdin"],
|
||||
@@ -4193,6 +4296,18 @@ function compactSubmitTaskConfirmation(task: unknown): Record<string, unknown> {
|
||||
};
|
||||
}
|
||||
|
||||
function compactSteerTaskConfirmation(task: unknown, steerId: string): Record<string, unknown> {
|
||||
const compact = compactSubmitTaskConfirmation(task);
|
||||
const commands = asRecord(compact.commands) ?? {};
|
||||
return {
|
||||
...compact,
|
||||
commands: {
|
||||
...commands,
|
||||
traceConfirm: steerConfirmationCommand(asString(compact.id) || "<taskId>", steerId),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function orderedUniqueStringList(values: string[]): string[] {
|
||||
const seen = new Set<string>();
|
||||
const items: string[] = [];
|
||||
@@ -6133,27 +6248,31 @@ function codexInterruptTask(taskId: string): unknown {
|
||||
function codexSteerTask(taskId: string, args: string[], fetcher: CodexResponseFetcher = coreInternalFetch): unknown {
|
||||
const options = parseSteerOptions(args);
|
||||
const promptLint = buildPromptLiveAuthorizationLint(options.prompt);
|
||||
const steerId = options.steerId ?? createSteerId(taskId, options.prompt);
|
||||
const targetPath = `/api/tasks/${encodeURIComponent(taskId)}/steer`;
|
||||
const stableProxyPath = codeQueueProxyPath(targetPath);
|
||||
const rawProxyEquivalent = codeQueueProxyEquivalentCommand(targetPath, "{\"prompt\":\"...\"}");
|
||||
const rawProxyEquivalent = codeQueueProxyEquivalentCommand(targetPath, `{"prompt":"...","steerId":"${steerId}"}`);
|
||||
const prompt = textView(options.prompt, false, steerPromptPreviewChars);
|
||||
const request = {
|
||||
path: targetPath,
|
||||
stableProxyPath,
|
||||
method: "POST",
|
||||
steerId,
|
||||
retryPolicy: {
|
||||
defaultAttempts: defaultSteerRetryAttempts,
|
||||
maxAttempts: options.retryAttempts,
|
||||
delayMs: options.retryDelayMs,
|
||||
retryableReasons: ["stable-proxy-failed", "backend-core-unreachable"],
|
||||
deliveryConfirmation: "success confirms Code Queue accepted the steer request; repeated stable-proxy failures mean delivery is unconfirmed",
|
||||
deliveryConfirmation: "success confirms Code Queue accepted the steer request; timeout-like failures trigger a bounded trace confirmation lookup by steerId",
|
||||
idempotency: "the same steerId is reused for every CLI retry and suppresses duplicate trace injection on a backend that supports the contract",
|
||||
},
|
||||
bodySummary: {
|
||||
steerId,
|
||||
promptChars: options.prompt.length,
|
||||
promptPreviewChars: steerPromptPreviewChars,
|
||||
promptTruncated: prompt.truncated,
|
||||
},
|
||||
body: { prompt },
|
||||
body: { steerId, prompt },
|
||||
};
|
||||
if (options.dryRun) {
|
||||
return {
|
||||
@@ -6162,8 +6281,9 @@ function codexSteerTask(taskId: string, args: string[], fetcher: CodexResponseFe
|
||||
promptLint,
|
||||
request,
|
||||
commands: {
|
||||
run: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path>`,
|
||||
noRetry: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --no-retry`,
|
||||
run: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --steer-id ${steerId}`,
|
||||
noRetry: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --steer-id ${steerId} --no-retry`,
|
||||
traceConfirm: steerConfirmationCommand(taskId, steerId),
|
||||
rawProxy: rawProxyEquivalent,
|
||||
},
|
||||
};
|
||||
@@ -6173,16 +6293,16 @@ function codexSteerTask(taskId: string, args: string[], fetcher: CodexResponseFe
|
||||
let successfulResponse: { ok: true; upstream: { ok: unknown; status: unknown }; body: Record<string, unknown> } | null = null;
|
||||
for (let attempt = 1; attempt <= options.retryAttempts; attempt += 1) {
|
||||
const startedAt = Date.now();
|
||||
const response = unwrapSteerResponse(fetcher(stableProxyPath, { method: "POST", body: { prompt: options.prompt } }), targetPath, stableProxyPath, rawProxyEquivalent);
|
||||
const response = unwrapSteerResponse(fetcher(stableProxyPath, { method: "POST", body: { prompt: options.prompt, steerId } }), targetPath, stableProxyPath, rawProxyEquivalent);
|
||||
const durationMs = Date.now() - startedAt;
|
||||
if (response.ok) {
|
||||
attempts.push(steerSuccessAttempt(attempt, durationMs, response.upstream));
|
||||
attempts.push(steerSuccessAttempt(attempt, durationMs, response.upstream, asString(response.body.steerId) || steerId, asString(response.body.deliveryState) as CodexSteerDeliveryState || "accepted"));
|
||||
successfulResponse = response;
|
||||
break;
|
||||
}
|
||||
attempts.push(steerFailureAttempt(attempt, durationMs, response.diagnostics));
|
||||
failedResponse = response;
|
||||
const terminalRejection = compactTerminalSteerRejection(taskId, response.rawResponse);
|
||||
const terminalRejection = compactTerminalSteerRejection(taskId, steerId, response.rawResponse);
|
||||
if (terminalRejection !== null) {
|
||||
terminalRejection.commands = {
|
||||
...(asRecord(terminalRejection.commands) ?? {}),
|
||||
@@ -6197,15 +6317,23 @@ function codexSteerTask(taskId: string, args: string[], fetcher: CodexResponseFe
|
||||
if (successfulResponse === null) {
|
||||
const diagnostics = failedResponse?.diagnostics ?? classifySteerFailure(null, targetPath, stableProxyPath, rawProxyEquivalent);
|
||||
const transportDeliveryUnconfirmed = diagnostics.reason === "stable-proxy-failed" || diagnostics.reason === "backend-core-unreachable";
|
||||
const traceConfirmation = transportDeliveryUnconfirmed ? safeFetchSteerTraceConfirmation(taskId, steerId, fetcher) : null;
|
||||
const confirmedAccepted = asBoolean(traceConfirmation?.accepted);
|
||||
const deliveryState = confirmedAccepted ? "accepted_response_timeout" : transportDeliveryUnconfirmed ? "unknown" : "not_accepted";
|
||||
const acceptanceStatus: CodexSteerAcceptanceStatus = confirmedAccepted ? "accepted_response_timeout" : transportDeliveryUnconfirmed ? "unknown" : "not_accepted";
|
||||
const compactDiagnostics = compactSteerFailureDiagnostics(diagnostics, options.full);
|
||||
return {
|
||||
ok: false,
|
||||
ok: confirmedAccepted,
|
||||
steer: {
|
||||
accepted: false,
|
||||
accepted: confirmedAccepted,
|
||||
status: acceptanceStatus,
|
||||
deliveryState,
|
||||
steerId,
|
||||
promptChars: options.prompt.length,
|
||||
promptOmitted: true,
|
||||
attempts,
|
||||
deliveryUnconfirmed: transportDeliveryUnconfirmed,
|
||||
deliveryUnconfirmed: transportDeliveryUnconfirmed && !confirmedAccepted,
|
||||
duplicateSuppressionKey: steerId,
|
||||
retryPolicy: {
|
||||
attempted: attempts.length,
|
||||
maxAttempts: options.retryAttempts,
|
||||
@@ -6233,18 +6361,23 @@ function codexSteerTask(taskId: string, args: string[], fetcher: CodexResponseFe
|
||||
},
|
||||
operatorGuidance: {
|
||||
rawProxyEquivalentIsFallback: false,
|
||||
deliveryUnconfirmed: transportDeliveryUnconfirmed,
|
||||
nextStep: transportDeliveryUnconfirmed
|
||||
? "Check task liveness and retry codex steer from the main-server CLI or explicit SSH transport; do not treat a raw proxy failure as separate evidence that the task rejected the correction."
|
||||
deliveryUnconfirmed: transportDeliveryUnconfirmed && !confirmedAccepted,
|
||||
traceConfirmationChecked: traceConfirmation !== null,
|
||||
nextStep: confirmedAccepted
|
||||
? "The stable proxy response timed out, but trace confirmation found this steerId. Do not resend the same corrective prompt."
|
||||
: transportDeliveryUnconfirmed
|
||||
? "Run the bounded trace confirmation command before retrying. If it remains unknown, retry with the same steerId to avoid duplicate trace injection on an updated backend."
|
||||
: "Inspect the non-retryable reason before resubmitting the correction.",
|
||||
},
|
||||
},
|
||||
traceConfirmation,
|
||||
commands: {
|
||||
dryRun: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --dry-run`,
|
||||
retry: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path>`,
|
||||
noRetry: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --no-retry`,
|
||||
fullDetails: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --full`,
|
||||
rawDetails: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --raw`,
|
||||
dryRun: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --steer-id ${steerId} --dry-run`,
|
||||
retry: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --steer-id ${steerId}`,
|
||||
noRetry: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --steer-id ${steerId} --no-retry`,
|
||||
traceConfirm: steerConfirmationCommand(taskId, steerId),
|
||||
fullDetails: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --steer-id ${steerId} --full`,
|
||||
rawDetails: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --steer-id ${steerId} --raw`,
|
||||
rawProxy: rawProxyEquivalent,
|
||||
tasks: "bun scripts/cli.ts codex tasks --view supervisor --limit 20",
|
||||
health: "bun scripts/cli.ts microservice health code-queue",
|
||||
@@ -6258,14 +6391,23 @@ function codexSteerTask(taskId: string, args: string[], fetcher: CodexResponseFe
|
||||
...(options.raw ? { rawFailure: failedResponse?.rawResponse ?? null } : {}),
|
||||
};
|
||||
}
|
||||
const responseSteerId = asString(successfulResponse.body.steerId) || steerId;
|
||||
const traceConfirmation = compactSteerTraceConfirmation(successfulResponse.body.traceConfirmation, taskId, responseSteerId);
|
||||
const deliveryState = asString(successfulResponse.body.deliveryState) || asString(traceConfirmation.deliveryState) || "accepted";
|
||||
const duplicateSuppressed = successfulResponse.body.duplicateSuppressed === true;
|
||||
return {
|
||||
ok: true,
|
||||
upstream: successfulResponse.upstream,
|
||||
steer: {
|
||||
accepted: true,
|
||||
status: "accepted",
|
||||
deliveryState,
|
||||
steerId: responseSteerId,
|
||||
taskId,
|
||||
promptChars: options.prompt.length,
|
||||
promptOmitted: true,
|
||||
duplicateSuppressed,
|
||||
duplicateSuppressionKey: responseSteerId,
|
||||
attempts,
|
||||
retryPolicy: {
|
||||
attempted: attempts.length,
|
||||
@@ -6280,18 +6422,45 @@ function codexSteerTask(taskId: string, args: string[], fetcher: CodexResponseFe
|
||||
reason: "codex steer is a write operation; default output confirms delivery and provides drill-down commands without echoing prompt text or full task state.",
|
||||
},
|
||||
},
|
||||
task: compactSubmitTaskConfirmation(successfulResponse.body.task),
|
||||
traceConfirmation,
|
||||
task: compactSteerTaskConfirmation(successfulResponse.body.task, responseSteerId),
|
||||
queue: compactSubmitQueueConfirmation(successfulResponse.body.queue),
|
||||
commands: {
|
||||
show: `bun scripts/cli.ts codex task ${taskId}`,
|
||||
detail: `bun scripts/cli.ts codex task ${taskId} --detail`,
|
||||
trace: `bun scripts/cli.ts codex task ${taskId} --trace --tail --limit ${defaultTraceLimit}`,
|
||||
traceConfirm: steerConfirmationCommand(taskId, responseSteerId),
|
||||
output: `bun scripts/cli.ts codex output ${taskId} --tail --limit ${defaultOutputLimit}`,
|
||||
supervisor: `bun scripts/cli.ts codex tasks --view supervisor --limit ${defaultTasksLimit}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function codexSteerTraceConfirm(taskId: string, args: string[], fetcher: CodexResponseFetcher = coreInternalFetch): unknown {
|
||||
const options = parseSteerConfirmOptions(args);
|
||||
const path = steerConfirmationPath(taskId, options.steerId);
|
||||
const response = unwrapCodexResponse(fetcher(codeQueueProxyPath(path)));
|
||||
const confirmation = compactSteerTraceConfirmation(response.body, taskId, options.steerId);
|
||||
return {
|
||||
ok: asBoolean(confirmation.accepted),
|
||||
upstream: response.upstream,
|
||||
traceConfirmation: confirmation,
|
||||
delivery: {
|
||||
steerId: options.steerId,
|
||||
status: asBoolean(confirmation.accepted) ? "accepted" : "unknown",
|
||||
deliveryState: confirmation.deliveryState,
|
||||
promptOmitted: true,
|
||||
},
|
||||
commands: {
|
||||
task: `bun scripts/cli.ts codex task ${taskId}`,
|
||||
trace: `bun scripts/cli.ts codex task ${taskId} --trace --tail --limit ${defaultTraceLimit}`,
|
||||
retrySameSteerId: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --steer-id ${options.steerId}`,
|
||||
rawLookup: rawSteerConfirmationCommand(taskId, options.steerId),
|
||||
},
|
||||
...(options.raw ? { raw: response.body } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export async function runCodeQueueCommand(config: UniDeskConfig, args: string[]): Promise<unknown> {
|
||||
const [action = "task", taskIdArg] = args;
|
||||
if (action === "prompt-lint" || action === "lint-prompt") {
|
||||
@@ -6350,5 +6519,9 @@ export async function runCodeQueueCommand(config: UniDeskConfig, args: string[])
|
||||
const taskId = requireTaskId(taskIdArg, "codex steer");
|
||||
return codexSteerTask(taskId, args.slice(2));
|
||||
}
|
||||
throw new Error("codex command must be one of: prompt-lint, submit, enqueue, task, summary, show, tasks, overview, unread, terminal-unread, output, judge, read, mark-read, dev-ready, health, skills-sync, pr-preflight, runtime-preflight, queues, queue list, queue create, queue merge, move, steer, interrupt, cancel");
|
||||
if (action === "steer-confirm" || action === "steer-confirmation") {
|
||||
const taskId = requireTaskId(taskIdArg, `codex ${action}`);
|
||||
return codexSteerTraceConfirm(taskId, args.slice(2));
|
||||
}
|
||||
throw new Error("codex command must be one of: prompt-lint, submit, enqueue, task, summary, show, tasks, overview, unread, terminal-unread, output, judge, read, mark-read, dev-ready, health, skills-sync, pr-preflight, runtime-preflight, queues, queue list, queue create, queue merge, move, steer, steer-confirm, interrupt, cancel");
|
||||
}
|
||||
|
||||
+5
-3
@@ -63,7 +63,8 @@ export function rootHelp(): unknown {
|
||||
{ command: "codex read <taskId>", description: "Mark one reviewed terminal task read and return terminal metadata plus final response; prompt/tool logs stay behind drill-down commands." },
|
||||
{ command: "codex dev-ready", description: "Fetch execution-container readiness, including sanitized skill injection status from /api/dev-ready." },
|
||||
{ command: "codex judge <taskId> --attempt N [--dry-run] [--include-prompt]", description: "Replay one stored Code Queue attempt through the same judge context builder and MiniMax judge call path used by the live queue worker." },
|
||||
{ command: "codex steer <taskId> [prompt|--prompt-file path|--prompt-stdin] [--dry-run] [--no-retry|--retry-attempts N] [--full|--raw]", description: "Push a corrective prompt into a running Code Queue task; retryable tunnel aborts get bounded diagnostics, terminal-task rejection suggests codex task/read plus codex submit --reference-task-id <taskId>, and upstream/raw rejection details require explicit --full or --raw." },
|
||||
{ command: "codex steer <taskId> [prompt|--prompt-file path|--prompt-stdin] [--steer-id id] [--dry-run] [--no-retry|--retry-attempts N] [--full|--raw]", description: "Push a corrective prompt into a running Code Queue task with a steerId/idempotency key; retryable tunnel aborts get bounded trace confirmation before any retry guidance." },
|
||||
{ command: "codex steer-confirm <taskId> --steer-id <id> [--raw]", description: "Read-only lookup for a steerId in task trace so deliveryUnconfirmed can be resolved without resending the corrective prompt." },
|
||||
{ command: "codex interrupt|cancel <taskId>", description: "Request interrupt for a running Code Queue task, or cancel a queued/retry_wait task, through the same private proxy." },
|
||||
{ command: "codex (queues [--full|--all] | queue create <queueId> | queue merge <sourceQueueId> --into <targetQueueId> | move <taskId> --queue <queueId>)", description: "List low-noise queue summaries by default, including effective activity counts that distinguish scheduler-local queues, DB running tasks, and heartbeat-fresh runners; full queue rows require --full/--all." },
|
||||
{ command: "job list [--limit N] [--include-command]", description: "List async jobs from .state/jobs with a bounded default page." },
|
||||
@@ -266,7 +267,8 @@ function codexHelp(): unknown {
|
||||
"bun scripts/cli.ts codex skills-sync --dry-run [--full]",
|
||||
"bun scripts/cli.ts codex pr-preflight [--remote] [--push-dry-run --push-dry-run-ref refs/heads/probe/<name>] [--pr-create-dry-run --pr-create-dry-run-head <head>] [--issue N] [--full|--raw]",
|
||||
"bun scripts/cli.ts codex judge <taskId> --attempt N [--dry-run] [--include-prompt]",
|
||||
"bun scripts/cli.ts codex steer <taskId> [prompt|--prompt-file path|--prompt-stdin] [--dry-run] [--no-retry|--retry-attempts N] [--full|--raw]",
|
||||
"bun scripts/cli.ts codex steer <taskId> [prompt|--prompt-file path|--prompt-stdin] [--steer-id id] [--dry-run] [--no-retry|--retry-attempts N] [--full|--raw]",
|
||||
"bun scripts/cli.ts codex steer-confirm <taskId> --steer-id <id> [--raw]",
|
||||
"bun scripts/cli.ts codex interrupt|cancel <taskId>",
|
||||
"bun scripts/cli.ts codex queues [--full|--all] [--limit N] [--page N|--offset N] | queue create <queueId> | queue merge <sourceQueueId> --into <targetQueueId> | move <taskId> --queue <queueId>",
|
||||
],
|
||||
@@ -330,7 +332,7 @@ function codexHelp(): unknown {
|
||||
embeddedIn: ["codex submit --dry-run", "codex steer --dry-run"],
|
||||
reference: "docs/reference/code-queue-supervision.md#dev-测试授权分级",
|
||||
},
|
||||
description: "Operate Code Queue through the stable backend-core private proxy path with bounded activity summaries for queue and supervisor views. Real submit/steer success is a low-noise write confirmation and does not echo prompt text; terminal steer rejection returns compact status plus codex task/read/submit follow-up commands, with upstream/raw details behind --full or --raw.",
|
||||
description: "Operate Code Queue through the stable backend-core private proxy path with bounded activity summaries for queue and supervisor views. Real submit/steer success is a low-noise write confirmation and does not echo prompt text; steer output includes steerId, delivery state, and a bounded trace confirmation command; terminal steer rejection returns compact status plus codex task/read/submit follow-up commands, with upstream/raw details behind --full or --raw.",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user