Skip to content

fix: get_step returns wrong step + pagination ceiling off-by-one#131

Open
vystartasv wants to merge 1 commit intoagi-inc:mainfrom
vystartasv:fix/get-step-id-and-pagination
Open

fix: get_step returns wrong step + pagination ceiling off-by-one#131
vystartasv wants to merge 1 commit intoagi-inc:mainfrom
vystartasv:fix/get-step-id-and-pagination

Conversation

@vystartasv
Copy link
Copy Markdown

Bugs Fixed

1. get_step() returns wrong step (critical)

InMemoryTaskDB.get_step(task_id, step_id) filters by s.task_id instead of s.step_id:

# BEFORE (bug): always returns first step of the task
step = next(filter(lambda s: s.task_id == task_id, task.steps), None)

# AFTER (fix): returns the correct step
step = next(filter(lambda s: s.step_id == step_id, task.steps), None)

Since all steps in task.steps share the same task_id, the filter matches EVERY step. next() returns the first one — regardless of which step_id was requested. This means GET /ap/v1/agent/tasks/{task_id}/steps/{step_id} always returns the wrong step.

2. Pagination off-by-one (2 locations)

total_pages uses floor division, undercounting when items don't divide evenly:

# BEFORE: 11 items / page_size 10 → total_pages = 1 (should be 2)
total_pages = len(tasks) // page_size

# AFTER: ceiling division
total_pages = (len(tasks) + page_size - 1) // page_size

Fixed in both list_agent_tasks and list_agent_task_steps.

Impact

  • get_step: The API returns incorrect step data for any task with multiple steps. Silent data corruption — no error, just wrong results.
  • pagination: Clients seeing total_pages=1 for 11 items at page_size=10 miss the second page entirely.

get_step(task_id, step_id) was filtering by s.task_id instead
of s.step_id, always returning the first step of the task
regardless of the requested step_id.

Pagination total_pages used floor division (len//page_size)
which undercounts when items don't divide evenly. Changed to
ceiling division: (len+page_size-1)//page_size.
Affects both list_agent_tasks and list_agent_task_steps.
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