Repository navigation
AUDIT-09 — Medium-High — session_id unbounded at the API, VARCHAR(255) in the DB #66
Description
Summary
Severity: Medium-High
Area: Persistence / API
Affected files: agentkit/api/schemas.py:9-18, agentkit/db/models.py:25-29
Suggested branch: fix/session-id-length-validation
Suggested PR title: fix(api): bound session_id at the request boundary
This is finding AUDIT-09 of 18 from a consolidated audit of agentkit/. It is deliberately self-contained so it can be fixed on its own branch with its own PR.
Related findings: Related: AUDIT-08.
AUDIT-09 — Medium-High — session_id unbounded at the API, VARCHAR(255) in the DB
Files
agentkit/api/schemas.py:9-18agentkit/db/models.py:25-29
Current code — agentkit/api/schemas.py:9-18
class RunCreateRequest(BaseModel):
"""Payload to initiate a new agent execution run."""
model_config = ConfigDict(extra="forbid")
goal: str = Field(..., min_length=1, description="Goal or task description for the agent.")
session_id: str | None = Field(
default=None,
description="Optional conversation session ID to preserve context across multiple runs.",
)Current code — agentkit/db/models.py:25-29
session_id: Mapped[str | None] = mapped_column(
String(255),
nullable=True,
index=True,
)Why this is a bug
The API accepts a session_id of any length; the column is VARCHAR(255). A 256+ character session id makes the INSERT in create_run fail with a data-length error → suppressed (AUDIT-08) → the client receives a phantom HTTP 200 succeeded and the run is never stored. The same id is also used verbatim as a Redis key (session:<id>:messages), so an oversized id also becomes an unbounded key.
Pass cases
-
RunCreateRequest.session_idhas an explicit maximum length (255) → an over-long id returns HTTP 422 with the validation error, before any agent work starts. - An over-long session id never reaches the database or Redis.
- A 255-character session id is accepted and round-trips (DB + Redis).
- The DB column length and the API limit are asserted to be equal by a test (so they cannot drift again).
- A test asserts an over-long session id yields 422 and no run record is created.
Definition of done (per AGENTS.md)
- New/updated unit and integration tests covering the pass cases above, all passing (
pytest). -
ruff check .,ruff format --check .andmypy agentkitclean. - Docstrings updated where behaviour changed;
docs/PROGRESS.mdupdated (status, PR link, commit count, notes). - A new ADR in
docs/DECISIONS.mdif an architectural decision was made. - Branch pushed and PR opened (never commit directly to
main).
Baseline at the time of writing: pytest is green on main (all tests pass; tests/real/* skipped unless AGENTKIT_REAL_INFRA=1).
Activity
getdownandcode commentedon Oct 20, 2026
Audit index (18 separate issues, fix one by one)
Each issue is self-contained: current code, reproduction, pass cases, suggested branch and PR title. Reference the relevant one with
Fixes #NNin your PR.HamzaKhanBUIC commentedon Oct 20, 2026
Opened PR #80 with the complete fix and regression test suite:
uff check,
uff format --check, and mypy agentkit.