From 236f7c2feab7161169f254ca423f2636ec36319e Mon Sep 17 00:00:00 2001 From: Eyejoker Date: Tue, 31 Mar 2026 12:14:24 +0900 Subject: [PATCH] fix: gate paired runtime on dual registrations --- src/db.test.ts | 9 +++++++-- src/db.ts | 9 ++++++++- src/service-routing.test.ts | 4 ++-- src/service-routing.ts | 4 ++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/db.test.ts b/src/db.test.ts index 54971af..48f7bca 100644 --- a/src/db.test.ts +++ b/src/db.test.ts @@ -17,6 +17,7 @@ import { getAllRegisteredGroups, getDueTasks, getEffectiveRoomMode, + getEffectiveRuntimeRoomMode, getExplicitRoomMode, getLatestMessageSeqAtOrBefore, getLatestPairedTaskForChat, @@ -824,6 +825,7 @@ describe('paired room registration', () => { expect(getExplicitRoomMode('dc:legacy-paired')).toBeUndefined(); expect(getEffectiveRoomMode('dc:legacy-paired')).toBe('tribunal'); + expect(getEffectiveRuntimeRoomMode('dc:legacy-paired')).toBe('tribunal'); expect(isPairedRoomJid('dc:legacy-paired')).toBe(true); }); @@ -847,10 +849,11 @@ describe('paired room registration', () => { expect(getExplicitRoomMode('dc:explicit-single')).toBe('single'); expect(getEffectiveRoomMode('dc:explicit-single')).toBe('single'); + expect(getEffectiveRuntimeRoomMode('dc:explicit-single')).toBe('single'); expect(isPairedRoomJid('dc:explicit-single')).toBe(false); }); - it('lets explicit tribunal override solo fallback and clears back to inferred mode', () => { + it('keeps explicit tribunal configured but not runnable without dual registration', () => { setRegisteredGroup('dc:explicit-tribunal', { name: 'Explicit Tribunal Claude', folder: 'explicit-tribunal-claude', @@ -865,12 +868,14 @@ describe('paired room registration', () => { expect(getExplicitRoomMode('dc:explicit-tribunal')).toBe('tribunal'); expect(getEffectiveRoomMode('dc:explicit-tribunal')).toBe('tribunal'); - expect(isPairedRoomJid('dc:explicit-tribunal')).toBe(true); + expect(getEffectiveRuntimeRoomMode('dc:explicit-tribunal')).toBe('single'); + expect(isPairedRoomJid('dc:explicit-tribunal')).toBe(false); clearExplicitRoomMode('dc:explicit-tribunal'); expect(getExplicitRoomMode('dc:explicit-tribunal')).toBeUndefined(); expect(getEffectiveRoomMode('dc:explicit-tribunal')).toBe('single'); + expect(getEffectiveRuntimeRoomMode('dc:explicit-tribunal')).toBe('single'); expect(isPairedRoomJid('dc:explicit-tribunal')).toBe(false); }); }); diff --git a/src/db.ts b/src/db.ts index 4fd0ed4..5a49424 100644 --- a/src/db.ts +++ b/src/db.ts @@ -1978,8 +1978,15 @@ export function getEffectiveRoomMode(chatJid: string): RoomMode { return getExplicitRoomMode(chatJid) ?? inferRoomModeForJid(chatJid); } +export function getEffectiveRuntimeRoomMode(chatJid: string): RoomMode { + return getEffectiveRoomMode(chatJid) === 'tribunal' && + inferRoomModeForJid(chatJid) === 'tribunal' + ? 'tribunal' + : 'single'; +} + export function isPairedRoomJid(jid: string): boolean { - return getEffectiveRoomMode(jid) === 'tribunal'; + return getEffectiveRuntimeRoomMode(jid) === 'tribunal'; } // --- Paired task/project/workspace state --- diff --git a/src/service-routing.test.ts b/src/service-routing.test.ts index 48f872f..2d5799a 100644 --- a/src/service-routing.test.ts +++ b/src/service-routing.test.ts @@ -108,7 +108,7 @@ describe('service-routing global failover', () => { }); }); - it('uses explicit tribunal room mode to add reviewer lease on solo rooms', () => { + it('does not create reviewer lease for explicit tribunal without dual registration capability', () => { setRegisteredGroup('dc:explicit-tribunal', { name: 'Explicit Tribunal Claude', folder: 'explicit-tribunal-claude', @@ -121,7 +121,7 @@ describe('service-routing global failover', () => { expect(getEffectiveChannelLease('dc:explicit-tribunal')).toMatchObject({ chat_jid: 'dc:explicit-tribunal', owner_service_id: 'claude', - reviewer_service_id: 'claude', + reviewer_service_id: null, explicit: false, }); }); diff --git a/src/service-routing.ts b/src/service-routing.ts index 107372a..8f5f6fc 100644 --- a/src/service-routing.ts +++ b/src/service-routing.ts @@ -12,7 +12,7 @@ import { import { clearChannelOwnerLease, getAllChannelOwnerLeases, - getEffectiveRoomMode, + getEffectiveRuntimeRoomMode, getRegisteredAgentTypesForJid, setChannelOwnerLease, type ChannelOwnerLeaseRow, @@ -59,7 +59,7 @@ function getDefaultLease(chatJid: string): EffectiveChannelLease { const types = getRegisteredAgentTypesForJid(chatJid); const hasClaude = types.includes('claude-code'); const hasCodex = types.includes('codex'); - const roomMode = getEffectiveRoomMode(chatJid); + const roomMode = getEffectiveRuntimeRoomMode(chatJid); if (roomMode === 'tribunal') { const ownerServiceId =