Refactor local memory and role-fixed runtime routing

This commit is contained in:
Eyejoker
2026-04-04 03:50:28 +09:00
parent ca58e8c8eb
commit 3dd772c229
47 changed files with 6158 additions and 669 deletions

View File

@@ -55,21 +55,29 @@ const group: RegisteredGroup = {
};
const ownerContext: RoomRoleContext = {
serviceId: 'codex-main',
serviceId: config.CODEX_MAIN_SERVICE_ID,
role: 'owner',
ownerServiceId: 'codex-main',
reviewerServiceId: 'codex-review',
ownerServiceId: config.CODEX_MAIN_SERVICE_ID,
reviewerServiceId: config.REVIEWER_SERVICE_ID_FOR_TYPE,
failoverOwner: false,
};
const reviewerContext: RoomRoleContext = {
serviceId: 'codex-review',
serviceId: config.REVIEWER_SERVICE_ID_FOR_TYPE,
role: 'reviewer',
ownerServiceId: 'codex-main',
reviewerServiceId: 'codex-review',
ownerServiceId: config.CODEX_MAIN_SERVICE_ID,
reviewerServiceId: config.REVIEWER_SERVICE_ID_FOR_TYPE,
failoverOwner: false,
};
const failoverOwnerContext: RoomRoleContext = {
serviceId: config.CODEX_REVIEW_SERVICE_ID,
role: 'owner',
ownerServiceId: config.CODEX_REVIEW_SERVICE_ID,
reviewerServiceId: config.REVIEWER_SERVICE_ID_FOR_TYPE,
failoverOwner: true,
};
function createCanonicalRepoWithCommit(commitMessage: string): string {
const repoDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-finalize-'));
execFileSync('git', ['init'], { cwd: repoDir, stdio: 'ignore' });
@@ -103,8 +111,8 @@ function buildPairedTask(overrides: Partial<PairedTask> = {}): PairedTask {
id: 'task-1',
chat_jid: 'dc:test',
group_folder: group.folder,
owner_service_id: 'codex-main',
reviewer_service_id: 'codex-review',
owner_service_id: config.CODEX_MAIN_SERVICE_ID,
reviewer_service_id: config.REVIEWER_SERVICE_ID_FOR_TYPE,
title: null,
source_ref: 'HEAD',
plan_notes: null,
@@ -181,7 +189,12 @@ describe('paired execution context', () => {
expect(db.createPairedTask).toHaveBeenCalledTimes(1);
expect(db.createPairedTask).toHaveBeenCalledWith(
expect.objectContaining({
owner_service_id: config.CODEX_MAIN_SERVICE_ID,
reviewer_service_id: config.REVIEWER_SERVICE_ID_FOR_TYPE,
status: 'active',
owner_agent_type: 'codex',
reviewer_agent_type: config.REVIEWER_AGENT_TYPE,
arbiter_agent_type: config.ARBITER_AGENT_TYPE ?? null,
}),
);
expect(result?.envOverrides).toMatchObject({
@@ -190,6 +203,25 @@ describe('paired execution context', () => {
});
});
it('persists stable role-slot service shadow instead of the transient failover owner lease', () => {
preparePairedExecutionContext({
group,
chatJid: 'dc:test',
runId: 'run-failover-owner',
roomRoleContext: failoverOwnerContext,
hasHumanMessage: true,
});
expect(db.createPairedTask).toHaveBeenCalledWith(
expect.objectContaining({
owner_service_id: config.CODEX_MAIN_SERVICE_ID,
reviewer_service_id: config.REVIEWER_SERVICE_ID_FOR_TYPE,
owner_agent_type: 'codex',
reviewer_agent_type: config.REVIEWER_AGENT_TYPE,
}),
);
});
it('uses the reviewer snapshot after lazy auto-refresh and marks the task in_review', () => {
vi.mocked(db.getLatestOpenPairedTaskForChat).mockReturnValue({
id: 'task-1',