@@ -86,7 +86,7 @@ import {
8686 type ParsedExecutionWorkspaceMode ,
8787} from "./execution-workspace-policy.js" ;
8888import { mergeExecutionWorkspaceConfig } from "./execution-workspaces.js" ;
89- import { buildInitialIssueMonitorFields , normalizeIssueExecutionPolicy } from "./issue-execution-policy.js" ;
89+ import { activeTypedIssueMonitorDeadline , buildInitialIssueMonitorFields , normalizeIssueExecutionPolicy } from "./issue-execution-policy.js" ;
9090import { instanceSettingsService } from "./instance-settings.js" ;
9191import { redactCurrentUserText } from "../log-redaction.js" ;
9292import { redactSensitiveText } from "../redaction.js" ;
@@ -783,25 +783,18 @@ function issueExecutionLockMonitorNextCheckAt(now: Date) {
783783export function executionLockAcquisitionFields (
784784 runId : string ,
785785 now : Date ,
786- options : { scheduleMonitor ?: boolean } = { } ,
786+ activeReviewMonitorDeadline : Date | null = null ,
787787) {
788- const monitorFields = options . scheduleMonitor
789- ? {
790- monitorNextCheckAt : sql < Date | null > `case
791- when ${ issues . monitorNextCheckAt } is null
792- and ${ issues . monitorLastTriggeredAt } is null
793- and ${ issues . monitorAttemptCount } = 0
794- then ${ issueExecutionLockMonitorNextCheckAt ( now ) . toISOString ( ) } ::timestamptz
795- else ${ issues . monitorNextCheckAt }
796- end` ,
797- monitorWakeRequestedAt : null ,
798- }
799- : { } ;
788+ const lockDeadline = issueExecutionLockMonitorNextCheckAt ( now ) ;
789+ const monitorNextCheckAt = activeReviewMonitorDeadline && activeReviewMonitorDeadline . getTime ( ) < lockDeadline . getTime ( )
790+ ? activeReviewMonitorDeadline
791+ : lockDeadline ;
800792
801793 return {
802794 executionRunId : runId ,
803795 executionLockedAt : now ,
804- ...monitorFields ,
796+ monitorNextCheckAt,
797+ monitorWakeRequestedAt : null ,
805798 } ;
806799}
807800
@@ -5111,7 +5104,6 @@ export function issueService(db: Db) {
51115104 actorAgentId : string ;
51125105 actorRunId : string ;
51135106 expectedCheckoutRunId : string ;
5114- scheduleMonitor : boolean ;
51155107 } ) {
51165108 return db . transaction ( async ( tx ) => {
51175109 const lockedIssue = await tx
@@ -5121,6 +5113,8 @@ export function issueService(db: Db) {
51215113 assigneeAgentId : issues . assigneeAgentId ,
51225114 checkoutRunId : issues . checkoutRunId ,
51235115 executionRunId : issues . executionRunId ,
5116+ executionPolicy : issues . executionPolicy ,
5117+ executionState : issues . executionState ,
51245118 } )
51255119 . from ( issues )
51265120 . where ( eq ( issues . id , input . issueId ) )
@@ -5169,7 +5163,7 @@ export function issueService(db: Db) {
51695163 . update ( issues )
51705164 . set ( {
51715165 checkoutRunId : input . actorRunId ,
5172- ...executionLockAcquisitionFields ( input . actorRunId , now , { scheduleMonitor : input . scheduleMonitor } ) ,
5166+ ...executionLockAcquisitionFields ( input . actorRunId , now , activeTypedIssueMonitorDeadline ( lockedIssue , now ) ) ,
51735167 updatedAt : now ,
51745168 } )
51755169 . where (
@@ -5211,7 +5205,6 @@ export function issueService(db: Db) {
52115205 issueId : string ;
52125206 actorAgentId : string ;
52135207 actorRunId : string ;
5214- scheduleMonitor : boolean ;
52155208 } ) {
52165209 return db . transaction ( async ( tx ) => {
52175210 await tx . execute (
@@ -5225,11 +5218,16 @@ export function issueService(db: Db) {
52255218 if ( ! actorRun || heartbeatRunIsDead ( actorRun ) ) return null ;
52265219
52275220 const now = new Date ( ) ;
5221+ const issue = await tx
5222+ . select ( { executionPolicy : issues . executionPolicy , executionState : issues . executionState } )
5223+ . from ( issues )
5224+ . where ( eq ( issues . id , input . issueId ) )
5225+ . then ( ( rows ) => rows [ 0 ] ?? null ) ;
52285226 const adopted = await tx
52295227 . update ( issues )
52305228 . set ( {
52315229 checkoutRunId : input . actorRunId ,
5232- ...executionLockAcquisitionFields ( input . actorRunId , now , { scheduleMonitor : input . scheduleMonitor } ) ,
5230+ ...executionLockAcquisitionFields ( input . actorRunId , now , activeTypedIssueMonitorDeadline ( issue ?? { } , now ) ) ,
52335231 updatedAt : now ,
52345232 } )
52355233 . where (
@@ -7992,18 +7990,17 @@ export function issueService(db: Db) {
79927990 agentId : string ,
79937991 expectedStatuses : string [ ] ,
79947992 checkoutRunId : string | null ,
7995- options : { scheduleMonitor ?: boolean } = { } ,
79967993 ) => {
79977994 const issueCompany = await db
7998- . select ( { companyId : issues . companyId } )
7995+ . select ( { companyId : issues . companyId , executionPolicy : issues . executionPolicy , executionState : issues . executionState } )
79997996 . from ( issues )
80007997 . where ( eq ( issues . id , id ) )
80017998 . then ( ( rows ) => rows [ 0 ] ?? null ) ;
80027999 if ( ! issueCompany ) throw notFound ( "Issue not found" ) ;
80038000 await assertAssignableAgent ( db , issueCompany . companyId , agentId , { kind : "work" } ) ;
80048001
80058002 const now = new Date ( ) ;
8006- const scheduleMonitor = options . scheduleMonitor ?? true ;
8003+ const initialActiveMonitorDeadline = activeTypedIssueMonitorDeadline ( issueCompany , now ) ;
80078004 const activePauseHold = await treeControlSvc . getActivePauseHoldGate ( issueCompany . companyId , id ) ;
80088005 if (
80098006 activePauseHold &&
@@ -8053,7 +8050,7 @@ export function issueService(db: Db) {
80538050 assigneeUserId : null ,
80548051 checkoutRunId,
80558052 ...( checkoutRunId
8056- ? executionLockAcquisitionFields ( checkoutRunId , now , { scheduleMonitor } )
8053+ ? executionLockAcquisitionFields ( checkoutRunId , now , initialActiveMonitorDeadline )
80578054 : { executionRunId : null } ) ,
80588055 status : "in_progress" ,
80598056 startedAt : now ,
@@ -8082,6 +8079,8 @@ export function issueService(db: Db) {
80828079 assigneeAgentId : issues . assigneeAgentId ,
80838080 checkoutRunId : issues . checkoutRunId ,
80848081 executionRunId : issues . executionRunId ,
8082+ executionPolicy : issues . executionPolicy ,
8083+ executionState : issues . executionState ,
80858084 } )
80868085 . from ( issues )
80878086 . where ( eq ( issues . id , id ) )
@@ -8101,7 +8100,7 @@ export function issueService(db: Db) {
81018100 . set ( {
81028101 checkoutRunId,
81038102 ...( checkoutRunId
8104- ? executionLockAcquisitionFields ( checkoutRunId , now , { scheduleMonitor } )
8103+ ? executionLockAcquisitionFields ( checkoutRunId , now , activeTypedIssueMonitorDeadline ( current , now ) )
81058104 : { executionRunId : null } ) ,
81068105 updatedAt : new Date ( ) ,
81078106 } )
@@ -8131,7 +8130,6 @@ export function issueService(db: Db) {
81318130 actorAgentId : agentId ,
81328131 actorRunId : checkoutRunId ,
81338132 expectedCheckoutRunId : current . checkoutRunId ,
8134- scheduleMonitor,
81358133 } ) ;
81368134 if ( staleAdoption . adopted ) {
81378135 const row = await db . select ( ) . from ( issues ) . where ( eq ( issues . id , id ) ) . then ( ( rows ) => rows [ 0 ] ?? null ) ;
@@ -8156,7 +8154,7 @@ export function issueService(db: Db) {
81568154 const adoptionSet : Record < string , unknown > = {
81578155 assigneeAgentId : agentId ,
81588156 checkoutRunId,
8159- ...executionLockAcquisitionFields ( checkoutRunId , now , { scheduleMonitor } ) ,
8157+ ...executionLockAcquisitionFields ( checkoutRunId , now , activeTypedIssueMonitorDeadline ( current , now ) ) ,
81608158 executionAgentNameKey : null ,
81618159 status : "in_progress" ,
81628160 updatedAt : now ,
@@ -8271,7 +8269,6 @@ export function issueService(db: Db) {
82718269 issueId : id ,
82728270 actorAgentId,
82738271 actorRunId : actorRunId ! ,
8274- scheduleMonitor : true ,
82758272 } ) ;
82768273
82778274 if ( adopted ) {
@@ -8298,7 +8295,6 @@ export function issueService(db: Db) {
82988295 actorAgentId,
82998296 actorRunId,
83008297 expectedCheckoutRunId : previousCheckoutRunId ,
8301- scheduleMonitor : true ,
83028298 } ) ;
83038299
83048300 if ( staleAdoption . adopted ) {
0 commit comments