Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Verify workspace switching and preserve ACP error reporting

Rach Pradhand6d6043664a8
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9ad3a7d7..97834222 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -92,6 +92,9 @@ jobs:
python3 scripts/test-json-controls.py zig-out/bin/graff
python3 scripts/test-json-cancel.py zig-out/bin/graff
+ - name: ACP cancellation and same-session follow-up
+ run: python3 scripts/test-acp-steer.py zig-out/bin/graff
+
- name: Isolated read-only review regression
run: python3 scripts/test-review-mode.py zig-out/bin/graff
diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsx
index 8c234458..8707daec 100644
--- a/apps/native/components/site/GraffHarness.tsx
+++ b/apps/native/components/site/GraffHarness.tsx
@@ -38,7 +38,7 @@ import { useChatScroll } from "./useChatScroll";
import { enqueuePrompt } from "@/lib/prompt-queue";
import { usePromptQueue } from "./usePromptQueue";
import { removeSession, type StoredSession } from "@/lib/sessions";
-import { loadHistory } from "@/lib/prompt-history";
+import { loadHistory, mergeHistory } from "@/lib/prompt-history";
import WorkspaceDialog from "@/components/site/WorkspaceDialog";
import {
basename,
diff --git a/apps/native/electron/workspace-layout-visual.cjs b/apps/native/electron/workspace-layout-visual.cjs
index 7bbb337f..c01fe454 100644
--- a/apps/native/electron/workspace-layout-visual.cjs
+++ b/apps/native/electron/workspace-layout-visual.cjs
@@ -39,6 +39,8 @@ app.whenReady().then(async () => {
sandbox: true, contextIsolation: true, nodeIntegration: false, backgroundThrottling: false,
} });
const wc = win.webContents;
+ // Start the hidden renderer before sending commands to its Page domain.
+ await wc.loadURL('about:blank');
const unexpected = [];
wc.session.webRequest.onBeforeRequest((details, callback) => {
const url = new URL(details.url);
@@ -82,12 +84,14 @@ app.whenReady().then(async () => {
await click('[aria-label="Show tasks"]');
await wait(`!!document.querySelector('[aria-label="Close tasks"]')`);
await click('[aria-label="Close tasks"]');
+ await js(`(()=>{const e=document.querySelector('textarea[aria-label="Prompt"]');Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,'value').set.call(e,'Unsent follow-up');e.dispatchEvent(new Event('input',{bubbles:true}));})()`);
await click('[aria-label="Show agents"]');
await wait(`!!document.querySelector('[aria-label="Agents panel"]')`);
assert.equal(await js(`document.querySelector('[data-chat-layout]').parentElement.style.display`), 'none');
const geometry = await js(`(()=>{const t=document.querySelector('[data-workspace-toolbar]').getBoundingClientRect(),a=document.querySelector('[aria-label="Agents panel"]').getBoundingClientRect();return {toolbar:t.width,agents:a.width,below:a.top>=t.bottom}})()`);
assert.ok(geometry.below && Math.abs(geometry.toolbar - geometry.agents) < 4, JSON.stringify(geometry));
await click('[aria-label="Close agents"]');
+ assert.equal(await js(`document.querySelector('textarea[aria-label="Prompt"]').value`), 'Unsent follow-up', 'Switching to Agents preserves chat drafts');
assert.equal(await js(`!!document.querySelector('[data-tasks-sidebar]')`), false, 'Tasks remains dismissed after navigation');
await key('d', { metaKey: true });
await wait(`document.querySelectorAll('[data-chat]').length===2`);
diff --git a/src/acp.zig b/src/acp.zig
index 708bb603..11b1fe6d 100644
--- a/src/acp.zig
+++ b/src/acp.zig
@@ -506,7 +506,7 @@ test "handleLine: turn failures map to a stopReason or a -32603" {
w = .fixed(&buf);
var failing: Dispatch = .{ .turn = failTurn, .ctx = undefined };
try handleLine(&failing, a, &w, prompt);
- try testing.expectEqualStrings("{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"stopReason\":\"failed\"}}\n", w.buffered());
+ try testing.expectEqualStrings("{\"jsonrpc\":\"2.0\",\"id\":1,\"error\":{\"code\":-32603,\"message\":\"ApiError\"}}\n", w.buffered());
}
test "isAcpSubcommand claims only `acp`, and arms the stdout discipline" {
@@ -536,6 +536,11 @@ test "ACP advertises the complete REPL command catalog including compact" {
}
test "handleLine: live context occupancy precedes the terminal prompt reply" {
+ const was_cancelled = engine.cancel_flag.swap(false, .acq_rel);
+ defer engine.cancel_flag.store(was_cancelled, .release);
+ const extra = engine.extra_cancelled;
+ engine.extra_cancelled = null;
+ defer engine.extra_cancelled = extra;
var state = std.heap.ArenaAllocator.init(testing.allocator);
defer state.deinit();
const a = state.allocator();
diff --git a/src/acp_engine.zig b/src/acp_engine.zig
index 1baf1990..87d3e00c 100644
--- a/src/acp_engine.zig
+++ b/src/acp_engine.zig
@@ -33,7 +33,7 @@ pub const SlashFn = *const fn (ctx: *anyopaque, arena: Allocator, text: []const
pub const AfterUserFn = *const fn (ctx: *anyopaque, arena: Allocator, text: []const u8) void;
pub const BindSessionFn = *const fn (ctx: *anyopaque, session_id: []const u8) void;
/// Optional per-turn context meter: used and window tokens for the
-/// `gui_context_meter` update the client renders as a remaining-context ring.
+/// `gui_context_meter` update available to clients.
/// Null when the embed has no live agent (pure in-process loop, tests).
pub const Meter = struct { used: u64, window: u64 };
pub const MeterFn = *const fn (ctx: *anyopaque) Meter;
@@ -100,14 +100,11 @@ fn promptTurn(d: *Dispatch, arena: Allocator, w: *Io.Writer, req: proto.Request)
return respond(w, req, .{ .stopReason = "cancelled" });
if (err == error.RunBudgetExhausted)
return respond(w, req, .{ .stopReason = "max_turn_requests" });
- if (err == error.ApiError)
- return respond(w, req, .{ .stopReason = "failed" });
return respondError(w, req, err_internal, @errorName(err));
};
if (final.len > 0) try writeSessionUpdate(w, sid, final);
if (d.meter) |meter| {
- // The context ring reads this, not the model catalog: used is the
- // live occupancy estimate, window the model's wall. No text, no PII.
+ // Report live occupancy independently of the model catalog.
const m = meter(d.ctx);
if (m.window > 0) try proto.writeNotification(w, "session/update", .{
.sessionId = sid,