@@ -16,6 +16,7 @@ import {
1616 markNativeComposeStorageBudgetRefusal ,
1717 type NativeComposeEffectRefusal ,
1818 nativeComposeEffectReason ,
19+ nativeComposeEffectRefusal ,
1920 retainNativeComposeEffectRefusal ,
2021} from "./native-compose-effect-diagnostics.ts" ;
2122import {
@@ -932,14 +933,21 @@ type StorageCommandRefusal = "probe-timeout" | "probe-cancel" | "probe-budget";
932933const storageCommandRefusals = new WeakMap < object , StorageCommandRefusal > ( ) ;
933934/** The same fixed refusal, keeping only its closed command cause (a timed-out or
934935 * cancelled child, or an exhausted publication/settlement budget) for the effect
935- * diagnostic. It grants nothing and changes no check, deadline or retention. */
936- function refuseCommand ( reason : StorageCommandRefusal | undefined ) : never {
936+ * diagnostic. A replaced `source` refusal keeps its issued owner boundary (for
937+ * example a helper policy refusal observed during admission), so a later carrier
938+ * boundary cannot relabel it. It grants nothing and changes no check, deadline or
939+ * retention. */
940+ function refuseCommand (
941+ reason : StorageCommandRefusal | undefined ,
942+ source ?: unknown
943+ ) : never {
937944 const error = new Error (
938945 "Native storage xattr proof refused; values omitted."
939946 ) ;
940947 if ( reason ) {
941948 storageCommandRefusals . set ( error , reason ) ;
942949 }
950+ copyNativeComposeEffectRefusal ( source , error ) ;
943951 throw error ;
944952}
945953function storageCommandRefusal (
@@ -964,12 +972,24 @@ export function nativeComposeStorageCarrierReason(
964972 return storageCommandRefusal ( error ) ?? nativeComposeEffectReason ( error ) ;
965973}
966974/**
967- * Effect reason at a carrier boundary of one storage carrier. When its own
968- * deadline, the named `HACK_NATIVE_STORAGE_TIMEOUT_MS` storage budget, is
969- * exhausted and the carrier was not cancelled, the refusal names that budget:
970- * every probe and command inside it is clipped to the remaining budget, so its
971- * timeout or budget refusal fires exactly at that end. Otherwise it keeps the
972- * classified command cause. Diagnostics only: no check, deadline or retention changes.
975+ * Reasons an expired carrier deadline itself can produce: every probe and
976+ * command inside a carrier is clipped to the remaining budget (a timeout or
977+ * budget refusal), its lifetime check marks `storage-budget`, and a refusal
978+ * with no observed cause stays `unclassified`. Any other reason, such as a
979+ * helper policy refusal, was observed independently of the deadline.
980+ */
981+ const deadlineReasons : ReadonlySet < NativeComposeEffectRefusal [ "reason" ] > =
982+ new Set ( [ "probe-timeout" , "probe-budget" , "storage-budget" , "unclassified" ] ) ;
983+ /**
984+ * Effect reason at a carrier boundary of one storage carrier. A refusal that
985+ * already carries its own observed reason (an issued boundary such as a helper
986+ * policy refusal, or a classified command cause) keeps it even when it is caught
987+ * after the deadline, so an operator is not sent to raise the storage budget for
988+ * a policy failure. Only a deadline-shaped refusal (timeout, budget, lifetime
989+ * mark or no observed cause) whose carrier deadline, the named
990+ * `HACK_NATIVE_STORAGE_TIMEOUT_MS` storage budget, has expired and whose carrier
991+ * was not cancelled names that budget. Diagnostics only: no check, deadline or
992+ * retention changes.
973993 */
974994export function nativeComposeStorageCarrierBudgetReason ( opts : {
975995 readonly error : unknown ;
@@ -978,10 +998,19 @@ export function nativeComposeStorageCarrierBudgetReason(opts: {
978998 readonly now ?: ( ) => number ;
979999} ) : NativeComposeEffectRefusal [ "reason" ] {
9801000 const now = opts . now ?? Date . now ;
981- if ( ! opts . signal . aborted && now ( ) >= opts . deadline ) {
1001+ const issued = nativeComposeEffectRefusal ( opts . error ) ?. reason ;
1002+ const observed =
1003+ issued && issued !== "unclassified"
1004+ ? issued
1005+ : nativeComposeStorageCarrierReason ( opts . error ) ;
1006+ if (
1007+ deadlineReasons . has ( observed ) &&
1008+ ! opts . signal . aborted &&
1009+ now ( ) >= opts . deadline
1010+ ) {
9821011 return "storage-budget" ;
9831012 }
984- return nativeComposeStorageCarrierReason ( opts . error ) ;
1013+ return observed ;
9851014}
9861015
9871016export async function runNativeComposeStorageDockerCommand ( supplied : {
@@ -1040,6 +1069,8 @@ export async function runNativeComposeStorageDockerCommand(supplied: {
10401069 let armed : NativeComposeStorageArmedCommand | null = null ;
10411070 let publicationRefused = false ;
10421071 let publicationCause : StorageCommandRefusal | undefined ;
1072+ // The first refusal that stopped publication; only its issued boundary is kept.
1073+ let publicationSource : unknown ;
10431074 const cancellation = new AbortController ( ) ;
10441075 try {
10451076 await opts . assertAdmitted ( ) ;
@@ -1058,7 +1089,7 @@ export async function runNativeComposeStorageDockerCommand(supplied: {
10581089 return refuseCommand ( "probe-budget" ) ;
10591090 }
10601091 if ( publicationRefused ) {
1061- return refuseCommand ( publicationCause ) ;
1092+ return refuseCommand ( publicationCause , publicationSource ) ;
10621093 }
10631094 if (
10641095 ! ( recordingSettlement || opts . cleanup ) &&
@@ -1100,11 +1131,12 @@ export async function runNativeComposeStorageDockerCommand(supplied: {
11001131 } catch ( error ) {
11011132 publicationRefused = true ;
11021133 publicationCause ??= storageCommandRefusal ( error ) ;
1134+ publicationSource ??= error ;
11031135 if ( record ) {
11041136 invalidateNativeComposeStorageCommandOwner ( record . owner ) ;
11051137 }
11061138 cancellation . abort ( ) ;
1107- return refuseCommand ( publicationCause ) ;
1139+ return refuseCommand ( publicationCause , publicationSource ) ;
11081140 } finally {
11091141 if ( timer !== undefined ) {
11101142 clearTimeout ( timer ) ;
@@ -1252,6 +1284,7 @@ export async function runNativeComposeStorageDockerCommand(supplied: {
12521284 } catch ( error ) {
12531285 publicationRefused = true ;
12541286 publicationCause ??= storageCommandRefusal ( error ) ;
1287+ publicationSource ??= error ;
12551288 invalidateNativeComposeStorageCommandOwner ( record . owner ) ;
12561289 cancellation . abort ( ) ;
12571290 }
@@ -1268,7 +1301,7 @@ export async function runNativeComposeStorageDockerCommand(supplied: {
12681301 settled = true ;
12691302 if ( record ) {
12701303 if ( publicationRefused ) {
1271- return refuseCommand ( publicationCause ) ;
1304+ return refuseCommand ( publicationCause , publicationSource ) ;
12721305 }
12731306 if ( ! ( armed && exit ) ) {
12741307 return refuse ( ) ;
@@ -1311,7 +1344,7 @@ export async function runNativeComposeStorageDockerCommand(supplied: {
13111344 } catch ( error ) {
13121345 if ( opts . originalCommand ) {
13131346 invalidateNativeComposeStorageCommandOwner ( opts . originalCommand . owner ) ;
1314- return refuseCommand ( storageCommandRefusal ( error ) ) ;
1347+ return refuseCommand ( storageCommandRefusal ( error ) , error ) ;
13151348 }
13161349 throw error ;
13171350 } finally {
0 commit comments