Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
c0d0d79
fix(steward): reject incomplete open PR pagination
hhyykk Nov 27, 2026
80cab8f
fix(steward): reject unidentifiable PR nodes in snapshots
hhyykk Nov 27, 2026
f04c236
fix(steward): check open PR count across GraphQL pages
hhyykk Nov 27, 2026
9f4df8a
fix(steward): adapt bounded scan for larger PR queues
hhyykk Nov 27, 2026
d8a1866
fix(steward): share one deadline across PR evidence reads
hhyykk Nov 27, 2026
0cce87a
fix(steward): target comment backfill to the monitor scope
hhyykk Nov 27, 2026
a49054c
fix(steward): apply firm age thresholds before comment coverage
hhyykk Nov 27, 2026
11ad88b
fix(steward): verify older comment pagination flags
hhyykk Nov 27, 2026
3b9efbd
fix(steward): reject unreadable comment coverage
hhyykk Nov 27, 2026
3ede75d
fix(steward): preserve uncertainty for unidentified replies
hhyykk Nov 27, 2026
3b8b17d
fix(steward): preserve uncertainty when PR creator is missing
hhyykk Nov 27, 2026
c922884
fix(steward): preserve uncertain author-scope membership
hhyykk Nov 27, 2026
72d9dcf
fix(steward): reject unreadable repository item lists
hhyykk Nov 27, 2026
248527f
fix(steward): reject unreadable repository PR rows
hhyykk Nov 27, 2026
6ac3659
fix(steward): preserve unknown stalled PR age
hhyykk Nov 27, 2026
56d029a
fix(steward): preserve ambiguous reply timing
hhyykk Nov 27, 2026
a3a73c9
fix(steward): gate review scopes on complete review evidence
hhyykk Nov 27, 2026
6c6b714
fix(steward): recover older review pages within the scan budget
hhyykk Nov 27, 2026
677df76
fix(steward): bind older comments to the observed PR head
hhyykk Nov 27, 2026
b1f6665
fix(steward): stop comment backfill on visited cursors
hhyykk Nov 27, 2026
211f9fc
fix(steward): reject older review pages with revision drift
hhyykk Nov 28, 2026
42cd1d1
fix(steward): verify the first review window during backfill
hhyykk Nov 28, 2026
5b2e438
fix(steward): revalidate consumed older review pages
hhyykk Nov 28, 2026
eb54fd4
fix(steward): bind nested check rollups to the observed head
hhyykk Nov 28, 2026
b071dc3
fix(steward): require complete head check contexts
hhyykk Nov 28, 2026
d5bf893
fix(steward): preserve prior checks on unclassified results
hhyykk Nov 28, 2026
8074733
Merge commit '63c7c487410827cd3b846fc47ef818d3800b9c06' into codex/st…
hhyykk Nov 28, 2026
26bd7d9
fix(steward): qualify head commit clocks before stall decisions
hhyykk Nov 28, 2026
ebbad02
fix(steward): require consistent comment windows during backfill
hhyykk Nov 28, 2026
6c22601
fix(steward): revalidate consumed open PR list windows
hhyykk Nov 28, 2026
95c1e92
fix(steward): revalidate carried head check tallies
hhyykk Nov 28, 2026
126b1ef
test(steward): distinguish a stale check tally in Lean
hhyykk Nov 28, 2026
a1ce4e1
Merge commit '9a9589a279021ee360ffcbfd7558793b10626d85' into codex/st…
hhyykk Nov 28, 2026
e96d418
fix(steward): revalidate carried review windows
hhyykk Nov 28, 2026
1b15efe
Merge commit '6181c1d115fc23cc5245ebbe41f7c104dd1bdba3' into codex/st…
hhyykk Nov 28, 2026
25e2465
Merge commit '811c1a1f66652d3fc3b9830d467e14b45b7423c1' into codex/st…
hhyykk Nov 28, 2026
1910db5
fix(steward): revalidate carried recent comment windows
hhyykk Nov 28, 2026
169e7d4
fix(steward): select PRs from terminal scope fields
hhyykk Nov 28, 2026
b8126e0
fix(steward): publish merge gates from terminal readback
hhyykk Nov 28, 2026
0d9873e
fix(steward): publish PR metadata from terminal readback
hhyykk Nov 28, 2026
06b82e9
fix(steward): isolate incomplete repo signals, validate comment conne…
codex Nov 28, 2026
777836e
Merge terminal metadata with repository observation isolation
hhyykk Nov 28, 2026
9ca1bd3
fix(steward): corroborate older comment supplements together
hhyykk Nov 28, 2026
1f891ab
fix(steward): corroborate older reviews in the joint readback
hhyykk Nov 28, 2026
785e962
fix(steward): bind PR supplements to the terminal list
hhyykk Nov 28, 2026
bb43452
fix(steward): corroborate two older sources on one PR
hhyykk Nov 28, 2026
c5bbad9
fix(steward): corroborate recent evidence in older page reads
hhyykk Nov 28, 2026
93b3337
test(steward): distinguish monitor recovery scopes
hhyykk Nov 28, 2026
27f5406
fix(steward): publish snapshots after native poll commit
hhyykk Nov 28, 2026
277dd1d
fix(steward): serialize signal scope changes with poll commit
hhyykk Nov 28, 2026
0687a46
fix(steward): fence poll commits to the observed repository
hhyykk Nov 28, 2026
26a91c8
fix(steward): require complete effect evidence for advancement retries
hhyykk Nov 28, 2026
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
5 changes: 5 additions & 0 deletions docs/reference/protocols/loopx-turn-v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ fresh task or repeated model call inferred from a failed CLI reply. This readbac
does not bypass controller completion validation, lease conflicts or quota gates.
Pre-execution failures retain known Turn-start hook writes without claiming Host
execution. Normal successful/replayed `effects` remain invocation-scoped.
Terminal journal replays also carry `recorded_effects` from the typed inspection.
Steward advancement retry requires explicit zero-effect facts and rejects
contradictory durable evidence.

中文:`recorded_effects` 是原 Turn 的持久观察,不是本次检查或恢复又发生了副作用。
`null` 表示未知:已登记 Host attempt 不等于模型已启动,`prepared` 不等于写回或扣额
Expand All @@ -673,6 +676,8 @@ execution. Normal successful/replayed `effects` remain invocation-scoped.
阶段绑定。未知或畸形 intent 阻断原恢复判定,不能建议重调 Host;保留合法身份与
阶段已经证明的执行事实,其余返回未知而非 `false`。不放松原 writer 的空 map
拒绝语义:无待决 intent 应省略该字段,已提交历史由完成 checkpoint 表达。
重放终态日志时,响应同时带回从类型化检查取得的 `recorded_effects`。Steward
推进任务的自动重试要求明确的零副作用证据,存在冲突的持久记录时保留原轮次。

Exit zero means that inspection completed, including when `decision` is
`replay_blocked`. A non-zero exit means the command could not inspect the
Expand Down
1,345 changes: 1,085 additions & 260 deletions loopx/capabilities/native_chat/github_pr_evidence.py

Large diffs are not rendered by default.

44 changes: 37 additions & 7 deletions loopx/capabilities/native_chat/steward_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from __future__ import annotations

from collections.abc import Mapping, Sequence
from collections.abc import Callable, Mapping, Sequence
import subprocess as subprocess

from ...control_plane.scheduler.monitor_todo import monitor_todo_is_due
Expand All @@ -22,7 +22,9 @@
pump_managed_session_monitors as pump_managed_session_monitors,
pump_steward_monitors as pump_steward_monitors,
)
from .steward_monitor_snapshots import commit_signal_snapshot, fence_observed_signal_scope
from .steward_monitor_signals import (
SignalMonitorCollection,
_accepts_backfill_comments as _accepts_backfill_comments,
_github_repo_slug as _github_repo_slug,
_signal_scope_uses_stalled_age as _signal_scope_uses_stalled_age,
Expand Down Expand Up @@ -64,11 +66,19 @@


def _observe_github_repository_prs(
repo_slug: str, *, backfill_comments: bool = False
repo_slug: str,
*,
backfill_comments: bool = False,
select_comment_backfill: Callable[[Sequence[Mapping[str, object]], float], set[int]] | None = None,
select_review_backfill: Callable[[Sequence[Mapping[str, object]], float], set[int]] | None = None,
) -> dict[str, object]:
"""Read bounded public/authorized open PR signal metadata without side effects."""
raw = observe_github_repository_prs(
repo_slug, runner=subprocess.run, backfill_comments=backfill_comments
repo_slug,
runner=subprocess.run,
backfill_comments=backfill_comments,
select_comment_backfill=select_comment_backfill,
select_review_backfill=select_review_backfill,
)
return _coerce_dict(raw)

Expand Down Expand Up @@ -231,6 +241,8 @@ def _commit_poll(
turn: Mapping[str, object],
context: Mapping[str, object],
argv: list[str],
*,
signal_snapshot: dict[str, object] | None = None,
) -> dict[str, object]:
# Configuration and revocation use this original binding fence too.
# Keep the final scoped admission and native write in one ordering;
Expand Down Expand Up @@ -270,9 +282,24 @@ def _commit_poll(
or admitted["observed_scope_id"] != context["authorization_scope_id"]
):
raise ValueError("the portfolio scope changed after observation")
return self._native_poll(argv)
if signal_snapshot is None:
return self._native_poll(argv)
root = self.controller.coordination_runtime_root
with fence_observed_signal_scope(root, signal_snapshot):
return commit_signal_snapshot(
root,
self.controller.registry_path,
signal_snapshot,
agent_id=str(actor["agent_id"]),
turn_instance_id=str(request["turn_instance_id"]),
poll=lambda: self._native_poll(
argv, observed_task_repository=str(signal_snapshot.get("task_repository") or ""),
),
)

def _native_poll(self, argv: Sequence[str]) -> dict[str, object]:
def _native_poll(
self, argv: Sequence[str], *, observed_task_repository: str | None = None,
) -> dict[str, object]:
"""Use the native poll owner; a Chat observation is no heartbeat task."""
from ...cli_runtime import _build_selected_parser
from ...cli_commands.lark_inbox import (
Expand Down Expand Up @@ -320,6 +347,7 @@ def _native_poll(self, argv: Sequence[str]) -> dict[str, object]:
).status_payload,
todo_id=args.todo_id,
target_key=args.target_key,
observed_task_repository=observed_task_repository,
turn_instance_id=args.turn_instance_id,
result_hash=args.result_hash,
material_change=args.material_change,
Expand Down Expand Up @@ -384,7 +412,7 @@ def _collect_signal_monitor(
actor: Mapping[str, object],
context: Mapping[str, object],
todo: Mapping[str, object],
) -> tuple[dict[str, object], list[str]]:
) -> SignalMonitorCollection:
return collect_signal_monitor(
self.controller,
actor=actor,
Expand Down Expand Up @@ -445,6 +473,7 @@ def observe(
]
host._admit(_coerce_dict(request), turn=_coerce_dict(turn))
successor_args: list[str] = []
signal_snapshot = None
if actor.get("schema_version") == "loopx_managed_session_actor_v0":
from .conversation_bindings import ChatConversationBindings

Expand All @@ -458,7 +487,7 @@ def observe(
},
)
elif todo.get("target_key") != TARGET:
observation, successor_args = self._collect_signal_monitor(
observation, successor_args, signal_snapshot = self._collect_signal_monitor(
actor, context, todo
)
else:
Expand Down Expand Up @@ -508,6 +537,7 @@ def observe(
*(["--material-change"] if observation["material_change"] else []),
*successor_args,
],
**({"signal_snapshot": signal_snapshot} if signal_snapshot is not None else {}),
)
finally:
self._release(actor, todo, lease)
Expand Down
128 changes: 86 additions & 42 deletions loopx/capabilities/native_chat/steward_monitor_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
from __future__ import annotations

from collections.abc import Callable, Mapping, Sequence
from datetime import timedelta
from functools import partial
import inspect
import math
from pathlib import Path
from typing import Protocol
from typing import NamedTuple, Protocol

from ...chat_store import _atomic_write_json
from ...control_plane.runtime.time import now_utc
from ..issue_fix.github_public import _REPO_PATTERN
from .steward_commands import NativeStewardCommandError, native_command
from .steward_monitor_snapshots import SIGNAL_MONITOR_SNAPSHOT_SCHEMA, read_committed_signal_snapshot
from .steward_monitor_turns import (
FOLLOWUP_TARGET_PREFIX,
StewardAcquireLeaseFn,
Expand All @@ -22,7 +24,6 @@
_coerce_dict,
is_exhausted_zero_write_followup_todo,
read_steward_monitor_scope,
steward_monitor_snapshot_path,
)


Expand Down Expand Up @@ -71,74 +72,101 @@ def _read_pending_inbox_items(
goal_id: str,
agent_id: str,
include_inbox: bool,
) -> list[dict[str, object]]:
) -> list[dict[str, object]] | None:
if not include_inbox:
return []
from ...control_plane.collaboration.inbox import pending as inbox_pending

try:
inbox_raw = inbox_pending(runtime_root, goal_id=goal_id, agent_id=agent_id)
inbox_page = inbox_pending(runtime_root, goal_id=goal_id, agent_id=agent_id)
return [
{"request_id": row["request_id"], "source_id": row.get("source_id")}
for row in inbox_raw
for row in inbox_page["items"]
if isinstance(row, dict) and row.get("request_id")
]
except (OSError, ValueError):
return []
return None


def _read_repository_snapshot(
todo: Mapping[str, object],
signal_scope: Mapping[str, object] | None,
observe_github_prs: Callable[..., dict[str, object]],
core: Callable[[str, Mapping[str, object]], Mapping[str, object]],
) -> dict[str, object] | None:
repo_slug = _github_repo_slug(todo.get("task_repository"))
if not repo_slug:
return None
backfill_comments = _signal_scope_uses_stalled_age(signal_scope)
if backfill_comments and _accepts_backfill_comments(observe_github_prs):
return observe_github_prs(repo_slug, backfill_comments=True)
return observe_github_prs(repo_slug)
if signal_scope is None:
return observe_github_prs(repo_slug)

def select_backfill(source: str, items: Sequence[Mapping[str, object]], remaining_seconds: float) -> set[int]:
latest_observation = now_utc() + timedelta(milliseconds=math.ceil(remaining_seconds * 1000))
planned = core(f"collaboration.steward.monitor.{source}_backfill.plan", {
"signal_scope": signal_scope,
"repository_items": items,
"observed_at": latest_observation.isoformat(),
}).get("pr_numbers")
if not isinstance(planned, list) or any(type(number) is not int or number <= 0 for number in planned):
raise TypeError(f"invalid Steward {source} backfill plan")
return set(planned)

parameters = inspect.signature(observe_github_prs).parameters
options: dict[str, object] = {}
if "select_review_backfill" in parameters:
options["select_review_backfill"] = partial(select_backfill, "review")
if _signal_scope_uses_stalled_age(signal_scope) and _accepts_backfill_comments(observe_github_prs):
options["backfill_comments"] = True
if "select_comment_backfill" in parameters:
options["select_comment_backfill"] = partial(select_backfill, "comment")
return observe_github_prs(repo_slug, **options)


def _previous_repository_snapshot(snapshot: Mapping[str, object] | None) -> dict[str, object] | None:
if snapshot is None:
return None
repository = _coerce_dict(snapshot.get("repository_snapshot"))
items = repository.get("items")
if repository.get("status") == "unavailable" or not isinstance(items, list):
return None
numbers = [_coerce_dict(row).get("number") for row in items]
if any(type(number) is not int or not 0 < number < 2**53 for number in numbers):
return None
return repository if len(set(numbers)) == len(numbers) else None


def _persist_signal_snapshot(
def _build_signal_snapshot(
*,
runtime_root: Path,
goal_id: str,
todo: Mapping[str, object],
signal_scope: Mapping[str, object] | None,
observed_at: str,
observation: Mapping[str, object],
repo_snapshot: dict[str, object] | None,
inbox_items: list[dict[str, object]],
) -> None:
) -> dict[str, object]:
persisted_repo_snapshot = repo_snapshot
if isinstance(repo_snapshot, Mapping) and "scoped_repository_items" in observation:
raw_items = observation["scoped_repository_items"]
if not isinstance(raw_items, Sequence) or isinstance(raw_items, (str, bytes)):
raise TypeError("scoped_repository_items must be a sequence")
persisted_repo_snapshot = {**repo_snapshot, "items": list(raw_items)}
snapshot_path = steward_monitor_snapshot_path(
runtime_root, goal_id, str(todo["todo_id"])
)
snapshot_path.parent.mkdir(parents=True, exist_ok=True)
_atomic_write_json(
snapshot_path,
{
"schema_version": "steward_signal_monitor_snapshot_v0",
"goal_id": goal_id,
"todo_id": todo["todo_id"],
"target_key": todo.get("target_key"),
"monitor_text": todo.get("text"),
"task_repository": todo.get("task_repository"),
**({"signal_scope": signal_scope} if signal_scope is not None else {}),
"result_hash": observation["result_hash"],
"material_change": observation["material_change"],
"observed_at": observed_at,
"repository_snapshot": persisted_repo_snapshot,
"inbox_items": inbox_items,
},
)
return {
"schema_version": SIGNAL_MONITOR_SNAPSHOT_SCHEMA,
"goal_id": goal_id,
"todo_id": todo["todo_id"],
"target_key": todo.get("target_key"),
"monitor_text": todo.get("text"),
"task_repository": todo.get("task_repository"),
**({"signal_scope": signal_scope} if signal_scope is not None else {}),
"result_hash": observation["result_hash"],
"material_change": observation["material_change"],
"observed_at": observed_at,
**({"repository_observation_incomplete": True}
if observation.get("repository_observation_incomplete") is True else {}),
"repository_snapshot": persisted_repo_snapshot,
"inbox_items": inbox_items,
}


def _build_followup_successor_args(
Expand Down Expand Up @@ -173,6 +201,12 @@ def _build_followup_successor_args(
]


class SignalMonitorCollection(NamedTuple):
observation: dict[str, object]
successor_args: list[str]
snapshot: dict[str, object]


def collect_signal_monitor(
controller: StewardControllerProtocol,
*,
Expand All @@ -182,8 +216,8 @@ def collect_signal_monitor(
session_scope_for_actor: _SessionScopeFn,
read_todos: StewardReadTodosFn,
observe_github_prs: Callable[..., dict[str, object]],
) -> tuple[dict[str, object], list[str]]:
"""Evaluate a scoped signal monitor, persist its snapshot, and emit follow-up args."""
) -> SignalMonitorCollection:
"""Evaluate a scoped signal monitor and prepare its candidate snapshot."""
target_key = str(todo.get("target_key") or "")
goal_id = str(actor["goal_id"])
agent_id = str(actor["agent_id"])
Expand Down Expand Up @@ -212,14 +246,23 @@ def collect_signal_monitor(
inbox_items = _read_pending_inbox_items(
runtime_root, goal_id=goal_id, agent_id=agent_id, include_inbox=include_inbox
)
repo_snapshot = _read_repository_snapshot(todo, signal_scope, observe_github_prs)
repo_snapshot = _read_repository_snapshot(todo, signal_scope, observe_github_prs, bindings._core)
previous_repository_snapshot = (
_previous_repository_snapshot(
read_committed_signal_snapshot(runtime_root, controller.registry_path, goal_id, todo, signal_scope)
)
if repo_snapshot is not None and (include_portfolio or include_inbox)
else None
)
observed_at = now_utc().isoformat()
signal_request: dict[str, object] = {
"portfolio_observation": portfolio,
"inbox_items": inbox_items,
"repository_snapshot": repo_snapshot,
"previous_hash": todo.get("result_hash"),
}
if previous_repository_snapshot is not None:
signal_request["previous_repository_snapshot"] = previous_repository_snapshot
if signal_scope is not None:
signal_request["signal_scope"] = signal_scope
signal_request["observed_at"] = observed_at
Expand All @@ -228,15 +271,16 @@ def collect_signal_monitor(
)
if observation.get("observation_incomplete") is True:
raise RuntimeError("steward monitor external signal source temporarily unavailable")
_persist_signal_snapshot(
runtime_root=runtime_root,
if observation.get("repository_observation_incomplete") is True:
repo_snapshot = previous_repository_snapshot
snapshot = _build_signal_snapshot(
goal_id=goal_id,
todo=todo,
signal_scope=signal_scope,
observed_at=observed_at,
observation=observation,
repo_snapshot=repo_snapshot,
inbox_items=inbox_items,
inbox_items=inbox_items or [],
)
successor_args = (
_build_followup_successor_args(
Expand All @@ -249,7 +293,7 @@ def collect_signal_monitor(
if observation.get("material_change")
else []
)
return observation, successor_args
return SignalMonitorCollection(dict(observation), successor_args, snapshot)


def rearm_exhausted_followup_if_needed(
Expand Down
Loading
Loading