Skip to content

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

Python

Read the shared claim ledger and close Accord inbound once

Cursor Agent646e922c7fce
diff --git a/scripts/eval/github_fixture.py b/scripts/eval/github_fixture.py
index a6ebd628..bf3a8390 100644
--- a/scripts/eval/github_fixture.py
+++ b/scripts/eval/github_fixture.py
@@ -1,6 +1,7 @@
"""Local-only GitHub CLI fixture for production dispatch regressions."""
import json
import os
+from pathlib import Path
import shutil
import subprocess
import sys
@@ -78,6 +79,26 @@ def prepare(work, env, state):
prepare_review(work, fixture["review_files"])
+def claim_ledger(work):
+ """Canonical claim file (Git common dir), then the legacy workspace copy."""
+ work = Path(work)
+ for args in (
+ ["git", "-C", str(work), "rev-parse", "--path-format=absolute", "--git-common-dir"],
+ ["git", "-C", str(work), "rev-parse", "--git-common-dir"],
+ ):
+ try:
+ raw = subprocess.check_output(args, text=True, timeout=10).strip()
+ except (subprocess.CalledProcessError, FileNotFoundError):
+ continue
+ if not raw:
+ continue
+ common = Path(raw) if Path(raw).is_absolute() else (work / raw)
+ path = common / "artifact-claims.json"
+ if path.exists():
+ return path
+ return work / ".graff" / "artifact-claims.json"
+
+
def prepare_review(work, files):
"""Give readiness fixtures an actual committed diff and resolvable base."""
state = json.loads((work / "gh-state.json").read_text())
diff --git a/scripts/regression-release-297.py b/scripts/regression-release-297.py
index 6f853e8d..d4de670c 100644
--- a/scripts/regression-release-297.py
+++ b/scripts/regression-release-297.py
@@ -21,7 +21,7 @@ sys.path.insert(0, str(ROOT / "scripts" / "eval"))
from mock_model import ScriptedModel
from process_guard import run as bounded_run
-from github_fixture import GH, prepare_review
+from github_fixture import GH, claim_ledger, prepare_review
def tool(command):
@@ -144,7 +144,8 @@ def handoff(graff):
(work / "notes.md").write_text("## Verification\nLocal: `python3 -m unittest` passed.\nRemote: passed.\n")
env = {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_TELEMETRY="1", GRAFF_FLEET="off", GRAFF_NO_SMOLIFY="1", GRAFF_NO_CODEDB_GUARD="1",
+ GRAFF_ISOLATION_FALLBACK="1", NO_COLOR="1") # shared-checkout claim handoff; isolation stays default elsewhere
prepare_review(work, ['notes.md'])
acquired, primed, transferred = (threading.Event() for _ in range(3))
def peer(action, kind="publication", key="fixture", **extra):
@@ -164,7 +165,7 @@ def handoff(graff):
if step == 1:
acquired.set()
assert primed.wait(35), "peer did not reach foreign claim gate"
- ledger = json.loads((work / ".graff/artifact-claims.json").read_text())
+ ledger = json.loads(claim_ledger(work).read_text())
receiver = next(c["session"] for c in ledger if c["key"] == "independent")
return peer("handoff", session=receiver)
if step == 2:
diff --git a/scripts/test-claim-lifecycle.py b/scripts/test-claim-lifecycle.py
index 342e9b02..87b64cc1 100644
--- a/scripts/test-claim-lifecycle.py
+++ b/scripts/test-claim-lifecycle.py
@@ -12,7 +12,7 @@ import tempfile
import threading
import time
sys.path.insert(0, str(Path(__file__).resolve().parent / 'eval'))
-from github_fixture import prepare
+from github_fixture import claim_ledger, prepare
from mock_model import ScriptedModel
@@ -84,7 +84,8 @@ def run(binary, recovery, evidence):
work = Path(temp)
env = {k:v for k,v in os.environ.items() if not k.endswith('_API_KEY')}
env.update(HOME=temp, LMSTUDIO_API_KEY='local', GRAFF_NO_TELEMETRY='1',
- GRAFF_FLEET='off', GRAFF_NO_SMOLIFY='1', GRAFF_NO_CODEDB_GUARD='1')
+ GRAFF_FLEET='off', GRAFF_NO_SMOLIFY='1', GRAFF_NO_CODEDB_GUARD='1',
+ GRAFF_ISOLATION_FALLBACK='1')
prepare(work, env, {'checks':'SUCCESS', 'runs':'success', 'new_runs':'success', 'head_branch':'fixture'})
subprocess.run(['git','init','--bare','-q',str(work/'remote.git')], check=True, timeout=10)
subprocess.run(['git','remote','add','origin',str(work/'remote.git')], cwd=work, check=True, timeout=10)
@@ -128,11 +129,11 @@ def run(binary, recovery, evidence):
caller.prompt('/resume claim-lifecycle')
blocked_round('Repeat the claimed writes after resuming the saved conversation.')
before_compact = len(model.requests)
- ledger_before = (work/'.graff/artifact-claims.json').read_text()
+ ledger_before = claim_ledger(work).read_text()
model.caller_steps = [{'text':'COMPACTED_LIFECYCLE_FIXTURE: publication ownership remains with the live peer.'}]
caller.prompt('/compact')
assert len(model.requests) > before_compact, 'compaction did not request a summary'
- assert (work/'.graff/artifact-claims.json').read_text() == ledger_before
+ assert claim_ledger(work).read_text() == ledger_before
compacted_turn = len(model.requests)
blocked_round('Repeat the claimed writes after compacting the conversation.')
assert 'COMPACTED_LIFECYCLE_FIXTURE' in json.dumps(model.requests[compacted_turn]), 'summary was not installed'
@@ -163,9 +164,11 @@ def run(binary, recovery, evidence):
(dest/'requests.json').write_text(json.dumps(model.requests,indent=2))
for label,client in [('owner',owner),('caller',caller)]:
if client: (dest/f'{label}-acp.json').write_text(json.dumps(client.events,indent=2))
- for name in ['mutations.jsonl','gh-argv.jsonl','.graff/artifact-claims.json']:
+ for name in ['mutations.jsonl','gh-argv.jsonl']:
source=work/name
if source.exists(): (dest/source.name).write_text(source.read_text())
+ ledger=claim_ledger(work)
+ if ledger.exists(): (dest/'artifact-claims.json').write_text(ledger.read_text())
if owner: owner.close()
if caller: caller.close()
model.stop()
@@ -177,7 +180,8 @@ def independent_issue(binary, evidence):
work = Path(temp)
env = {k:v for k,v in os.environ.items() if not k.endswith('_API_KEY')}
env.update(HOME=temp, LMSTUDIO_API_KEY='local', GRAFF_NO_TELEMETRY='1',
- GRAFF_FLEET='off', GRAFF_NO_SMOLIFY='1', GRAFF_NO_CODEDB_GUARD='1')
+ GRAFF_FLEET='off', GRAFF_NO_SMOLIFY='1', GRAFF_NO_CODEDB_GUARD='1',
+ GRAFF_ISOLATION_FALLBACK='1')
prepare(work,env,{'checks':'SUCCESS'})
owner = caller = None
model.start(1234)
diff --git a/scripts/test-claim-repository.py b/scripts/test-claim-repository.py
index 3eab09a6..f9cd943b 100644
--- a/scripts/test-claim-repository.py
+++ b/scripts/test-claim-repository.py
@@ -12,7 +12,7 @@ import sys
import tempfile
import threading
sys.path.insert(0, str(Path(__file__).resolve().parent / 'eval'))
-from github_fixture import prepare, prepare_review
+from github_fixture import claim_ledger, prepare, prepare_review
from mock_model import ScriptedModel
@@ -64,7 +64,7 @@ class Model(ScriptedModel):
assert 'claim released' in json.dumps(body), body
(self.work/'release-done').touch()
if c.get('legacy') and step == 1:
- command = "python3 - <<'PYCLAIM'\nimport json\nfrom pathlib import Path\np=Path('.graff/artifact-claims.json')\nrows=json.loads(p.read_text())\nfor row in rows: row.pop('repo',None)\np.write_text(json.dumps(rows))\nPYCLAIM"
+ command = "python3 - <<'PYCLAIM'\nimport json, subprocess\nfrom pathlib import Path\nraw=subprocess.check_output(['git','rev-parse','--git-common-dir'],text=True).strip()\np=Path(raw if Path(raw).is_absolute() else raw)/'artifact-claims.json'\nif not p.exists(): p=Path('.graff/artifact-claims.json')\nrows=json.loads(p.read_text())\nfor row in rows: row.pop('repo',None)\np.write_text(json.dumps(rows))\nPYCLAIM"
return tool('bash', command=command)
if c.get('rebind') and step == 2:
return tool('peer_message', action='claim', kind=c.get('owner_kind','publication'), key=c['held'], repo=c['owner'])
@@ -93,7 +93,8 @@ def run_case(binary, name, case, evidence):
model.work = work
env = {k: v for k, v in os.environ.items() if not k.endswith('_API_KEY')}
env.update(HOME=temp, LMSTUDIO_API_KEY='local', GRAFF_NO_TELEMETRY='1',
- GRAFF_FLEET='off', GRAFF_NO_SMOLIFY='1', GRAFF_NO_CODEDB_GUARD='1')
+ GRAFF_FLEET='off', GRAFF_NO_SMOLIFY='1', GRAFF_NO_CODEDB_GUARD='1',
+ GRAFF_ISOLATION_FALLBACK='1')
state = dict(checks='SUCCESS', head_branch='feature', pr_unavailable=case.get('pr_unavailable', False))
state['wait_release'] = case.get('wait_release', False)
if 'head_repo' in case: state['head_repo'] = case['head_repo']
@@ -123,7 +124,7 @@ def run_case(binary, name, case, evidence):
release_thread.start()
done = subprocess.run(argv, cwd=work, env=env, input=json.dumps({'type': 'user', 'text': 'Claim the target branch and PR, then edit and mark it ready.'})+'\n', capture_output=True, text=True, timeout=45)
events = [json.loads(line) for line in done.stdout.splitlines() if line.startswith('{')]
- claims = json.loads((work/'.graff/artifact-claims.json').read_text())
+ claims = json.loads(claim_ledger(work).read_text())
mutations = (work/'mutations.jsonl').read_text().splitlines() if (work/'mutations.jsonl').exists() else []
if evidence:
dest = evidence/name
diff --git a/src/presence_accord.zig b/src/presence_accord.zig
index 6d78a97e..349a0a69 100644
--- a/src/presence_accord.zig
+++ b/src/presence_accord.zig
@@ -308,15 +308,19 @@ fn holdInbound(sess: *accord.Session) void {
fn dropInbound(sess: *accord.Session) void {
const io = sess.io;
const gpa = sess.gpa;
+ var owned = false;
g_mu.lockUncancelable(io);
for (g_ins.items, 0..) |item, i| {
if (item == sess) {
_ = g_ins.orderedRemove(i);
+ owned = true;
break;
}
}
g_mu.unlock(io);
- sess.shutdown();
+ // stop() already shutdown every inbound and cleared the list. Accord's
+ // second close is BADF and Debug-aborts the process.
+ if (owned) sess.shutdown();
gpa.destroy(sess);
}