diff --git a/project/ticket-138/README.md b/project/ticket-138/README.md new file mode 100644 index 0000000..a87f885 --- /dev/null +++ b/project/ticket-138/README.md @@ -0,0 +1,37 @@ +# Ticket 138: MON-01 follow-up: report ExecCondition skips as AUTONOMY_UNIT_SKIPPED instead of a CRITICAL failure + +- **ID**: ticket-138 +- **Owner**: agent:claude +- **Status**: IN_PROGRESS +- **Workflow state**: EDIT +- **Created**: 2026-11-15 + +## Goal and scope + +SESSION_EXECUTION_AUTHORIZATION: the user asked to analyse the Heyasa autonomy +stall with semcod/monag, semcod/diagit and subactor/reflex and to plan fixes, +then repeatedly said "kontynuuj". This is a follow-up correction to MON-01 +(#162, PR #166) found while verifying it on the live host +(heyasa/heyasa docs/analysis/heyasa-autonomy-fix-deployment-gap-2026-11-15.md). + +`_probe_systemd_user_units` reported `subactor-repair-agent.service` with +`ActiveState=inactive, Result=exec-condition` as a CRITICAL +`AUTONOMY_UNIT_FAILED`. An ExecCondition exit of 1-254 is a deliberate skip, +not a crash. It is now reported as `AUTONOMY_UNIT_SKIPPED` (MEDIUM, weight +700, below failures) with its own remediation text. A condition crash that +leaves the unit failed stays CRITICAL. + +## Acceptance criteria + +- [x] AC-01: `inactive` + `Result=exec-condition` yields one MEDIUM + `AUTONOMY_UNIT_SKIPPED`; failed units and other non-success results stay + `AUTONOMY_UNIT_FAILED` CRITICAL; healthy units report nothing. +- [x] AC-02: New tests (5) and `tests/test_wave2_mon01_mon04.py` pass (15 in + total, unittest); Ruff keeps 141 existing findings in autodiagnosis.py and + the new test file has none; governance check passes. +- [ ] AC-03: Protected CI and independent Validator approval lead to merge. + +## Tracking boundary + +This directory contains the minimal reviewed intent. Optional participant prose +and raw command logs are not required delivery output. diff --git a/project/ticket-138/intent.json b/project/ticket-138/intent.json new file mode 100644 index 0000000..cf24771 --- /dev/null +++ b/project/ticket-138/intent.json @@ -0,0 +1,25 @@ +{ + "schema": "new-project.intent/v3", + "ticket": "ticket-138", + "summary": "MON-01 follow-up: report ExecCondition skips as AUTONOMY_UNIT_SKIPPED instead of a CRITICAL failure", + "workstream": "application", + "classification": { + "kind": "BUG", + "priority": "P2", + "origin": "health" + }, + "allowedPaths": [ + "project/ticket-138/**", + "TODO.md", + "project/TICKETS.md", + "src/monag/autodiagnosis.py", + "tests/test_autonomy_unit_skip.py" + ], + "forbiddenPaths": [ + "project/ticket-*/user-*.md" + ], + "stacks": [], + "dependsOn": [], + "conflictsWith": [], + "integrationTicket": null +} diff --git a/src/monag/autodiagnosis.py b/src/monag/autodiagnosis.py index 31fc319..9895743 100644 --- a/src/monag/autodiagnosis.py +++ b/src/monag/autodiagnosis.py @@ -638,12 +638,45 @@ def _probe_systemd_user_units( target = AUTONOMY_UNIT_TARGETS.get(unit_id, "subactor/autonom") target_path = root / target if (root / target).is_dir() else root - is_failed = ( + # An ExecCondition= exit of 1-254 is a deliberate cycle skip that + # systemd records as Result=exec-condition on an inactive unit; it is + # not a crash (exit 255 or above still leaves the unit failed). + is_skipped = ( + result_state == "exec-condition" + and active_state == "inactive" + and sub_state != "failed" + ) + is_failed = not is_skipped and ( active_state == "failed" or sub_state == "failed" or (result_state not in ("", "success") and active_state != "active") ) - if is_failed: + if is_skipped: + anomalies.append({ + "code": "AUTONOMY_UNIT_SKIPPED", + "tier": TIER_FLOOR, + "severity": "MEDIUM", + "weight": 700, + "autonomy_probe": True, + "target": target, + "path": str(target_path), + "summary": ( + f"Autonomy systemd --user unit '{unit_id}' skipped its last run: " + "ExecCondition declined to start it (Result=exec-condition)." + ), + "evidence": ( + f"systemctl --user show {unit_id}: LoadState={load_state}, " + f"ActiveState={active_state}, SubState={sub_state}, Result={result_state}." + ), + "details": { + "unit": unit_id, + "load_state": load_state, + "active_state": active_state, + "sub_state": sub_state, + "result": result_state, + }, + }) + elif is_failed: anomalies.append({ "code": "AUTONOMY_UNIT_FAILED", "tier": TIER_FLOOR, @@ -1107,6 +1140,7 @@ def _parse_subllm_response(text: str, fallback_anomaly: Dict[str, Any]) -> Dict[ "SYSTEM_LOG_ERROR": "Diagnose root cause of runtime system log error, apply code/configuration fix, and verify service stability with tests.", "AUTONOMY_UNIT_FAILED": "Inspect failed systemd --user journal logs, repair unit configuration or runtime crash, and verify active service health.", "AUTONOMY_DAEMON_INACTIVE": "Inspect heyasa.service user unit status and restart or re-enable autonomous orchestrator daemon.", + "AUTONOMY_UNIT_SKIPPED": "Inspect why the unit ExecCondition declines to start it (journal of the condition check) and restore the missing precondition.", "AUTONOMY_ELIGIBLE_PROJECTS_ZERO": "Inspect Heyasa flowguard project_exclusions and unblock repository eligibility or lease gates.", "AUTONOMY_ADMISSION_STALL": "Inspect Heyasa flowguard blocked_reasons and slot capacity to restore candidate admission.", "AUTONOMY_VELOCITY_STALL": "Inspect stalled Heyasa execution pipeline, executor health, and open candidate backlog.", diff --git a/tests/test_autonomy_unit_skip.py b/tests/test_autonomy_unit_skip.py new file mode 100644 index 0000000..d21bbd2 --- /dev/null +++ b/tests/test_autonomy_unit_skip.py @@ -0,0 +1,70 @@ +"""ExecCondition skips are reported as AUTONOMY_UNIT_SKIPPED, not as failures.""" +from __future__ import annotations + +import subprocess +import tempfile +import unittest +from pathlib import Path + +from monag import autodiagnosis + + +def _runner(stdout: str): + def run(cmd, **kwargs): + return subprocess.CompletedProcess(cmd, 0, stdout, "") + return run + + +def _unit(uid: str, active: str, sub: str, result: str, status: str = "0") -> str: + return f"Id={uid}\nLoadState=loaded\nActiveState={active}\nSubState={sub}\nResult={result}\nExecMainStatus={status}" + + +class AutonomyUnitSkipTests(unittest.TestCase): + def setUp(self) -> None: + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + + def probe(self, *units: str): + return autodiagnosis._probe_systemd_user_units(self.root, runner=_runner("\n\n".join(units))) + + def test_exec_condition_skip_is_medium_skip_not_critical_failure(self) -> None: + anomalies = self.probe(_unit("subactor-repair-agent.service", "inactive", "dead", "exec-condition")) + self.assertEqual([a["code"] for a in anomalies], ["AUTONOMY_UNIT_SKIPPED"]) + skip = anomalies[0] + self.assertEqual(skip["severity"], "MEDIUM") + self.assertTrue(skip["autonomy_probe"]) + self.assertEqual(skip["details"]["unit"], "subactor-repair-agent.service") + self.assertEqual(skip["target"], autodiagnosis.AUTONOMY_UNIT_TARGETS.get("subactor-repair-agent.service", "subactor/autonom")) + + def test_condition_crash_that_leaves_unit_failed_stays_critical(self) -> None: + # ExecCondition exit 255 makes systemd mark the unit failed (coding-agent on 2026-11-14). + anomalies = self.probe(_unit("subactor-coding-agent.service", "failed", "failed", "exit-code", "0")) + self.assertEqual([a["code"] for a in anomalies], ["AUTONOMY_UNIT_FAILED"]) + self.assertEqual(anomalies[0]["severity"], "CRITICAL") + + def test_other_inactive_non_success_results_stay_failures(self) -> None: + for result in ("exit-code", "timeout", "signal", "start-limit-hit"): + with self.subTest(result=result): + codes = [a["code"] for a in self.probe(_unit("subactor-autonom-user.service", "inactive", "dead", result))] + self.assertEqual(codes, ["AUTONOMY_UNIT_FAILED"]) + + def test_healthy_units_report_nothing(self) -> None: + self.assertEqual(self.probe( + _unit("subactor-repair-agent.service", "inactive", "dead", "success"), + _unit("heyasa.service", "active", "running", "success"), + ), []) + + def test_skip_ranks_below_failures_and_has_a_remediation(self) -> None: + anomalies = self.probe( + _unit("subactor-repair-agent.service", "inactive", "dead", "exec-condition"), + _unit("subactor-pr-controller.service", "failed", "failed", "exit-code", "200"), + ) + by_code = {a["code"]: a for a in anomalies} + self.assertLess(by_code["AUTONOMY_UNIT_SKIPPED"]["weight"], by_code["AUTONOMY_UNIT_FAILED"]["weight"]) + tickets = autodiagnosis.synthesize_tickets_with_subllm({"anomalies": [by_code["AUTONOMY_UNIT_SKIPPED"]]}, runner=None) + self.assertIn("ExecCondition", " ".join(str(v) for v in tickets[0].values())) + + +if __name__ == "__main__": + unittest.main()