@@ -120,8 +120,6 @@ interface BoxThread {
120120 readonly finished : Deferred . Deferred < void > ;
121121 /** While set, reading the thread there waits: completed once a read starts, released by `releaseRead`. */
122122 readonly holdRead : Ref . Ref < boolean > ;
123- /** Reads there refuse `beforePosition`, as a box from before it does. */
124- readonly forwardReadsOnly : Ref . Ref < boolean > ;
125123 readonly readStarted : Deferred . Deferred < void > ;
126124 readonly releaseRead : Deferred . Deferred < void > ;
127125 readonly holdFirstStop : Ref . Ref < boolean > ;
@@ -158,7 +156,6 @@ const makeBoxThread = Effect.gen(function* () {
158156 interruptedOnce : yield * Deferred . make < void > ( ) ,
159157 finished : yield * Deferred . make < void > ( ) ,
160158 holdRead : yield * Ref . make ( false ) ,
161- forwardReadsOnly : yield * Ref . make ( false ) ,
162159 readStarted : yield * Deferred . make < void > ( ) ,
163160 releaseRead : yield * Deferred . make < void > ( ) ,
164161 holdFirstStop : yield * Ref . make ( false ) ,
@@ -309,9 +306,6 @@ const boxToolkitLayer = (thread: BoxThread) => {
309306 yield * Deferred . succeed ( thread . readStarted , undefined ) ;
310307 yield * Deferred . await ( thread . releaseRead ) ;
311308 }
312- if ( options . beforePosition !== undefined && ( yield * Ref . get ( thread . forwardReadsOnly ) ) ) {
313- return yield * Effect . die ( "Unknown key beforePosition" ) ;
314- }
315309 const reply = yield * Ref . get ( thread . reply ) ;
316310 const later = yield * Ref . get ( thread . laterReply ) ;
317311 const error = yield * Ref . get ( thread . error ) ;
@@ -358,13 +352,9 @@ const boxToolkitLayer = (thread: BoxThread) => {
358352 ( entry ) => options . view === "activity" || entry . type === "assistant_message" ,
359353 )
360354 : replies . filter ( ( entry ) => entry . id === options . itemId ) ;
361- const inRange = visible . filter (
362- ( entry ) =>
363- entry . position > ( options . afterPosition ?? - 1 ) &&
364- entry . position < ( options . beforePosition ?? Number . POSITIVE_INFINITY ) ,
365- ) ;
366- const matching =
367- options . beforePosition === undefined ? inRange . slice ( 0 , 1 ) : inRange . slice ( - 1 ) ;
355+ const matching = visible
356+ . filter ( ( entry ) => entry . position > ( options . afterPosition ?? - 1 ) )
357+ . slice ( 0 , 1 ) ;
368358 return {
369359 items : matching . map ( ( { id, runId : itemRunId , text, position, type } ) => ( {
370360 position,
@@ -1246,50 +1236,47 @@ it.effect("fails the task when the box revokes the link, and cancel interrupts i
12461236 ) . pipe ( Effect . provide ( NodeHttpServer . layerTest ) ) ,
12471237) ;
12481238
1249- it . effect . each ( [ false , true ] ) (
1250- "a task's result is its own run's whole last reply, not a later run's (forward reads only: %s)" ,
1251- ( forwardReadsOnly ) =>
1252- Effect . scoped (
1253- Effect . gen ( function * ( ) {
1254- const thread = yield * makeBoxThread ;
1255- yield * Ref . set ( thread . forwardReadsOnly , forwardReadsOnly ) ;
1256- const b = yield * serveBox ( thread ) ;
1257- const offers = yield * SubscriptionRef . make <
1258- ReadonlyArray < ProviderContinuationRequests . ProviderContinuationRequest >
1259- > ( [ ] ) ;
1260- const database = yield * SqlitePersistence . layerMemory . pipe ( Layer . build ) ;
1261- const a = yield * makeLaptop ( database , offers ) ;
1262- yield * linkTo ( a . links , b , "full-access" ) ;
1263- yield * seedParent ( a ) ;
1239+ it . effect ( "a task's result is its own run's whole last reply, not a later run's" , ( ) =>
1240+ Effect . scoped (
1241+ Effect . gen ( function * ( ) {
1242+ const thread = yield * makeBoxThread ;
1243+ const b = yield * serveBox ( thread ) ;
1244+ const offers = yield * SubscriptionRef . make <
1245+ ReadonlyArray < ProviderContinuationRequests . ProviderContinuationRequest >
1246+ > ( [ ] ) ;
1247+ const database = yield * SqlitePersistence . layerMemory . pipe ( Layer . build ) ;
1248+ const a = yield * makeLaptop ( database , offers ) ;
1249+ yield * linkTo ( a . links , b , "full-access" ) ;
1250+ yield * seedParent ( a ) ;
12641251
1265- const result = yield * a . call ( "delegate_task" , {
1266- task : "Review the diff." ,
1267- role : "review" ,
1268- target : { environmentId : box . environmentId } ,
1269- clientRequestId : "review-on-box" ,
1270- } ) ;
1271- expect ( result . isError , JSON . stringify ( result . content ) ) . toBe ( false ) ;
1272- const { taskId } = result . structuredContent as { taskId : NodeId } ;
1273- // The role reaches the thread there, as it does a child here.
1274- expect ( yield * Ref . get ( thread . message ) ) . toBe (
1275- "Act as the review sub-agent for this task.\n\nReview the diff." ,
1276- ) ;
1252+ const result = yield * a . call ( "delegate_task" , {
1253+ task : "Review the diff." ,
1254+ role : "review" ,
1255+ target : { environmentId : box . environmentId } ,
1256+ clientRequestId : "review-on-box" ,
1257+ } ) ;
1258+ expect ( result . isError , JSON . stringify ( result . content ) ) . toBe ( false ) ;
1259+ const { taskId } = result . structuredContent as { taskId : NodeId } ;
1260+ // The role reaches the thread there, as it does a child here.
1261+ expect ( yield * Ref . get ( thread . message ) ) . toBe (
1262+ "Act as the review sub-agent for this task.\n\nReview the diff." ,
1263+ ) ;
12771264
1278- // A reply longer than one read, then a later run's reply on the same thread.
1279- const long = "x" . repeat ( 45_000 ) ;
1280- yield * Ref . set ( thread . reply , long ) ;
1281- yield * Ref . set ( thread . laterReply , "Someone else asked a follow-up." ) ;
1282- yield * Ref . set ( thread . status , "completed" ) ;
1283- yield * Deferred . succeed ( thread . finished , undefined ) ;
1284- const task = yield * taskResult ( a , taskId ) ;
1285- expect ( task ?. status ) . toBe ( "completed" ) ;
1286- expect ( task ?. result ) . toBe ( long ) ;
1287- // Every wait was for the run the launch started.
1288- const waits = yield * Ref . get ( thread . waitedFor ) ;
1289- expect ( waits . length ) . toBeGreaterThan ( 0 ) ;
1290- expect ( waits . every ( ( runId ) => runId === boxRunId ) ) . toBe ( true ) ;
1291- } ) ,
1292- ) . pipe ( Effect . provide ( NodeHttpServer . layerTest ) ) ,
1265+ // A reply longer than one read, then a later run's reply on the same thread.
1266+ const long = "x" . repeat ( 45_000 ) ;
1267+ yield * Ref . set ( thread . reply , long ) ;
1268+ yield * Ref . set ( thread . laterReply , "Someone else asked a follow-up." ) ;
1269+ yield * Ref . set ( thread . status , "completed" ) ;
1270+ yield * Deferred . succeed ( thread . finished , undefined ) ;
1271+ const task = yield * taskResult ( a , taskId ) ;
1272+ expect ( task ?. status ) . toBe ( "completed" ) ;
1273+ expect ( task ?. result ) . toBe ( long ) ;
1274+ // Every wait was for the run the launch started.
1275+ const waits = yield * Ref . get ( thread . waitedFor ) ;
1276+ expect ( waits . length ) . toBeGreaterThan ( 0 ) ;
1277+ expect ( waits . every ( ( runId ) => runId === boxRunId ) ) . toBe ( true ) ;
1278+ } ) ,
1279+ ) . pipe ( Effect . provide ( NodeHttpServer . layerTest ) ) ,
12931280) ;
12941281
12951282it . effect ( "a task whose thread there waits on its own task ends with the answer after it" , ( ) =>
0 commit comments