Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence): delegated refusals keep why, reason and contract_version (#8130)

garrytan0733bab6e6ea
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1f54b882e4..9c72b849aa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,7 +19,7 @@ Writer status for a `recovery_required` refresh now reads the checkout HEAD: at
### Itemized changes
- `src/core/persistence/worktree-refresh.ts`: the owner scan checks member progress before it takes the refresh lock, caches a syncing orphan it could not complete because of its HEAD, fails one row (not the scan) on a lock error, and prunes its caches each scan (#7712, #7728, #7730, #7731); `refreshHolderReport` reads HEAD (#7712, #7731); `next` is host-scoped and shell-quoted (#7731).
-- `src/core/persistence/ipc.ts`: a refusal's `fix` survives the owner socket (#7707).
+- `src/core/persistence/ipc.ts`: a refusal's `fix`, `why`, `reason` and `contract_version` survive the owner socket (#7707, #8130).
- Tests: the #7679 state matrix gains the `--abandon` action for every kind (#7718-#7727, #7729), plus red tests for the owner scan's syncing filter and test 7's adoption guard (#7708) and the unreadable-lock branch (#7728).
## [0.60.529.0] - 2026-10-31
diff --git a/src/core/persistence/ipc.ts b/src/core/persistence/ipc.ts
index 3d5ecb3d7e..cf954a1b61 100644
--- a/src/core/persistence/ipc.ts
+++ b/src/core/persistence/ipc.ts
@@ -353,13 +353,16 @@ function remoteOperationError(value: unknown): OperationError {
if (isWriteReceipt(value.write_request)) error.writeRequest = publicWriteReceipt(value.write_request);
if (isWriteRequestId(value.request_id)) error.requestId = value.request_id;
if (isWriteErrorCode(value.write_error)) error.writeError = value.write_error;
+ if (typeof value.why === 'string') error.why = value.why;
+ if (typeof value.reason === 'string') error.reason = value.reason;
+ if (value.contract_version === 1) error.contractVersion = 1;
const fix = wireAction(value.fix);
if (fix) error.fix = fix;
return error;
}
/**
- * #7707: the owner sends a refusal's `fix` already rendered (`toJSON`), or as the stored Action when it never loaded the renderer.
+ * #7707, #8130: the owner sends a refusal's `fix` already rendered (`toJSON`), or as the stored Action when it never loaded the renderer.
* Back to an Action, so a delegated refusal prints the same structured fix as the direct path; a value of any other shape is dropped.
*/
function wireAction(value: unknown): Action | undefined {
diff --git a/test/persistence-ipc.test.ts b/test/persistence-ipc.test.ts
index c9c72dd7a1..66f4dc55fb 100644
--- a/test/persistence-ipc.test.ts
+++ b/test/persistence-ipc.test.ts
@@ -222,7 +222,7 @@ describe('dedicated persistence IPC', () => {
await expect(startPersistenceIpcServer(path, { brainId: BRAIN, dispatch: async () => ({}) })).rejects.toThrow('not a socket');
expect(readFileSync(path, 'utf8')).toBe('keep');
});
- test('#7707: a refusal\'s structured fix survives the owner socket, so a delegated sources refresh prints the direct path\'s v1 fix', async () => {
+ test('#7707, #8130: a refusal\'s structured fix, why and reason survive the owner socket, so a delegated sources refresh prints the direct path\'s v1 fix', async () => {
// Value: protects=a refusal delegated to a resident owner keeps its structured fix (argv, actor, ask_user) instead of falling back to the
// prose suggestion; fails_when=remoteOperationError drops `fix`; why_new=test 4e reads the direct path only; seam=an owner whose
// administration throws the refusal; no_claim=a real resident refresh.
@@ -232,6 +232,9 @@ describe('dedicated persistence IPC', () => {
error.fix = { argv: ['gbrain', 'git', 'commit-push', '--push-only', '--keep-checkout', '--path', '/tmp/brain-example', '--json'], consent: [], actor: 'user',
ask_user: true, requires_exclusive: false, why: 'HEAD has a local commit the upstream lacks.', user_message: 'Push the local commit of source-a?',
docs: 'docs/guides/write-refusals.md#refresh_diverged' };
+ error.why = 'The checkout holds a commit the upstream lacks.';
+ error.reason = 'local_commits';
+ error.contractVersion = 1;
return error;
};
const result = await startPersistenceIpcServer(path, { brainId: BRAIN, dispatch: async () => ({}), administer: async () => { throw refusal(); } });
@@ -249,5 +252,6 @@ describe('dedicated persistence IPC', () => {
const direct = printed(refusal()).fix;
expect(direct).toMatchObject({ argv: refusal().fix!.argv, next: 'ask_user', actor: 'user' });
expect(printed(delegated as OperationError).fix).toEqual(direct);
+ expect((delegated as OperationError).toJSON()).toMatchObject({ why: 'The checkout holds a commit the upstream lacks.', reason: 'local_commits', contract_version: 1 });
});
});