When Claude hit a limit the run was handed to a Codex service (codex-main/codex-review) through service_handoffs and a global owner failover. That service does not exist in this deployment, so handoffs stayed pending forever (2 rows since May) and the user got no answer. Removed: - handoff creation (message-agent-executor-handoff, paired-turn-fallback) and the delegated paired-execution path - the pending-handoff poll/claim worker (message-runtime-handoffs) and the service_handoffs CRUD module (db/service-handoffs, db exports) - global owner failover in service-routing, its recovery timer in index, the dashboard failover line, the codex-review failover prompt pack and prompts/codex-review-failover-platform.md - failoverOwner in RoomRoleContext and the `failover=` ROOM_ROLE field - OWNER_/REVIEWER_/ARBITER_FALLBACK_ENABLED and FAILOVER_MIN_DURATION_MS - tests for the removed behaviour Now, when a Claude run fails with a usage/rate limit (trigger reason 429 or usage-exhausted) the executor closes the open paired task as completed/claude_usage_limit and sends the room one final notice: "Claude 사용 한도에 도달했습니다. 21:40에 재개할 수 있습니다." The reset time comes from the error text (CLI banner "resets 9:40pm (Asia/Seoul)", dated banners, "try again at ...", ISO timestamps), else from the cached usage API window at 100%, else "잠시 후 다시 시도해 주세요". Nothing retries silently; the next user message starts a new task. Other Claude failures (session failure, org access denied) now end as ordinary run errors. The service_handoffs table, its columns on paired_turn_attempts and the migrations stay untouched for the later migration squash; the runtime no longer reads or writes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
142 lines
6.1 KiB
TypeScript
142 lines
6.1 KiB
TypeScript
import { loadConfig } from './config/load-config.js';
|
|
import type { RoleModelConfig } from './config/schema.js';
|
|
|
|
export type { AppConfig, RoleModelConfig } from './config/schema.js';
|
|
export { loadConfig } from './config/load-config.js';
|
|
|
|
const CONFIG = loadConfig();
|
|
|
|
export const ASSISTANT_NAME = CONFIG.assistant.name;
|
|
export const ASSISTANT_HAS_OWN_NUMBER = CONFIG.assistant.hasOwnNumber;
|
|
export const SERVICE_ID = CONFIG.service.id;
|
|
export const CLAUDE_SERVICE_ID = CONFIG.service.claudeId;
|
|
export const CODEX_MAIN_SERVICE_ID = CONFIG.service.codexMainId;
|
|
export const CODEX_REVIEW_SERVICE_ID = CONFIG.service.codexReviewId;
|
|
|
|
export function normalizeServiceId(serviceId: string): string {
|
|
if (serviceId === 'codex') {
|
|
return CODEX_MAIN_SERVICE_ID;
|
|
}
|
|
return serviceId;
|
|
}
|
|
|
|
export const SERVICE_SESSION_SCOPE = normalizeServiceId(SERVICE_ID);
|
|
export const CURRENT_RUNTIME_AGENT_TYPE =
|
|
SERVICE_SESSION_SCOPE === CLAUDE_SERVICE_ID ? 'claude-code' : 'codex';
|
|
|
|
export function isClaudeService(serviceId: string = SERVICE_ID): boolean {
|
|
return normalizeServiceId(serviceId) === CLAUDE_SERVICE_ID;
|
|
}
|
|
|
|
export function isReviewService(serviceId: string = SERVICE_ID): boolean {
|
|
return normalizeServiceId(serviceId) === CODEX_REVIEW_SERVICE_ID;
|
|
}
|
|
export const POLL_INTERVAL = CONFIG.runtime.pollInterval;
|
|
export const SCHEDULER_POLL_INTERVAL = CONFIG.runtime.schedulerPollInterval;
|
|
|
|
export const SENDER_ALLOWLIST_PATH = CONFIG.paths.senderAllowlistPath;
|
|
export const STORE_DIR = CONFIG.paths.storeDir;
|
|
export const GROUPS_DIR = CONFIG.paths.groupsDir;
|
|
export const DATA_DIR = CONFIG.paths.dataDir;
|
|
export const CACHE_DIR = CONFIG.paths.cacheDir;
|
|
|
|
export const AGENT_TIMEOUT = CONFIG.runtime.agentTimeout;
|
|
export const AGENT_MAX_OUTPUT_SIZE = CONFIG.runtime.agentMaxOutputSize;
|
|
export const IPC_POLL_INTERVAL = CONFIG.runtime.ipcPollInterval;
|
|
export const IDLE_TIMEOUT = CONFIG.runtime.idleTimeout;
|
|
export const MAX_CONCURRENT_AGENTS = CONFIG.runtime.maxConcurrentAgents;
|
|
export const RECOVERY_CONCURRENT_AGENTS =
|
|
CONFIG.runtime.recoveryConcurrentAgents;
|
|
export const LOG_LEVEL = CONFIG.logging.level;
|
|
export const IS_TEST_ENV = CONFIG.logging.isTestEnv;
|
|
|
|
// ── Paired review ─────────────────────────────────────────────────
|
|
|
|
/** Owner agent type. Default: codex. Set OWNER_AGENT_TYPE=claude-code to use Claude as owner. */
|
|
export const OWNER_AGENT_TYPE = CONFIG.paired.ownerAgentType;
|
|
|
|
/** Reviewer agent type. Default: claude-code. Set REVIEWER_AGENT_TYPE=codex to use Codex as reviewer. */
|
|
export const REVIEWER_AGENT_TYPE = CONFIG.paired.reviewerAgentType;
|
|
|
|
/** Service ID for the reviewer based on agent type. */
|
|
export const REVIEWER_SERVICE_ID_FOR_TYPE =
|
|
CONFIG.paired.reviewerServiceIdForType;
|
|
|
|
/** Arbiter agent type. Disabled by default. Set ARBITER_AGENT_TYPE=codex or claude-code to enable. */
|
|
export const ARBITER_AGENT_TYPE = CONFIG.paired.arbiterAgentType;
|
|
|
|
/** Service ID for the arbiter. Defaults to codex-review for internal routing when arbiter is enabled. */
|
|
export const ARBITER_SERVICE_ID = CONFIG.paired.arbiterServiceId;
|
|
|
|
/** Whether to re-inject the previous task's latest owner final into a superseding task. Default: false. */
|
|
export const PAIRED_CARRY_FORWARD_LATEST_OWNER_FINAL =
|
|
CONFIG.paired.carryForwardLatestOwnerFinal;
|
|
|
|
/** Whether unsafe-host Claude reviewers must always start on a fresh SDK session. Default: false. */
|
|
export const PAIRED_FORCE_FRESH_CLAUDE_REVIEWER_SESSION =
|
|
CONFIG.paired.forceFreshClaudeReviewerSessionInUnsafeHostMode;
|
|
|
|
export function shouldForceFreshClaudeReviewerSessionInUnsafeHostMode(): boolean {
|
|
return PAIRED_FORCE_FRESH_CLAUDE_REVIEWER_SESSION;
|
|
}
|
|
|
|
/** Language for agent responses. When set, a language instruction is appended to all paired room prompts. */
|
|
export const AGENT_LANGUAGE = CONFIG.paired.agentLanguage;
|
|
|
|
/** Number of consecutive owner↔reviewer round trips before arbiter is auto-requested. */
|
|
export const ARBITER_DEADLOCK_THRESHOLD =
|
|
CONFIG.paired.arbiterDeadlockThreshold;
|
|
|
|
/**
|
|
* Maximum number of times the arbiter may intervene on a single task before the
|
|
* task is escalated to the user instead of re-invoking the arbiter. This bounds
|
|
* the owner↔reviewer↔arbiter loop: once the arbiter has ruled this many times
|
|
* and the loop still deadlocks, a human is asked to step in.
|
|
*/
|
|
export const ARBITER_MAX_INTERVENTIONS = CONFIG.paired.arbiterMaxInterventions;
|
|
|
|
export function isArbiterEnabled(): boolean {
|
|
return ARBITER_AGENT_TYPE !== undefined;
|
|
}
|
|
|
|
// ── Per-role model configuration ─────────────────────────────────
|
|
|
|
export const OWNER_MODEL_CONFIG = CONFIG.models.owner;
|
|
export const REVIEWER_MODEL_CONFIG = CONFIG.models.reviewer;
|
|
export const ARBITER_MODEL_CONFIG = CONFIG.models.arbiter;
|
|
export const DEFAULT_CLAUDE_MODEL = CONFIG.providers.claudeDefaultModel;
|
|
export const DEFAULT_CODEX_MODEL = CONFIG.providers.codexDefaultModel;
|
|
|
|
export function getRoleModelConfig(
|
|
role: 'owner' | 'reviewer' | 'arbiter',
|
|
): RoleModelConfig {
|
|
switch (role) {
|
|
case 'owner':
|
|
return OWNER_MODEL_CONFIG;
|
|
case 'reviewer':
|
|
return REVIEWER_MODEL_CONFIG;
|
|
case 'arbiter':
|
|
return ARBITER_MODEL_CONFIG;
|
|
}
|
|
}
|
|
|
|
export const PAIRED_MAX_ROUND_TRIPS = CONFIG.paired.maxRoundTrips;
|
|
|
|
export const RECOVERY_STAGGER_MS = CONFIG.runtime.recoveryStaggerMs;
|
|
export const RECOVERY_DURATION_MS = CONFIG.runtime.recoveryDurationMs;
|
|
|
|
export const TRIGGER_PATTERN = CONFIG.assistant.triggerPattern;
|
|
|
|
// Status dashboard: Discord channel ID for live agent status updates
|
|
export const STATUS_CHANNEL_ID = CONFIG.status.channelId;
|
|
export const STATUS_UPDATE_INTERVAL = CONFIG.status.updateInterval;
|
|
export const USAGE_UPDATE_INTERVAL = CONFIG.status.usageUpdateInterval;
|
|
export const STATUS_SHOW_ROOMS = CONFIG.status.showRooms;
|
|
export const STATUS_SHOW_ROOM_DETAILS = CONFIG.status.showRoomDetails;
|
|
export const USAGE_DASHBOARD_ENABLED = CONFIG.status.usageDashboardEnabled;
|
|
export const CODEX_WARMUP_CONFIG = CONFIG.codexWarmup;
|
|
|
|
// Timezone for scheduled tasks (cron expressions, etc.)
|
|
// Uses system timezone by default
|
|
export const TIMEZONE = CONFIG.status.timezone;
|