Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

refactor(persistence): the former-binding retry refusal lives in one guard wrapper, outside the per-effect loop (#7985)

garrytanf341bb0690f9
diff --git a/src/core/persistence/effect-retry.ts b/src/core/persistence/effect-retry.ts
index 2e17d8c7d3..399e03481a 100644
--- a/src/core/persistence/effect-retry.ts
+++ b/src/core/persistence/effect-retry.ts
@@ -101,6 +101,22 @@ async function ownerRevokedError(tx: BrainEngine, sourceId: string, request: Wri
: 'Relay fix.user_message; nothing can retry this withdrawal under another authority.', { fix });
}
+/**
+ * The binding guard for a retried effect. #7985: an effect of a former binding is refused `source_changed` as before, but
+ * the refusal names its recorded binding, the current one and the settle preview, never only "inspect the owner".
+ */
+async function guardRetriedEffect(tx: BrainEngine, effect: PersistenceEffect, hostId: string, request: WriteRequest): Promise<void> {
+ try { await guardEffectSource(tx, effect, hostId); }
+ catch (error) {
+ if (!(error instanceof OperationError) || error.code !== 'source_changed') throw error;
+ const current = await getWorktreeBinding(tx, effect.source_id, hostId);
+ throw opError('source_changed', error.message,
+ `Request ${request.request_id}'s ${effect.kind} effect was recorded under worktree ${effect.worktree_id ?? '(none)'} of source incarnation ${effect.source_incarnation}; source ${effect.source_id} is now bound to ${current ? `worktree ${current.worktree_id} of incarnation ${current.source_incarnation}` : 'no worktree'}. Retry cannot run it, and the bulk retry previews (--parked-code, --parked-pushes) select only the current binding's effects, so their zero does not cover it. Preview settling it on proof: the fix command settles it or names what blocks it. Do not claim or transfer the source to force it through.`,
+ { fix: readFix(`Previews settling request ${request.request_id}'s effects of a former binding of source ${effect.source_id} on proof, read-only.`,
+ { argv: ['gbrain', 'sources', 'writer', 'settle-effects', effect.source_id, '--request-id', request.request_id, '--dry-run', '--json'] }) });
+ }
+}
+
/**
* #5612: parked Git and withdrawal effects of one committed request, plus
* (GBRA-130) parked embedding targets and failed Git, withdrawal-mirror, links
@@ -133,16 +149,7 @@ export async function retryParkedEffects(engine: BrainEngine, sourceId: string,
tracked.some(effect => effect.kind === 'git' && effect.state === 'failed' && effect.error_code === 'targets_parked')) : null;
const effects = [];
for (const selected of tracked) {
- try { await guardEffectSource(tx, selected, hostId); }
- catch (error) {
- if (!(error instanceof OperationError) || error.code !== 'source_changed') throw error;
- // #7985: an effect of a former binding: name its recorded binding, the current one and the settle preview, never only "inspect".
- const current = await getWorktreeBinding(tx, sourceId, hostId);
- throw opError('source_changed', error.message,
- `Request ${request.request_id}'s ${selected.kind} effect was recorded under worktree ${selected.worktree_id ?? '(none)'} of source incarnation ${selected.source_incarnation}; source ${sourceId} is now bound to ${current ? `worktree ${current.worktree_id} of incarnation ${current.source_incarnation}` : 'no worktree'}. Retry cannot run it, and the bulk retry previews (--parked-code, --parked-pushes) select only the current binding's effects, so their zero does not cover it. Preview settling it on proof: the fix command settles it or names what blocks it. Do not claim or transfer the source to force it through.`,
- { fix: readFix(`Previews settling request ${request.request_id}'s effects of a former binding of source ${sourceId} on proof, read-only.`,
- { argv: ['gbrain', 'sources', 'writer', 'settle-effects', sourceId, '--request-id', request.request_id, '--dry-run', '--json'] }) });
- }
+ await guardRetriedEffect(tx, selected, hostId, request);
const [effect] = await tx.executeRaw<PersistenceEffect>('SELECT * FROM persistence_effects WHERE id=$1 FOR UPDATE', [selected.id]);
const parked = effect.data.parked ?? [];
const summary = { kind: effect.kind, error_code: effect.error_code, parked_targets: parked.length, targets: parked.slice(0, 20), retried: effect.data.retried ?? 0 };