Commit 2ffde24
authored
fix: page ready agents during health-check startup (#345)
## Summary
- page through READY agents when starting health-check workflows at
startup
- avoid loading non-ready agents just to filter them in Python
- add a focused unit test covering pagination beyond one page
## Tests
- uv run ruff check src/temporal/run_healthcheck_workflow.py
tests/unit/temporal/test_run_healthcheck_workflow.py
- uv run --group test pytest
tests/unit/temporal/test_run_healthcheck_workflow.py -q
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes the health-check startup path to page through only `READY`
agents server-side, replacing a full table scan followed by in-Python
filtering. A new `READY_AGENT_PAGE_SIZE = 200` constant drives
offset-based pagination with a stable `order_by="id"` sort, and two
focused unit tests verify both the multi-page and exact-page-size
boundary paths.
- **`run_healthcheck_workflow.py`**: Replaces a single
`agent_repo.list()` call (no filter) with a `while True` pagination loop
filtered on `status=READY`, breaking on an empty page or a partial page.
- **`test_run_healthcheck_workflow.py`**: New test file with a helper
that monkeypatches all external dependencies; covers multi-page
traversal and the exact-multiple-of-page-size edge case.
<details><summary><h3>Confidence Score: 5/5</h3></summary>
Safe to merge — the change is a straightforward pagination refactor with
no mutations, no new external dependencies, and deterministic
termination.
The pagination loop correctly handles all exit conditions (empty page,
partial page), uses a stable immutable sort key, and pushes filtering to
the database. Both new tests exercise the logic end-to-end with full
dependency isolation. No regressions expected.
No files require special attention.
</details>
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| agentex/src/temporal/run_healthcheck_workflow.py | Pagination loop is
correct — stable sort key (`order_by="id"`), server-side status filter,
and two break conditions handle both partial-page and empty-page
termination. No issues found. |
| agentex/tests/unit/temporal/test_run_healthcheck_workflow.py | New
unit tests cover the multi-page and exact-page-size boundary cases with
thorough monkeypatching; helper is structured cleanly as a reusable
async coroutine. |
</details>
<details><summary><h3>Flowchart</h3></summary>
<a href="#gh-light-mode-only">
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[main starts] --> B[load GlobalDependencies]
B --> C{env configured?}
C -- no --> Z[return]
C -- yes --> D{health-check enabled?}
D -- no --> Z
D -- yes --> E{Temporal configured?}
E -- no --> Z
E -- yes --> F[init AgentRepository + TemporalAdapter]
F --> G[page_number = 1]
G --> H[agent_repo.list status=READY limit=200 page=N order_by=id]
H --> I{agents empty?}
I -- yes --> Z
I -- no --> J[for each agent: start_workflow healthcheck_workflow_agentId]
J --> K{len agents < 200?}
K -- yes --> Z
K -- no --> L[page_number += 1]
L --> H
```
</a>
<a href="#gh-dark-mode-only">
```mermaid
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[main starts] --> B[load GlobalDependencies]
B --> C{env configured?}
C -- no --> Z[return]
C -- yes --> D{health-check enabled?}
D -- no --> Z
D -- yes --> E{Temporal configured?}
E -- no --> Z
E -- yes --> F[init AgentRepository + TemporalAdapter]
F --> G[page_number = 1]
G --> H[agent_repo.list status=READY limit=200 page=N order_by=id]
H --> I{agents empty?}
I -- yes --> Z
I -- no --> J[for each agent: start_workflow healthcheck_workflow_agentId]
J --> K{len agents < 200?}
K -- yes --> Z
K -- no --> L[page_number += 1]
L --> H
```
</a>
</details>
<sub>Reviews (5): Last reviewed commit: ["Merge branch 'main'
into
fix/page-ready-..."](5fa8d7e)
| [Re-trigger
Greptile](https://app.greptile.com/api/retrigger?id=41266248)</sub>
<!-- /greptile_comment -->1 parent 38f917b commit 2ffde24
2 files changed
Lines changed: 189 additions & 24 deletions
File tree
- agentex
- src/temporal
- tests/unit/temporal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
79 | 93 | | |
80 | 94 | | |
81 | 95 | | |
| |||
Lines changed: 151 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
0 commit comments