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
1 change: 1 addition & 0 deletions project/TICKETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) | - | - | - | - | - |
<!-- AUTO:TICKET_INDEX:END -->
36 changes: 36 additions & 0 deletions project/ticket-168/README.md
Original file line number Diff line number Diff line change
@@ -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:start -->
## 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.
<!-- ticket-radar:end -->
25 changes: 25 additions & 0 deletions project/ticket-168/intent.json
Original file line number Diff line number Diff line change
@@ -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
}
49 changes: 43 additions & 6 deletions src/monag/autonomy_probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json
import os
import re
import sqlite3
import subprocess
import urllib.error
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -123,18 +157,21 @@ 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",
"priority": "critical",
"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,
})
Expand Down
56 changes: 56 additions & 0 deletions tests/test_planfile_discovery_probe.py
Original file line number Diff line number Diff line change
@@ -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, "<html>Bad Gateway</html>", "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) == []