|
| 1 | +--- |
| 2 | +name: acknowledg-client |
| 3 | +description: >- |
| 4 | + Works on the AcknowlEDG Python client: BatchClient vs DirectClient, |
| 5 | + ReviewClient Protocol, resilient websocket reconnect, and test/bench |
| 6 | + provider handlers. Use when editing edgacknowledg.client, edgy-review, |
| 7 | + edg-bench-review, edg-acknowledg-cli, or section subscribe/reconnect logic. |
| 8 | +--- |
| 9 | + |
| 10 | +# AcknowlEDG client |
| 11 | + |
| 12 | +Canonical package: [`dev_tools/pylibs/edgacknowledg/`](../../../dev_tools/pylibs/edgacknowledg/). |
| 13 | +`dev_tools/services/acknowledg/server/edgacknowledg` is a **symlink** — edit |
| 14 | +pylibs only. |
| 15 | + |
| 16 | +Wire protocol (tags, routes, auth, occupancy): |
| 17 | +[PROTOCOL.md](../../../dev_tools/services/acknowledg/PROTOCOL.md). Keep |
| 18 | +`PROTOCOL_REVISION` in sync with |
| 19 | +`dev_tools/services/acknowledg/client/src/sockets.js`. |
| 20 | + |
| 21 | +## Public API |
| 22 | + |
| 23 | +From `edgacknowledg.client` (`__all__`): |
| 24 | + |
| 25 | +- `BatchClient` / `DirectClient` — async context managers; constructor takes |
| 26 | + endpoint settings and optional `status_listener` |
| 27 | +- `BatchClientSession` / `DirectClientSession` — yielded by client `__aenter__`; |
| 28 | + `create_review` / `remove_review`, `close()`, `stopped()`, `start()`, `stop()` |
| 29 | + (client `__aexit__` awaits `stopped()` then `stop()`) |
| 30 | +- `ConnectionStatusListener` — `connected` / `attempting_reconnect` / |
| 31 | + `disconnected` |
| 32 | +- `ReviewClient` (structural **Protocol**): `review_id`, `name`, `timestamp`, |
| 33 | + `sections()`, `add_section` / `remove_section` |
| 34 | +- URL/env helpers: `add_endpoint_arguments`, `form_section_http_url`, |
| 35 | + `default_*` host/port helpers |
| 36 | +- Shared: `BackgroundWorkerPool`, errors |
| 37 | + |
| 38 | +Usage: |
| 39 | + |
| 40 | +```python |
| 41 | +async with BatchClient( |
| 42 | + api_host=..., api_port=..., status_listener=listener |
| 43 | +) as session: |
| 44 | + review = await session.create_review(...) |
| 45 | + # Block ends when session.stop() is called, or on cancellation. |
| 46 | +``` |
| 47 | + |
| 48 | +Private (leading `_`): `_ClientReview`, `_BatchClientReview`, |
| 49 | +`_DirectClientReview`, channel helpers. Callers should type against |
| 50 | +`ReviewClient`, not private classes. |
| 51 | + |
| 52 | +## Batch vs Direct |
| 53 | + |
| 54 | +| | Batch | Direct | |
| 55 | +| --- | --- | --- | |
| 56 | +| Socket | One resilient `/batch` | Per-section `/source|edit/<uuid>/<kind>/<slug>` | |
| 57 | +| Mux | `batch.subscribe` / `unsubscribe` / `event` | Dedicated WS per section | |
| 58 | +| CLI | `edg-acknowledg-cli` | `edgy-review`, `edg-bench-review` | |
| 59 | +| Reconnect | Drop local subs, `_restore_subscriptions()` | Each section's `ResilientWebsocket` loop | |
| 60 | + |
| 61 | +Direct URL mapping uses handler `subscription_type` (e.g. `test.src` → |
| 62 | +`/source/.../test/<slug>`, `bench.edit` → `/edit/.../bench/<slug>`). |
| 63 | + |
| 64 | +## Reconnect |
| 65 | + |
| 66 | +[`client/websocket.py`](../../../dev_tools/pylibs/edgacknowledg/client/websocket.py): |
| 67 | +`ResilientWebsocket`, exponential backoff + jitter on connect failure; |
| 68 | +jitter-only delay after a drop. Pattern: |
| 69 | + |
| 70 | +```python |
| 71 | +async for websocket in ResilientWebsocket(...): |
| 72 | + try: |
| 73 | + ... |
| 74 | + except ConnectionClosed: |
| 75 | + continue |
| 76 | +``` |
| 77 | + |
| 78 | +Auth header: `X-AcknowlEDG-API-Key` (never put the key in query strings). |
| 79 | +`RoleOccupied`: discard that handler / stop reconnecting that section; keep |
| 80 | +other sections running. |
| 81 | + |
| 82 | +## Batch subscription maps |
| 83 | + |
| 84 | +`_BatchClientReview` tracks: |
| 85 | + |
| 86 | +- `_subscriptions: Dict[int, uuid.UUID]` — `id(handler)` → server subscription id |
| 87 | +- `_subscription_tasks: Dict[uuid.UUID, asyncio.Task]` — subscription id → task |
| 88 | + |
| 89 | +Unsubscribe needs the server id; the handler-key map provides it after |
| 90 | +reconnect bookkeeping. |
| 91 | + |
| 92 | +## Providers |
| 93 | + |
| 94 | +| Package | Handlers | |
| 95 | +| --- | --- | |
| 96 | +| `client/test/__init__.py` | `TestSourceHandler` (`test.src`), `TestEditHandler` (`test.edit`) | |
| 97 | +| `client/bench/__init__.py` | `BenchSourceHandler` (`bench.src`), `BenchEditHandler` (`bench.edit`) | |
| 98 | + |
| 99 | +Shared: `ReviewClientHandler`, `Channel`, `announce_section`, |
| 100 | +`trunc_display_content` in `client/shared.py`. |
| 101 | + |
| 102 | +## Env / URLs |
| 103 | + |
| 104 | +- `EDG_ACKNOWLEDG_API_{HOST,PORT}`, `EDG_ACKNOWLEDG_UI_{HOST,PORT}`, |
| 105 | + `EDG_ACKNOWLEDG_API_KEY` |
| 106 | +- Defaults: API `localhost:2727`, UI `localhost:5173`; non-localhost hosts |
| 107 | + default port 80 |
| 108 | +- Print UI section URLs as soon as the section exists (`form_section_http_url`) |
| 109 | +- Timestamps: `utc_now_iso` / `is_iso_timestamp` — no `Z` / `+00:00` munging |
| 110 | + |
| 111 | +## Python style here |
| 112 | + |
| 113 | +Follow skill **edg-python-style** (2-space indent, ` = ` in kwargs, |
| 114 | +`f"..."` / `'...'`, match neighbors). |
0 commit comments