Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(persistence): the connector-retry supersession reads the candidate row by its sequence (#6824)
time-attack820eac63d07e
diff --git a/src/core/persistence/terminal-classify.ts b/src/core/persistence/terminal-classify.tsindex 60ead2ad4b..68c24b3656 100644--- a/src/core/persistence/terminal-classify.ts+++ b/src/core/persistence/terminal-classify.ts@@ -391,18 +391,20 @@ const UUID_TEXT = `'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}/*** #6824: a connector retry records `retryBase`/`retryOf`/`retryAttempt` in its intent, so its digest never equals the- * refusal it replaces. A committed retry `c` supersedes the refused `r` (read whole as `k`) only when every hop of its+ * refusal it replaces. A committed retry `c` (read whole as `cc` by its unique sequence) supersedes the refused `r`+ * (read whole as `k` by id; callers may pass narrow row aliases) only when every hop of its* recorded `retryOf` chain, back to `r`, has the same principal, source and incarnation, operation, slug and connector* intent kind, at a lower sequence, within CONNECTOR_RETRY_LINEAGE_MAX_DEPTH hops. Another refusal of the same item with* no recorded link is not proof. Each hop is one lookup on the (principal_kind, principal_id, request_id) unique index.*/function connectorRetrySql(r: string, c: string): string {return `(${r}.operation='submit_job' AND ${c}.operation='submit_job' AND ${c}.state='committed' AND COALESCE(${c}.intent ? 'retryOf', false)- AND EXISTS (SELECT 1 FROM persistence_requests k WHERE k.id=${r}.id AND k.intent->>'kind' IN (${CONNECTOR_WRITE_KINDS})- AND ${c}.intent->>'kind'=k.intent->>'kind' AND ${c}.principal_kind=k.principal_kind AND ${c}.principal_id=k.principal_id- AND ${c}.source_incarnation=k.source_incarnation+ AND EXISTS (SELECT 1 FROM persistence_requests k, persistence_requests cc WHERE k.id=${r}.id AND cc.sequence=${c}.sequence+ AND k.intent->>'kind' IN (${CONNECTOR_WRITE_KINDS})+ AND cc.intent->>'kind'=k.intent->>'kind' AND cc.principal_kind=k.principal_kind AND cc.principal_id=k.principal_id+ AND cc.source_incarnation=k.source_incarnationAND EXISTS (WITH RECURSIVE lineage(request_id, sequence, intent, depth) AS (- SELECT ${c}.request_id, ${c}.sequence, ${c}.intent, 0+ SELECT cc.request_id, cc.sequence, cc.intent, 0UNION ALLSELECT p.request_id, p.sequence, p.intent, l.depth+1 FROM lineage l JOIN persistence_requests pON p.principal_kind=k.principal_kind AND p.principal_id=k.principal_id