richfrem/agent-plugins-skills / plugins/agent-agentic-os/.apm/skills/running-control-plane
running-control-plane
FlaggedCRITICAL INTAKE GATEWAY: use at the start of any non-trivial engineering task, feature, refactor, multi-file bugfix, work package or new idea, including requests to explore, brainstorm, build, fix or change something, before planning or code changes. Enforces read-only discovery, 1-3 structured questions with defaults, control-plane registration and the immutable four-pillar TASK_SPEC.md. Also runs the rest of the control plane: health ("run health check", "check os metrics", "system monitor", event bus, locks, memory, "is my signing identity ready" status check), transition simulation ("dry run transition", "simulate transition", "check edge X -> Y"), worktree selection, and gating on/off ("disable the control plane", "turn off the push guard", "stop gating my commits"). Not for project setup or key creation (use setting-up-agentic-os) or improving skills (use improving-skills-in-lab).
tests/test_kernel_security.py
View on GitHub"""
Purpose:
Security-focused unit tests for kernel.py: lock double-read concurrency
detection (_safe_clear_stale) and event-log rotation ordering relative
to the write lock.
Key Input Dependencies:
- kernel.py (in ../scripts/, imported directly)
- pytest tmp_path and monkeypatch fixtures
"""
import sys, os, json, time
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).parent.parent / "scripts"))
import kernel as K
@pytest.fixture
def tmp_kernel(tmp_path, monkeypatch):
"""Redirect kernel.py's module-level path constants into an isolated tmp_path sandbox."""
monkeypatch.setattr(K, "KERNEL_DIR", tmp_path)
monkeypatch.setattr(K, "EVENTS_FILE", tmp_path / "events.jsonl")
monkeypatch.setattr(K, "LOCKS_DIR", tmp_path / ".locks")
monkeypatch.setattr(K, "STATE_FILE", tmp_path / "os-state.json")
monkeypatch.setattr(K, "AGENTS_FILE", tmp_path / "agents.json")
monkeypatch.setattr(K, "AGENTS_DIR", tmp_path / "agents")
(tmp_path / ".locks").mkdir()
(tmp_path / "agents").mkdir()
(tmp_path / "agents.json").write_text(
json.dumps({"permitted_agents": ["test-agent"]})
)
return tmp_path
def test_safe_clear_stale_rejects_concurrent_acquisition(tmp_kernel, monkeypatch):
"""_safe_clear_stale must return False if lock is acquired between its two reads.
Uses monkeypatch on time.sleep to inject a concurrent acquisition deterministically
rather than relying on thread scheduling jitter.
"""
lock_path = tmp_kernel / ".locks" / "test.lock"
lock_path.mkdir()
meta = {"pid": 99999999, "expires_at": time.time() - 10, "acquired_at": "2000-01-01T00:00:00Z"}
(lock_path / "meta.json").write_text(json.dumps(meta))
original_sleep = time.sleep
def sleep_and_inject(seconds):
"""Rewrite the lock's meta.json to simulate a concurrent acquisition, then sleep normally."""
# Simulate concurrent acquisition during the pause between double-reads
new_meta = {
"pid": os.getpid(),
"expires_at": time.time() + 300,
"acquired_at": "2026-01-01T00:00:00Z",
}
(lock_path / "meta.json").write_text(json.dumps(new_meta))
original_sleep(seconds)
monkeypatch.setattr(time, "sleep", sleep_and_inject)
result = K._safe_clear_stale(lock_path)
assert result is False, "_safe_clear_stale must detect concurrent acquisition via double-read"
assert lock_path.exists(), "Lock must not be cleared when concurrent acquisition detected"
def test_rotation_happens_inside_write_lock(tmp_kernel, monkeypatch):
"""File size check and rename must happen inside events_write.lock, not before."""
events_file = tmp_kernel / "events.jsonl"
events_file.write_bytes(b"x" * (K.EVENTS_MAX_BYTES + 1))
rotation_order = []
original_spinlock = K._spinlock
def tracked_spinlock(lock_path, timeout=30):
"""Record each spinlock acquisition attempt, then delegate to the real _spinlock."""
rotation_order.append(("spinlock", str(lock_path)))
return original_spinlock(lock_path, timeout)
original_rename = os.rename
def tracked_rename(src, dst):
"""Record each rename call, then delegate to the real os.rename."""
rotation_order.append(("rename", str(src)))
return original_rename(src, dst)
monkeypatch.setattr(K, "_spinlock", tracked_spinlock)
monkeypatch.setattr(os, "rename", tracked_rename)
K.emit_event("test-agent", "result", "test_action")
spinlock_indices = [i for i, op in enumerate(rotation_order) if op[0] == "spinlock"]
rename_indices = [i for i, op in enumerate(rotation_order) if op[0] == "rename"]
assert rename_indices, "Rotation must have occurred for file above EVENTS_MAX_BYTES (H-1)"
write_lock_idx = next(
i for i in spinlock_indices if "events_write" in rotation_order[i][1]
)
assert rename_indices[0] > write_lock_idx, (
"Rotation rename must happen AFTER events_write.lock is acquired (H-1)"
)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Unverified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |