Skip to content

Commit 0a19aee

Browse files
committed
Expose saved Prompt failures through Journal
1 parent 58060b0 commit 0a19aee

11 files changed

Lines changed: 350 additions & 59 deletions

File tree

‎architecture.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8488,6 +8488,11 @@ forms one row per retained `Yield` and `Close` in append order: marker, type,
84888488
name, status, optional source position, prompt number, agent and supported exec
84898489
facts. A saved Prompt's row takes its semantic outcome, number and agent from
84908490
the turn that same reading parsed; the root close takes the parsed entry outcome.
8491+
Journal joins that row to its entry-local turn by marker and exposes `promptError`:
8492+
the selected saved message, optional name/cause and optional diagnostic for a
8493+
failed or cancelled Prompt with a retained error. Completed Prompts, missing
8494+
errors and non-Prompt rows have null. The model detaches and freezes the error
8495+
and its nested diagnostic containers; the existing failure summary stays text.
84918496
Other rows retain their protocol status. An exec result with protocol `ok`
84928497
projects its validated integral `exitCode` and independently retained string
84938498
channels. An absent channel stays absent; an empty retained channel stays empty.

‎packages/acp/ACPX_RUNTIME.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ spelling and leaving existing string commands unchanged.
3737
**Failure details:** the local in-process result projection preserves the
3838
normalizer's origin and selected numeric ACP code/message/`data.details` under
3939
the `XMD prompt diagnostic:` seam. It carries no arbitrary protocol data. Core
40-
screens the optional diagnostic before saving it; the REPL's existing Prompt
41-
error page reads those facts without a runtime log or another agent call.
40+
screens the optional diagnostic before saving it; the REPL's existing Journal
41+
query reads those facts under `promptError` without a runtime log or another agent call.
4242
Classification and retryable hints never authorize resend or establish acceptance.
4343

4444
**Maintenance:** keep the runtime and its declarations on the same exact

‎packages/acp/vendor/acpx/MANIFEST.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{
3232
"path": "PROVENANCE.md",
3333
"kind": "provenance",
34-
"sha256": "bdd6b6770293029665d52eb309ffbc8c872fc53cfd489e2c6162e8263e317ad4"
34+
"sha256": "c90afafa92a157ff5db4b3b14c1c8042dafe91313365b727278e3f99340ee7c9"
3535
},
3636
{
3737
"path": "generated/agent-registry-Cz9fD9H1.js",

‎packages/acp/vendor/acpx/PROVENANCE.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ The uniquely named `XMD prompt diagnostic:` seam bounds this correction in Tier
128128
Pristine upstream, exact pins, materialization and strict-resume patches stay
129129
unchanged. The shared/queue result projection is unchanged. Real adapter-child
130130
failures pass through this runtime into production Prompt publication and cold
131-
REPL error reads; no runtime log is needed for retained selected facts.
131+
REPL Journal queries of `promptError`; no runtime log is needed for retained
132+
selected facts.
132133

133134
Other arbitrary adapter data remains unavailable through this selected result.
134135
This correction establishes no cause for the historical `Internal error` incident,

‎packages/cli/src/repl/model.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export interface ReplAgentTurn {
208208
* transcript is a reader's view of their own entry.
209209
*/
210210
readonly failure: string | undefined;
211-
readonly diagnostic?: NonNullable<PromptRecord["error"]>["diagnostic"];
211+
readonly error: PromptRecord["error"];
212212
readonly configuration: ReplAgentConfiguration | undefined;
213213
readonly permissions: readonly ReplAgentPermission[];
214214
}
@@ -1323,14 +1323,21 @@ function agentTurn(
13231323
stopReason: record.stopReason,
13241324
text: record.text,
13251325
failure: record.error?.message,
1326-
diagnostic:
1327-
record.error?.diagnostic === undefined
1326+
error:
1327+
record.error === undefined
13281328
? undefined
13291329
: freeze({
1330-
...record.error.diagnostic,
1331-
...(record.error.diagnostic.acp === undefined
1330+
...record.error,
1331+
...(record.error.diagnostic === undefined
13321332
? {}
1333-
: { acp: freeze({ ...record.error.diagnostic.acp }) }),
1333+
: {
1334+
diagnostic: freeze({
1335+
...record.error.diagnostic,
1336+
...(record.error.diagnostic.acp === undefined
1337+
? {}
1338+
: { acp: freeze({ ...record.error.diagnostic.acp }) }),
1339+
}),
1340+
}),
13341341
}),
13351342
configuration:
13361343
record.configuration === undefined

‎packages/cli/src/repl/sidekick/controls.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,12 @@ function entryInspections(requests: SidekickRequests, journal: ControlJournal):
660660
additionalProperties: false,
661661
},
662662
description:
663-
"Inspect saved commands and locate agent turns in one entry. " +
664-
'`<REPL.Entry.Journal entry={22} yq=".records" />` ' +
665-
"queries complete retained facts before paging. Read .exec.exitCode, .exec.stdout and " +
666-
".exec.stderr on a command record; reuse next, prev or last as yq with the same positive entry.",
663+
"Inspect saved commands and Prompt failures in one entry. " +
664+
"`<REPL.Entry.Journal entry={22} yq={'[.records[] | select(.prompt != null and .status == \"failed\")]'} />` " +
665+
"finds failed Prompts across the complete entry before paging. Select a returned " +
666+
"Prompt number with .records[] | select(.prompt == 9) | .promptError to read its saved error. " +
667+
"Read .exec.exitCode, .exec.stdout and .exec.stderr on a command record; " +
668+
"reuse next, prev or last as yq with the same positive entry.",
667669
*fn(props: EntryJournalRequest): Operation<EntryJournalPage | string> {
668670
return yield* inspected(
669671
journal,

‎packages/cli/src/repl/sidekick/entry-inspection.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export type EntryPromptPage = {
130130
readonly field: PromptField;
131131
/** The saved text, or `null` where the turn recorded none at all. */
132132
readonly text: string | null;
133-
readonly diagnostic?: ReplAgentTurn["diagnostic"] | null;
134133
readonly offset: number;
135134
readonly length: number;
136135
readonly limit: number;
@@ -147,6 +146,7 @@ type PageRecord = {
147146
readonly position: PagePosition | null;
148147
readonly prompt: number | null;
149148
readonly agent: string | null;
149+
readonly promptError: NonNullable<ReplAgentTurn["error"]> | null;
150150
readonly exec: {
151151
readonly exitCode: number;
152152
readonly stdout?: string;
@@ -292,7 +292,6 @@ export function readEntryPrompt(
292292
promptStatus: turn.status,
293293
position: pagePosition(turn.position),
294294
field: field.value,
295-
...(field.value === "error" ? { diagnostic: turn.diagnostic ?? null } : {}),
296295
};
297296
if (text === undefined) {
298297
return Ok(
@@ -336,7 +335,12 @@ export function* readEntryJournal(
336335
status: statusOf(entry, history.printing),
337336
failure: entry.terminal?.message ?? null,
338337
prompts: countPrompts(entry.turns),
339-
records: entry.records.map(pageRecord),
338+
records: entry.records.map((record) =>
339+
pageRecord(
340+
record,
341+
entry.turns.find((turn) => turn.marker === record.marker),
342+
),
343+
),
340344
});
341345
}
342346

@@ -603,7 +607,7 @@ function countPrompts(turns: readonly ReplAgentTurn[]): PromptCounts {
603607
return Object.freeze({ completed, failed, cancelled });
604608
}
605609

606-
function pageRecord(record: ReplRecord): PageRecord {
610+
function pageRecord(record: ReplRecord, turn: ReplAgentTurn | undefined): PageRecord {
607611
return Object.freeze({
608612
marker: record.marker,
609613
type: record.type,
@@ -613,6 +617,7 @@ function pageRecord(record: ReplRecord): PageRecord {
613617
prompt: record.prompt ?? null,
614618
agent: record.agent ?? null,
615619
exec: record.exec ?? null,
620+
promptError: turn !== undefined && turn.status !== "completed" ? (turn.error ?? null) : null,
616621
});
617622
}
618623

‎packages/cli/tests/repl-sidekick-acp.test.ts‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ describe("minimal live Sidekick ACP attachment", () => {
695695
expect(one.held.fake.prompts).toHaveLength(one.baselineTurns + 3);
696696
});
697697

698-
it("1006 E3/E4/E7: passive Journal reads match the component route across cold three-page navigation", function* () {
698+
it("1006 E3/E4/E7: passive Journal reads match component, attachment and CLI for shell pages and saved Prompt errors", function* () {
699699
const text = "A🦊".repeat(7000);
700700
let launches = 0;
701701
const one = yield* world({
@@ -719,6 +719,13 @@ describe("minimal live Sidekick ACP attachment", () => {
719719
throw submitted.error;
720720
}
721721
expect((yield* submitted.value.join()).ok).toBe(false);
722+
one.held.fake.script({ reply: "partial reply", failure: "controlled Prompt failure" });
723+
const failedPrompt = yield* one.held.session.submit('<Prompt text="record a failure" />');
724+
if (!failedPrompt.ok) {
725+
throw failedPrompt.error;
726+
}
727+
expect((yield* failedPrompt.value.join()).ok).toBe(false);
728+
expect(one.held.session.model.entries).toHaveLength(2);
722729
const before = yield* readTextFile(one.held.execution.stream.path);
723730
const beforeChat = yield* records(one.held.execution);
724731
const calls = one.held.fake.prompts.length;
@@ -753,6 +760,33 @@ describe("minimal live Sidekick ACP attachment", () => {
753760
),
754761
).toEqual(component.value);
755762
}
763+
const failureQuery = ".records[] | select(.prompt == 1) | .promptError";
764+
const failure = yield* reads.inspectJournal({ entry: 2, yq: failureQuery });
765+
if (!failure.ok) {
766+
throw failure.error;
767+
}
768+
expect(failure.value).toMatchObject({ value: { message: "controlled Prompt failure" } });
769+
expect(
770+
pageSchema.parse(
771+
yield* requestAttachment(one.path, {
772+
method: "entry",
773+
entry: 2,
774+
view: "journal",
775+
yq: failureQuery,
776+
}),
777+
),
778+
).toEqual(failure.value);
779+
const reopenedFailure = yield* one.held.repository.open(one.held.execution.id);
780+
const coldFailure = yield* openReplSession({ execution: reopenedFailure });
781+
if (!coldFailure.ok) {
782+
throw coldFailure.error;
783+
}
784+
expect(
785+
yield* rootReads(coldFailure.value, one.held.profile).inspectJournal({
786+
entry: 2,
787+
yq: failureQuery,
788+
}),
789+
).toEqual(failure);
756790
let yq: string | null = ".records[1].exec.stdout";
757791
let collected = "";
758792
let count = 0;
@@ -833,6 +867,8 @@ describe("minimal live Sidekick ACP attachment", () => {
833867
expect(Request.safeParse({ method: "entry", entry: 1, view: "source", yq: "." }).success).toBe(
834868
false,
835869
);
870+
const afterLater = yield* readTextFile(one.held.execution.stream.path);
871+
expect(one.held.session.model.entries).toHaveLength(3);
836872
const cli = cliCommand([
837873
"sidekick",
838874
"read",
@@ -851,6 +887,29 @@ describe("minimal live Sidekick ACP attachment", () => {
851887
}).join();
852888
expect(actual.code).toBe(0);
853889
expect(JSON.parse(actual.stdout)).toEqual({ value: 1, next: null, prev: null, last: null });
890+
const promptCli = cliCommand([
891+
"sidekick",
892+
"read",
893+
"--attach",
894+
one.path,
895+
"entry",
896+
"2",
897+
"journal",
898+
"--yq",
899+
failureQuery,
900+
]);
901+
const actualFailure = yield* exec(promptCli.command, {
902+
arguments: promptCli.arguments,
903+
cwd: one.held.workspace,
904+
env: { HOME: one.home, PATH: process.env.PATH ?? "", DENO_DIR: process.env.DENO_DIR ?? "" },
905+
}).join();
906+
expect(actualFailure.code).toBe(0);
907+
expect(pageSchema.parse(JSON.parse(actualFailure.stdout))).toEqual(failure.value);
908+
expect(yield* readTextFile(one.held.execution.stream.path)).toBe(afterLater);
909+
expect(one.held.session.model.entries).toHaveLength(3);
910+
expect(one.held.fake.prompts).toHaveLength(calls);
911+
expect(launches).toBe(1);
912+
expect(yield* records(one.held.execution)).toEqual(beforeChat);
854913
});
855914

856915
it("A1/A3: the actual embedded provider keeps serial attachment identity and completing RPC metadata", function* () {

0 commit comments

Comments
 (0)