Skip to content

Introduce centralized defaults, add streaming HTTP body-size middleware, and improve error handling with tests#2

Merged
arty-kk merged 1 commit intomainfrom
codex/implement-evolution_plan.md-with-best-practices
Mar 30, 2026
Merged

Introduce centralized defaults, add streaming HTTP body-size middleware, and improve error handling with tests#2
arty-kk merged 1 commit intomainfrom
codex/implement-evolution_plan.md-with-best-practices

Conversation

@arty-kk
Copy link
Copy Markdown
Owner

@arty-kk arty-kk commented Mar 30, 2026

Motivation

  • Consolidate repeated numeric and boolean defaults into a single defaults module to avoid drift and make configuration consistent across modules.
  • Protect the HTTP API from oversized request bodies even when Content-Length is missing or unreliable by enforcing a streaming-aware body size limit.
  • Ensure worker/worker-thread errors surface as internal server errors (HTTP 500) rather than being exposed as bad requests (HTTP 400).

Description

  • Add hyperquant/defaults.py and replace hard-coded default values with named constants across api.models, cli, context_codec, resident_tier, and vector_codec to centralize configuration defaults using symbols like VECTOR_BITS_DEFAULT and CONTEXT_PAGE_SIZE_DEFAULT.
  • Implement _BodySizeLimitMiddleware in hyperquant/api/app.py and register it on the FastAPI app to enforce max_http_body_bytes during streaming requests, including Content-Length checks and draining the request stream when rejecting with 413.
  • Replace several broad internal-exception handlers that returned HTTP 400 with a uniform internal_server_error helper that returns HTTP 500 and keep metrics instrumentation for internal errors.
  • Update CLI behavior to avoid exposing decode-only arguments in the context-decompress-file subcommand and wire defaults into the argument definitions.
  • Add and refactor tests and utilities: introduce tests/array_builders.py, add tests/test_cli.py, expand tests/test_api.py with tests for 500 responses and streaming oversize rejection, and update tests/test_context_codec.py and tests/test_resident_tier.py to use shared builders and to cover planner error propagation.

Testing

  • Ran the unit test suite with pytest including new tests tests/test_api.py::test_api_returns_500_for_internal_worker_error and tests/test_api.py::test_api_rejects_oversized_body_without_reliable_content_length, and all executed tests passed.
  • Exercised CLI parsing via tests/test_cli.py::test_context_decompress_file_help_has_only_decode_inputs which passed.
  • Verified codec and resident-tier behavior via tests/test_context_codec.py::test_context_roundtrip_and_ratio and tests/test_resident_tier.py scenarios covering error propagation and qualification, which passed.

Codex Task

@arty-kk arty-kk merged commit 6d8cf0c into main Mar 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant