diff --git a/project/TICKETS.md b/project/TICKETS.md index 117535f..676615c 100644 --- a/project/TICKETS.md +++ b/project/TICKETS.md @@ -154,4 +154,5 @@ | **ticket-165** | [`README.md`](./ticket-165/README.md) | - | - | - | - | - | | **ticket-166** | [`README.md`](./ticket-166/README.md) | - | - | - | - | - | | **ticket-167** | [`README.md`](./ticket-167/README.md) | - | - | - | - | - | +| **ticket-168** | [`README.md`](./ticket-168/README.md) | - | - | - | - | - | diff --git a/project/ticket-168/README.md b/project/ticket-168/README.md new file mode 100644 index 0000000..43dca57 --- /dev/null +++ b/project/ticket-168/README.md @@ -0,0 +1,36 @@ +# Ticket 168: PLF-29794 Qualify the Coding Agent queue in scheduled Monag triage + +- **ID**: ticket-168 +- **Owner**: unresolved:human +- **Status**: IN_PROGRESS +- **Workflow state**: EDIT +- **Created**: 2026-11-24 + +## Goal and scope + +To be completed from human-owned input. + +## Acceptance criteria + +- [ ] AC-01: Scope is approved by a human owner. + +## Tracking boundary + +This directory contains the minimal reviewed intent. Optional participant prose +and raw command logs are not required delivery output. + + +## Ticket Radar + +Initial planned-scope estimate; advisory only, not execution or merge approval. + +| Measure | Initial assessment | +| --- | --- | +| Impact score | 52/100 | +| Complexity | M | +| Estimated effort | 51 min | +| Planning budget | 30 min | +| Split recommended | yes | + +Diagnostics: RADAR-ACCEPTANCE-MISSING, RADAR-BUDGET-EXCEEDED. + diff --git a/project/ticket-168/intent.json b/project/ticket-168/intent.json new file mode 100644 index 0000000..c3cda58 --- /dev/null +++ b/project/ticket-168/intent.json @@ -0,0 +1,25 @@ +{ + "schema": "new-project.intent/v3", + "ticket": "ticket-168", + "summary": "PLF-29794 Qualify the Coding Agent queue in scheduled Monag triage", + "workstream": "application", + "classification": { + "kind": "BUG", + "priority": "P1", + "origin": "requested" + }, + "allowedPaths": [ + "project/ticket-168/**", + "TODO.md", + "project/TICKETS.md", + "src/monag/autonomy_probes.py", + "tests/test_planfile_discovery_probe.py" + ], + "forbiddenPaths": [ + "project/ticket-*/user-*.md" + ], + "stacks": [], + "dependsOn": [], + "conflictsWith": [], + "integrationTicket": null +} diff --git a/src/monag/autonomy_probes.py b/src/monag/autonomy_probes.py index 6776427..045b55a 100644 --- a/src/monag/autonomy_probes.py +++ b/src/monag/autonomy_probes.py @@ -3,6 +3,7 @@ import json import os +import re import sqlite3 import subprocess import urllib.error @@ -85,6 +86,38 @@ def _planfile_bridge_alert(url: str, timeout: float) -> dict[str, Any] | None: } +def _discovery_failure(url: str, *, configured: bool, timeout: float) -> tuple[int | None, str] | None: + """Check the projection selected by MONAG_PLANFILE_DISCOVERY_URL.""" + try: + endpoint = urllib.parse.urlsplit(url) + if endpoint.scheme not in {"http", "https"} or not endpoint.hostname: + return None, "invalid_discovery_url" + query = urllib.parse.parse_qs(endpoint.query, keep_blank_values=True) + status, body = _http_probe(url, timeout) + except ValueError: + return None, "invalid_discovery_url" + if status is None: + return (None, "discovery_unreachable") if configured else None + + data = body if isinstance(body, dict) else {} + if status != 200 or data.get("error") == "ticket_index_stale": + reason = data.get("detail") or data.get("error") or data.get("code") + if isinstance(reason, dict): + reason = reason.get("code") + # Retain machine codes. Backend diagnostics can contain ticket data. + if not isinstance(reason, str) or not re.fullmatch(r"[a-z][a-z0-9_]{0,79}", reason): + reason = f"http_{status}" + return status, reason + + if query.get("mode") == ["queue"]: + scope = data.get("scope") + if (data.get("schema") != "planfile.ticket-discovery/v1" + or not isinstance(data.get("tickets"), list) or not isinstance(scope, dict) + or any(query[key] != [scope.get(key)] for key in ("mode", "queue", "state") if key in query)): + return status, "discovery_response_mismatch" + return None + + def probe_live_autonomy_blockers( *, timeout: float = 1.5, @@ -102,7 +135,8 @@ def probe_live_autonomy_blockers( blockers: list[dict[str, Any]] = [] urls = endpoint_urls or {} willman_url = urls.get("willman") or os.environ.get("MONAG_WILLMAN_HEALTH_URL", "http://127.0.0.1:7655/v1/health?readiness=1") - planfile_url = urls.get("planfile") or os.environ.get("MONAG_PLANFILE_DISCOVERY_URL", "http://127.0.0.1:8765/tickets/discovery") + configured_discovery = urls.get("planfile") or os.environ.get("MONAG_PLANFILE_DISCOVERY_URL") + planfile_url = configured_discovery or "http://127.0.0.1:8765/tickets/discovery" heyasa_url = urls.get("heyasa") or os.environ.get("MONAG_HEYASA_HEALTH_URL", "http://127.0.0.1:8787/health") # 1. Willman readiness probe @@ -123,9 +157,9 @@ def probe_live_autonomy_blockers( }) # 2. Central Planfile /tickets/discovery probe - p_status, p_body = _http_probe(planfile_url, timeout) - if p_status == 503 or (isinstance(p_body, dict) and p_body.get("error") == "ticket_index_stale"): - detail = p_body.get("error") if isinstance(p_body, dict) else str(p_body) + failure = _discovery_failure(planfile_url, configured=bool(configured_discovery), timeout=timeout) + if failure is not None: + p_status, detail = failure blockers.append({ "origin": "runtime-planfile-health", "category": "autonomy-blocker", @@ -133,8 +167,11 @@ def probe_live_autonomy_blockers( "tier": "floor", "score": 5150, "unblock_impact": 5150, - "suggested_command": f"curl -fsS {planfile_url}", - "repo": "wellmanifest/new-project", + "suggested_command": "monag --json triage", + "repo": "semcod/planfile", + "http_status": p_status, + "cause": detail, + "evidence": f"Planfile discovery: {detail} (HTTP {p_status})" if p_status else f"Planfile discovery: {detail}", "title": f"P0 Autonomy Blocker: Planfile /tickets/discovery unhealthy ({p_status or 'err'}: {detail})", "detail": detail, }) diff --git a/tests/test_planfile_discovery_probe.py b/tests/test_planfile_discovery_probe.py new file mode 100644 index 0000000..29f88ed --- /dev/null +++ b/tests/test_planfile_discovery_probe.py @@ -0,0 +1,56 @@ +from subprocess import CompletedProcess +from unittest.mock import patch + +import pytest + +from monag.autonomy_probes import probe_live_autonomy_blockers + + +QUEUE = "http://planfile.invalid/tickets/discovery?mode=queue&queue=coding-agent&state=pending" +PAGE = { + "schema": "planfile.ticket-discovery/v1", + "tickets": [], + "scope": {"mode": "queue", "queue": "coding-agent", "state": "pending"}, +} + + +def observe(monkeypatch, tmp_path, status, response, *, configured=True): + monkeypatch.delenv("MONAG_PLANFILE_DISCOVERY_URL", raising=False) + monkeypatch.delenv("MONAG_PLANFILE_URTLOG_HEALTH_URL", raising=False) + if configured: + monkeypatch.setenv("MONAG_PLANFILE_DISCOVERY_URL", QUEUE) + + def probe(url, _timeout): + return (status, response) if "/tickets/discovery" in url else (200, {}) + + with patch("monag.autonomy_probes._http_probe", side_effect=probe), patch( + "monag.autonomy_probes.probe_fact_advisories", return_value=[] + ): + candidates = probe_live_autonomy_blockers( + include_runtime_probes=True, willman_db=tmp_path / "willman", + heyasa_plans=tmp_path / "plans", systemctl_runner=lambda argv: CompletedProcess(argv, 1), + ) + return [item for item in candidates if item["origin"] == "runtime-planfile-health"] + + +@pytest.mark.parametrize(("status", "body", "reason"), [ + (503, {"detail": "ticket_index_stale"}, "ticket_index_stale"), + (503, {"detail": "ticket_index_repair_pending"}, "ticket_index_repair_pending"), + (503, {"detail": {"code": "store_lock_timeout"}}, "store_lock_timeout"), + (503, {"error": "ticket_index_stale"}, "ticket_index_stale"), + (502, "Bad Gateway", "http_502"), + (None, "connection refused", "discovery_unreachable"), + (200, {"status": "ok"}, "discovery_response_mismatch"), + (200, {**PAGE, "tickets": {}}, "discovery_response_mismatch"), + (200, {**PAGE, "scope": {**PAGE["scope"], "state": "ready"}}, "discovery_response_mismatch"), +]) +def test_configured_queue_reports_actionable_evidence(monkeypatch, tmp_path, status, body, reason): + [alert] = observe(monkeypatch, tmp_path, status, body) + assert (alert["repo"], alert["detail"], alert["http_status"]) == ("semcod/planfile", reason, status) + assert alert["cause"] == reason + assert reason in alert["title"] and reason in alert["evidence"] + + +def test_valid_empty_queue_and_absent_optional_installation(monkeypatch, tmp_path): + assert observe(monkeypatch, tmp_path, 200, PAGE) == [] + assert observe(monkeypatch, tmp_path, None, "refused", configured=False) == []