Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
import atexit
import hashlib
import json
from functools import wraps
from datetime import datetime, timezone
from pathlib import Path
from typing import Optional, Dict, Any, Mapping, Sequence
from typing import Optional, Dict, Any, Callable, Mapping, Sequence

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

def _reddog_record_queue_control_result(repo_root: Path, result: Mapping[str, Any]) -> Dict[str, Any]:
"""Record and expose one resident queue control-loop result."""

recorded = dict(result)
recorded = _reddog_control_lock_annotated_result(result)
try:
from modules.communication.moltbot_bridge.src.reddog_resident_queue_binding_profile import (
resident_queue_runtime_file_path,
Expand Down Expand Up @@ -3955,6 +3955,49 @@ def _reddog_record_queue_control_result(repo_root: Path, result: Mapping[str, An
return recorded


def _reddog_control_lock_annotated_result(result: Mapping[str, Any]) -> Dict[str, Any]:
from modules.communication.moltbot_bridge.src.reddog_resident_queue_control_lock import (
resident_queue_control_lock_held,
)

recorded = dict(result)
recorded["control_lock_acquired"] = resident_queue_control_lock_held()
return recorded


def _with_reddog_queue_control_lock(control_loop: Callable[[Path], bool]) -> Callable[[Path], bool]:
"""Decorate every control-loop call with the shared non-blocking lock."""

@wraps(control_loop)
def locked(repo_root: Path) -> bool:
from modules.communication.moltbot_bridge.src.reddog_resident_queue_control_lock import (
acquire_resident_queue_control_lock,
)

with acquire_resident_queue_control_lock(repo_root) as lock:
if not lock.acquired:
locked.last_result = _reddog_locked_control_result(lock.reason, lock.path)
return False
return control_loop(repo_root)

return locked


def _reddog_locked_control_result(reason: str, lock_path: Path) -> Dict[str, Any]:
return {
"accepted": False,
"status": "CONTROL_LOOP_LOCKED",
"rounds": 0,
"serial_progress": 0,
"claim_progress": 0,
"receipt_ids": (),
"rejection_reasons": (reason,),
"control_lock_path": str(lock_path),
"control_lock_acquired": False,
}


@_with_reddog_queue_control_lock
def run_reddog_resident_queue_control_loop_preflight(repo_root: Path) -> bool:
"""
Drive the resident queue through bounded serial/claim rounds.
Expand Down
11 changes: 11 additions & 0 deletions modules/communication/moltbot_bridge/INTERFACE.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,17 @@ Resident OpenClaw contract:
- `tail <dae>` = recent window
- `watch|follow <dae> since <sequence>` = incremental follow with returned `next_cursor`

Resident RedDog live-canary contract:
- Entry point: `python -m modules.communication.moltbot_bridge.src.reddog_resident_live_canary`
- Default mode performs readiness checks only and writes an audit-safe receipt outside the repository.
- Live invocation requires Linux, `--execute`, and exact confirmation token `REDDOG_RESIDENT_LIVE_CANARY_PHASE1`.
- The selected profile is fixed to `signed_0102_bounded_code_fusion_worktree_draft_pr_pattern_memory`.
- The harness delegates to `main.run_reddog_resident_queue_control_loop_preflight`; it does not duplicate queue stages.
- `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.
- `--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.
- `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.
- The surface has no signer launch, secret resolution, PR-ready, merge, reward, or HoloIndex re-index authority.

### OpenClaw Supervisor Contract

Canonical 0102 lifecycle owner:
Expand Down
39 changes: 39 additions & 0 deletions modules/communication/moltbot_bridge/ModLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
# ModLog - moltbot_bridge

## 2026-07-18: REDDOG_RESIDENT_LIVE_CANARY_PHASE1

**WSP Protocol**: WSP 00, 06, 15, 22, 46, 62, 71, 97
**Phase**: Audit-hardened operator harness; live proof blocked pending operator artifacts
**Agent**: 0102 focused worker under architect review

**Changes**:

- Added a Linux-only, explicit-confirmation operator surface for one invocation
of the existing highest guarded resident queue profile.
- Reused the existing control loop and planner; no queue stage, signer, Fusion,
worktree, verifier, draft-PR, or PatternMemory orchestration was duplicated.
- Added outside-repo atomic receipts that distinguish static readiness from a
completed live proof and serialize only secret/reference presence.
- Added a shared OS advisory lock around every main resident control-loop call;
the persisted v1 control receipt records and proves lock ownership.
- Required a matching newly persisted control receipt with exact schema,
accepted PASS, repo digest, positive serial progress, and changed pre/post
chain revisions.
- Required the exact chain envelope, matching queue/slice, a new chain-store
receipt bound to the final revision, and draft/held-out/PatternMemory lineage
for one work order, slice, and candidate head.
- Repaired the chain-store commit witness: its canonical revision normalizes
only the newest receipt witness before hashing, then atomically persists that
revision in both the envelope and receipt for non-circular readback proof.
- Required accepted invoke/result worktree decisions plus an existing external
Git worktree registered by the repository with matching `rev-parse` HEAD.
- Required PatternMemory admission/record/digest identities to recompute from
the canonical SQLite row read back through the production sink adapter.
- Restricted runtime-root receipt output to canonical
`live_canary_receipt.json`; alternate output must be outside both roots.
- Split evidence and lock helpers so every live-canary production file is at
most 675 lines and every function in those files is at most 50 lines.

**Truth boundary**: Focused tests prove the harness and evidence gates. No live
signer was started and no production draft PR was created by this slice; the
live proof remains blocked until WSL receives the required outside-repo
authority/signer artifacts and an already-running isolated signer.

## 2026-07-18: REDDOG_HOLOINDEX_QUERY_OWNER_BOUNDARY_POC_PHASE1

**WSP Protocol**: WSP 00, 05, 06, 15, 22, 50, 62, 87, 96, 97
Expand Down
32 changes: 32 additions & 0 deletions modules/communication/moltbot_bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,38 @@ Supervisor repair policy:
- exhausted restart budget escalates instead of looping forever
- every cycle advances a DAEmon follow cursor so repair decisions stay tied to observed runtime history

### Resident RedDog live canary

`reddog_resident_live_canary` is the operator admission surface for one run of
the existing highest guarded resident profile. Run it on Linux/WSL first
without `--execute`; readiness never invokes the control loop:

```bash
python -m modules.communication.moltbot_bridge.src.reddog_resident_live_canary \
--repo-root /mnt/o/Foundups-Agent \
--runtime-root /mnt/o/.reddog/resident/Foundups-Agent
```

Execution additionally requires `--execute --confirm
REDDOG_RESIDENT_LIVE_CANARY_PHASE1`. The runtime root must be outside the
repository and already contain the authority, permission, execution-valve,
signer config/run-packet, and live signer socket artifacts named by the CLI
receipt. The harness never starts the signer or resolves secret values.

`READY_FOR_EXECUTION` is only static readiness. Every main control-loop caller
uses one shared OS advisory lock. `LIVE_PROOF_COMPLETE` requires the matching
new v1 control receipt to prove lock ownership, accepted PASS, repository
binding, and positive serial progress; changed pre/post chain revisions; an
exact completed chain envelope with a new final-revision store receipt;
work-order/slice/head lineage; accepted draft-only PR evidence; an external
Git worktree registered by the repository with matching `HEAD`; and
PatternMemory identities recomputed from the canonical SQLite record. The
chain revision is non-circular: the store normalizes the newest receipt witness
for hashing, then persists the same revision in the envelope and that receipt.
It never marks a PR ready or merges it. Inside the runtime root, receipt output
is reserved to canonical `live_canary_receipt.json`; other outputs must be
outside both the runtime root and repository.

PQN runtime examples:
- `run pqn simulation`
- `status pqn simulation`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ResidentControlLoopReceipt:
rejection_reasons: tuple[str, ...]
created_at: str
repo_root_digest: str
control_lock_acquired: bool
no_authority_issued: bool = True
no_worker_spawn_performed: bool = True
no_shell_command_executed: bool = True
Expand Down Expand Up @@ -66,6 +67,7 @@ def build_resident_control_loop_receipt(
"rejection_reasons": _string_tuple(result.get("rejection_reasons")),
"created_at": str(created_at or ""),
"repo_root_digest": _digest(str(Path(repo_root).resolve())),
"control_lock_acquired": result.get("control_lock_acquired") is True,
"no_authority_issued": True,
"no_worker_spawn_performed": True,
"no_shell_command_executed": True,
Expand Down
Loading
Loading