Finalize turn-role invariants and legacy migration cutover

This commit is contained in:
ejclaw
2026-04-10 11:44:34 +09:00
parent 7753ee46f0
commit c67bd1c622
45 changed files with 15014 additions and 1381 deletions

View File

@@ -9,6 +9,7 @@ import {
executePendingPairedTurn,
isBotOnlyPairedRoomTurn,
} from './message-runtime-flow.js';
import { buildPairedTurnIdentity } from './paired-turn-identity.js';
import {
advanceLastAgentCursor,
resolveActiveRole,
@@ -202,8 +203,23 @@ export async function runQueuedGroupTurn(args: {
const turnChannel =
turnRole === 'owner' ? args.ownerChannel : roleToChannel[turnRole];
const cursorKey = resolveCursorKeyForRole(chatJid, turnRole);
const forcedRole =
task && turnRole !== resolveActiveRole(taskStatus) ? turnRole : undefined;
const forcedRole = task ? turnRole : undefined;
const queuedIntentKind = task
? resolveQueuedTurnReservationIntent({
task,
turnRole,
hasHumanMessage: hasHumanMsg,
})
: null;
const pairedTurnIdentity =
task && queuedIntentKind
? buildPairedTurnIdentity({
taskId: task.id,
taskUpdatedAt: task.updated_at,
intentKind: queuedIntentKind,
role: turnRole,
})
: undefined;
let prompt: string;
if (turnRole === 'arbiter' && task) {
@@ -257,16 +273,11 @@ export async function runQueuedGroupTurn(args: {
}
if (task) {
const intentKind = resolveQueuedTurnReservationIntent({
task,
turnRole,
hasHumanMessage: hasHumanMsg,
});
const claimed = claimPairedTurnExecution({
chatJid,
runId,
task,
intentKind,
intentKind: queuedIntentKind!,
});
if (!claimed) {
log.info(
@@ -274,7 +285,7 @@ export async function runQueuedGroupTurn(args: {
taskId: task.id,
taskStatus,
taskUpdatedAt: task.updated_at,
intentKind,
intentKind: queuedIntentKind,
turnRole,
},
'Skipped queued paired turn because the task revision was already claimed elsewhere',
@@ -304,6 +315,7 @@ export async function runQueuedGroupTurn(args: {
endSeq,
hasHumanMessage: hasHumanMsg,
forcedRole,
pairedTurnIdentity,
});
if (!deliverySucceeded) {