@@ -44,6 +44,7 @@ interface CreateCopilotAgentHarnessOptions {
4444}
4545
4646interface TrackedSession {
47+ journalVersion ?: 1 ;
4748 sdkSessionId : string ;
4849 client : CopilotClient ;
4950 clientOptions : ClientCreateOptions ;
@@ -91,6 +92,7 @@ interface CopilotHistoryCompactSession {
9192
9293export type CopilotSessionBinding = {
9394 schemaVersion : 2 ;
95+ journalVersion ?: 1 ;
9496 sdkSessionId : string ;
9597 compatKey : string ;
9698 compactKey : string ;
@@ -107,7 +109,10 @@ type LegacyCopilotSessionBinding = {
107109 updatedAt : number ;
108110} ;
109111
110- type CopilotAttemptSessionBinding = Pick < CopilotSessionBinding , "compatKey" | "sdkSessionId" > ;
112+ type CopilotAttemptSessionBinding = Pick <
113+ CopilotSessionBinding ,
114+ "compatKey" | "journalVersion" | "sdkSessionId"
115+ > ;
111116type DeferredCompactionCleanupOutcome = "aborted" | "completed" | "deadline" ;
112117type DeferredCompactionCleanup = {
113118 abort : ( ) => void ;
@@ -160,6 +165,7 @@ function normalizeBinding(
160165 value . compatKey . trim ( ) === "" ||
161166 typeof value . compactKey !== "string" ||
162167 value . compactKey . trim ( ) === "" ||
168+ ( value . journalVersion !== undefined && value . journalVersion !== 1 ) ||
163169 ( value . authMode !== "gitHubToken" &&
164170 value . authMode !== "byok" &&
165171 value . authMode !== "useLoggedInUser" ) ||
@@ -175,6 +181,7 @@ function normalizeBinding(
175181 }
176182 return {
177183 schemaVersion : 2 ,
184+ ...( value . journalVersion === 1 ? { journalVersion : 1 as const } : { } ) ,
178185 sdkSessionId : value . sdkSessionId . trim ( ) ,
179186 compatKey : value . compatKey ,
180187 compactKey : value . compactKey ,
@@ -704,12 +711,13 @@ export function createCopilotAgentHarness(
704711 ? undefined
705712 : lookupStoredBinding ( options ?. sessionStore , openclawSessionId )
706713 : undefined ;
707- const resumableSessionId =
714+ const resumableBinding =
708715 tracked && tracked . compatKey === currentCompatKey
709- ? tracked . sdkSessionId
716+ ? tracked
710717 : ! tracked && stored && stored . compatKey === currentCompatKey
711- ? stored . sdkSessionId
718+ ? stored
712719 : undefined ;
720+ const resumableSessionId = resumableBinding ?. sdkSessionId ;
713721 if ( operation === "settled-tool-finalization" && ! resumableSessionId ) {
714722 throw new Error (
715723 "[copilot] cannot safely finalize a settled tool turn without its compatible SDK session" ,
@@ -739,15 +747,19 @@ export function createCopilotAgentHarness(
739747 // still requiring the exact compatible native session above.
740748 initialReplayState :
741749 operation === "settled-tool-finalization"
742- ? { sdkSessionId : resumableSessionId }
750+ ? {
751+ ...( resumableBinding ?. journalVersion === 1 ? { journalValidated : true } : { } ) ,
752+ sdkSessionId : resumableSessionId ,
753+ }
743754 : {
744755 ...params . initialReplayState ,
756+ ...( resumableBinding ?. journalVersion === 1 ? { journalValidated : true } : { } ) ,
745757 sdkSessionId : resumableSessionId ,
746758 } ,
747759 } as AgentHarnessAttemptParams )
748760 : params ;
749761
750- return runCopilotAttempt ( effectiveParams , {
762+ const result = await runCopilotAttempt ( effectiveParams , {
751763 pool,
752764 ...( operation === "settled-tool-finalization" ? { operation } : { } ) ,
753765 onSessionEstablished :
@@ -835,6 +847,32 @@ export function createCopilotAgentHarness(
835847 }
836848 : undefined ,
837849 } ) ;
850+ if ( operation === "attempt" && openclawSessionId ) {
851+ const attemptResult = result as AgentHarnessAttemptResult & {
852+ journalValidated ?: boolean ;
853+ sdkSessionId ?: string ;
854+ } ;
855+ const sdkSessionId = attemptResult . sdkSessionId ;
856+ const trackedSession = trackedSessions . get ( openclawSessionId ) ;
857+ if ( sdkSessionId && trackedSession ?. sdkSessionId === sdkSessionId ) {
858+ const { journalVersion : _journalVersion , ...baseTracked } = trackedSession ;
859+ const nextTracked : TrackedSession = {
860+ ...baseTracked ,
861+ ...( attemptResult . journalValidated ? { journalVersion : 1 } : { } ) ,
862+ } ;
863+ trackedSessions . set ( openclawSessionId , nextTracked ) ;
864+ registerStoredBinding ( options ?. sessionStore , openclawSessionId , {
865+ schemaVersion : 2 ,
866+ ...( attemptResult . journalValidated ? { journalVersion : 1 } : { } ) ,
867+ sdkSessionId,
868+ compatKey : nextTracked . compatKey ,
869+ compactKey : nextTracked . compactKey ,
870+ ...sessionAuthFields ( nextTracked ) ,
871+ updatedAt : Date . now ( ) ,
872+ } ) ;
873+ }
874+ }
875+ return result ;
838876 } ) ( ) ;
839877 inFlight . add ( attemptPromise ) ;
840878 try {
0 commit comments