diff --git a/src/db.test.ts b/src/db.test.ts index de7487e..1b34f2e 100644 --- a/src/db.test.ts +++ b/src/db.test.ts @@ -1130,7 +1130,7 @@ describe('paired room registration', () => { expect(getEffectiveRuntimeRoomMode('dc:explicit-tribunal')).toBe('single'); }); - it('keeps explicit tribunal non-runnable when the configured reviewer service is unavailable', () => { + it('trusts stored tribunal mode even when legacy capability rows are incomplete', () => { _setRegisteredGroupForTests('dc:explicit-tribunal-codex', { name: 'Explicit Tribunal Codex', folder: 'explicit-tribunal-codex', @@ -1143,7 +1143,7 @@ describe('paired room registration', () => { expect(getEffectiveRoomMode('dc:explicit-tribunal-codex')).toBe('tribunal'); expect(getEffectiveRuntimeRoomMode('dc:explicit-tribunal-codex')).toBe( - 'single', + 'tribunal', ); }); }); diff --git a/src/db.ts b/src/db.ts index 32ecf88..1f113f4 100644 --- a/src/db.ts +++ b/src/db.ts @@ -2770,7 +2770,12 @@ function canRunTribunalFromRegisteredAgentTypes( } export function getEffectiveRuntimeRoomMode(chatJid: string): RoomMode { - return getEffectiveRoomMode(chatJid) === 'tribunal' && + const stored = getStoredRoomSettings(chatJid); + if (stored) { + return stored.roomMode; + } + + return inferStoredRoomModeForJid(chatJid) === 'tribunal' && canRunTribunalFromRegisteredAgentTypes( getRegisteredAgentTypesForJid(chatJid), ) diff --git a/src/service-routing.test.ts b/src/service-routing.test.ts index 63f3c1e..a2ce005 100644 --- a/src/service-routing.test.ts +++ b/src/service-routing.test.ts @@ -138,7 +138,7 @@ describe('service-routing global failover', () => { }); }); - it('falls back to the available service when stored owner agent type is unavailable', () => { + it('trusts stored owner agent type over incomplete legacy capability rows', () => { _setRegisteredGroupForTests('dc:stored-owner-fallback', { name: 'Stored Owner Fallback', folder: 'stored-owner-fallback', @@ -150,7 +150,7 @@ describe('service-routing global failover', () => { expect(getEffectiveChannelLease('dc:stored-owner-fallback')).toMatchObject({ chat_jid: 'dc:stored-owner-fallback', - owner_service_id: 'claude', + owner_service_id: 'codex-main', reviewer_service_id: null, explicit: false, }); @@ -174,7 +174,7 @@ describe('service-routing global failover', () => { }); }); - it('keeps reviewer lease disabled when explicit tribunal cannot deliver the configured reviewer', () => { + it('builds reviewer lease from stored tribunal mode even when legacy rows are incomplete', () => { _setRegisteredGroupForTests('dc:explicit-tribunal-codex', { name: 'Explicit Tribunal Codex', folder: 'explicit-tribunal-codex', @@ -189,7 +189,7 @@ describe('service-routing global failover', () => { ).toMatchObject({ chat_jid: 'dc:explicit-tribunal-codex', owner_service_id: 'codex-main', - reviewer_service_id: null, + reviewer_service_id: 'claude', explicit: false, }); }); diff --git a/src/service-routing.ts b/src/service-routing.ts index 9194228..f20bbd4 100644 --- a/src/service-routing.ts +++ b/src/service-routing.ts @@ -72,17 +72,14 @@ function inferFallbackOwnerAgentType( } function resolveDefaultOwnerAgentType(chatJid: string): AgentType | undefined { + const storedOwnerAgentType = getStoredRoomSettings(chatJid)?.ownerAgentType; + if (storedOwnerAgentType) { + return storedOwnerAgentType; + } + const types = getRegisteredAgentTypesForJid(chatJid); const hasClaude = types.includes('claude-code'); const hasCodex = types.includes('codex'); - const storedOwnerAgentType = getStoredRoomSettings(chatJid)?.ownerAgentType; - - if (storedOwnerAgentType === 'claude-code' && hasClaude) { - return 'claude-code'; - } - if (storedOwnerAgentType === 'codex' && hasCodex) { - return 'codex'; - } return inferFallbackOwnerAgentType(hasClaude, hasCodex); }