feat: dual-run facade to repo-manager for task writeback
RMGR-WP-0002 Stage B: when RM_WRITEBACK/RM_RECONCILE flags are set, PATCH /tasks and C-15 writeback call rmgr; fix_repo runs rmgr reconcile for pilots.
This commit is contained in:
parent
462f4a47d2
commit
bfaff50b4e
4 changed files with 360 additions and 13 deletions
|
|
@ -2607,6 +2607,23 @@ def fix_repo(
|
|||
if any(i.check_id == "C-00" for i in report.failures):
|
||||
return report
|
||||
|
||||
# RMGR-WP-0002: optional repo-manager reconcile proxy (index rebuild) for pilots
|
||||
try:
|
||||
from api.services.repo_manager_dual_run import reconcile_for_repo, rm_reconcile
|
||||
|
||||
if reconcile_for_repo(repo_slug) and report.repo_path:
|
||||
rm_rec = rm_reconcile(repo_path=report.repo_path, repo_slug=repo_slug)
|
||||
if rm_rec.get("ok") or rm_rec.get("exit_code") == 0:
|
||||
report.fixes_applied.append(
|
||||
f"RM dual-run reconcile ok: index={rm_rec.get('index_path') or 'written'}"
|
||||
)
|
||||
else:
|
||||
report.fixes_applied.append(
|
||||
f"RM dual-run reconcile note: {rm_rec.get('error') or rm_rec}"
|
||||
)
|
||||
except Exception as rec_exc: # noqa: BLE001
|
||||
report.fixes_applied.append(f"RM dual-run reconcile skipped: {rec_exc}")
|
||||
|
||||
# Auto-register this machine's path in host_paths so future runs work
|
||||
# without --repo-path. Idempotent: skipped when already correct.
|
||||
repo_path = report.repo_path
|
||||
|
|
@ -3043,22 +3060,68 @@ def fix_repo(
|
|||
task_block_id = ctx["task_block_id"]
|
||||
db_status = ctx["db_status"]
|
||||
old_status = issue.file_value
|
||||
if _patch_task_status_in_file(wp_file, task_block_id, db_status):
|
||||
committed = _git_commit_writeback(
|
||||
repo_path,
|
||||
wp_file,
|
||||
[f"{task_block_id}: {old_status} → {db_status}"],
|
||||
# RMGR-WP-0002 dual-run: prefer repo-manager writeback when flagged
|
||||
rm_done = False
|
||||
try:
|
||||
from api.services.repo_manager_dual_run import (
|
||||
try_writeback_for_task,
|
||||
writeback_for_repo,
|
||||
)
|
||||
suffix = " (committed)" if committed else " (file patched, commit failed)"
|
||||
|
||||
if writeback_for_repo(repo_slug) and repo_path:
|
||||
# Prefer hub UUID when available for robust matching
|
||||
task_ref = ctx.get("task_id") or task_block_id
|
||||
rm_result = try_writeback_for_task(
|
||||
repo_path=repo_path,
|
||||
repo_slug=repo_slug,
|
||||
task_id=str(task_ref),
|
||||
status=db_status,
|
||||
reason="state-hub C-15 dual-run writeback",
|
||||
)
|
||||
if rm_result and rm_result.get("status") == "applied":
|
||||
git_sha = (rm_result.get("evidence") or {}).get("git_sha")
|
||||
suffix = f" (repo-manager git_sha={git_sha})" if git_sha else " (repo-manager)"
|
||||
report.fixes_applied.append(
|
||||
f"C-15 fixed: task '{task_block_id}' "
|
||||
f"{old_status} → {db_status}{suffix}"
|
||||
)
|
||||
rm_done = True
|
||||
except Exception as rm_exc: # noqa: BLE001
|
||||
report.fixes_applied.append(
|
||||
f"C-15 fixed: task '{task_block_id}' "
|
||||
f"{old_status} → {db_status}{suffix}"
|
||||
)
|
||||
else:
|
||||
report.fixes_applied.append(
|
||||
f"C-15 SKIP: could not locate task block '{task_block_id}' "
|
||||
f"in {wp_file.name}"
|
||||
f"C-15 dual-run fallback to native: {rm_exc}"
|
||||
)
|
||||
if not rm_done:
|
||||
if _patch_task_status_in_file(wp_file, task_block_id, db_status):
|
||||
committed = _git_commit_writeback(
|
||||
repo_path,
|
||||
wp_file,
|
||||
[f"{task_block_id}: {old_status} → {db_status}"],
|
||||
)
|
||||
try:
|
||||
from api.services.repo_manager_dual_run import record_mutation
|
||||
|
||||
record_mutation(
|
||||
source="state-hub",
|
||||
kind="task_status_writeback_c15",
|
||||
repo_slug=repo_slug,
|
||||
detail={
|
||||
"task_block_id": task_block_id,
|
||||
"status": db_status,
|
||||
"committed": committed,
|
||||
},
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
suffix = " (committed)" if committed else " (file patched, commit failed)"
|
||||
report.fixes_applied.append(
|
||||
f"C-15 fixed: task '{task_block_id}' "
|
||||
f"{old_status} → {db_status}{suffix}"
|
||||
)
|
||||
else:
|
||||
report.fixes_applied.append(
|
||||
f"C-15 SKIP: could not locate task block '{task_block_id}' "
|
||||
f"in {wp_file.name}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
report.fixes_applied.append(f"{issue.check_id} ERROR: {e}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue