From c6c79b291d239c4ab9fef5f669e18b99dad50fed Mon Sep 17 00:00:00 2001 From: Dotta Date: Tue, 27 Oct 2026 04:43:20 -0500 Subject: [PATCH] fix: expire stale managed arguments before consuming admission Co-Authored-By: Paperclip --- doc/idle-approved-tool-recovery.md | 23 +++++++++++++++++ server/src/services/tool-gateway.ts | 40 +++++++++++++++-------------- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/doc/idle-approved-tool-recovery.md b/doc/idle-approved-tool-recovery.md index 48e629f691a..dec6cfa028d 100644 --- a/doc/idle-approved-tool-recovery.md +++ b/doc/idle-approved-tool-recovery.md @@ -231,3 +231,26 @@ claim validation fixed it. Typechecking then exposed root-client-only signatures which were narrowed to their actual database capabilities. The final complete suites and TypeScript check pass; stack integration and current-head CI remain separate gates. This proves worker and admission behavior, not deployed host sleep. + + +## Managed-argument expiry ordering + +Latest-head CI exposed a preparation-order regression in +`tool-gateway.test.ts`: a valid historical Shopify approval whose managed UCP +arguments were obsolete became `failed` instead of `expired`. The new consuming +admission compared the current invocation identity before the existing managed +argument expiry owner ran. It prevented dispatch, but bypassed the correct saved +expiry outcome. + +Approved execution now verifies target/signed/managed arguments and content +before consuming admission. Exact claim fencing, fresh policy checks, atomic +rate receipts, and the final issue-open check remain before dispatch. No check +was removed and stale payloads are not permitted to execute. + +The existing regression reproduced the CI failure on this owner in +`/tmp/sleep-approved-managed-expiry-red.log`. All 92 gateway acceptance cases +pass after the ordering change (`/tmp/sleep-approved-managed-expiry-full.log`), +including the historical approval's expired request, failed invocation with +`approvalState: expired`, and zero provider requests. Server typecheck passes +in `/tmp/sleep-approved-managed-expiry-types.log`. Latest-head remote CI and +combined-stack acceptance still need their own results. diff --git a/server/src/services/tool-gateway.ts b/server/src/services/tool-gateway.ts index 958862a42b8..98fd5b4e0f2 100644 --- a/server/src/services/tool-gateway.ts +++ b/server/src/services/tool-gateway.ts @@ -8092,25 +8092,6 @@ export function createToolGatewayService( session, tool, ); - const currentAccess = await policyService.admitInvocation( - policyInputForTool({ - session, - tool, - parameters: signedPayload.arguments, - consumeRateLimit: false, - }), - invocation.id, - claim, - ); - if ( - !currentAccess.allowed && - currentAccess.decision !== "require_approval" - ) - throw new ToolGatewayHttpError( - 403, - currentAccess.explanation, - currentAccess.reasonCode, - ); if ( !approvalSnapshotsMatch( signedPayload.approvalSnapshot, @@ -8169,6 +8150,27 @@ export function createToolGatewayService( sensitiveMode: "redact", promptInjectionMode: "ignore", })).summary; + // Validate the signed and managed payload before consuming admission. + // Historical payload drift belongs to the expiry owner above. + const currentAccess = await policyService.admitInvocation( + policyInputForTool({ + session, + tool, + parameters: signedPayload.arguments, + consumeRateLimit: false, + }), + invocation.id, + claim, + ); + if ( + !currentAccess.allowed && + currentAccess.decision !== "require_approval" + ) + throw new ToolGatewayHttpError( + 403, + currentAccess.explanation, + currentAccess.reasonCode, + ); // Final recheck at the last DB write before dispatch: tool and snapshot // resolution above involve network calls, so re-verify the issue is still // open now that only the provider call remains. A close that commits after