code-coordinator 0.5.332__py3-none-any.whl → 0.5.333__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-coordinator
3
- Version: 0.5.332
3
+ Version: 0.5.333
4
4
  Summary: Coordinate Claude Code workers across multiple machines and repos.
5
5
  Author-email: John Donaghy <johnfdonaghy@gmail.com>
6
6
  License-Expression: LicenseRef-FSL-1.1-MIT
@@ -1,4 +1,4 @@
1
- code_coordinator-0.5.332.dist-info/licenses/LICENSE,sha256=851BVZZwf_pEv2ydSlMmcZrwnwSS5YJ98wdLze7lyL8,4212
1
+ code_coordinator-0.5.333.dist-info/licenses/LICENSE,sha256=851BVZZwf_pEv2ydSlMmcZrwnwSS5YJ98wdLze7lyL8,4212
2
2
  coord/__init__.py,sha256=3FN2qrrxtW87xSsSD557YcMwHLDahnFK8LvqQI7Wlf4,9783
3
3
  coord/_board_mapping.py,sha256=SGq8hC-gsyXHEZe2L58qy6pyOVQvswTpQ5FzPa_vZ8w,11012
4
4
  coord/acceptance.py,sha256=v7k1e_shUIjWKolKDQ9oJv67o0O8L659El3grvcF8ns,75452
@@ -63,7 +63,7 @@ coord/interactive.py,sha256=AEK-5S2aMknpP6k3Xx-aBuTEulw0_c-gbYPEKTwUjRE,219083
63
63
  coord/issue_store.py,sha256=abywea0vpXE_BZ5F3QHLDxLKYKDYF7iQYabZhppVYto,69451
64
64
  coord/issues_sync_status.py,sha256=_6ucx7oW3TUGZZvs93wRbzR_SUQcNlz-7RptOzr4alo,9262
65
65
  coord/liveness_auditor.py,sha256=sf_xBklt37DUnrIEeD4fVp4_gWPDaXbydZgfuWAPFRE,12478
66
- coord/machine_metrics.py,sha256=mBEciin6gdYJaPw73gY7mrDnalm01WhX7kpzt8t0NEk,9396
66
+ coord/machine_metrics.py,sha256=paWqBTZgeIi7w1pgH5QSJL59UxwetxE8bXblzzcspSI,16300
67
67
  coord/machine_onboard.py,sha256=BTUAC7bdERcDyaIvO2yKkQ8xPwsdR063yHUrOznmHWk,58555
68
68
  coord/machine_pause.py,sha256=6s7Dtr5zLs1qB2NWI2-cfbMdPyigK62FTtLjzmY6slE,47521
69
69
  coord/merge_queue.py,sha256=UdwyoyfE9DplS6Mia4_aY6TK5a-f933M04Ns5mVHnsw,392677
@@ -108,7 +108,7 @@ coord/revalidate.py,sha256=fQaYCvObqUawSZWMEOkVWFtYswz9PQQwSMApAyP5zeA,66266
108
108
  coord/review.py,sha256=hsY6HUif44HL3pY52H7SoqNuMMZzA_9gfHfJKnC-fWE,183282
109
109
  coord/scorecard.py,sha256=axe_doBJBBFWtN21JZDRSijwDI0xaZrt2oVYbwJPW7U,20211
110
110
  coord/self_health.py,sha256=9PLVdaEReFLUY6y2QXMGVd6U1CdHAh9_8MzduwBOzAY,10651
111
- coord/serve_app.py,sha256=_vyNSXqAUWVfsQfYCjJRnqefczof7qKObrMnTysyUkw,509398
111
+ coord/serve_app.py,sha256=8xveD7Y9zmP-J-dIE6GcJJJl0CVMIubIZqJFojrbIw0,516163
112
112
  coord/smoke.py,sha256=INLh9Wu57WOcCoOY4CMOcbzArIhMxMolsV2D8hAW7zw,70481
113
113
  coord/spend_ceiling.py,sha256=hfuiXlnD4or7Wqoqf6BHcOMT2CXd92FBZuVdnQVlI2M,13573
114
114
  coord/split_work.py,sha256=Gp_cNtYBe7nDxBN7cDRs8CJG3V_Y0C1QUi35fHGcvnY,8502
@@ -249,8 +249,8 @@ coord/skills/release-now/SKILL.md,sha256=u5JY0Jm0IiZYs2JGjRSqNj265CUWcIA6pMaeulb
249
249
  coord/skills/review-verdict-recovery/SKILL.md,sha256=Grg8GWkJLK20ct2YiigbTFfNOkit7tNrdRIhdocKGJk,3941
250
250
  coord/skills/tui-quadraui-workflow/SKILL.md,sha256=4hUZza9wSSnPhf0eRAOh2r_MQZxK2pXYO5g-kxmJq-U,3832
251
251
  coord/skills/update-issue/SKILL.md,sha256=VrPinEmLZrCSNDrnz96hQomyO403o5c4i0RdsnUnWA0,3642
252
- code_coordinator-0.5.332.dist-info/METADATA,sha256=1zZHh_75sV2go8WtKq1cX-YI4TfozgKZnV3-wkhwgDk,27178
253
- code_coordinator-0.5.332.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
254
- code_coordinator-0.5.332.dist-info/entry_points.txt,sha256=o-Hq8pvG7ReGePvN_4iOKjLNqiq-MJ43HbPurqjNPZo,41
255
- code_coordinator-0.5.332.dist-info/top_level.txt,sha256=w5sTrXesTCebhXyYv2qufOZGo0PoD1Lxgn0Q3MAXjh4,6
256
- code_coordinator-0.5.332.dist-info/RECORD,,
252
+ code_coordinator-0.5.333.dist-info/METADATA,sha256=SSM5mybV2eP7ywLeaVk2qZuh8JjxAm03egtylQ81ZB0,27178
253
+ code_coordinator-0.5.333.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
254
+ code_coordinator-0.5.333.dist-info/entry_points.txt,sha256=o-Hq8pvG7ReGePvN_4iOKjLNqiq-MJ43HbPurqjNPZo,41
255
+ code_coordinator-0.5.333.dist-info/top_level.txt,sha256=w5sTrXesTCebhXyYv2qufOZGo0PoD1Lxgn0Q3MAXjh4,6
256
+ code_coordinator-0.5.333.dist-info/RECORD,,
coord/machine_metrics.py CHANGED
@@ -48,10 +48,12 @@ for exactly this reason) are not this module's job.
48
48
  from __future__ import annotations
49
49
 
50
50
  import logging
51
+ import re
51
52
  import time
52
53
  from collections import deque
53
54
  from concurrent.futures import ThreadPoolExecutor
54
55
  from dataclasses import dataclass
56
+ from datetime import datetime
55
57
 
56
58
  import httpx
57
59
 
@@ -215,3 +217,174 @@ class MachineMetricsSampler:
215
217
  except Exception as exc: # noqa: BLE001 — one bad machine must never abort the refresh
216
218
  log.warning("machine-metrics poll: %s raised %s", machine.name, exc)
217
219
  return _unknown(f"poll raised: {exc}")
220
+
221
+
222
+ # ── read path: GET /machines/metrics (#3021) ────────────────────────────────
223
+ #
224
+ # Everything below is pure — no I/O, no dependence on the sampler's internal
225
+ # deques beyond the plain ``list[dict]`` returned by ``series()``/
226
+ # ``all_series()``. That keeps it trivially unit-testable and reusable from
227
+ # `coord.serve_app`'s request handler without either side needing to know
228
+ # about the other's internals.
229
+
230
+ _DURATION_RE = re.compile(r"^\s*(\d+(?:\.\d+)?)\s*([smhdw])\s*$", re.IGNORECASE)
231
+ _UNIT_SECONDS = {"s": 1.0, "m": 60.0, "h": 3600.0, "d": 86400.0, "w": 604800.0}
232
+
233
+
234
+ def resolve_since(raw: str | None, *, now: float | None = None) -> float | None:
235
+ """Resolve a ``?since=`` query value to an absolute epoch timestamp.
236
+
237
+ Accepts three forms (mirrors the vocabulary the issue asks for,
238
+ ``<epoch|duration>``, plus ISO-8601 for parity with ``coord audit``'s
239
+ ``since``/``until``):
240
+
241
+ - ``None`` or ``""`` → ``None``, meaning "no lower bound" (the full
242
+ retained window — the endpoint's documented default).
243
+ - A duration like ``"6h"``, ``"90m"``, ``"3d"`` (units: s, m, h, d, w) →
244
+ ``now - duration``.
245
+ - An epoch number (``"1699999999"``) or an ISO-8601 timestamp
246
+ (``"2026-01-01T00:00:00Z"``) → that instant, verbatim.
247
+
248
+ Raises :class:`ValueError` on anything else, so the HTTP handler can
249
+ turn it into a 400 with the bad value quoted back.
250
+ """
251
+ if raw is None or raw == "":
252
+ return None
253
+ now = now if now is not None else time.time()
254
+ match = _DURATION_RE.match(raw)
255
+ if match:
256
+ return now - float(match.group(1)) * _UNIT_SECONDS[match.group(2).lower()]
257
+ try:
258
+ return float(raw)
259
+ except (TypeError, ValueError):
260
+ pass
261
+ try:
262
+ return datetime.fromisoformat(raw.replace("Z", "+00:00")).timestamp()
263
+ except ValueError as exc:
264
+ raise ValueError(
265
+ f"not an epoch number, ISO-8601 timestamp, or duration: {raw!r} "
266
+ "(duration units: s, m, h, d, w)"
267
+ ) from exc
268
+
269
+
270
+ def _filter_since(samples: list[dict], since: float | None) -> list[dict]:
271
+ if since is None:
272
+ return list(samples)
273
+ return [s for s in samples if s["timestamp"] >= since]
274
+
275
+
276
+ def _sample_intensity(sample: dict) -> float:
277
+ """How "interesting" a sample is for peak-preserving downsampling.
278
+
279
+ An ``unknown`` sample never outranks a real one — it always scores
280
+ below every possible real reading (percentages are 0-100) — so a bucket
281
+ with even one real sample surfaces that reading rather than the gap.
282
+ """
283
+ if sample.get("status") != STATUS_OK:
284
+ return -1.0
285
+ cpu = sample.get("cpu_percent") or 0.0
286
+ mem = sample.get("mem_percent") or 0.0
287
+ return max(cpu, mem)
288
+
289
+
290
+ def _pick_representative(bucket: list[dict]) -> dict:
291
+ """The single sample that best represents ``bucket``.
292
+
293
+ Picks the highest-intensity real sample in the bucket (see
294
+ :func:`_sample_intensity`) so a brief spike survives downsampling
295
+ instead of being averaged away or dropped by naive striding. A bucket
296
+ with no real samples at all — every poll in that span came back
297
+ ``unknown`` — reports its first ``unknown`` sample, so a renderer still
298
+ sees the gap rather than the bucket silently vanishing.
299
+ """
300
+ best = bucket[0]
301
+ best_score = _sample_intensity(best)
302
+ for sample in bucket[1:]:
303
+ score = _sample_intensity(sample)
304
+ if score > best_score:
305
+ best, best_score = sample, score
306
+ return best
307
+
308
+
309
+ def downsample(samples: list[dict], resolution: int) -> list[dict]:
310
+ """Reduce ``samples`` (oldest-first) to at most ``resolution`` points.
311
+
312
+ A 6h window at the default ~15s cadence is ~1440 points per machine; a
313
+ phone asking for ``resolution=100`` must get **at most** 100 back, and
314
+ the server must do the reduction — never ship the raw buffer and let
315
+ the client thin it (the whole point of #3021).
316
+
317
+ Buckets ``samples`` into ``resolution`` roughly-equal, chronologically
318
+ contiguous spans and keeps one representative per bucket (see
319
+ :func:`_pick_representative`) — naive fixed-stride sampling (every Nth
320
+ point) would silently skip over a spike that lands on a dropped index;
321
+ this always surfaces the bucket's peak instead.
322
+
323
+ Raises :class:`ValueError` if ``resolution`` is not positive.
324
+ """
325
+ if resolution <= 0:
326
+ raise ValueError("resolution must be positive")
327
+ n = len(samples)
328
+ if n <= resolution:
329
+ return list(samples)
330
+ out: list[dict] = []
331
+ for i in range(resolution):
332
+ lo = (i * n) // resolution
333
+ hi = ((i + 1) * n) // resolution
334
+ bucket = samples[lo:hi]
335
+ if bucket:
336
+ out.append(_pick_representative(bucket))
337
+ return out
338
+
339
+
340
+ def build_metrics_response(
341
+ series_by_machine: dict[str, list[dict]],
342
+ *,
343
+ machine: str | None = None,
344
+ since: float | None = None,
345
+ resolution: int | None = None,
346
+ now: float | None = None,
347
+ ) -> dict:
348
+ """Assemble the versioned ``GET /machines/metrics`` response body.
349
+
350
+ ``series_by_machine`` is exactly :meth:`MachineMetricsSampler.all_series`'s
351
+ shape (name → oldest-first list of :meth:`MetricsSample.to_dict`), kept
352
+ as a plain argument rather than the sampler itself so this stays a pure
353
+ function a test can call with a synthetic dict.
354
+
355
+ - ``machine`` narrows to a single machine's series; a name with no
356
+ buffer yet (never polled, or simply unknown) comes back as ``[]``,
357
+ same as :meth:`MachineMetricsSampler.series` — never a 404, since "no
358
+ data yet" and "no such machine" are indistinguishable from here and
359
+ both mean the same thing to a renderer: nothing to draw.
360
+ - ``since`` filters to samples at or after that epoch timestamp
361
+ (:func:`resolve_since` turns the query string into this).
362
+ - ``resolution`` server-side downsamples each machine's filtered series
363
+ independently (:func:`downsample`); omitted means the full filtered
364
+ series.
365
+
366
+ ``schema: 1`` — versioned explicitly, matching
367
+ ``FleetHealthSnapshot.to_dict()``'s posture, so a client can detect a
368
+ future incompatible reshape rather than guess from field presence.
369
+ """
370
+ now = now if now is not None else time.time()
371
+ selected = (
372
+ {machine: series_by_machine.get(machine, [])}
373
+ if machine is not None
374
+ else series_by_machine
375
+ )
376
+
377
+ machines_out: dict[str, list[dict]] = {}
378
+ for name, series in selected.items():
379
+ windowed = _filter_since(series, since)
380
+ if resolution is not None:
381
+ windowed = downsample(windowed, resolution)
382
+ machines_out[name] = windowed
383
+
384
+ return {
385
+ "schema": 1,
386
+ "generated_at": now,
387
+ "since": since,
388
+ "resolution": resolution,
389
+ "machines": machines_out,
390
+ }
coord/serve_app.py CHANGED
@@ -4957,6 +4957,91 @@ def openapi_spec() -> dict:
4957
4957
  },
4958
4958
  }
4959
4959
  },
4960
+ "/machines/metrics": {
4961
+ "get": {
4962
+ "summary": (
4963
+ "#3021: server-downsampled cpu/mem history from #3020's "
4964
+ "bounded per-machine ring buffers (~6h at ~15s cadence). "
4965
+ "Never ships the raw buffer for the client to thin — pass "
4966
+ "`resolution` and the server reduces it."
4967
+ ),
4968
+ "parameters": [
4969
+ {
4970
+ "name": "since",
4971
+ "in": "query",
4972
+ "schema": {"type": "string"},
4973
+ "description": (
4974
+ "epoch seconds, ISO-8601, or a duration like '6h' "
4975
+ "('now minus 6h'). Omitted = the full retained window."
4976
+ ),
4977
+ },
4978
+ {
4979
+ "name": "resolution",
4980
+ "in": "query",
4981
+ "schema": {"type": "integer"},
4982
+ "description": (
4983
+ "max points per machine per series in the response, "
4984
+ "e.g. 100. Downsampling is peak-preserving (keeps the "
4985
+ "highest cpu/mem reading per bucket, never naive "
4986
+ "striding). Omitted = full filtered series."
4987
+ ),
4988
+ },
4989
+ {
4990
+ "name": "machine",
4991
+ "in": "query",
4992
+ "schema": {"type": "string"},
4993
+ "description": "narrow to a single machine's series",
4994
+ },
4995
+ ],
4996
+ "responses": {
4997
+ "200": {
4998
+ "description": "OK",
4999
+ "content": {
5000
+ "application/json": {
5001
+ "schema": {
5002
+ "type": "object",
5003
+ "properties": {
5004
+ "schema": {"type": "integer", "enum": [1]},
5005
+ "generated_at": {"type": "number"},
5006
+ "since": {"type": ["number", "null"]},
5007
+ "resolution": {"type": ["integer", "null"]},
5008
+ "machines": {
5009
+ "type": "object",
5010
+ "description": (
5011
+ "machine name -> oldest-first list "
5012
+ "of samples; status=unknown carries "
5013
+ "no cpu/mem values so a renderer "
5014
+ "draws a gap instead of interpolating"
5015
+ ),
5016
+ "additionalProperties": {
5017
+ "type": "array",
5018
+ "items": {
5019
+ "type": "object",
5020
+ "properties": {
5021
+ "timestamp": {"type": "number"},
5022
+ "status": {
5023
+ "type": "string",
5024
+ "enum": ["ok", "unknown"],
5025
+ },
5026
+ "cpu_percent": {"type": ["number", "null"]},
5027
+ "mem_percent": {"type": ["number", "null"]},
5028
+ "mem_used_mb": {"type": ["number", "null"]},
5029
+ "mem_total_mb": {"type": ["number", "null"]},
5030
+ "reason": {"type": "string"},
5031
+ },
5032
+ },
5033
+ },
5034
+ },
5035
+ },
5036
+ "required": ["schema", "generated_at", "machines"],
5037
+ }
5038
+ }
5039
+ },
5040
+ },
5041
+ "400": {"description": "Bad `since` or `resolution`"},
5042
+ },
5043
+ }
5044
+ },
4960
5045
  "/report": {
4961
5046
  "get": {
4962
5047
  "summary": (
@@ -5304,11 +5389,23 @@ def openapi_spec() -> dict:
5304
5389
  )
5305
5390
 
5306
5391
 
5307
- def build_app(store: CoordStore, config: Config, *, token: str | None = None) -> Starlette:
5392
+ def build_app(
5393
+ store: CoordStore,
5394
+ config: Config,
5395
+ *,
5396
+ token: str | None = None,
5397
+ machine_metrics_sampler: MachineMetricsSampler | None = None,
5398
+ ) -> Starlette:
5308
5399
  """Build the read-only control-center Starlette app bound to *store* + *config*.
5309
5400
 
5310
5401
  *token* — when set, every endpoint except ``/healthz`` requires
5311
5402
  ``Authorization: Bearer <token>``.
5403
+
5404
+ *machine_metrics_sampler* — injectable for tests (#3021): a fresh
5405
+ :class:`~coord.machine_metrics.MachineMetricsSampler` is created when
5406
+ omitted, exactly as before. Passing a pre-seeded instance lets a test
5407
+ drive ``GET /machines/metrics`` against known ring-buffer contents
5408
+ without waiting on the tick loop or a live agent poll.
5312
5409
  """
5313
5410
  # #1081: track the backing coordinator.yml's mtime so the handlers below
5314
5411
  # can swap in a freshly-reloaded Config when it changes on disk, instead
@@ -5343,11 +5440,12 @@ def build_app(store: CoordStore, config: Config, *, token: str | None = None) ->
5343
5440
  # #3020: same shape again — polling every agent's own /metrics is real
5344
5441
  # per-machine I/O, so it runs on the tick loop's cadence
5345
5442
  # (`_machine_metrics_loop` below), never inline off a request handler.
5346
- # Series live only in this sampler's bounded in-memory ring buffers; no
5347
- # read endpoint exists yet (that's #A2) and nothing here touches /board.
5443
+ # Series live only in this sampler's bounded in-memory ring buffers;
5444
+ # `GET /machines/metrics` (#3021, below) is the read endpoint and does
5445
+ # bare in-memory reads only. Nothing here touches /board.
5348
5446
  from coord.machine_metrics import MachineMetricsSampler # noqa: PLC0415
5349
5447
 
5350
- _machine_metrics_sampler = MachineMetricsSampler()
5448
+ _machine_metrics_sampler = machine_metrics_sampler or MachineMetricsSampler()
5351
5449
 
5352
5450
  # Short-TTL cache for the computed /board projection so burst polls from the
5353
5451
  # TUI don't each pay the full board_projection + merge-plan + stage-projection
@@ -8882,6 +8980,39 @@ def build_app(store: CoordStore, config: Config, *, token: str | None = None) ->
8882
8980
  )
8883
8981
  return JSONResponse(result.to_dict())
8884
8982
 
8983
+ async def get_machine_metrics(request: Request) -> Response:
8984
+ # #3021: the read side of #3020's sampler. Bare in-memory reads +
8985
+ # pure filtering/downsampling — no I/O, so (unlike /board) this
8986
+ # never needs a threadpool hop and can't be slowed by a hanging
8987
+ # agent (that's `_machine_metrics_loop`'s problem, not this
8988
+ # handler's).
8989
+ from coord.machine_metrics import build_metrics_response, resolve_since # noqa: PLC0415
8990
+
8991
+ qp = request.query_params
8992
+
8993
+ resolution_raw = qp.get("resolution")
8994
+ try:
8995
+ resolution = int(resolution_raw) if resolution_raw else None
8996
+ if resolution is not None and resolution <= 0:
8997
+ raise ValueError("resolution must be a positive integer")
8998
+ except ValueError as e:
8999
+ return JSONResponse(
9000
+ {"error": f"bad resolution={resolution_raw!r}: {e}"}, status_code=400
9001
+ )
9002
+
9003
+ try:
9004
+ since = resolve_since(qp.get("since"))
9005
+ except ValueError as e:
9006
+ return JSONResponse({"error": str(e)}, status_code=400)
9007
+
9008
+ result = build_metrics_response(
9009
+ _machine_metrics_sampler.all_series(),
9010
+ machine=qp.get("machine") or None,
9011
+ since=since,
9012
+ resolution=resolution,
9013
+ )
9014
+ return JSONResponse(result)
9015
+
8885
9016
  async def post_merge(request: Request) -> Response:
8886
9017
  # #584: the merge queue + board live in THIS (canonical) DB, and gh is
8887
9018
  # authenticated here — so a thin client's `coord merge` / TUI 'Go' routes
@@ -10292,6 +10423,9 @@ def build_app(store: CoordStore, config: Config, *, token: str | None = None) ->
10292
10423
  # read-only, both alongside /audit because they read the same data.
10293
10424
  Route("/report", get_report_catalogue, methods=["GET"]),
10294
10425
  Route("/report/{report_id}", get_report, methods=["GET"]),
10426
+ # #3021: read side of #3020's sampler — server-downsampled machine
10427
+ # cpu/mem history for the coord-web Machines panel.
10428
+ Route("/machines/metrics", get_machine_metrics, methods=["GET"]),
10295
10429
  Route("/config", serve_config, methods=["GET"]),
10296
10430
  Route("/result", post_result, methods=["POST"]),
10297
10431
  Route("/completion", post_completion, methods=["POST"]),