@@ -355,6 +355,7 @@ function createNodeHostRequest(
355355
356356type MockNodeInvokeParams = {
357357 command ?: string ;
358+ timeoutMs ?: number ;
358359 params ?: Record < string , unknown > ;
359360} ;
360361
@@ -417,10 +418,21 @@ function requireRegisteredApprovalRequest(): Record<string, unknown> {
417418 return firstCall [ 0 ] ;
418419}
419420
420- function expectSystemRunInvoke ( params : { invokeTimeoutMs : number ; runTimeoutMs : number } ) {
421+ function expectSystemRunInvoke ( params : {
422+ invokeDeadlineMs : number ;
423+ invokeWaitMs : number ;
424+ runTimeoutMs : number ;
425+ } ) {
421426 const call = requireGatewayCommand ( "system.run" ) ;
422- expect ( call . options . timeoutMs ) . toBe ( params . invokeTimeoutMs ) ;
427+ // Three ordered budgets: node program runtime < Gateway invocation deadline <
428+ // caller wait, so the Gateway deadline answer wins over a caller giving up.
423429 expect ( requireRunParams ( call ) . timeoutMs ) . toBe ( params . runTimeoutMs ) ;
430+ expect ( call . params ?. timeoutMs ) . toBe ( params . invokeDeadlineMs ) ;
431+ expect ( call . options . timeoutMs ) . toBe ( params . invokeWaitMs ) ;
432+ expect ( params . runTimeoutMs ) . toBeLessThanOrEqual ( params . invokeDeadlineMs ) ;
433+ expect ( params . invokeDeadlineMs ) . toBeLessThanOrEqual ( params . invokeWaitMs ) ;
434+ expect ( params . invokeDeadlineMs ) . toBeGreaterThan ( 0 ) ;
435+ expect ( Number . isFinite ( params . invokeWaitMs ) ) . toBe ( true ) ;
424436}
425437
426438function mockGatewayInvokesWithNodeApprovals ( file : Record < string , unknown > ) {
@@ -952,7 +964,8 @@ describe("executeNodeHostCommand", () => {
952964 } ) ;
953965
954966 const call = requireGatewayCall ( 2 ) ;
955- expect ( call . options . timeoutMs ) . toBe ( 35_000 ) ;
967+ expect ( call . options . timeoutMs ) . toBe ( 40_000 ) ;
968+ expect ( call . params ?. timeoutMs ) . toBe ( 35_000 ) ;
956969 expect ( call . callOptions ) . toEqual ( { scopes : [ "operator.write" , "operator.approvals" ] } ) ;
957970 const runParams = requireRunParams ( call ) ;
958971 expect ( runParams . approved ) . toBe ( true ) ;
@@ -1867,7 +1880,7 @@ describe("executeNodeHostCommand", () => {
18671880 expect ( resolveExecApprovalsFromFileMock ) . toHaveBeenCalledWith (
18681881 expect . objectContaining ( { agentId : "prepared-agent" } ) ,
18691882 ) ;
1870- expectSystemRunInvoke ( { invokeTimeoutMs : 35_000 , runTimeoutMs : 30_000 } ) ;
1883+ expectSystemRunInvoke ( { invokeDeadlineMs : 35_000 , invokeWaitMs : 40_000 , runTimeoutMs : 30_000 } ) ;
18711884 } ) ;
18721885
18731886 it ( "does not let transport wrapper allowlist matches approve shell payloads" , async ( ) => {
@@ -2036,7 +2049,7 @@ describe("executeNodeHostCommand", () => {
20362049
20372050 expect ( result . details ?. status ) . toBe ( "completed" ) ;
20382051 expect ( createAndRegisterDefaultExecApprovalRequestMock ) . not . toHaveBeenCalled ( ) ;
2039- expectSystemRunInvoke ( { invokeTimeoutMs : 35_000 , runTimeoutMs : 30_000 } ) ;
2052+ expectSystemRunInvoke ( { invokeDeadlineMs : 35_000 , invokeWaitMs : 40_000 , runTimeoutMs : 30_000 } ) ;
20402053 } ) ;
20412054
20422055 it . each ( [ "bash" , "sh" , "/bin/sh" ] ) (
@@ -2252,7 +2265,7 @@ describe("executeNodeHostCommand", () => {
22522265
22532266 expect ( result . details ?. status ) . toBe ( "completed" ) ;
22542267 expect ( createAndRegisterDefaultExecApprovalRequestMock ) . not . toHaveBeenCalled ( ) ;
2255- expectSystemRunInvoke ( { invokeTimeoutMs : 35_000 , runTimeoutMs : 30_000 } ) ;
2268+ expectSystemRunInvoke ( { invokeDeadlineMs : 35_000 , invokeWaitMs : 40_000 , runTimeoutMs : 30_000 } ) ;
22562269 } ) ;
22572270
22582271 it ( "requests human approval when node auto-review asks on an approval miss" , async ( ) => {
@@ -3562,7 +3575,8 @@ describe("executeNodeHostCommand", () => {
35623575
35633576 expect ( callGatewayToolMock ) . toHaveBeenCalledTimes ( 1 ) ;
35643577 const call = requireGatewayCall ( 0 ) ;
3565- expect ( call . options . timeoutMs ) . toBe ( 35_000 ) ;
3578+ expect ( call . options . timeoutMs ) . toBe ( 40_000 ) ;
3579+ expect ( call . params ?. timeoutMs ) . toBe ( 35_000 ) ;
35663580 const runParams = requireRunParams ( call ) ;
35673581 expect ( runParams . command ) . toEqual ( [ "/bin/sh" , "-lc" , "bun ./script.ts" ] ) ;
35683582 expect ( runParams . rawCommand ) . toBe ( "bun ./script.ts" ) ;
@@ -3676,7 +3690,7 @@ describe("executeNodeHostCommand", () => {
36763690 } ) ,
36773691 ) ;
36783692
3679- expectSystemRunInvoke ( { invokeTimeoutMs : 17_000 , runTimeoutMs : 12_000 } ) ;
3693+ expectSystemRunInvoke ( { invokeDeadlineMs : 17_000 , invokeWaitMs : 22_000 , runTimeoutMs : 12_000 } ) ;
36803694 } ) ;
36813695
36823696 it ( "normalizes unsafe explicit timeouts before invoking node system.run" , async ( ) => {
@@ -3686,7 +3700,7 @@ describe("executeNodeHostCommand", () => {
36863700 } ) ,
36873701 ) ;
36883702
3689- expectSystemRunInvoke ( { invokeTimeoutMs : 35_000 , runTimeoutMs : 30_000 } ) ;
3703+ expectSystemRunInvoke ( { invokeDeadlineMs : 35_000 , invokeWaitMs : 40_000 , runTimeoutMs : 30_000 } ) ;
36903704
36913705 callGatewayToolMock . mockClear ( ) ;
36923706
@@ -3697,7 +3711,8 @@ describe("executeNodeHostCommand", () => {
36973711 ) ;
36983712
36993713 expectSystemRunInvoke ( {
3700- invokeTimeoutMs : MAX_SAFE_TIMEOUT_DELAY_MS ,
3714+ invokeDeadlineMs : MAX_SAFE_TIMEOUT_DELAY_MS ,
3715+ invokeWaitMs : MAX_SAFE_TIMEOUT_DELAY_MS ,
37013716 runTimeoutMs : MAX_SAFE_TIMEOUT_DELAY_MS ,
37023717 } ) ;
37033718
@@ -3710,7 +3725,8 @@ describe("executeNodeHostCommand", () => {
37103725 ) ;
37113726
37123727 expectSystemRunInvoke ( {
3713- invokeTimeoutMs : MAX_SAFE_TIMEOUT_DELAY_MS ,
3728+ invokeDeadlineMs : MAX_SAFE_TIMEOUT_DELAY_MS ,
3729+ invokeWaitMs : MAX_SAFE_TIMEOUT_DELAY_MS ,
37143730 runTimeoutMs : MAX_SAFE_TIMEOUT_DELAY_MS ,
37153731 } ) ;
37163732 } ) ;
@@ -3722,7 +3738,54 @@ describe("executeNodeHostCommand", () => {
37223738 } ) ,
37233739 ) ;
37243740
3725- expectSystemRunInvoke ( { invokeTimeoutMs : 35_000 , runTimeoutMs : 0 } ) ;
3741+ expectSystemRunInvoke ( { invokeDeadlineMs : 35_000 , invokeWaitMs : 40_000 , runTimeoutMs : 0 } ) ;
3742+ const call = requireGatewayCommand ( "system.run" ) ;
3743+ // Zero means "no program-runtime timer" on the node and must never be
3744+ // rewritten into a finite process timeout, but the Gateway deadline and the
3745+ // caller wait still have to stay positive and finite.
3746+ expect ( requireRunParams ( call ) . timeoutMs ) . toBe ( 0 ) ;
3747+ expect ( call . params ?. timeoutMs ) . toBeGreaterThan ( 0 ) ;
3748+ expect ( Number . isFinite ( call . params ?. timeoutMs ) ) . toBe ( true ) ;
3749+ } ) ;
3750+
3751+ it ( "arms the gateway invocation deadline for a budget longer than the 30s registry fallback" , async ( ) => {
3752+ await executeNodeHostCommand (
3753+ createNodeHostRequest ( {
3754+ timeoutSec : 120 ,
3755+ } ) ,
3756+ ) ;
3757+
3758+ // A 120s program budget must not be cut short by the registry's fixed 30s
3759+ // pending-invoke fallback in resolveTimerTimeoutMs(params.timeoutMs, 30_000, 0).
3760+ expectSystemRunInvoke ( {
3761+ invokeDeadlineMs : 125_000 ,
3762+ invokeWaitMs : 130_000 ,
3763+ runTimeoutMs : 120_000 ,
3764+ } ) ;
3765+ } ) ;
3766+
3767+ it ( "leaves system.run.prepare without a gateway invocation deadline" , async ( ) => {
3768+ mockGatewayInvokesWithNodeApprovals ( { version : 1 , agents : { } } ) ;
3769+ resolveExecHostApprovalContextMock . mockReturnValue ( {
3770+ approvals : { allowlist : [ ] , file : { version : 1 , agents : { } } } ,
3771+ hostSecurity : "allowlist" ,
3772+ hostAsk : "on-miss" ,
3773+ askFallback : "deny" ,
3774+ } ) ;
3775+
3776+ await executeNodeHostCommand (
3777+ createNodeHostRequest ( {
3778+ security : "allowlist" ,
3779+ ask : "on-miss" ,
3780+ timeoutSec : 120 ,
3781+ } ) ,
3782+ ) . catch ( ( ) => undefined ) ;
3783+
3784+ // The short prepare round-trip keeps the registry default; only the actual
3785+ // system.run dispatch carries the command budget.
3786+ const prepare = requireGatewayCommand ( "system.run.prepare" ) ;
3787+ expect ( prepare . params ?. timeoutMs ) . toBeUndefined ( ) ;
3788+ expect ( prepare . options . timeoutMs ) . toBe ( 15_000 ) ;
37263789 } ) ;
37273790
37283791 it ( "allows exec when requestedNode is display name matching boundNode's device" , async ( ) => {
0 commit comments