pi-background-tasks 2.1.3 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,8 @@ export const FUSION_CALIBRATION_VIOLATION_SCHEMA_VERSION =
30
30
  export const FUSION_VALIDATE_CANDIDATE_CONTRACT_EVENT_SCHEMA_VERSION =
31
31
  'pi-background-tasks.fusion-validation-candidate-contract-event.v1';
32
32
  export const FUSION_TOOL_CALL_LOG_SCHEMA_VERSION = 'pi-background-tasks.fusion-tool-call.v1';
33
+ export const FUSION_FAILURE_SUMMARY_SCHEMA_VERSION =
34
+ 'pi-background-tasks.fusion-failure-summary.v1';
33
35
 
34
36
  /**
35
37
  * Conversation-projection transform shared by every Fusion entry point.
@@ -877,6 +879,91 @@ export interface FusionArtifactRef {
877
879
  sha256: string;
878
880
  }
879
881
 
882
+ export type FusionFailureArtifactClassification =
883
+ | 'complete_stage_output'
884
+ | 'partial_stage_output'
885
+ | 'oversized_original'
886
+ | 'empty_rejected_output'
887
+ | 'evidence_only';
888
+
889
+ export interface FusionFailureEvidenceArtifact {
890
+ name: string;
891
+ classification: FusionFailureArtifactClassification;
892
+ ref: FusionArtifactRef;
893
+ }
894
+
895
+ export interface FusionFailureAttemptMetadata {
896
+ stage: FusionStage;
897
+ slot?: 1 | 2 | 3 | undefined;
898
+ attempt: number;
899
+ status: 'completed' | 'failed' | 'cancelled';
900
+ child_created: boolean;
901
+ }
902
+
903
+ export interface FusionFailureList<T> {
904
+ listed: readonly T[];
905
+ omitted_count: number;
906
+ }
907
+
908
+ export interface FusionFailureMessageMetadata {
909
+ byte_length: number;
910
+ sha256: string;
911
+ inline_message?: string | undefined;
912
+ omission_reason?: 'exceeds_inline_message_bytes_cap' | 'result_view_byte_budget' | undefined;
913
+ }
914
+
915
+ export interface FusionFailureSummaryV1 {
916
+ schema_version: typeof FUSION_FAILURE_SUMMARY_SCHEMA_VERSION;
917
+ run_id: string;
918
+ workflow: FusionWorkflowId;
919
+ source: FusionSource;
920
+ terminal_state: Exclude<FusionTerminalState, 'completed'>;
921
+ created_at: string;
922
+ answer: { present: false; reason: 'run_did_not_commit' };
923
+ failure: {
924
+ code: FusionErrorCode | null;
925
+ stage?: FusionStage | undefined;
926
+ slot?: 1 | 2 | 3 | undefined;
927
+ attempt?: number | undefined;
928
+ child_created: boolean;
929
+ message: FusionFailureMessageMetadata;
930
+ };
931
+ progress: FusionRunProgress;
932
+ usage_so_far: FusionUsage;
933
+ attempts: FusionFailureList<FusionFailureAttemptMetadata>;
934
+ evidence_artifacts: FusionFailureList<FusionFailureEvidenceArtifact>;
935
+ remediation_ids: readonly (
936
+ | 'inspect_manifest_bound_evidence'
937
+ | 'inspect_terminal_error'
938
+ | 'split_or_reduce_work'
939
+ | 'retry_same_route_after_operator_review'
940
+ )[];
941
+ }
942
+
943
+ export interface FusionFailureViewFailure {
944
+ code?: FusionErrorCode | null | undefined;
945
+ stage?: FusionStage | undefined;
946
+ slot?: 1 | 2 | 3 | undefined;
947
+ attempt?: number | undefined;
948
+ child_created?: boolean | undefined;
949
+ message: FusionFailureMessageMetadata;
950
+ }
951
+
952
+ export interface FusionFailureResultView {
953
+ schema_version: typeof FUSION_FAILURE_SUMMARY_SCHEMA_VERSION;
954
+ summary_status: 'verified' | 'legacy_manifest_only' | 'unavailable' | 'integrity_failed';
955
+ terminal_state: Exclude<FusionTerminalState, 'completed'>;
956
+ answer: { present: false; reason: 'run_did_not_commit' };
957
+ failure?: FusionFailureViewFailure | undefined;
958
+ progress?: FusionRunProgress | undefined;
959
+ usage_so_far?: FusionUsage | undefined;
960
+ attempts?: FusionFailureList<FusionFailureAttemptMetadata> | undefined;
961
+ evidence_artifacts?: FusionFailureList<FusionFailureEvidenceArtifact> | undefined;
962
+ remediation_ids?: FusionFailureSummaryV1['remediation_ids'] | undefined;
963
+ failure_summary_ref?: FusionArtifactRef | undefined;
964
+ summary_unavailable_reason?: 'no_durable_summary' | 'manifest_untrusted' | 'summary_integrity_failed' | undefined;
965
+ }
966
+
880
967
  export interface FusionArtifactManifest {
881
968
  schema_version: typeof FUSION_MANIFEST_SCHEMA_VERSION;
882
969
  run_id: string;
@@ -11,8 +11,13 @@ import { Type, type Static } from 'typebox';
11
11
  import type { BgTask, BgTaskSnapshot, StartDelegateTaskOptions } from './core/common.js';
12
12
  import { truncateChars } from './core/common.js';
13
13
  import { sha256Buffer } from './core/attested-pi-run.js';
14
- import { readFusionCommittedResult } from './core/fusion/result-package.js';
15
- import { cloneFusionUsage, type FusionUsage, type FusionWorkflowId } from './core/fusion/types.js';
14
+ import { readFusionCommittedResult, readFusionFailureResult } from './core/fusion/result-package.js';
15
+ import {
16
+ cloneFusionUsage,
17
+ type FusionFailureResultView,
18
+ type FusionUsage,
19
+ type FusionWorkflowId,
20
+ } from './core/fusion/types.js';
16
21
  import {
17
22
  DELEGATE_AUTO_DELIVER_MODES,
18
23
  DELEGATE_CAPABILITIES,
@@ -161,6 +166,16 @@ export interface FusionBackgroundResultDetails {
161
166
  answer_bytes?: number | undefined;
162
167
  answer_sha256?: string | undefined;
163
168
  usage_delivered?: boolean | undefined;
169
+ answer?: { present: false; reason: 'run_did_not_commit' } | undefined;
170
+ summary_status?: FusionFailureResultView['summary_status'] | undefined;
171
+ failure_summary_ref?: FusionFailureResultView['failure_summary_ref'] | undefined;
172
+ failure?: FusionFailureResultView['failure'] | undefined;
173
+ progress?: FusionFailureResultView['progress'] | undefined;
174
+ usage_so_far?: FusionFailureResultView['usage_so_far'] | undefined;
175
+ attempts?: FusionFailureResultView['attempts'] | undefined;
176
+ evidence_artifacts?: FusionFailureResultView['evidence_artifacts'] | undefined;
177
+ remediation_ids?: FusionFailureResultView['remediation_ids'] | undefined;
178
+ summary_unavailable_reason?: FusionFailureResultView['summary_unavailable_reason'] | undefined;
164
179
  }
165
180
 
166
181
  export type BackgroundResultDetails = DelegateResultDetails | FusionBackgroundResultDetails;
@@ -508,9 +523,48 @@ export function registerDelegateExtension(
508
523
  };
509
524
  }
510
525
  if (task.status !== 'completed' || fusion.outcome?.status !== 'committed') {
511
- throw new Error(
512
- `Fusion ${task.id} did not commit a result (${task.status}): ${fusion.outcome?.error ?? task.error ?? 'no terminal detail'}`,
513
- );
526
+ const terminal = await readFusionFailureResult({
527
+ artifactDirAbs: fusion.artifactDirAbs,
528
+ artifactDir: fusion.artifactDir,
529
+ runId: fusion.runId,
530
+ workflow: fusion.workflow,
531
+ });
532
+ const state =
533
+ fusion.outcome?.status === 'cancelled' || task.status === 'killed'
534
+ ? 'cancelled'
535
+ : 'failed';
536
+ const details: FusionBackgroundResultDetails = {
537
+ schema_version: 'pi-background-tasks.fusion-result-view.v1',
538
+ task_id: task.id,
539
+ state,
540
+ delivery: 'none',
541
+ workflow: fusion.workflow,
542
+ artifact_dir: fusion.artifactDir,
543
+ answer: terminal.answer,
544
+ summary_status: terminal.summary_status,
545
+ ...(terminal.failure_summary_ref === undefined
546
+ ? {}
547
+ : { failure_summary_ref: terminal.failure_summary_ref }),
548
+ ...(terminal.failure === undefined ? {} : { failure: terminal.failure }),
549
+ ...(terminal.progress === undefined ? {} : { progress: terminal.progress }),
550
+ ...(terminal.usage_so_far === undefined ? {} : { usage_so_far: terminal.usage_so_far }),
551
+ ...(terminal.attempts === undefined ? {} : { attempts: terminal.attempts }),
552
+ ...(terminal.evidence_artifacts === undefined
553
+ ? {}
554
+ : { evidence_artifacts: terminal.evidence_artifacts }),
555
+ ...(terminal.remediation_ids === undefined
556
+ ? {}
557
+ : { remediation_ids: terminal.remediation_ids }),
558
+ ...(terminal.summary_unavailable_reason === undefined
559
+ ? {}
560
+ : { summary_unavailable_reason: terminal.summary_unavailable_reason }),
561
+ };
562
+ return {
563
+ content: textContent(
564
+ `Fusion ${task.id} ${state}; no answer was committed. Terminal evidence status: ${terminal.summary_status}. Delivery is none; use only the manifest-bound artifact references in details.`,
565
+ ),
566
+ details,
567
+ };
514
568
  }
515
569
  const verified = await readFusionCommittedResult({
516
570
  artifactDirAbs: fusion.artifactDirAbs,
@@ -673,6 +727,13 @@ export function registerDelegateExtension(
673
727
  0,
674
728
  0,
675
729
  );
730
+ if (fusion && (details.state === 'failed' || details.state === 'cancelled')) {
731
+ return new Text(
732
+ theme.fg('warning', `${details.state} fusion; no committed answer · ${details.summary_status ?? 'unavailable'}`),
733
+ 0,
734
+ 0,
735
+ );
736
+ }
676
737
  return new Text(
677
738
  `${theme.fg('success', fusion ? '✓ fusion answer' : '✓ delegate answer')} ${theme.fg('dim', `${String(details.answer_bytes ?? 0)}B · ${details.delivery}`)}`,
678
739
  0,