Fix owner context loss after finalize; green the test suite

Owner continuity:
- Seed a freshly created owner task with the previous task's latest owner
  final on a cold start after the previous task already closed, so a user
  reply to a finalized TASK_DONE no longer produces a "no context" answer.
  Activated for this deployment via PAIRED_CARRY_FORWARD_LATEST_OWNER_FINAL
  (.env); carried text is injected as clearly-marked background only.
- Skip intermediate STEP_DONE outputs when picking the carry-forward anchor.

Single-mode routing:
- enforceRoomModeOnLease strips a stale reviewer/arbiter lease from a room
  switched back to single, preventing single-mode messages from stalling in
  the paired path on a stuck execution lease.

Session auth / credentials:
- Pre-sync Claude credentials into each session dir before the agent spawns.
- Honor CLAUDE_CREDENTIALS_PATH in setup/login.ts (per-service isolation).
- Add a relogin-required gate so a permanently logged-out claude-code room
  asks the user to re-login instead of spawning a doomed agent.

Other:
- Arbiter verdicts written in the user's language (verdict keyword stays EN).
- status-dashboard chatName field; runtime-inventory credential path resolver.

Tests (make suite fully green: 1595 pass / 3 skip):
- service-routing: default owner is now the claude service and reviewer is
  codex-review; update the 7 failover/default expectations accordingly.
- migrate-room-registrations: owner inferred as claude-code (configured
  OWNER_AGENT_TYPE) for a dual legacy room; reviewer becomes codex.
- register: mock paired-workspace provisioning + reload signal (registration
  now provisions a workspace and hot-reloads); assert RELOADED status.
- paired-execution-context: force a claude-code reviewer to exercise the
  Claude read-only branch regardless of the deployment default.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-08-25 18:40:14 +09:00
parent 80df025672
commit 712664ca00
17 changed files with 457 additions and 91 deletions

View File

@@ -36,6 +36,10 @@ import {
hasHumanMessageAfterWorkItem,
} from './message-runtime-preflight-messages.js';
import { deliverCanonicalOutboundMessage } from './ipc-outbound-delivery.js';
import {
isReloginRequired,
RELOGIN_REQUIRED_MESSAGE,
} from './token-refresh.js';
import { findChannel, formatMessages } from './router.js';
import { createScopedLogger, logger } from './logger.js';
import type { AgentOutput } from './agent-runner.js';
@@ -308,6 +312,15 @@ async function processMissedMessages(
return gateOutcome;
}
const reloginOutcome = await runReloginRequiredGate(
args,
runtime,
missedMessages,
);
if (reloginOutcome !== null) {
return reloginOutcome;
}
return runQueuedGroupTurn({
chatJid: runtime.chatJid,
group: runtime.group,
@@ -415,6 +428,48 @@ function advancePastBotOnlyCollaboration(
);
}
/**
* When Claude OAuth auto-refresh has permanently given up (login lost and the
* refresh token is dead — see token-refresh.ts), don't spawn a doomed agent.
* Instead reply once, in this chat, asking the user to re-login, then advance
* the cursor so a still-logged-out bot doesn't re-notify on every poll. The
* next fresh incoming request re-triggers the notice. Recovers automatically
* once a manual re-login writes a valid token (isReloginRequired() clears).
*
* Returns true when the notice was sent (turn handled), null to fall through.
*/
async function runReloginRequiredGate(
args: ProcessGroupMessagesDeps,
runtime: RuntimeContext,
missedMessages: NewMessage[],
): Promise<boolean | null> {
// Only claude-code turns depend on the Claude OAuth token. Codex-backed
// groups authenticate separately and must not be blocked here.
const agentType = runtime.group.agentType ?? 'claude-code';
if (agentType !== 'claude-code') return null;
if (!isReloginRequired()) return null;
await deliverSessionCommandMessage(
args,
runtime.chatJid,
RELOGIN_REQUIRED_MESSAGE,
);
const lastMessage = missedMessages[missedMessages.length - 1];
if (lastMessage?.seq != null) {
advanceLastAgentCursor(
args.getLastAgentTimestamps(),
args.saveState,
runtime.chatJid,
lastMessage.seq,
);
}
runtime.log.warn(
'Claude OAuth login lost (gave up refreshing) — asked user to re-login instead of running the agent',
);
return true;
}
async function runQueuedRunGates(
args: ProcessGroupMessagesDeps,
runtime: RuntimeContext,