Skip to content

Commit b352256

Browse files
author
Foundups Agent
committed
feat(reddog): add guarded resident live canary harness
1 parent 6b54583 commit b352256

19 files changed

Lines changed: 2508 additions & 17 deletions

main.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
import atexit
3636
import hashlib
3737
import json
38+
from functools import wraps
3839
from datetime import datetime, timezone
3940
from pathlib import Path
40-
from typing import Optional, Dict, Any, Mapping, Sequence
41+
from typing import Optional, Dict, Any, Callable, Mapping, Sequence
4142

4243
# Load environment variables for DAEs (API keys, ports, feature flags).
4344
# Managed mode builds `.env.managed` from `.env` (last duplicate wins) for
@@ -3904,8 +3905,7 @@ def _reddog_queue_stage_rejection_reasons(stage_callable: Any) -> tuple[str, ...
39043905

39053906
def _reddog_record_queue_control_result(repo_root: Path, result: Mapping[str, Any]) -> Dict[str, Any]:
39063907
"""Record and expose one resident queue control-loop result."""
3907-
3908-
recorded = dict(result)
3908+
recorded = _reddog_control_lock_annotated_result(result)
39093909
try:
39103910
from modules.communication.moltbot_bridge.src.reddog_resident_queue_binding_profile import (
39113911
resident_queue_runtime_file_path,
@@ -3955,6 +3955,49 @@ def _reddog_record_queue_control_result(repo_root: Path, result: Mapping[str, An
39553955
return recorded
39563956

39573957

3958+
def _reddog_control_lock_annotated_result(result: Mapping[str, Any]) -> Dict[str, Any]:
3959+
from modules.communication.moltbot_bridge.src.reddog_resident_queue_control_lock import (
3960+
resident_queue_control_lock_held,
3961+
)
3962+
3963+
recorded = dict(result)
3964+
recorded["control_lock_acquired"] = resident_queue_control_lock_held()
3965+
return recorded
3966+
3967+
3968+
def _with_reddog_queue_control_lock(control_loop: Callable[[Path], bool]) -> Callable[[Path], bool]:
3969+
"""Decorate every control-loop call with the shared non-blocking lock."""
3970+
3971+
@wraps(control_loop)
3972+
def locked(repo_root: Path) -> bool:
3973+
from modules.communication.moltbot_bridge.src.reddog_resident_queue_control_lock import (
3974+
acquire_resident_queue_control_lock,
3975+
)
3976+
3977+
with acquire_resident_queue_control_lock(repo_root) as lock:
3978+
if not lock.acquired:
3979+
locked.last_result = _reddog_locked_control_result(lock.reason, lock.path)
3980+
return False
3981+
return control_loop(repo_root)
3982+
3983+
return locked
3984+
3985+
3986+
def _reddog_locked_control_result(reason: str, lock_path: Path) -> Dict[str, Any]:
3987+
return {
3988+
"accepted": False,
3989+
"status": "CONTROL_LOOP_LOCKED",
3990+
"rounds": 0,
3991+
"serial_progress": 0,
3992+
"claim_progress": 0,
3993+
"receipt_ids": (),
3994+
"rejection_reasons": (reason,),
3995+
"control_lock_path": str(lock_path),
3996+
"control_lock_acquired": False,
3997+
}
3998+
3999+
4000+
@_with_reddog_queue_control_lock
39584001
def run_reddog_resident_queue_control_loop_preflight(repo_root: Path) -> bool:
39594002
"""
39604003
Drive the resident queue through bounded serial/claim rounds.

modules/communication/moltbot_bridge/INTERFACE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,17 @@ Resident OpenClaw contract:
489489
- `tail <dae>` = recent window
490490
- `watch|follow <dae> since <sequence>` = incremental follow with returned `next_cursor`
491491

492+
Resident RedDog live-canary contract:
493+
- Entry point: `python -m modules.communication.moltbot_bridge.src.reddog_resident_live_canary`
494+
- Default mode performs readiness checks only and writes an audit-safe receipt outside the repository.
495+
- Live invocation requires Linux, `--execute`, and exact confirmation token `REDDOG_RESIDENT_LIVE_CANARY_PHASE1`.
496+
- The selected profile is fixed to `signed_0102_bounded_code_fusion_worktree_draft_pr_pattern_memory`.
497+
- The harness delegates to `main.run_reddog_resident_queue_control_loop_preflight`; it does not duplicate queue stages.
498+
- `LIVE_PROOF_COMPLETE` requires a shared-lock-proven, newly persisted `reddog_resident_control_loop_receipt.v1` with accepted PASS, matching repository digest, and positive serial progress; changed pre/post chain revisions; a canonically recomputable chain revision and new persisted final-revision receipt witness; matching queue/slice and work-order/slice/head lineage; accepted verified draft-PR evidence; an external Git worktree present in the repository worktree registry with accepted invoke/create decisions and matching `HEAD`; and PatternMemory admission/record/digest identities recomputed from the canonical SQLite row.
499+
- `--receipt-path` may name only canonical `live_canary_receipt.json` inside the runtime root. Any alternate receipt must resolve outside both repository and runtime roots; reserved runtime artifacts and nested collisions fail before execution.
500+
- `READY_FOR_EXECUTION` does not claim that a live canary ran. Missing authority artifacts, signer socket, Git/GitHub readiness, or OpenRouter key presence returns `BLOCKED` without exposing values.
501+
- The surface has no signer launch, secret resolution, PR-ready, merge, reward, or HoloIndex re-index authority.
502+
492503
### OpenClaw Supervisor Contract
493504

494505
Canonical 0102 lifecycle owner:

modules/communication/moltbot_bridge/ModLog.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
# ModLog - moltbot_bridge
22

3+
## 2026-07-18: REDDOG_RESIDENT_LIVE_CANARY_PHASE1
4+
5+
**WSP Protocol**: WSP 00, 06, 15, 22, 46, 62, 71, 97
6+
**Phase**: Audit-hardened operator harness; live proof blocked pending operator artifacts
7+
**Agent**: 0102 focused worker under architect review
8+
9+
**Changes**:
10+
11+
- Added a Linux-only, explicit-confirmation operator surface for one invocation
12+
of the existing highest guarded resident queue profile.
13+
- Reused the existing control loop and planner; no queue stage, signer, Fusion,
14+
worktree, verifier, draft-PR, or PatternMemory orchestration was duplicated.
15+
- Added outside-repo atomic receipts that distinguish static readiness from a
16+
completed live proof and serialize only secret/reference presence.
17+
- Added a shared OS advisory lock around every main resident control-loop call;
18+
the persisted v1 control receipt records and proves lock ownership.
19+
- Required a matching newly persisted control receipt with exact schema,
20+
accepted PASS, repo digest, positive serial progress, and changed pre/post
21+
chain revisions.
22+
- Required the exact chain envelope, matching queue/slice, a new chain-store
23+
receipt bound to the final revision, and draft/held-out/PatternMemory lineage
24+
for one work order, slice, and candidate head.
25+
- Repaired the chain-store commit witness: its canonical revision normalizes
26+
only the newest receipt witness before hashing, then atomically persists that
27+
revision in both the envelope and receipt for non-circular readback proof.
28+
- Required accepted invoke/result worktree decisions plus an existing external
29+
Git worktree registered by the repository with matching `rev-parse` HEAD.
30+
- Required PatternMemory admission/record/digest identities to recompute from
31+
the canonical SQLite row read back through the production sink adapter.
32+
- Restricted runtime-root receipt output to canonical
33+
`live_canary_receipt.json`; alternate output must be outside both roots.
34+
- Split evidence and lock helpers so every live-canary production file is at
35+
most 675 lines and every function in those files is at most 50 lines.
36+
37+
**Truth boundary**: Focused tests prove the harness and evidence gates. No live
38+
signer was started and no production draft PR was created by this slice; the
39+
live proof remains blocked until WSL receives the required outside-repo
40+
authority/signer artifacts and an already-running isolated signer.
41+
342
## 2026-07-18: REDDOG_HOLOINDEX_QUERY_OWNER_BOUNDARY_POC_PHASE1
443

544
**WSP Protocol**: WSP 00, 05, 06, 15, 22, 50, 62, 87, 96, 97

modules/communication/moltbot_bridge/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,38 @@ Supervisor repair policy:
202202
- exhausted restart budget escalates instead of looping forever
203203
- every cycle advances a DAEmon follow cursor so repair decisions stay tied to observed runtime history
204204

205+
### Resident RedDog live canary
206+
207+
`reddog_resident_live_canary` is the operator admission surface for one run of
208+
the existing highest guarded resident profile. Run it on Linux/WSL first
209+
without `--execute`; readiness never invokes the control loop:
210+
211+
```bash
212+
python -m modules.communication.moltbot_bridge.src.reddog_resident_live_canary \
213+
--repo-root /mnt/o/Foundups-Agent \
214+
--runtime-root /mnt/o/.reddog/resident/Foundups-Agent
215+
```
216+
217+
Execution additionally requires `--execute --confirm
218+
REDDOG_RESIDENT_LIVE_CANARY_PHASE1`. The runtime root must be outside the
219+
repository and already contain the authority, permission, execution-valve,
220+
signer config/run-packet, and live signer socket artifacts named by the CLI
221+
receipt. The harness never starts the signer or resolves secret values.
222+
223+
`READY_FOR_EXECUTION` is only static readiness. Every main control-loop caller
224+
uses one shared OS advisory lock. `LIVE_PROOF_COMPLETE` requires the matching
225+
new v1 control receipt to prove lock ownership, accepted PASS, repository
226+
binding, and positive serial progress; changed pre/post chain revisions; an
227+
exact completed chain envelope with a new final-revision store receipt;
228+
work-order/slice/head lineage; accepted draft-only PR evidence; an external
229+
Git worktree registered by the repository with matching `HEAD`; and
230+
PatternMemory identities recomputed from the canonical SQLite record. The
231+
chain revision is non-circular: the store normalizes the newest receipt witness
232+
for hashing, then persists the same revision in the envelope and that receipt.
233+
It never marks a PR ready or merges it. Inside the runtime root, receipt output
234+
is reserved to canonical `live_canary_receipt.json`; other outputs must be
235+
outside both the runtime root and repository.
236+
205237
PQN runtime examples:
206238
- `run pqn simulation`
207239
- `status pqn simulation`

modules/communication/moltbot_bridge/src/reddog_resident_control_loop_receipt_store.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ResidentControlLoopReceipt:
3333
rejection_reasons: tuple[str, ...]
3434
created_at: str
3535
repo_root_digest: str
36+
control_lock_acquired: bool
3637
no_authority_issued: bool = True
3738
no_worker_spawn_performed: bool = True
3839
no_shell_command_executed: bool = True
@@ -66,6 +67,7 @@ def build_resident_control_loop_receipt(
6667
"rejection_reasons": _string_tuple(result.get("rejection_reasons")),
6768
"created_at": str(created_at or ""),
6869
"repo_root_digest": _digest(str(Path(repo_root).resolve())),
70+
"control_lock_acquired": result.get("control_lock_acquired") is True,
6971
"no_authority_issued": True,
7072
"no_worker_spawn_performed": True,
7173
"no_shell_command_executed": True,

0 commit comments

Comments
 (0)