graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Keep the pending-head reread; proceed on create only after it (#1189)
justrach34230ff6a014
diff --git a/scripts/regression-release-297.py b/scripts/regression-release-297.pyindex 59a03c7b..5b8901a1 100644--- a/scripts/regression-release-297.py+++ b/scripts/regression-release-297.py@@ -33,7 +33,7 @@ def completion(text="Verification complete."):return {"tool": "attempt_completion", "arguments": {"result": text}}-def run_case(graff, name, script, state=None, expected_mutations=0, refused=0, expected_final=None, resume_check=False, review=False):+def run_case(graff, name, script, state=None, expected_mutations=0, refused=0, expected_final=None, resume_check=False, review=False, env_extra=None):with tempfile.TemporaryDirectory(prefix="graff-297-") as temp:work = Path(temp)(work / "bin").mkdir()@@ -50,7 +50,7 @@ def run_case(graff, name, script, state=None, expected_mutations=0, refused=0, eenv = {k: v for k, v in os.environ.items() if not k.endswith("_API_KEY")}env.update(HOME=temp, PATH=str(work / "bin") + os.pathsep + os.environ["PATH"],LMSTUDIO_API_KEY="local", GRAFF_NO_TELEMETRY="1", GRAFF_FLEET="off",- GRAFF_NO_SMOLIFY="1", GRAFF_NO_CODEDB_GUARD="1", NO_COLOR="1")+ GRAFF_NO_SMOLIFY="1", GRAFF_NO_CODEDB_GUARD="1", NO_COLOR="1", **(env_extra or {}))if review:prepare_review(work, ['notes.md'])if (state or {}).get('remote_head') == 'initial':@@ -255,7 +255,7 @@ def main():for bad in ({"runs": "failure"}, {"unavailable": True}, {"runs": "malformed"}):run_case(args.graff, f"non-draft refuses {bad}", [tool(create), {"text": "Publication blocked."}], bad)# #1189: the push started the head's runs; create proceeds, completion still waits.- run_case(args.graff, "non-draft create proceeds while the head run is pending", [tool(create), completion(), {"text": "CI is still running."}], {"runs": "pending"}, expected_mutations=1, refused=1, review=True)+ run_case(args.graff, "non-draft create proceeds while the head run is pending", [tool(create), completion(), {"text": "CI is still running."}], {"runs": "pending"}, expected_mutations=1, refused=1, review=True, env_extra={"GRAFF_PUBLISH_PENDING_WAIT_MS": "2000"})run_case(args.graff, "body flag cannot turn non-draft into draft", [tool("gh pr create --title fixture --body '--draft'"), {"text": "Blocked."}], {"runs": "failure"})run_case(args.graff, "local-only and repeated completion cannot pass PR CI", [tool(create), completion(), completion(), {"text": "CI remains unverified."}], {"runs": "none"}, expected_mutations=1, refused=2, resume_check=True, review=True)run_case(args.graff, "fresh passing remote head completes", [tool(create), completion()], {"checks": "SUCCESS"}, expected_mutations=1, expected_final="Verification complete.", review=True)diff --git a/src/pr_publish.zig b/src/pr_publish.zigindex 482653e5..4f670140 100644--- a/src/pr_publish.zig+++ b/src/pr_publish.zig@@ -22,8 +22,9 @@ pub const Evidence = struct {body: []const u8 = "",coverage: Coverage = .{},/// `gh pr create`: the push that preceded it started the head's runs, so a- /// pending run is evidence not yet arrived, not a failure (#1189). The- /// verification obligation armed at publication still gates completion.+ /// run still pending after the gate's reread is evidence not yet arrived,+ /// not a failure (#1189). The obligation armed at publication still gates+ /// completion; a run that fails during the reread is refused (#1179).creating: bool = false,};diff --git a/src/publish_gate.zig b/src/publish_gate.zigindex 03c68e50..ed455cf9 100644--- a/src/publish_gate.zig+++ b/src/publish_gate.zig@@ -31,7 +31,6 @@ fn observe(self: *Agent, cmd: []const u8) !?ExecResult {if (self.publication_checks.unresolved(try @import("pr_local_checks.zig").repositoryRoot(self, target.cwd))) |command_text|return .{ .text = try std.fmt.allocPrint(self.arena, "PR publication preflight: observed local check has no successful completion: {s}. Rerun it successfully or publish a draft; write NOT performed.", .{command_text}), .is_error = true };if (creating) {- ev.creating = true;ev.head_sha = evmod.localHead(self.gpa, self.io, self.arena, target) catch "";// An explicit alternate head must be resolved independently of HEAD.if (command.flag("--head", "-H")) |head| {@@ -50,8 +49,9 @@ fn observe(self: *Agent, cmd: []const u8) !?ExecResult {ev = .{ .head_sha = receipt.head, .head_status = receipt.status, .body = receipt.body };}}- // A create proceeds while the head's runs are in flight (#1189); ready waits.- if (!draft and !creating and ev.head_status == .pending) {+ // Reread a pending head (#1179). A create still pending after the wait+ // proceeds (#1189): pr_publish.decide allows it and completion waits.+ if (!draft and ev.head_status == .pending) {var poll: PendingPoll = .{ .agent = self, .target = target, .creating = creating, .alternate_head = command.flag("--head", "-H"), .initial = ev, .started = std.Io.Timestamp.now(self.io, .awake) };ev = waitPending(&poll, ev) catch |err| return .{.text = if (err == error.Interrupted) "PR publication preflight: waiting for CI was cancelled; write NOT performed." else "PR publication preflight: the head changed or readiness could not be refreshed while waiting; write NOT performed.",@@ -59,6 +59,7 @@ fn observe(self: *Agent, cmd: []const u8) !?ExecResult {.cancelled = err == error.Interrupted,};}+ ev.creating = creating; // a reread returns fresh evidence without itif (pr_publish.decide(draft, ev) != .allow) return .{ .text = pr_publish.refuseText(self.arena, cmd, ev), .is_error = true };if (!draft) {const review = @import("pr_claim_review.zig").review(self, target, command.flag("--base", "-B"), creating, ev.head_sha, ev.body, ev.head_status) catch |err|@@ -79,6 +80,10 @@ fn headStatus(self: *Agent, target: @import("pr_evidence.zig").Target, head: []creturn pr_publish.headStatusFromRunList(json);}+/// How long publication rereads a pending head before deciding. 60 s by+/// default; GRAFF_PUBLISH_PENDING_WAIT_MS is a fixture seam (#1189).+pub var pending_wait_ms: i64 = 60_000;+const PendingPoll = struct {agent: *Agent,target: @import("pr_evidence.zig").Target,@@ -88,7 +93,7 @@ const PendingPoll = struct {started: std.Io.Timestamp,fn expired(self: *PendingPoll) bool {- return self.started.untilNow(self.agent.io, .awake).toMilliseconds() >= 60_000;+ return self.started.untilNow(self.agent.io, .awake).toMilliseconds() >= pending_wait_ms;}fn cancelled(self: *PendingPoll) bool {return Agent.esc_cancel.load(.acquire) or if (self.agent.loop_deadline_ms) |deadline| @import("util.zig").unixMs(self.agent.io) >= deadline else false;diff --git a/src/session_settings.zig b/src/session_settings.zigindex bfa549e6..33e16a1d 100644--- a/src/session_settings.zig+++ b/src/session_settings.zig@@ -73,6 +73,7 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {main_mod.g_codedb_guard = environ_map.get("GRAFF_NO_CODEDB_GUARD") == null; // issue #626 guard, opt-out via envjob_idle.applyEnv(environ_map); // #199: background-job idle warn/stop, minutes (0 = off)main_mod.g_force_stall_once = environ_map.get("GRAFF_FORCE_STALL_ONCE") != null; // #134 test seam+ if (environ_map.get("GRAFF_PUBLISH_PENDING_WAIT_MS")) |v| @import("publish_gate.zig").pending_wait_ms = std.fmt.parseInt(i64, v, 10) catch 60_000; // #1189 fixture seammain_mod.g_force_drop_once = environ_map.get("GRAFF_FORCE_DROP_ONCE") != null; // #132/#133 test seammain_mod.g_force_stall_always = environ_map.get("GRAFF_FORCE_STALL_ALWAYS") != null; // #56 test seam (exhaust the reconnect budget)main_mod.g_force_drop_always = environ_map.get("GRAFF_FORCE_DROP_ALWAYS") != null; // #56 test seam