fleetproof 0.7.0__tar.gz → 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. {fleetproof-0.7.0/src/fleetproof.egg-info → fleetproof-0.7.1}/PKG-INFO +1 -1
  2. {fleetproof-0.7.0 → fleetproof-0.7.1}/pyproject.toml +1 -1
  3. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/_version.py +1 -1
  4. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/cli.py +14 -3
  5. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/config.py +28 -0
  6. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/hookgate.py +89 -19
  7. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/ledger.py +18 -0
  8. {fleetproof-0.7.0 → fleetproof-0.7.1/src/fleetproof.egg-info}/PKG-INFO +1 -1
  9. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof.egg-info/SOURCES.txt +1 -0
  10. fleetproof-0.7.1/tests/test_v071.py +239 -0
  11. {fleetproof-0.7.0 → fleetproof-0.7.1}/LICENSE +0 -0
  12. {fleetproof-0.7.0 → fleetproof-0.7.1}/README.md +0 -0
  13. {fleetproof-0.7.0 → fleetproof-0.7.1}/setup.cfg +0 -0
  14. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/__init__.py +0 -0
  15. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/__main__.py +0 -0
  16. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/checker.py +0 -0
  17. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/checks.py +0 -0
  18. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/controls.py +0 -0
  19. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/library/__init__.py +0 -0
  20. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/library/fixtures/README.md +0 -0
  21. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/library/fixtures/http_json_field.sample.json +0 -0
  22. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/library/http_json_field.py +0 -0
  23. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/library/py_tests_pinned.py +0 -0
  24. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/library/worktree_landed.py +0 -0
  25. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/phase.py +0 -0
  26. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/report.py +0 -0
  27. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/runlog.py +0 -0
  28. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/telemetry.py +0 -0
  29. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof/telemetry_export.py +0 -0
  30. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof.egg-info/dependency_links.txt +0 -0
  31. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof.egg-info/entry_points.txt +0 -0
  32. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof.egg-info/requires.txt +0 -0
  33. {fleetproof-0.7.0 → fleetproof-0.7.1}/src/fleetproof.egg-info/top_level.txt +0 -0
  34. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_adversarial_regressions.py +0 -0
  35. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_checker.py +0 -0
  36. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_checks.py +0 -0
  37. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_cli.py +0 -0
  38. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_controls.py +0 -0
  39. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_hookgate.py +0 -0
  40. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_ledger.py +0 -0
  41. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_library.py +0 -0
  42. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_phase.py +0 -0
  43. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_report.py +0 -0
  44. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_runlog.py +0 -0
  45. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_telemetry.py +0 -0
  46. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_telemetry_export.py +0 -0
  47. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_v070.py +0 -0
  48. {fleetproof-0.7.0 → fleetproof-0.7.1}/tests/test_version_surfaces.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fleetproof
3
- Version: 0.7.0
3
+ Version: 0.7.1
4
4
  Summary: Independent, out-of-band verification for agent fleets.
5
5
  Author: Gathrazio
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fleetproof"
7
- version = "0.7.0"
7
+ version = "0.7.1"
8
8
  description = "Independent, out-of-band verification for agent fleets."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -5,4 +5,4 @@ itself imports (runlog, ledger) can stamp the version into records without a
5
5
  circular import. ``fleetproof.__version__`` re-exports this value.
6
6
  """
7
7
 
8
- __version__ = "0.7.0"
8
+ __version__ = "0.7.1"
@@ -1572,7 +1572,10 @@ def _cmd_fleet(args: argparse.Namespace) -> int:
1572
1572
  if args.format == "json":
1573
1573
  payload = {
1574
1574
  "dispatches": [
1575
- dict(r.to_dict(), age=_format_age(r.started_at)) for r in records
1575
+ dict(r.to_dict(), age=_format_age(r.started_at),
1576
+ silent_age=(None if r.is_terminal
1577
+ else _format_age(r.last_event_at)))
1578
+ for r in records
1576
1579
  ],
1577
1580
  "listing_session": listing_session,
1578
1581
  "orphan_stop_count": len(orphans),
@@ -1612,12 +1615,20 @@ def _cmd_fleet(args: argparse.Namespace) -> int:
1612
1615
  if budget_line:
1613
1616
  print(budget_line)
1614
1617
  return 0
1618
+ # `silent` is the ledger-silence age (time since the last transition),
1619
+ # distinct from `age` (time since dispatch): a lane that went quiet after
1620
+ # an interim event looks young by `age` and dead by `silent`, and the
1621
+ # passive board line hiding that difference is how a stalled wave went
1622
+ # unnoticed until a human looked (GCC lesson L55). Terminal rows have
1623
+ # nothing to be silent about, so they render '-'.
1615
1624
  print(f"{'run_id':<24} {'state':<26} {'tier':<12} {'agent':<18} "
1616
- f"{'verdict':<13} {'age':>7} {'session':<14}")
1625
+ f"{'verdict':<13} {'age':>7} {'silent':>7} {'session':<14}")
1617
1626
  for r in records:
1627
+ silent = "-" if r.is_terminal else _format_age(r.last_event_at)
1618
1628
  print(f"{r.run_id:<24} {state_label(r):<26} {tier_label(r):<12} "
1619
1629
  f"{_truncate(agent_label(r), 18):<18} {verdict_label(r):<13} "
1620
- f"{_format_age(r.started_at):>7} {_short_session(r.session_id):<14}")
1630
+ f"{_format_age(r.started_at):>7} {silent:>7} "
1631
+ f"{_short_session(r.session_id):<14}")
1621
1632
  open_count = sum(1 for r in records if r.is_open)
1622
1633
  ungraded = sum(1 for r in records if r.verdict is None)
1623
1634
  print(f"{len(records)} dispatch(es), {open_count} awaiting a report, "
@@ -136,6 +136,34 @@ def run_context(config: dict[str, Any] | None = None) -> str:
136
136
  return RUN_CONTEXT_PRODUCTION
137
137
 
138
138
 
139
+ STALE_DISPATCH_DEFAULT_MINUTES = 15
140
+
141
+
142
+ def stale_dispatch_minutes(config: dict[str, Any] | None = None) -> int:
143
+ """Minutes of ledger silence before an in-fleet dispatch escalates; 0 = off.
144
+
145
+ ``stale_dispatch_minutes`` in ``.fleetproof/config.json``. A dispatched
146
+ lane that went idle after an interim message re-invoked nobody, and the
147
+ wave stalled invisibly until a human noticed — three recurrences across
148
+ one field deployment's sessions before the operator ordered this
149
+ mechanized (GCC lesson L55, operator-caught third instance). So the
150
+ default is ON at 15 minutes: silence past the threshold turns the
151
+ dispatch's passive board line into an escalated one. An explicit ``0``
152
+ (or a negative number, or ``false``) disables the escalation entirely —
153
+ that is a deliberate operator posture, distinct from a malformed value,
154
+ which falls back to the default rather than crashing a hook or quietly
155
+ turning the escalation off.
156
+ """
157
+ cfg = config if config is not None else load_config()
158
+ raw = cfg.get("stale_dispatch_minutes")
159
+ if raw is False or (isinstance(raw, int)
160
+ and not isinstance(raw, bool) and raw <= 0):
161
+ return 0
162
+ if isinstance(raw, bool) or not isinstance(raw, int):
163
+ return STALE_DISPATCH_DEFAULT_MINUTES
164
+ return raw
165
+
166
+
139
167
  def _config_str(key: str, config: dict[str, Any] | None = None) -> str | None:
140
168
  cfg = config if config is not None else load_config()
141
169
  value = cfg.get(key)
@@ -84,6 +84,7 @@ from .ledger import (
84
84
  TIER_COORDINATOR,
85
85
  TIER_SOURCE_DEFAULTED,
86
86
  TIER_SOURCE_INHERITED,
87
+ DispatchRecord,
87
88
  LedgerError,
88
89
  advisory_failure_line,
89
90
  advisory_verdict_line,
@@ -536,8 +537,10 @@ def _failure_reason(report) -> str:
536
537
  return "\n".join([GATE_BLOCK_MARKER, header, per_check, evidence, _BLOCK_EXITS])
537
538
 
538
539
 
539
- def ledger_sweep(session_id: str | None) -> tuple[list[str], list[str], list[str]]:
540
- """Return ``(stalled, retrying, in_fleet)`` dispatch run ids for a session.
540
+ def ledger_sweep(
541
+ session_id: str | None,
542
+ ) -> tuple[list[DispatchRecord], list[DispatchRecord], list[DispatchRecord]]:
543
+ """Return ``(stalled, retrying, in_fleet)`` dispatch records for a session.
541
544
 
542
545
  *stalled* — a dispatch that reported (or was graded) and then never terminated.
543
546
  Something started closing it out and stopped halfway, which is exactly the
@@ -555,43 +558,110 @@ def ledger_sweep(session_id: str | None) -> tuple[list[str], list[str], list[str
555
558
  *in_fleet* — still in state ``dispatched``. That is a legitimately-running
556
559
  background agent, not a fault, so it is reported and not blocked on. Blocking
557
560
  here would make it impossible to ever stop while a long subagent runs.
561
+
562
+ Whole records, not run ids: the context renderer reads each record's
563
+ silence age off its transitions, so a dispatch whose agent went quiet can
564
+ escalate instead of hiding in a passive list (GCC lesson L55).
558
565
  """
559
566
  if not session_id:
560
567
  return [], [], []
561
- stalled: list[str] = []
562
- retrying: list[str] = []
563
- in_fleet: list[str] = []
568
+ stalled: list[DispatchRecord] = []
569
+ retrying: list[DispatchRecord] = []
570
+ in_fleet: list[DispatchRecord] = []
564
571
  for record_obj in list_dispatches(session_id=session_id, non_terminal_only=True):
565
572
  if record_obj.state == STATE_DISPATCHED:
566
- in_fleet.append(record_obj.run_id)
573
+ in_fleet.append(record_obj)
567
574
  elif record_obj.state == STATE_CONTRADICTED:
568
- retrying.append(record_obj.run_id)
575
+ retrying.append(record_obj)
569
576
  else:
570
- stalled.append(record_obj.run_id)
577
+ stalled.append(record_obj)
571
578
  return stalled, retrying, in_fleet
572
579
 
573
580
 
574
- def _stalled_reason(stalled: list[str]) -> str:
581
+ def _stalled_reason(stalled: list[DispatchRecord]) -> str:
575
582
  return (
576
583
  f"FleetProof: {len(stalled)} dispatch(es) reported but never terminated — "
577
- + ", ".join(stalled)
584
+ + ", ".join(r.run_id for r in stalled)
578
585
  + ". Verify or close each one (`fleetproof dispatch close <run_id>`) "
579
586
  "before stopping; a half-closed dispatch is how work goes missing."
580
587
  )
581
588
 
582
589
 
590
+ def _silence_minutes(
591
+ record: DispatchRecord, now: datetime | None = None,
592
+ ) -> int | None:
593
+ """Whole minutes since this record's last ledger event, or None.
594
+
595
+ None means "age unknown" — a record with no usable stamp at all, or one
596
+ whose stamp does not parse. Unknown must never read as stale: a damaged
597
+ record already degrades to ``dispatched`` on the board, and compounding
598
+ that with a false STALE escalation on every bridge stop would train the
599
+ dispatcher to ignore the one line that exists to interrupt it.
600
+ """
601
+ stamp = record.last_event_at
602
+ if not stamp:
603
+ return None
604
+ try:
605
+ last = datetime.fromisoformat(stamp)
606
+ except ValueError:
607
+ return None
608
+ if last.tzinfo is None:
609
+ last = last.replace(tzinfo=timezone.utc)
610
+ reference = now if now is not None else datetime.now(timezone.utc)
611
+ seconds = (reference - last).total_seconds()
612
+ if seconds < 0:
613
+ return 0
614
+ return int(seconds // 60)
615
+
616
+
617
+ def _silence_suffix(record: DispatchRecord, now: datetime | None = None) -> str:
618
+ """`` (silent M min)`` for a record with a known age, else nothing."""
619
+ minutes = _silence_minutes(record, now)
620
+ return f" (silent {minutes} min)" if minutes is not None else ""
621
+
622
+
583
623
  def _ledger_context(
584
- stalled: list[str], retrying: list[str], in_fleet: list[str],
624
+ stalled: list[DispatchRecord],
625
+ retrying: list[DispatchRecord],
626
+ in_fleet: list[DispatchRecord],
627
+ now: datetime | None = None,
585
628
  ) -> str | None:
586
- """Operator-facing ledger summary, or None when this session has no dispatches."""
629
+ """Operator-facing ledger summary, or None when this session has no dispatches.
630
+
631
+ An in-fleet dispatch silent past ``stale_dispatch_minutes`` escalates to
632
+ a ``[STALE in fleet]`` line. Field provenance: three times in one
633
+ deployment a dispatched lane went idle after an interim message, nothing
634
+ re-invoked anyone, and the wave stalled invisibly until a HUMAN noticed —
635
+ the passive "still in fleet" line read identically for a working agent
636
+ and a dead one (GCC lesson L55, third recurrence operator-caught).
637
+ Staleness stays context, never a block: blocking here would make it
638
+ impossible to stop while a long legitimate subagent runs, and the
639
+ stop-block budget exists precisely to kill unbounded wedges. Louder, not
640
+ blocking.
641
+ """
642
+ from .config import stale_dispatch_minutes
643
+ threshold = stale_dispatch_minutes()
587
644
  parts: list[str] = []
588
- for run_id in stalled:
589
- parts.append(f"- [stalled] {run_id}: reported but never terminated")
590
- for run_id in retrying:
591
- parts.append(f"- [in retry] {run_id}: contradicted, awaiting the "
592
- "agent's fixed report")
593
- for run_id in in_fleet:
594
- parts.append(f"- [still in fleet] {run_id}: dispatched, no report yet")
645
+ for record_obj in stalled:
646
+ parts.append(f"- [stalled] {record_obj.run_id}: reported but never "
647
+ f"terminated{_silence_suffix(record_obj, now)}")
648
+ for record_obj in retrying:
649
+ parts.append(f"- [in retry] {record_obj.run_id}: contradicted, awaiting the "
650
+ f"agent's fixed report{_silence_suffix(record_obj, now)}")
651
+ for record_obj in in_fleet:
652
+ minutes = _silence_minutes(record_obj, now)
653
+ # Strictly past the threshold: an agent silent for exactly the
654
+ # threshold has not yet exceeded it, and an unknown age never
655
+ # escalates (see _silence_minutes).
656
+ if threshold > 0 and minutes is not None and minutes > threshold:
657
+ parts.append(
658
+ f"- [STALE in fleet] {record_obj.run_id}: dispatched, no ledger "
659
+ f"event for {minutes} min (threshold {threshold}) — check the "
660
+ "agent now: verify deliverables on disk, nudge it, or take "
661
+ "the work over")
662
+ else:
663
+ parts.append(f"- [still in fleet] {record_obj.run_id}: dispatched, "
664
+ "no report yet")
595
665
  if not parts:
596
666
  return None
597
667
  parts.append("Board: `fleetproof fleet --open`")
@@ -373,6 +373,24 @@ class DispatchRecord:
373
373
  def is_terminal(self) -> bool:
374
374
  return self.state in TERMINAL_STATES
375
375
 
376
+ @property
377
+ def last_event_at(self) -> str | None:
378
+ """ISO stamp of the last ledger event on this record, or None.
379
+
380
+ The last transition's ``at``, falling back to ``started_at`` when the
381
+ transitions list is empty or its last entry carries no stamp — the
382
+ same damaged-record tolerance :attr:`state` extends (an empty list
383
+ reads as ``dispatched``, not a crash). A record with neither stamp
384
+ returns None, and silence math must read that as "age unknown",
385
+ never "infinitely old": escalating on a missing field would turn one
386
+ damaged file into a false alarm on every bridge stop.
387
+ """
388
+ if self.transitions:
389
+ at = self.transitions[-1].get("at")
390
+ if at:
391
+ return str(at)
392
+ return self.started_at
393
+
376
394
  @property
377
395
  def is_open(self) -> bool:
378
396
  """True while this dispatch has not reported yet.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fleetproof
3
- Version: 0.7.0
3
+ Version: 0.7.1
4
4
  Summary: Independent, out-of-band verification for agent fleets.
5
5
  Author: Gathrazio
6
6
  License: MIT
@@ -42,4 +42,5 @@ tests/test_runlog.py
42
42
  tests/test_telemetry.py
43
43
  tests/test_telemetry_export.py
44
44
  tests/test_v070.py
45
+ tests/test_v071.py
45
46
  tests/test_version_surfaces.py
@@ -0,0 +1,239 @@
1
+ """0.7.1 feature tests: stale-dispatch escalation in the bridge stop's ledger
2
+ context. Field provenance: three times in one deployment a dispatched lane went
3
+ idle after an interim message, nothing re-invoked anyone, and the wave stalled
4
+ invisibly until a HUMAN noticed (GCC sessions 0064/0067/0070, lesson L55, third
5
+ recurrence operator-caught). The passive `[still in fleet]` line read
6
+ identically for a working agent and a dead one; these tests pin the loud form —
7
+ and pin that it stays context, never a block."""
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import sys
13
+ from datetime import datetime, timedelta, timezone
14
+ from pathlib import Path
15
+
16
+ import pytest
17
+
18
+ from fleetproof import runlog
19
+ from fleetproof.cli import main
20
+ from fleetproof.config import STALE_DISPATCH_DEFAULT_MINUTES, stale_dispatch_minutes
21
+ from fleetproof.hookgate import _ledger_context, _silence_minutes, stop_gate
22
+ from fleetproof.ledger import DispatchRecord, create_dispatch, record_report
23
+
24
+ _PASS = {"id": "ok", "run": f'"{sys.executable}" -c "raise SystemExit(0)"',
25
+ "expect": "exit0", "block": True}
26
+
27
+ _NOW = datetime(2026, 11, 17, 12, 0, 0, tzinfo=timezone.utc)
28
+
29
+
30
+ def _setup_project(tmp_path: Path, checks: list[dict], monkeypatch) -> None:
31
+ marker = tmp_path / ".fleetproof"
32
+ marker.mkdir(exist_ok=True)
33
+ (marker / "checks.json").write_text(json.dumps({"checks": checks}), encoding="utf-8")
34
+ monkeypatch.chdir(tmp_path)
35
+ runlog.set_runs_dir(marker / "runs")
36
+
37
+
38
+ @pytest.fixture(autouse=True)
39
+ def _reset_runs():
40
+ yield
41
+ runlog.set_runs_dir(None)
42
+ import os
43
+ os.environ.pop(runlog.SESSION_ID_ENV, None)
44
+
45
+
46
+ def _record(run_id="d-1", transitions=None, started_at=None) -> DispatchRecord:
47
+ return DispatchRecord(
48
+ run_id=run_id, run_dir=Path("."), parent_run_id=None, session_id="s",
49
+ prompt="p", tier="lane", tier_source="declared",
50
+ transitions=transitions if transitions is not None else [],
51
+ started_at=started_at)
52
+
53
+
54
+ def _iso(minutes_ago: int, now: datetime = _NOW) -> str:
55
+ return (now - timedelta(minutes=minutes_ago)).isoformat()
56
+
57
+
58
+ def _age_on_disk(run_id: str, minutes_ago: int) -> None:
59
+ """Rewrite every transition stamp on a stored dispatch to the given age."""
60
+ path = runlog.runs_dir() / run_id / "dispatch.json"
61
+ raw = json.loads(path.read_text(encoding="utf-8"))
62
+ stamp = (datetime.now(timezone.utc) - timedelta(minutes=minutes_ago)).isoformat()
63
+ for t in raw["transitions"]:
64
+ t["at"] = stamp
65
+ path.write_text(json.dumps(raw), encoding="utf-8")
66
+
67
+
68
+ # === Age math ===
69
+
70
+ def test_silence_age_reads_the_last_transition_stamp():
71
+ r = _record(transitions=[
72
+ {"state": "dispatched", "at": _iso(90)},
73
+ {"state": "reported", "at": _iso(40)},
74
+ ])
75
+ assert _silence_minutes(r, now=_NOW) == 40
76
+
77
+
78
+ def test_silence_age_falls_back_to_started_at_on_empty_transitions():
79
+ # Damaged-record convention: empty transitions already read back as
80
+ # `dispatched` for state; the age read extends the same tolerance.
81
+ r = _record(transitions=[], started_at=_iso(25))
82
+ assert _silence_minutes(r, now=_NOW) == 25
83
+
84
+
85
+ def test_record_with_no_stamp_at_all_has_unknown_age_and_never_escalates(tmp_runs):
86
+ r = _record(transitions=[], started_at=None)
87
+ assert _silence_minutes(r, now=_NOW) is None
88
+ context = _ledger_context([], [], [r], now=_NOW)
89
+ assert "[still in fleet] d-1" in context
90
+ assert "STALE" not in context
91
+
92
+
93
+ def test_unparseable_stamp_reads_as_unknown_not_stale():
94
+ r = _record(transitions=[{"state": "dispatched", "at": "not-a-date"}],
95
+ started_at=None)
96
+ assert _silence_minutes(r, now=_NOW) is None
97
+
98
+
99
+ def test_future_stamp_clamps_to_zero_not_negative():
100
+ r = _record(transitions=[{"state": "dispatched", "at": _iso(-5)}])
101
+ assert _silence_minutes(r, now=_NOW) == 0
102
+
103
+
104
+ # === Threshold boundary and the escalated line ===
105
+
106
+ def test_in_fleet_at_the_threshold_is_not_yet_stale(tmp_runs):
107
+ r = _record(transitions=[{"state": "dispatched",
108
+ "at": _iso(STALE_DISPATCH_DEFAULT_MINUTES)}])
109
+ context = _ledger_context([], [], [r], now=_NOW)
110
+ assert "[still in fleet] d-1: dispatched, no report yet" in context
111
+ assert "STALE" not in context
112
+
113
+
114
+ def test_in_fleet_past_the_threshold_renders_the_escalated_line(tmp_runs):
115
+ r = _record(transitions=[{"state": "dispatched", "at": _iso(37)}])
116
+ context = _ledger_context([], [], [r], now=_NOW)
117
+ assert ("- [STALE in fleet] d-1: dispatched, no ledger event for 37 min "
118
+ "(threshold 15) — check the agent now: verify deliverables on "
119
+ "disk, nudge it, or take the work over") in context
120
+ assert "[still in fleet]" not in context
121
+
122
+
123
+ def test_stalled_and_retry_lines_carry_the_silence_age(tmp_runs):
124
+ stalled = _record(run_id="d-s",
125
+ transitions=[{"state": "reported", "at": _iso(7)}])
126
+ retrying = _record(run_id="d-r",
127
+ transitions=[{"state": "contradicted", "at": _iso(3)}])
128
+ context = _ledger_context([stalled], [retrying], [], now=_NOW)
129
+ assert "- [stalled] d-s: reported but never terminated (silent 7 min)" in context
130
+ assert ("- [in retry] d-r: contradicted, awaiting the agent's fixed "
131
+ "report (silent 3 min)") in context
132
+
133
+
134
+ # === Config key: stale_dispatch_minutes ===
135
+
136
+ def test_threshold_defaults_to_fifteen_and_reads_overrides():
137
+ assert STALE_DISPATCH_DEFAULT_MINUTES == 15
138
+ assert stale_dispatch_minutes({}) == 15
139
+ assert stale_dispatch_minutes({"stale_dispatch_minutes": 30}) == 30
140
+ # Explicit 0 / negative / false = the operator turned the escalation off.
141
+ assert stale_dispatch_minutes({"stale_dispatch_minutes": 0}) == 0
142
+ assert stale_dispatch_minutes({"stale_dispatch_minutes": -5}) == 0
143
+ assert stale_dispatch_minutes({"stale_dispatch_minutes": False}) == 0
144
+ # Malformed values fall back to the default rather than crashing a hook
145
+ # or silently disabling the one line that interrupts a stalled wave.
146
+ assert stale_dispatch_minutes({"stale_dispatch_minutes": "soon"}) == 15
147
+ assert stale_dispatch_minutes({"stale_dispatch_minutes": True}) == 15
148
+
149
+
150
+ def test_zero_threshold_disables_the_escalation(tmp_path, monkeypatch):
151
+ _setup_project(tmp_path, [_PASS], monkeypatch)
152
+ (tmp_path / ".fleetproof" / "config.json").write_text(
153
+ json.dumps({"stale_dispatch_minutes": 0}), encoding="utf-8")
154
+ r = _record(transitions=[{"state": "dispatched", "at": _iso(100000)}])
155
+ context = _ledger_context([], [], [r], now=_NOW)
156
+ assert "[still in fleet] d-1" in context
157
+ assert "STALE" not in context
158
+
159
+
160
+ # === Through the bridge stop gate: loud, never a block ===
161
+
162
+ def test_stop_gate_escalates_a_stale_dispatch_without_blocking(tmp_path, monkeypatch):
163
+ _setup_project(tmp_path, [_PASS], monkeypatch)
164
+ monkeypatch.setenv(runlog.SESSION_ID_ENV, "sess-stale")
165
+ run_id = create_dispatch("quiet lane", tier="lane")
166
+ _age_on_disk(run_id, minutes_ago=45)
167
+
168
+ decision, code = stop_gate()
169
+ assert code == 0
170
+ assert decision is not None
171
+ # The invariant the module's own comments defend: in-fleet dispatches are
172
+ # context, never a block — stale makes the context louder, not blocking.
173
+ assert "decision" not in decision
174
+ context = decision["hookSpecificOutput"]["additionalContext"]
175
+ assert f"[STALE in fleet] {run_id}" in context
176
+ assert "(threshold 15)" in context
177
+ assert "check the agent now" in context
178
+
179
+
180
+ def test_stop_gate_keeps_the_plain_line_for_a_fresh_dispatch(tmp_path, monkeypatch):
181
+ _setup_project(tmp_path, [_PASS], monkeypatch)
182
+ monkeypatch.setenv(runlog.SESSION_ID_ENV, "sess-fresh")
183
+ run_id = create_dispatch("busy lane", tier="lane")
184
+
185
+ decision, code = stop_gate()
186
+ assert code == 0
187
+ context = decision["hookSpecificOutput"]["additionalContext"]
188
+ assert f"[still in fleet] {run_id}: dispatched, no report yet" in context
189
+ assert "STALE" not in context
190
+
191
+
192
+ def test_stale_dispatch_exit_semantics_match_fresh_exactly(tmp_path, monkeypatch):
193
+ # Byte-for-byte on the decision keys: staleness changes the words in the
194
+ # context, and nothing else about the stop.
195
+ _setup_project(tmp_path, [_PASS], monkeypatch)
196
+ monkeypatch.setenv(runlog.SESSION_ID_ENV, "sess-keys")
197
+ run_id = create_dispatch("quiet lane", tier="lane")
198
+ fresh_decision, fresh_code = stop_gate()
199
+ _age_on_disk(run_id, minutes_ago=400)
200
+ stale_decision, stale_code = stop_gate()
201
+ assert (fresh_code, set(fresh_decision)) == (stale_code, set(stale_decision))
202
+ assert "decision" not in stale_decision
203
+
204
+
205
+ # === Board: the silent column ===
206
+
207
+ def test_fleet_board_shows_silence_age_for_open_rows(tmp_path, monkeypatch, capsys):
208
+ _setup_project(tmp_path, [_PASS], monkeypatch)
209
+ run_id = create_dispatch("p", tier="lane", session_id="sess-board")
210
+ _age_on_disk(run_id, minutes_ago=17)
211
+ capsys.readouterr()
212
+ assert main(["fleet", "--open", "--all"]) == 0
213
+ out = capsys.readouterr().out
214
+ assert "silent" in out
215
+ row = next(line for line in out.splitlines() if run_id in line)
216
+ assert "17m" in row
217
+
218
+
219
+ def test_fleet_json_nulls_silence_on_terminal_rows(tmp_path, monkeypatch, capsys):
220
+ # A terminal row has nothing to be silent about.
221
+ from fleetproof.ledger import close_dispatch
222
+ _setup_project(tmp_path, [_PASS], monkeypatch)
223
+ run_id = create_dispatch("p", tier="lane", session_id="sess-term")
224
+ record_report(run_id, {"summary": "done"})
225
+ close_dispatch(run_id)
226
+ capsys.readouterr()
227
+ assert main(["fleet", "--all", "--format", "json"]) == 0
228
+ payload = json.loads(capsys.readouterr().out)
229
+ record = next(d for d in payload["dispatches"] if d["run_id"] == run_id)
230
+ assert record["silent_age"] is None
231
+
232
+
233
+ def test_fleet_json_carries_silent_age(tmp_path, monkeypatch, capsys):
234
+ _setup_project(tmp_path, [_PASS], monkeypatch)
235
+ create_dispatch("p", tier="lane", session_id="sess-json")
236
+ capsys.readouterr()
237
+ assert main(["fleet", "--all", "--format", "json"]) == 0
238
+ payload = json.loads(capsys.readouterr().out)
239
+ assert payload["dispatches"][0]["silent_age"]
File without changes
File without changes
File without changes
File without changes