Skip to content

fix: page ready agents during health-check startup#345

Open
scale-sf wants to merge 2 commits into
mainfrom
fix/page-ready-healthchecks
Open

fix: page ready agents during health-check startup#345
scale-sf wants to merge 2 commits into
mainfrom
fix/page-ready-healthchecks

Conversation

@scale-sf

@scale-sf scale-sf commented Jul 2, 2026

Copy link
Copy Markdown

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 Summary

This PR replaces a full-table agent_repo.list() call (loaded all agents and filtered in Python) with a stable, paginated query that applies the READY status filter at the database level. A new READY_AGENT_PAGE_SIZE = 200 constant drives the loop, which exits on either an empty page or a partial page.

  • Pagination loop in run_healthcheck_workflow.py now passes filters={\"status\": AgentStatus.READY}, order_by=\"id\", and order_direction=\"asc\" to the repository, giving deterministic offset-based pagination with no Python-side status filtering.
  • Unit tests add two new async scenarios: a multi-page case (full page + partial page) and an exact-multiple boundary case (full page + empty page), covering both exit conditions of the while True loop.

Confidence Score: 5/5

Safe to merge — the change is a well-scoped correctness improvement to startup logic with no side-effects beyond health-check workflow registration.

The pagination loop is logically correct: it exits on an empty page or a partial page, starts at page 1 (matching the 1-based offset formula (page_number - 1) * limit in the base repository), and passes order_by=id which resolves to a stable, unique primary-key sort in create_order_by_clauses. The status filter is applied at the DB layer and confirmed reachable through create_where_clauses_from_filters. Both boundary conditions (exact multiple and partial remainder) are covered by the new tests.

No files require special attention.

Important Files Changed

Filename Overview
agentex/src/temporal/run_healthcheck_workflow.py Replaces single unbounded list() call with a paginated loop filtered to READY agents; logic, exit conditions, and parameter passing are all correct.
agentex/tests/unit/temporal/test_run_healthcheck_workflow.py New test file with two async unit tests covering the multi-page and exact-page-size boundary cases; monkeypatching is correct and both loop-exit paths are exercised.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Main as run_healthcheck_workflow.main()
    participant Repo as AgentRepository
    participant DB as PostgreSQL
    participant Temporal as TemporalAdapter

    Main->>Repo: "list(filters={status: READY}, limit=200, page_number=1, order_by="id")"
    Repo->>DB: "SELECT ... WHERE status=READY ORDER BY id ASC LIMIT 200 OFFSET 0"
    DB-->>Repo: agents[0..199]
    Repo-->>Main: agents (200 items)
    loop For each agent on page 1
        Main->>Temporal: "start_workflow(healthcheck_workflow_{agent.id})"
    end
    Main->>Repo: "list(..., page_number=2)"
    Repo->>DB: SELECT ... LIMIT 200 OFFSET 200
    DB-->>Repo: agents[200..N]
    Repo-->>Main: "agents (< 200 or empty)"
    loop For each agent on page 2
        Main->>Temporal: "start_workflow(healthcheck_workflow_{agent.id})"
    end
    Note over Main: Break on empty page or len(agents) < 200
Loading
%%{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"}}}%%
sequenceDiagram
    participant Main as run_healthcheck_workflow.main()
    participant Repo as AgentRepository
    participant DB as PostgreSQL
    participant Temporal as TemporalAdapter

    Main->>Repo: "list(filters={status: READY}, limit=200, page_number=1, order_by="id")"
    Repo->>DB: "SELECT ... WHERE status=READY ORDER BY id ASC LIMIT 200 OFFSET 0"
    DB-->>Repo: agents[0..199]
    Repo-->>Main: agents (200 items)
    loop For each agent on page 1
        Main->>Temporal: "start_workflow(healthcheck_workflow_{agent.id})"
    end
    Main->>Repo: "list(..., page_number=2)"
    Repo->>DB: SELECT ... LIMIT 200 OFFSET 200
    DB-->>Repo: agents[200..N]
    Repo-->>Main: "agents (< 200 or empty)"
    loop For each agent on page 2
        Main->>Temporal: "start_workflow(healthcheck_workflow_{agent.id})"
    end
    Note over Main: Break on empty page or len(agents) < 200
Loading

Reviews (4): Last reviewed commit: "Merge branch 'main' into fix/page-ready-..." | Re-trigger Greptile

@scale-sf scale-sf requested a review from a team as a code owner July 2, 2026 02:21
@scale-sf scale-sf changed the title Fix health-check startup pagination fix: page ready agents during health-check startup Jul 2, 2026
Comment thread agentex/src/temporal/run_healthcheck_workflow.py
Comment thread agentex/tests/unit/temporal/test_run_healthcheck_workflow.py Outdated
@scale-sf scale-sf force-pushed the fix/page-ready-healthchecks branch from 8586b34 to dd0e73d Compare July 2, 2026 02:32
@scale-sf

scale-sf commented Jul 2, 2026

Copy link
Copy Markdown
Author

@greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant