@@ -175,34 +175,39 @@ const server: Plugin = async (ctx) => {
175175 }
176176 }
177177
178- setTimeout ( ( ) => {
179- try {
180- const db = openDatabase ( ) ;
181- if ( ! db || ! isDatabasePersisted ( db ) ) return ;
182- const ocDb = openOpenCodeDb ( ) ;
183- if ( ! ocDb ) return ;
178+ // Gated like the v22 backfill above: a conflict-disabled plugin must not
179+ // touch storage at all (openDatabase() would CREATE context.db, breaking
180+ // the disabled-path invariant that no state is written).
181+ if ( pluginConfig . enabled && hooks . magicContext ) {
182+ setTimeout ( ( ) => {
184183 try {
185- const sessions = ocDb
186- . prepare (
187- "SELECT id, COALESCE(directory, '') AS directory FROM session ORDER BY id ASC" ,
188- )
189- . all ( ) as Array < { id : string ; directory : string } > ;
190- void runSessionProjectBackfill (
191- db ,
192- sessions . map ( ( session ) => ( {
193- sessionId : session . id ,
194- directory : session . directory ,
195- } ) ) ,
196- ) . catch ( ( err ) => {
197- log ( `[session-projects] background runner failed: ${ err } ` ) ;
198- } ) ;
199- } finally {
200- closeQuietly ( ocDb ) ;
184+ const db = openDatabase ( ) ;
185+ if ( ! db || ! isDatabasePersisted ( db ) ) return ;
186+ const ocDb = openOpenCodeDb ( ) ;
187+ if ( ! ocDb ) return ;
188+ try {
189+ const sessions = ocDb
190+ . prepare (
191+ "SELECT id, COALESCE(directory, '') AS directory FROM session ORDER BY id ASC" ,
192+ )
193+ . all ( ) as Array < { id : string ; directory : string } > ;
194+ void runSessionProjectBackfill (
195+ db ,
196+ sessions . map ( ( session ) => ( {
197+ sessionId : session . id ,
198+ directory : session . directory ,
199+ } ) ) ,
200+ ) . catch ( ( err ) => {
201+ log ( `[session-projects] background runner failed: ${ err } ` ) ;
202+ } ) ;
203+ } finally {
204+ closeQuietly ( ocDb ) ;
205+ }
206+ } catch ( err ) {
207+ log ( `[session-projects] failed to start background runner: ${ err } ` ) ;
201208 }
202- } catch ( err ) {
203- log ( `[session-projects] failed to start background runner: ${ err } ` ) ;
204- }
205- } , 0 ) ;
209+ } , 0 ) ;
210+ }
206211
207212 // Resolve storage dir up front. Used by the RPC server below AND by
208213 // the auto-update checker (for cross-process dedup of npm hits when
0 commit comments