mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-30 17:14:54 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Task execution recovery prevents failed, timed-out, or interrupted runs from leaving tasks permanently blocked. > - Three concrete recovery gaps still leave tasks stuck: `hermes_gateway` is omitted from `CONVERSATION_ADAPTER_TYPES` (so timed-out/cancelled runs stick in `legacy_execution_requires_reconciliation`), terminal `hermes_gateway` 429/529 failures omit `errorFamily` (so bounded transient retry never fires), and automatic continuation after a non-retryable workspace `binding_mismatch` chooses `writer_ended` (reusing the broken workspace in a loop) while stranded notices omit the saved failure reason. > - Users cannot unblock `hermes_gateway` tasks via Retry or board comments, transient provider rate limits park tasks indefinitely, and `binding_mismatch` tasks exhaust the hourly retry cap with only a generic chat notice. > - This pull request adds `hermes_gateway` to conversation continuation and explicit continuation admission (delegating terminal stop proof to the Hermes adapter), classifies terminal `hermes_gateway` 429/529/5xx/quota/gateway-shutdown failures with `errorFamily` and `retryNotBefore`, switches automatic continuation to `fresh_isolated_workspace` on non-retryable `binding_mismatch`, and surfaces the Core-owned failure reason in stranded no-running-execution notices. > - The benefit is that stuck `hermes_gateway` holds clear cleanly when stopped, transient upstream errors retry automatically, and `binding_mismatch` continuations start in a fresh isolated workspace with clear user-facing diagnostics. ## Linked Issues or Issue Description - Fixes: #17196 - Fixes: #17526 - Refs #21289 (extends non-retryable `binding_mismatch` fresh-workspace handling from manual board Retry to automatic continuation fallback and stranded recovery notices) - Related open PRs checked during dedup search (no overlap): #22756, #22810, #22738 ## What Changed - **`hermes_gateway` conversation continuation and hold clearing (#17196)**: - Add `"hermes_gateway"` to `CONVERSATION_ADAPTER_TYPES` in `server/src/services/conversation-continuation.ts` so failed, interrupted, and acknowledged-cancelled `hermes_gateway` runs receive `conversationContinuation` policy and matching holds retire cleanly. - Export `hasHermesGatewayTerminalStopProof` from `@paperclipai/hermes-paperclip-adapter/gateway/server` (`packages/adapters/hermes/src/gateway/server/terminal-failure.ts`) and consume its boolean result in `server/src/services/explicit-native-continuation.ts` so pre-existing `legacy_execution_requires_reconciliation` holds for remote `hermes_gateway` runs clear `process_identity_missing` only when the Hermes adapter confirms a terminal gateway response or pre-fetch configuration error, while unconfirmed `hermes_gateway` timeouts fail closed. - **`hermes_gateway` terminal transient/quota classification (#17526)**: - Extract terminal error classification into `packages/adapters/hermes/src/gateway/server/terminal-failure.ts` and wire it in `packages/adapters/hermes/src/gateway/server/execute.ts` (`extractErrorMessage`, `classifyTerminalFailure`, `mapFinalResultForTest`) to classify terminal provider 429/529/5xx/rate-limit/overload errors (including camelCase `statusCode`/`httpStatus`, `HTTP/x.y` status lines, and `Bad Gateway`/`Gateway Timeout` phrases) as `errorFamily: "transient_upstream"`, structured/message quota errors (including `insufficient_quota`) as `errorFamily: "provider_quota"`, and forward range-checked `retryNotBefore` from `retry_not_before` / `retry_after`. - Map unexpected `hermes_gateway` shutdown/restart interruptions (`status: "cancelled"` with shutdown/restart wording) to retryable failed outcomes (`errorCode: "hermes_gateway_run_failed"`, `signal: null`, `errorFamily: "transient_upstream"`, `resultJson: { status: "interrupted", gateway_status: "cancelled" }`) while keeping deliberate cancels as `cancelled`, keeping HTTP 400/403 errors (even with rate-limit/overloaded text) non-transient, and never forging `connectionFailure` from remote text. - **Automatic continuation `binding_mismatch` isolation and saved failure cause**: - Export `readWorkspaceProviderFailure` and `workspaceProviderFailureMessage` in `server/src/services/workspace-provider-failure.ts` using only Core-owned closed messages (no raw provider text). - Update `server/src/services/fresh-continuation-fallback.ts` to choose `isolation: "fresh_isolated_workspace"` instead of `"writer_ended"` strictly when `run.resultJson.workspaceProviderFailure?.retryable === false && workspaceProviderFailure.reason === "binding_mismatch"`, clearing `issues.executionWorkspaceId` and tagging `freshContinuationIsolation` while preserving `"writer_ended"` for retryable and non-binding errors (e.g. `storage_pending`, `credential_unavailable`). - Update `buildNoRunningExecutionNoticeSeed` and `buildImmediateExecutionPathRecoveryNoticeSeed` in `server/src/services/recovery/stranded-notice.ts` to accept typed `WorkspaceProviderFailureSummary | PluginWorkspaceOperationFailureReason | null` (resolving once and dropping unknown strings) and pass `readWorkspaceProviderFailure(latestRun?.resultJson)` from `server/src/services/recovery/service.ts` (minimal argument additions at existing escalation call sites). - **Regression and embedded-Postgres E2E tests**: - Added tests to existing test suites (`packages/adapters/hermes/src/gateway/server/execute.test.ts`, `server/src/services/conversation-continuation.test.ts`, `server/src/services/fresh-continuation-fallback.test.ts`, `server/src/__tests__/workspace-provider-failure.test.ts`, `server/src/__tests__/heartbeat-retry-scheduling.test.ts`, `server/src/services/heartbeat/run-completion.test.ts`) without adding new test files. ## Verification - **Hermes adapter unit tests**: `pnpm --filter @paperclipai/hermes-paperclip-adapter exec vitest run src/gateway/server/execute.test.ts` — 122/122 passed. - **Hermes adapter typecheck**: `pnpm --filter @paperclipai/hermes-paperclip-adapter typecheck` — passed. - **Server typecheck**: `pnpm --filter @paperclipai/server typecheck` — passed (all 7 project layers). - **Module boundaries**: `node scripts/check-module-boundaries.mjs` — passed. - **Server recovery, retry scheduling, `completeRun`, and embedded-Postgres E2E suites**: - `pnpm --filter @paperclipai/server exec vitest run --hookTimeout=60000 src/services/conversation-continuation.test.ts src/__tests__/workspace-provider-failure.test.ts` — 11/11 passed. - `pnpm --filter @paperclipai/server exec vitest run --hookTimeout=60000 src/services/fresh-continuation-fallback.test.ts -t "binding_mismatch|workspaceProviderFailure"` — 3/3 passed. - `pnpm --filter @paperclipai/server exec vitest run --hookTimeout=60000 src/services/heartbeat/run-completion.test.ts -t "hermes_gateway shutdown"` — 1/1 passed. - `pnpm --filter @paperclipai/server exec vitest run --hookTimeout=60000 src/__tests__/heartbeat-retry-scheduling.test.ts -t "hermes_gateway 429"` — 1/1 passed. - **Test budget check**: `node scripts/check-test-budget.mjs --files server/src/services/conversation-continuation.test.ts server/src/services/fresh-continuation-fallback.test.ts server/src/__tests__/workspace-provider-failure.test.ts server/src/__tests__/heartbeat-retry-scheduling.test.ts server/src/services/heartbeat/run-completion.test.ts` — passed. ## Risks - Low risk; no database schema migrations or breaking API changes. - `hermes_gateway` holds without a confirmed terminal gateway response (such as unconfirmed client-side timeouts) intentionally fail closed with `process_identity_missing` to prevent overlapping remote execution. - Only `binding_mismatch` workspace provider failures trigger `fresh_isolated_workspace` on automatic continuation; retryable and non-binding non-retryable failures keep `writer_ended` so usable task workspaces are not discarded. - Stranded recovery notices render only Core-owned closed failure messages and drop unrecognized values, preventing raw provider error strings from reaching issue threads. ## Model Used - Google Gemini (Antigravity agent with tool use and code execution) ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs)
317 lines
16 KiB
TypeScript
317 lines
16 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { and, eq } from "drizzle-orm";
|
|
import { agents, companies, createDb, heartbeatRuns, issueComments, issues, issueRecoveryActions, type Db } from "@paperclipai/db";
|
|
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "../__tests__/helpers/embedded-postgres.js";
|
|
import { CONVERSATION_CONTINUATION_POLICY, conversationRecoveryActionPredicate, getConversationOwnershipBlocker, isConversationAdapter, runUsedConversationAdapter } from "./conversation-continuation.js";
|
|
import { deliverExecutionStatuses } from "./execution-status-delivery.js";
|
|
import { admitExplicitNativeContinuation } from "./explicit-native-continuation.js";
|
|
import { getExecutionBlocker } from "./execution-blocker.js";
|
|
import { legacyExecutionNeedsReconciliation } from "./legacy-execution-recovery.js";
|
|
|
|
const support = await getEmbeddedPostgresTestSupport();
|
|
const describePostgres = support.supported ? describe : describe.skip;
|
|
if (!support.supported) console.warn(`Skipping execution identity regressions: ${support.reason}`);
|
|
|
|
describePostgres("execution identity query contracts", () => {
|
|
let database: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>>;
|
|
let db: Db;
|
|
beforeAll(async () => { database = await startEmbeddedPostgresTestDatabase("execution-identity-"); db = createDb(database.connectionString); }, 20_000);
|
|
afterAll(async () => { await db?.$client.end({ timeout: 0 }); await database?.cleanup(); });
|
|
async function fixture() {
|
|
const companyId = randomUUID(), agentId = randomUUID(), issueId = randomUUID(), otherIssueId = randomUUID();
|
|
await db.insert(companies).values({ id: companyId, name: "Identity", issuePrefix: `I${companyId.slice(0, 7)}` });
|
|
await db.insert(agents).values({ id: agentId, companyId, name: "Fixture", adapterType: "codex_local" });
|
|
await db.insert(issues).values([{ id: issueId, companyId, title: "Target" }, { id: otherIssueId, companyId, title: "Other" }]);
|
|
return { companyId, agentId, issueId, otherIssueId };
|
|
}
|
|
async function run(f: Awaited<ReturnType<typeof fixture>>, context: Record<string, unknown> | null, nativeIssueId: string | null = null, pid: number | null = null) {
|
|
const [row] = await db.insert(heartbeatRuns).values({ companyId: f.companyId, agentId: f.agentId, nativeIssueId,
|
|
status: "interrupted", runtimeMode: "legacy", contextSnapshot: context, processPid: pid,
|
|
runnerProfileJson: { adapterDispatch: { adapterType: "codex_local" } } }).returning();
|
|
return row;
|
|
}
|
|
it("matches only canonical evidence IDs and keeps source issue and company scope", async () => {
|
|
const f = await fixture(), foreign = await fixture();
|
|
const ours = await run(f, { issueId: f.issueId });
|
|
const elsewhere = await run(f, { issueId: f.otherIssueId });
|
|
const foreignRun = await run(foreign, { issueId: f.issueId });
|
|
const ids: unknown[] = [ours.id, ours.id.toUpperCase(), ours.id.replaceAll("-", ""), `{${ours.id}}`, "bad", "", null, 42, {}, [ours.id], elsewhere.id, foreignRun.id];
|
|
const actions = await db.insert(issueRecoveryActions).values(ids.map((runId, index) => ({
|
|
companyId: f.companyId, sourceIssueId: f.issueId, kind: "active_run_watchdog", status: "resolved", ownerType: "board",
|
|
cause: "legacy_execution_requires_reconciliation", fingerprint: `fixture-${index}`, evidence: { runId }, nextAction: "Fixture",
|
|
}))).returning();
|
|
const matches = await db.select({ id: issueRecoveryActions.id }).from(issueRecoveryActions)
|
|
.where(and(eq(issueRecoveryActions.companyId, f.companyId), conversationRecoveryActionPredicate()));
|
|
expect(matches).toEqual([{ id: actions[0].id }]);
|
|
});
|
|
it("preserves native issue precedence and does not broaden legacy spellings", async () => {
|
|
const f = await fixture();
|
|
await run(f, { issueId: f.issueId }, f.otherIssueId, process.pid);
|
|
const uppercase = await run(f, { issueId: f.issueId.toUpperCase() }, null, process.pid);
|
|
const malformed = await run(f, { issueId: "bad" }, null, process.pid);
|
|
expect(await getConversationOwnershipBlocker(db, f.companyId, f.issueId)).toBeNull();
|
|
const native = await run(f, { issueId: f.otherIssueId }, f.issueId, process.pid);
|
|
expect(await getConversationOwnershipBlocker(db, f.companyId, f.issueId)).toMatchObject({ runId: native.id, cause: "execution_owner_active" });
|
|
expect(await getConversationOwnershipBlocker(db, f.companyId, f.issueId.toUpperCase())).toMatchObject({ runId: uppercase.id });
|
|
expect(await getConversationOwnershipBlocker(db, f.companyId, "bad")).toMatchObject({ runId: malformed.id });
|
|
});
|
|
it("retains legacy ownership holds and releases only after ownership ends", async () => {
|
|
const f = await fixture();
|
|
const legacy = await run(f, { issueId: f.issueId }, null, process.pid);
|
|
expect(await getConversationOwnershipBlocker(db, f.companyId, f.issueId)).toMatchObject({ runId: legacy.id });
|
|
await db.update(heartbeatRuns).set({ processPid: null }).where(eq(heartbeatRuns.id, legacy.id));
|
|
expect(await getConversationOwnershipBlocker(db, f.companyId, f.issueId)).toBeNull();
|
|
});
|
|
it("delivers canonical same-company task IDs and keeps malformed IDs private", async () => {
|
|
const f = await fixture(), foreign = await fixture();
|
|
const contexts: unknown[] = [f.issueId, f.issueId.toUpperCase(), "bad", `{${f.issueId}}`, f.issueId.replaceAll("-", ""), null, 42, {}, [f.issueId], foreign.issueId];
|
|
const expected = new Map<string, string | null>();
|
|
for (const [index, issueId] of contexts.entries()) {
|
|
const row = await run(f, { issueId });
|
|
await db.update(heartbeatRuns).set({ executionStatusDeliveryId: randomUUID() }).where(eq(heartbeatRuns.id, row.id));
|
|
expected.set(row.id, index === 0 ? f.issueId : null);
|
|
}
|
|
const native = await run(f, { issueId: f.otherIssueId }, f.issueId);
|
|
await db.update(heartbeatRuns).set({ executionStatusDeliveryId: randomUUID() }).where(eq(heartbeatRuns.id, native.id));
|
|
expected.set(native.id, f.issueId);
|
|
const seen = new Map<string, string | null>();
|
|
const result = await deliverExecutionStatuses(db, { publish: event => { seen.set(event.payload!.runId as string, event.payload!.issueId as string | null); return { ...event, id: 0, payload: event.payload ?? {}, createdAt: new Date().toISOString() }; } });
|
|
expect(result.delivered).toBe(expected.size);
|
|
expect(seen).toEqual(expected);
|
|
expect(await deliverExecutionStatuses(db, { publish: () => { throw new Error("duplicate delivery"); } })).toEqual({ scanned: 0, delivered: 0 });
|
|
});
|
|
|
|
it("treats hermes_gateway as a conversation adapter and lets Retry and board comments clear timed-out or cancelled holds", async () => {
|
|
expect(isConversationAdapter("hermes_gateway")).toBe(true);
|
|
|
|
const f = await fixture();
|
|
await db.update(agents).set({ adapterType: "hermes_gateway" }).where(eq(agents.id, f.agentId));
|
|
await db.update(issues).set({ status: "blocked", assigneeAgentId: f.agentId }).where(eq(issues.id, f.issueId));
|
|
|
|
const timedOutRunId = randomUUID();
|
|
const finishedAt = new Date("2026-09-11T10:00:00Z");
|
|
await db.insert(heartbeatRuns).values({
|
|
id: timedOutRunId,
|
|
companyId: f.companyId,
|
|
agentId: f.agentId,
|
|
issueId: f.issueId,
|
|
status: "timed_out",
|
|
errorCode: "hermes_gateway_timeout",
|
|
runtimeMode: "legacy",
|
|
processPid: null,
|
|
processGroupId: null,
|
|
finishedAt,
|
|
contextSnapshot: { issueId: f.issueId },
|
|
runnerProfileJson: { adapterDispatch: { adapterType: "hermes_gateway" } },
|
|
resultJson: { run_id: "hermes-remote-1", status: "cancelled" },
|
|
});
|
|
const [hold] = await db.insert(issueRecoveryActions).values({
|
|
companyId: f.companyId,
|
|
sourceIssueId: f.issueId,
|
|
kind: "active_run_watchdog",
|
|
status: "resolved",
|
|
outcome: "blocked",
|
|
ownerType: "board",
|
|
cause: "legacy_execution_requires_reconciliation",
|
|
fingerprint: `legacy-execution:${timedOutRunId}`,
|
|
evidence: { runId: timedOutRunId, automaticRecovery: { replay: "blocked", actionOutcome: "unknown" } },
|
|
nextAction: "Inspect the stopped run before continuing.",
|
|
}).returning();
|
|
|
|
// Hold is currently blocking until user Retry or board comment arrives.
|
|
expect(await getExecutionBlocker(db, f.companyId, f.issueId)).toMatchObject({ recoveryActionId: hold!.id });
|
|
|
|
// (a) Board Retry clears the timed-out hermes_gateway hold (no local PID exists for gateway runs).
|
|
const retryBlocked: string[] = [];
|
|
const retryAdmitted = await admitExplicitNativeContinuation({
|
|
db,
|
|
companyId: f.companyId,
|
|
issueId: f.issueId,
|
|
agentId: f.agentId,
|
|
actorType: "user",
|
|
actorId: "board",
|
|
reason: "retry_failed_run",
|
|
commentId: null,
|
|
failedRunId: timedOutRunId,
|
|
successorRunId: randomUUID(),
|
|
dryRun: true,
|
|
onBlocked: reason => retryBlocked.push(reason),
|
|
});
|
|
expect(retryBlocked).toEqual([]);
|
|
expect(retryAdmitted).toMatchObject({ previousRunId: timedOutRunId, failedRunId: timedOutRunId });
|
|
|
|
// (b) Board comment also clears the timed-out hermes_gateway hold.
|
|
const commentId = randomUUID();
|
|
await db.insert(issueComments).values({
|
|
id: commentId,
|
|
companyId: f.companyId,
|
|
issueId: f.issueId,
|
|
authorType: "user",
|
|
authorUserId: "board",
|
|
body: "Please continue with the remaining steps.",
|
|
createdAt: new Date("2026-09-11T10:05:00Z"),
|
|
});
|
|
const commentBlocked: string[] = [];
|
|
const commentAdmitted = await admitExplicitNativeContinuation({
|
|
db,
|
|
companyId: f.companyId,
|
|
issueId: f.issueId,
|
|
agentId: f.agentId,
|
|
actorType: "user",
|
|
actorId: "board",
|
|
reason: "issue_commented",
|
|
commentId,
|
|
successorRunId: randomUUID(),
|
|
onBlocked: reason => commentBlocked.push(reason),
|
|
});
|
|
expect(commentBlocked).toEqual([]);
|
|
expect(commentAdmitted).toMatchObject({ previousRunId: timedOutRunId, commentId });
|
|
expect(await getExecutionBlocker(db, f.companyId, f.issueId)).toBeNull();
|
|
|
|
// (c) New hermes_gateway runs with conversationContinuation policy are retired by conversationRecoveryActionPredicate.
|
|
const policyRunId = randomUUID();
|
|
await db.insert(heartbeatRuns).values({
|
|
id: policyRunId,
|
|
companyId: f.companyId,
|
|
agentId: f.agentId,
|
|
issueId: f.otherIssueId,
|
|
status: "timed_out",
|
|
errorCode: "hermes_gateway_timeout",
|
|
runtimeMode: "legacy",
|
|
finishedAt,
|
|
contextSnapshot: { issueId: f.otherIssueId },
|
|
runnerProfileJson: { adapterDispatch: { adapterType: "hermes_gateway" } },
|
|
resultJson: { status: "cancelled", conversationContinuation: CONVERSATION_CONTINUATION_POLICY },
|
|
});
|
|
const [policyHold] = await db.insert(issueRecoveryActions).values({
|
|
companyId: f.companyId,
|
|
sourceIssueId: f.otherIssueId,
|
|
kind: "active_run_watchdog",
|
|
status: "resolved",
|
|
ownerType: "board",
|
|
cause: "legacy_execution_requires_reconciliation",
|
|
fingerprint: `legacy-execution:${policyRunId}`,
|
|
evidence: { runId: policyRunId },
|
|
nextAction: "Fixture",
|
|
}).returning();
|
|
const matched = await db.select({ id: issueRecoveryActions.id }).from(issueRecoveryActions)
|
|
.where(and(eq(issueRecoveryActions.id, policyHold!.id), conversationRecoveryActionPredicate()));
|
|
expect(matched).toEqual([{ id: policyHold!.id }]);
|
|
|
|
// (d) A cancelled hermes_gateway run (e.g. issue_reassigned) also unblocks on a new board comment.
|
|
const cancelledIssueId = randomUUID();
|
|
const cancelledRunId = randomUUID();
|
|
await db.insert(issues).values({ id: cancelledIssueId, companyId: f.companyId, title: "Cancelled Hermes", status: "blocked", assigneeAgentId: f.agentId });
|
|
await db.insert(heartbeatRuns).values({
|
|
id: cancelledRunId,
|
|
companyId: f.companyId,
|
|
agentId: f.agentId,
|
|
issueId: cancelledIssueId,
|
|
status: "cancelled",
|
|
errorCode: "issue_reassigned",
|
|
runtimeMode: "legacy",
|
|
processPid: null,
|
|
processGroupId: null,
|
|
finishedAt,
|
|
contextSnapshot: { issueId: cancelledIssueId },
|
|
runnerProfileJson: { adapterDispatch: { adapterType: "hermes_gateway" } },
|
|
resultJson: { run_id: "hermes-remote-2", status: "cancelled" },
|
|
});
|
|
await db.insert(issueRecoveryActions).values({
|
|
companyId: f.companyId,
|
|
sourceIssueId: cancelledIssueId,
|
|
kind: "active_run_watchdog",
|
|
status: "resolved",
|
|
outcome: "blocked",
|
|
ownerType: "board",
|
|
cause: "legacy_execution_requires_reconciliation",
|
|
fingerprint: `legacy-execution:${cancelledRunId}`,
|
|
evidence: { runId: cancelledRunId, automaticRecovery: { replay: "blocked", actionOutcome: "unknown" } },
|
|
nextAction: "Inspect the stopped run before continuing.",
|
|
});
|
|
const followUpCommentId = randomUUID();
|
|
await db.insert(issueComments).values({
|
|
id: followUpCommentId,
|
|
companyId: f.companyId,
|
|
issueId: cancelledIssueId,
|
|
authorType: "user",
|
|
authorUserId: "board",
|
|
body: "Reassigned back to you, please continue.",
|
|
createdAt: new Date("2026-09-11T10:10:00Z"),
|
|
});
|
|
const cancelledBlocked: string[] = [];
|
|
const cancelledAdmitted = await admitExplicitNativeContinuation({
|
|
db,
|
|
companyId: f.companyId,
|
|
issueId: cancelledIssueId,
|
|
agentId: f.agentId,
|
|
actorType: "user",
|
|
actorId: "board",
|
|
reason: "issue_commented",
|
|
commentId: followUpCommentId,
|
|
successorRunId: randomUUID(),
|
|
onBlocked: reason => cancelledBlocked.push(reason),
|
|
});
|
|
expect(cancelledBlocked).toEqual([]);
|
|
expect(cancelledAdmitted).toMatchObject({ previousRunId: cancelledRunId, commentId: followUpCommentId });
|
|
expect(await getExecutionBlocker(db, f.companyId, cancelledIssueId)).toBeNull();
|
|
|
|
// (e) A timed-out hermes_gateway run whose remote stop was never confirmed (status: "timeout") fails closed
|
|
// across reconciliation classification, conversation hold retirement, execution blocking, and explicit Retry.
|
|
const unconfirmedIssueId = randomUUID();
|
|
const unconfirmedRunId = randomUUID();
|
|
await db.insert(issues).values({ id: unconfirmedIssueId, companyId: f.companyId, title: "Unconfirmed Hermes timeout", status: "blocked", assigneeAgentId: f.agentId });
|
|
const [unconfirmedRun] = await db.insert(heartbeatRuns).values({
|
|
id: unconfirmedRunId,
|
|
companyId: f.companyId,
|
|
agentId: f.agentId,
|
|
issueId: unconfirmedIssueId,
|
|
status: "timed_out",
|
|
errorCode: "execution_reconciliation_required",
|
|
runtimeMode: "legacy",
|
|
processPid: null,
|
|
processGroupId: null,
|
|
finishedAt,
|
|
contextSnapshot: { issueId: unconfirmedIssueId },
|
|
runnerProfileJson: { adapterDispatch: { adapterType: "hermes_gateway" } },
|
|
resultJson: { run_id: "hermes-remote-3", status: "timeout" },
|
|
}).returning();
|
|
expect(legacyExecutionNeedsReconciliation(unconfirmedRun!)).toBe(true);
|
|
expect(await runUsedConversationAdapter(db, unconfirmedRun!)).toBe(false);
|
|
const [unconfirmedHold] = await db.insert(issueRecoveryActions).values({
|
|
companyId: f.companyId,
|
|
sourceIssueId: unconfirmedIssueId,
|
|
kind: "active_run_watchdog",
|
|
status: "resolved",
|
|
outcome: "blocked",
|
|
ownerType: "board",
|
|
cause: "legacy_execution_requires_reconciliation",
|
|
fingerprint: `legacy-execution:${unconfirmedRunId}`,
|
|
evidence: { runId: unconfirmedRunId, automaticRecovery: { replay: "blocked", actionOutcome: "unknown" } },
|
|
nextAction: "Inspect the stopped run before continuing.",
|
|
}).returning();
|
|
const unconfirmedRetired = await db.select({ id: issueRecoveryActions.id }).from(issueRecoveryActions)
|
|
.where(and(eq(issueRecoveryActions.id, unconfirmedHold!.id), conversationRecoveryActionPredicate()));
|
|
expect(unconfirmedRetired).toEqual([]);
|
|
const unconfirmedBlocked: string[] = [];
|
|
const unconfirmedAdmitted = await admitExplicitNativeContinuation({
|
|
db,
|
|
companyId: f.companyId,
|
|
issueId: unconfirmedIssueId,
|
|
agentId: f.agentId,
|
|
actorType: "user",
|
|
actorId: "board",
|
|
reason: "retry_failed_run",
|
|
commentId: null,
|
|
failedRunId: unconfirmedRunId,
|
|
successorRunId: randomUUID(),
|
|
dryRun: true,
|
|
onBlocked: reason => unconfirmedBlocked.push(reason),
|
|
});
|
|
expect(unconfirmedAdmitted).toBeNull();
|
|
expect(unconfirmedBlocked).toEqual(["process_identity_missing"]);
|
|
expect(await getExecutionBlocker(db, f.companyId, unconfirmedIssueId)).toMatchObject({ recoveryActionId: unconfirmedHold!.id });
|
|
});
|
|
});
|