@@ -3288,21 +3288,68 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
32883288 } ) . pipe ( Effect . scoped ) ,
32893289 ) ;
32903290
3291+ it . effect ( "rejects unreadable rollback history before cutting the native session" , ( ) =>
3292+ Effect . gen ( function * ( ) {
3293+ const { runtime, thread } = yield * resumed ( [
3294+ out ( "message.list" , { sessionID : SESSION , limit : "100" , type : undefined } ) ,
3295+ reply ( "message.list" , {
3296+ data : [
3297+ { id : "msg_kept" , time : { created : 1 } , text : "first" , type : "user" } ,
3298+ {
3299+ id : "msg_compaction" ,
3300+ time : { created : 2 } ,
3301+ type : "compaction" ,
3302+ status : "completed" ,
3303+ reason : "auto" ,
3304+ summary : "First turn summary" ,
3305+ } ,
3306+ { id : "msg_dropped" , time : { created : 3 } , text : "second" , type : "user" } ,
3307+ ] ,
3308+ cursor : { } ,
3309+ } ) ,
3310+ ] ) ;
3311+ const now = yield * DateTime . now ;
3312+ const turns = [ "msg_kept" , "msg_dropped" ] . map ( ( nativeId , index ) => ( {
3313+ id : ProviderTurnId . make ( `provider-turn:rollback-history:${ index } ` ) ,
3314+ providerThreadId : thread . id ,
3315+ nodeId : NodeId . make ( `node:rollback-history:${ index } ` ) ,
3316+ runAttemptId : RunAttemptId . make ( `attempt:rollback-history:${ index } ` ) ,
3317+ nativeTurnRef : { driver : OPENCODE_PROVIDER , nativeId, strength : "weak" as const } ,
3318+ ordinal : index + 1 ,
3319+ status : "completed" as const ,
3320+ startedAt : now ,
3321+ completedAt : now ,
3322+ } ) ) ;
3323+ const failure = yield * runtime
3324+ . rollbackThread ( {
3325+ providerThread : thread ,
3326+ target : {
3327+ type : "provider_turn" ,
3328+ checkpointId : CheckpointId . make ( "checkpoint:rollback-history" ) ,
3329+ appRunOrdinal : 1 ,
3330+ providerTurn : turns [ 0 ] ! ,
3331+ } ,
3332+ providerThreadTurns : turns ,
3333+ } )
3334+ . pipe ( Effect . flip ) ;
3335+ assert . equal ( failure . _tag , "ProviderAdapterRollbackThreadError" ) ;
3336+ assert . include ( Cause . pretty ( Cause . fail ( failure ) ) , '["recent"]' ) ;
3337+ } ) . pipe ( Effect . scoped ) ,
3338+ ) ;
3339+
32913340 it . effect ( "clears a staged revert whose commit failed, before the next prompt too" , ( ) =>
32923341 Effect . gen ( function * ( ) {
32933342 const kept = "msg_t3_turn_run-attempt:kept:1" ;
32943343 const dropped = "msg_t3_turn_run-attempt:dropped:1" ;
32953344 const { runtime, thread } = yield * resumed ( [
3296- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "user" } ) ,
3345+ out ( "message.list" , "<any>" ) ,
32973346 reply ( "message.list" , {
32983347 data : [
32993348 { id : dropped , time : { created : 2 } , text : "second" , type : "user" } ,
33003349 { id : kept , time : { created : 1 } , text : "first" , type : "user" } ,
33013350 ] ,
33023351 cursor : { } ,
33033352 } ) ,
3304- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "synthetic" } ) ,
3305- reply ( "message.list" , { data : [ ] , cursor : { } } ) ,
33063353 out ( "session.revert.stage" , { sessionID : SESSION , messageID : dropped , files : false } ) ,
33073354 replyData ( "session.revert.stage" , { messageID : dropped , files : [ ] } ) ,
33083355 out ( "session.revert.commit" , { sessionID : SESSION } ) ,
@@ -3364,16 +3411,14 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
33643411 const dropped = "msg_t3_turn_run-attempt:dropped:1" ;
33653412 const offers : Array < ProviderContinuationRequests . ProviderContinuationRequest > = [ ] ;
33663413 const { runtime, thread } = yield * resumed ( [
3367- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "user" } ) ,
3414+ out ( "message.list" , "<any>" ) ,
33683415 reply ( "message.list" , {
33693416 data : [
33703417 { id : dropped , time : { created : 2 } , text : "second" , type : "user" } ,
33713418 { id : kept , time : { created : 1 } , text : "first" , type : "user" } ,
33723419 ] ,
33733420 cursor : { } ,
33743421 } ) ,
3375- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "synthetic" } ) ,
3376- reply ( "message.list" , { data : [ ] , cursor : { } } ) ,
33773422 out ( "session.revert.stage" , { sessionID : SESSION , messageID : dropped , files : false } ) ,
33783423 replyData ( "session.revert.stage" , { messageID : dropped , files : [ ] } ) ,
33793424 out ( "session.revert.commit" , { sessionID : SESSION } ) ,
@@ -3596,13 +3641,11 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
35963641 ...( running
35973642 ? [ ]
35983643 : [
3599- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "user" } ) ,
3644+ out ( "message.list" , "<any>" ) ,
36003645 reply ( "message.list" , {
36013646 data : [ { id : prompt , time : { created : 1 } , text : "hi" , type : "user" } ] ,
36023647 cursor : { } ,
36033648 } ) ,
3604- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "synthetic" } ) ,
3605- reply ( "message.list" , { data : [ ] , cursor : { } } ) ,
36063649 out ( "session.revert.stage" , {
36073650 sessionID : SESSION ,
36083651 messageID : prompt ,
@@ -3758,16 +3801,14 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
37583801 promptAccepted ,
37593802 event ( "session.execution.started" , { sessionID : SESSION } ) ,
37603803 event ( "session.execution.succeeded" , { sessionID : SESSION } ) ,
3761- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "user" } ) ,
3804+ out ( "message.list" , "<any>" ) ,
37623805 reply ( "message.list" , {
37633806 data : [
37643807 { id : dropped , time : { created : 2 } , text : "second" , type : "user" } ,
37653808 { id : kept , time : { created : 1 } , text : "first" , type : "user" } ,
37663809 ] ,
37673810 cursor : { } ,
37683811 } ) ,
3769- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "synthetic" } ) ,
3770- reply ( "message.list" , { data : [ ] , cursor : { } } ) ,
37713812 out ( "session.revert.stage" , { sessionID : SESSION , messageID : dropped , files : false } ) ,
37723813 replyData ( "session.revert.stage" , { messageID : dropped , files : [ ] } ) ,
37733814 out ( "session.revert.commit" , { sessionID : SESSION } ) ,
@@ -3820,13 +3861,11 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
38203861 Effect . gen ( function * ( ) {
38213862 const prompted = `msg_t3_turn_${ SESSION } :attempt:earlier` ;
38223863 const { runtime, thread } = yield * resumed ( [
3823- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "user" } ) ,
3864+ out ( "message.list" , "<any>" ) ,
38243865 reply ( "message.list" , {
38253866 data : [ { id : prompted , time : { created : 1 } , text : "earlier" , type : "user" } ] ,
38263867 cursor : { } ,
38273868 } ) ,
3828- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "synthetic" } ) ,
3829- reply ( "message.list" , { data : [ ] , cursor : { } } ) ,
38303869 out ( "session.revert.stage" , { sessionID : SESSION , messageID : prompted , files : false } ) ,
38313870 replyData ( "session.revert.stage" , { messageID : prompted , files : [ ] } ) ,
38323871 out ( "session.revert.commit" , { sessionID : SESSION } ) ,
@@ -3888,16 +3927,14 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
38883927 out ( "session.get" , { sessionID : SESSION } ) ,
38893928 replyData ( "session.get" , sessionInfo ( ) ) ,
38903929 ...noOpenRequests ,
3891- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "user" } ) ,
3930+ out ( "message.list" , "<any>" ) ,
38923931 reply ( "message.list" , {
38933932 data : [
38943933 { id : second , time : { created : 2 } , text : "second" , type : "user" } ,
38953934 { id : first , time : { created : 1 } , text : "first" , type : "user" } ,
38963935 ] ,
38973936 cursor : { } ,
38983937 } ) ,
3899- out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "synthetic" } ) ,
3900- reply ( "message.list" , { data : [ ] , cursor : { } } ) ,
39013938 out ( "session.revert.stage" , {
39023939 sessionID : SESSION ,
39033940 messageID : second ,
0 commit comments