Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
fix(tools): keep freshness recovery tool-specific
CloudTianTiandcf935ee1b10
diff --git a/src/main/model/core-agent/read-tracker.ts b/src/main/model/core-agent/read-tracker.tsindex e0b7d51b..61187a07 100644--- a/src/main/model/core-agent/read-tracker.ts+++ b/src/main/model/core-agent/read-tracker.ts@@ -81,12 +81,11 @@ export type EditBlock = { code: 'E_NOT_READ' | 'E_STALE'; msg: string };* - never read this run → E_NOT_READ* - read, but mtime/size changed → E_STALE*- * Message contract: every consumer (edit_file, apply_patch) appends a- * recovery block with the current bytes and a fresh file_hash, and refreshes- * the read baseline on rejection — so the messages steer the model at that- * returned context first. A bare "call read_file again" here made models pay- * a full re-read round the trailer had already made unnecessary- * (2026-08-16 latency review P0-4).+ * Message contract: every consumer (edit_file, apply_patch) appends bounded+ * current context plus its own executable recovery instruction, and refreshes+ * the read baseline on rejection. Keep these shared messages limited to the+ * failure reason so they cannot prescribe a parameter or workflow that one+ * consumer does not support (2026-08-16 latency review P0-4).*/export function checkEditFreshness(ctx: ToolContext,@@ -109,7 +108,7 @@ export function checkEditFreshness(if (!seen) {return {code: 'E_NOT_READ',- msg: `${abs}: not read in this run, so old_string cannot be checked against the real current contents. Use the current context and file_hash returned below to retry (pass expected_hash); use read_file with a bounded range only if that window misses your target.`,+ msg: `${abs}: not read in this run, so the proposed change cannot be checked against the real current contents. Follow the current-context recovery guidance returned below.`,};}if (@@ -119,7 +118,7 @@ export function checkEditFreshness() {return {code: 'E_STALE',- msg: `${abs}: file changed on disk since you read it (another worker, a command, or an external edit). Retry against the current context and file_hash returned below (pass expected_hash); re-read only the affected region with read_file range if that window is insufficient.`,+ msg: `${abs}: file changed on disk since you read it (another worker, a command, or an external edit). Follow the current-context recovery guidance returned below.`,};}return null;diff --git a/test/main/model/core-agent/local-tools.test.ts b/test/main/model/core-agent/local-tools.test.tsindex eabb0ee6..6fc97381 100644--- a/test/main/model/core-agent/local-tools.test.ts+++ b/test/main/model/core-agent/local-tools.test.ts@@ -987,6 +987,47 @@ describe('local-tools › apply_patch › transactional text changes', () => {expect(fs.readFileSync(source, 'utf8')).toBe('const value = 2;\n');});+ it('returns apply_patch-compatible recovery after E_NOT_READ and accepts a rebuilt patch', async () => {+ await grant();+ const { applyPatch, wsDir } = await buildPatchTool();+ const source = path.join(wsDir, 'source.ts');+ fs.writeFileSync(source, 'const value = 1;\nconst label = "before";\n');+ const ctx = { workingDir: wsDir, state: { readFileState: new Map() } } as any;++ const blocked = await applyPatch.execute({+ patch: [+ '*** Begin Patch',+ `*** Update File: ${source}`,+ '@@',+ '-const label = "before";',+ '+const label = "after";',+ '*** End Patch',+ ].join('\n'),+ }, ctx);++ expect(blocked.isError).toBe(true);+ expect(blocked.content).toContain('E_NOT_READ');+ expect(blocked.content).toContain('<patch-recovery file_hash=');+ expect(blocked.content).toContain('rebuild the patch against these bytes');+ expect(blocked.content).not.toContain('expected_hash');+ expect(fs.readFileSync(source, 'utf8')).toBe('const value = 1;\nconst label = "before";\n');++ const retried = await applyPatch.execute({+ patch: [+ '*** Begin Patch',+ `*** Update File: ${source}`,+ '@@',+ ' const value = 1;',+ '-const label = "before";',+ '+const label = "after";',+ '*** End Patch',+ ].join('\n'),+ }, ctx);++ expect(retried.isError).toBeFalsy();+ expect(fs.readFileSync(source, 'utf8')).toBe('const value = 1;\nconst label = "after";\n');+ });+it('moves an updated file while preserving its mode and reporting the destination', async () => {await grant();const { applyPatch, wsDir } = await buildPatchTool();diff --git a/test/main/model/core-agent/read-tracker.test.ts b/test/main/model/core-agent/read-tracker.test.tsindex 46037dfa..1e3daeac 100644--- a/test/main/model/core-agent/read-tracker.test.ts+++ b/test/main/model/core-agent/read-tracker.test.ts@@ -53,12 +53,10 @@ describe('read-tracker › checkEditFreshness', () => {const st = fs.statSync(file);const block = checkEditFreshness(ctx, file, st);expect(block?.code).toBe('E_NOT_READ');- // The refusal steers at the recovery block every consumer appends, not at- // a bare full re-read: a "call read_file" instruction here made models pay- // a whole re-read round the returned context had already made unnecessary.- expect(block?.msg).toContain('expected_hash');- expect(block?.msg).toContain('bounded range');- expect(block?.msg).not.toMatch(/read the file with read_file before/);+ // The shared refusal points at each consumer's own recovery block instead+ // of prescribing edit_file-only parameters or a redundant read round.+ expect(block?.msg).toContain('current-context recovery guidance');+ expect(block?.msg).not.toMatch(/expected_hash|read_file/);});it('allows the edit after a read records the baseline', () => {@@ -86,11 +84,9 @@ describe('read-tracker › checkEditFreshness', () => {fs.writeFileSync(file, 'a much longer body than before', 'utf8'); // size changesconst block = checkEditFreshness(ctx, file, fs.statSync(file));expect(block?.code).toBe('E_STALE');- // Same recovery-first contract as E_NOT_READ: retry against the returned- // context/hash, bounded range re-read only as the fallback.- expect(block?.msg).toContain('expected_hash');- expect(block?.msg).toContain('read_file range');- expect(block?.msg).not.toMatch(/Call read_file again/);+ // Same consumer-neutral contract as E_NOT_READ.+ expect(block?.msg).toContain('current-context recovery guidance');+ expect(block?.msg).not.toMatch(/expected_hash|read_file/);});it('blocks with E_STALE when only mtime changed (same size)', () => {