@@ -91,29 +91,18 @@ function writeMigratedSessionState(stateDir: string): void {
9191}
9292
9393function createMigratedSessionFileStore (
94- stateDir : string ,
9594 options : { includePrompt ?: boolean } = { } ,
9695) : Record < string , Record < string , unknown > > {
97- const agentSessionsDir = join ( stateDir , "agents" , "main" , "sessions" ) ;
98- const main : Record < string , unknown > = {
99- sessionId : "upgrade-main-session" ,
100- sessionFile : join ( agentSessionsDir , "upgrade-main-session.jsonl" ) ,
101- } ;
96+ const main : Record < string , unknown > = { sessionId : "upgrade-main-session" } ;
10297 if ( options . includePrompt !== false ) {
10398 main . skillsSnapshot = {
10499 prompt : "legacy prompt survives as metadata" ,
105100 } ;
106101 }
107102 return {
108103 "agent:main:main" : main ,
109- "agent:main:+15551234567" : {
110- sessionId : "upgrade-direct-session" ,
111- sessionFile : join ( agentSessionsDir , "upgrade-direct-session.jsonl" ) ,
112- } ,
113- "agent:main:slack:channel:cupgrade" : {
114- sessionId : "upgrade-group-session" ,
115- sessionFile : join ( agentSessionsDir , "upgrade-group-session.jsonl" ) ,
116- } ,
104+ "agent:main:+15551234567" : { sessionId : "upgrade-direct-session" } ,
105+ "agent:main:slack:channel:cupgrade" : { sessionId : "upgrade-group-session" } ,
117106 } ;
118107}
119108
@@ -123,10 +112,7 @@ function writeMigratedSessionFiles(
123112) : void {
124113 const agentSessionsDir = join ( stateDir , "agents" , "main" , "sessions" ) ;
125114 mkdirSync ( agentSessionsDir , { recursive : true } ) ;
126- writeJson (
127- join ( agentSessionsDir , "sessions.json" ) ,
128- createMigratedSessionFileStore ( stateDir , options ) ,
129- ) ;
115+ writeJson ( join ( agentSessionsDir , "sessions.json" ) , createMigratedSessionFileStore ( options ) ) ;
130116 for ( const sessionId of [
131117 "upgrade-main-session" ,
132118 "upgrade-direct-session" ,
@@ -162,7 +148,7 @@ function writeLegacyCacheSessionState(
162148 const insert = db . prepare (
163149 "INSERT INTO cache_entries (scope, key, value_json) VALUES (?, ?, ?)" ,
164150 ) ;
165- for ( const [ key , entry ] of Object . entries ( createMigratedSessionFileStore ( stateDir , options ) ) ) {
151+ for ( const [ key , entry ] of Object . entries ( createMigratedSessionFileStore ( options ) ) ) {
166152 insert . run ( "session_entries" , key , JSON . stringify ( entry ) ) ;
167153 }
168154 } finally {
@@ -187,7 +173,7 @@ function writeLegacySessionEntriesState(stateDir: string): void {
187173 INSERT INTO session_entries (session_key, session_id, entry_json, updated_at)
188174 VALUES (?, ?, ?, ?)
189175 ` ) ;
190- for ( const [ key , entry ] of Object . entries ( createMigratedSessionFileStore ( stateDir ) ) ) {
176+ for ( const [ key , entry ] of Object . entries ( createMigratedSessionFileStore ( ) ) ) {
191177 const sessionId = entry . sessionId ;
192178 if ( typeof sessionId !== "string" ) {
193179 throw new TypeError ( `missing fixture session id for ${ key } ` ) ;
@@ -594,6 +580,27 @@ describe("upgrade survivor assertions", () => {
594580 ) . not . toThrow ( ) ;
595581 } ) ;
596582
583+ it ( "rejects retired sessionFile metadata in SQLite-backed session rows" , ( ) => {
584+ expect ( ( ) =>
585+ runSessionStateAssertion ( ( stateDir ) => {
586+ writeMigratedSessionState ( stateDir ) ;
587+ const db = new DatabaseSync (
588+ join ( stateDir , "agents" , "main" , "agent" , "openclaw-agent.sqlite" ) ,
589+ ) ;
590+ try {
591+ db . prepare ( "UPDATE session_nodes SET entry_json = ? WHERE session_key = ?" ) . run (
592+ JSON . stringify ( {
593+ sessionFile : join ( stateDir , "sessions" , "upgrade-main-session.jsonl" ) ,
594+ } ) ,
595+ "agent:main:main" ,
596+ ) ;
597+ } finally {
598+ db . close ( ) ;
599+ }
600+ } ) ,
601+ ) . toThrow ( / r e t a i n e d r e t i r e d s e s s i o n F i l e m e t a d a t a / ) ;
602+ } ) ;
603+
597604 it ( "rejects ClawHub npm-pack installs outside the managed extensions root" , ( ) => {
598605 const root = mkdtempSync ( join ( tmpdir ( ) , "openclaw-upgrade-survivor-outside-" ) ) ;
599606 try {
0 commit comments