fix(kvb-org-organize): move the council root out of /tmp with a lossless migration

councilroot.py resolves one durable council root for every script and migrates the old /tmp root under the held locks: a preflight conflict moves nothing, each legacy file is renamed to a staging name before it is copied so a late writer is merged by the catch-up, id-less journals merge by line multiset, a differing whole file is kept beside its namesake, and a crash marker makes install copy the skills and report. One settings-file list, managed drop-ins included, serves councilroot.py and queue.py. Tests run once on unify/skills-20261114 after the merge (operator order 2026-11-14).

🎯 Fix: 88 %
💥 Break: 7 %
💸 Tokens: 100 %
⏱️ Velocity: 100 %
🛡️ Security: 100 %
🏆 Score: 82
🚦 Gate: ⛔ fix 88 % < 90, break 7 % > 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-14 21:18:41 +00:00
1 parent 699f3227c9
commit 8726ed37a7
47 files changed
+2199 -191

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@
--replay: this runner's replay store, outside the hub's reach, e.g.
~/.local/state/kvb-orchestrator-approvals/offices.json.
--council: the council directory every agent shares, e.g.
/tmp/agents-council.
~/.local/state/agents-shared.
--script: the installed council.py of the kvb-org-organize skill.
Returns:
+36 -8
View File
@@ -43,7 +43,9 @@ from __future__ import annotations
import argparse
import base64
import contextlib
import datetime
import errno
import functools
import hashlib
import json
@@ -51,7 +53,6 @@ import os
import shutil
import stat
import subprocess
import tempfile
import time
from collections.abc import Callable
from pathlib import Path
@@ -367,20 +368,47 @@ def encoded(rows: list[dict]) -> str:
return "".join(json.dumps(row, separators=(",", ":")) + "\n" for row in rows)
def folder(path: Path) -> int:
return os.open(path.parent, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC)
def append_rows(path: Path, rows: list[dict]) -> None:
"""Args:
path: the file; a link at it or its directory, or a file that is not
regular with a single link, raises OSError.
rows: appended as JSON lines.
"""
if rows:
with path.open("a", encoding="utf-8") as handle:
parent = folder(path)
try:
fd = os.open(path.name, os.O_WRONLY | os.O_CREAT | os.O_APPEND | os.O_NOFOLLOW | os.O_NONBLOCK | os.O_CLOEXEC, 0o600, dir_fd=parent)
finally:
os.close(parent)
with open(fd, "a", encoding="utf-8") as handle:
info = os.fstat(fd)
if not stat.S_ISREG(info.st_mode) or info.st_nlink != 1:
raise OSError(errno.EINVAL, "not a regular file with a single link", str(path))
handle.write(encoded(rows))
def replace(path: Path, text: str) -> None:
with tempfile.NamedTemporaryFile("w", encoding="utf-8", dir=path.parent, prefix=f".{path.name}.", delete=False) as handle:
try:
"""Args:
path: the file, replaced through a fresh temp file beside it; a link
at its directory raises OSError, one at path is replaced.
text: the new content.
"""
parent = folder(path)
temp = f".{path.name}.{os.urandom(8).hex()}"
try:
with open(os.open(temp, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW | os.O_CLOEXEC, 0o600, dir_fd=parent), "w", encoding="utf-8") as handle:
handle.write(text)
except BaseException:
os.unlink(handle.name)
raise
os.replace(handle.name, path)
os.replace(temp, path.name, src_dir_fd=parent, dst_dir_fd=parent)
except BaseException:
with contextlib.suppress(OSError):
os.unlink(temp, dir_fd=parent)
raise
finally:
os.close(parent)
def rewrite(path: Path, keep: Callable[[list[dict], float], list[dict]], now: float) -> None:
+4 -7
View File
@@ -13,6 +13,7 @@ services:
read_only: true
environment:
TMPDIR: /scratch
AGENTS_COUNCIL_ROOT: "${KVB_ORCHESTRATOR_COUNCIL:?written into .env by scripts/install.sh}"
cap_drop:
- ALL
security_opt:
@@ -36,9 +37,9 @@ services:
- --public-port
- "${KVB_ORCHESTRATOR_PORT:?set in .env}"
- --council
- /tmp/agents-council
- "${KVB_ORCHESTRATOR_COUNCIL:?written into .env by scripts/install.sh}"
- --pages
- /tmp/kvb-git-diff
- "${KVB_ORCHESTRATOR_COUNCIL:?written into .env by scripts/install.sh}/pages"
- --state
- /state
- --host-state
@@ -88,13 +89,9 @@ services:
tmpfs:
- /scratch:size=64m,mode=1777,noexec,nosuid,nodev
volumes:
- type: bind
source: /tmp
target: /tmp
read_only: true
- type: bind
source: "${KVB_ORCHESTRATOR_COUNCIL:?written into .env by scripts/install.sh}"
target: /tmp/agents-council
target: "${KVB_ORCHESTRATOR_COUNCIL:?written into .env by scripts/install.sh}"
bind:
create_host_path: false
- type: bind
+1 -1
View File
@@ -48,7 +48,7 @@ def branch_gates(gates: ModuleType, db: sqlite3.Connection, repo: str, branch: s
def read_gates(gates: ModuleType | None, db: Path, scan: dict) -> dict:
"""Args:
gates: the gates.py module, or None.
db: gates.db under the read-only mount of ~/.local/state/agents-council.
db: gates.db under the read-only mount of the durable council root.
scan: the tree; its repositories and branches are the ones shown.
Returns:
+2 -2
View File
@@ -25,8 +25,8 @@
--tree-file: the JSON file `pkgmgr branch tree --output` writes, mounted
read-only; read again whenever it changes.
--timers: directory holding the systemd user units (*.timer).
--kept: ~/.local/state/agents-council, mounted read-only: gates.db and
the resources/ files of the host sampler.
--kept: the durable council root (councilroot.py durable), mounted
read-only: gates.db and the resources/ files of the host sampler.
--vendor: directory holding the vendored Bootstrap Icons sprite,
3d-force-graph and three with their licence texts.
--cleanup: host-mounted directory the hub writes signed branch deletions