@@ -15,6 +15,7 @@ import {
1515 appendTranscriptEvent ,
1616 loadSessionEntry ,
1717 loadTranscriptEvents ,
18+ upsertSessionEntryCore ,
1819} from "../../config/sessions/session-accessor.js" ;
1920import { runExclusiveSessionStoreWrite } from "../../config/sessions/store-writer.js" ;
2021import { formatZonedTimestamp } from "../../infra/format-time/format-datetime.ts" ;
@@ -36,6 +37,10 @@ import {
3637 runExclusiveSessionLifecycleMutation ,
3738} from "../../sessions/session-lifecycle-admission.js" ;
3839import { listSessionStateEventsSince } from "../../sessions/session-state-events.js" ;
40+ import {
41+ closeOpenClawAgentDatabasesForTest ,
42+ resolveIncognitoOpenClawAgentSqlitePath ,
43+ } from "../../state/openclaw-agent-db.js" ;
3944import { closeOpenClawStateDatabaseForTest } from "../../state/openclaw-state-db.js" ;
4045import {
4146 createChannelTestPluginBase ,
@@ -428,6 +433,47 @@ afterEach(async () => {
428433 await sessionMcpTesting . resetSessionMcpRuntimeManager ( ) ;
429434} ) ;
430435describe ( "initSessionState guarded initialization" , ( ) => {
436+ it ( "pins an admitted non-default-agent incognito session to its process-local store" , async ( ) => {
437+ const stateDir = await makeCaseDir ( "openclaw-session-incognito-init-" ) ;
438+ await withEnvAsync ( { OPENCLAW_STATE_DIR : stateDir } , async ( ) => {
439+ const agentId = "work" ;
440+ const sessionId = "incognito-work-session" ;
441+ const sessionKey = "agent:work:dashboard:incognito-work-session" ;
442+ const storePath = resolveIncognitoOpenClawAgentSqlitePath ( { agentId } ) ;
443+ await upsertSessionEntryCore (
444+ { agentId, sessionKey, storePath } ,
445+ { sessionId, incognito : true , updatedAt : Date . now ( ) } ,
446+ ) ;
447+
448+ try {
449+ await expect (
450+ initSessionState ( {
451+ cfg : {
452+ agents : { list : [ { id : "main" , default : true } , { id : agentId } ] } ,
453+ session : { store : path . join ( stateDir , "durable" , "{agentId}" , "sessions.json" ) } ,
454+ } as OpenClawConfig ,
455+ ctx : {
456+ Body : "hello from incognito webchat" ,
457+ Provider : "webchat" ,
458+ SessionKey : sessionKey ,
459+ Surface : "webchat" ,
460+ } ,
461+ expectedExistingSessionId : sessionId ,
462+ pinExpectedExistingSession : true ,
463+ requestedSessionId : sessionId ,
464+ resumeRequestedSession : true ,
465+ } ) ,
466+ ) . resolves . toMatchObject ( {
467+ sessionId,
468+ sessionKey,
469+ storePath,
470+ } ) ;
471+ } finally {
472+ closeOpenClawAgentDatabasesForTest ( ) ;
473+ }
474+ } ) ;
475+ } ) ;
476+
431477 it ( "rejects inbound work for an archived session" , async ( ) => {
432478 const storePath = await createStorePath ( "openclaw-session-init-archived-" ) ;
433479 const sessionKey = "agent:main:telegram:chat:archived" ;
0 commit comments