Skip to content

LCORE-2917 Adding image attachment capabilities to /query and /streaming_query#2222

Open
JslYoon wants to merge 1 commit into
lightspeed-core:mainfrom
JslYoon:JslYoon-image-attachments
Open

LCORE-2917 Adding image attachment capabilities to /query and /streaming_query#2222
JslYoon wants to merge 1 commit into
lightspeed-core:mainfrom
JslYoon:JslYoon-image-attachments

Conversation

@JslYoon

@JslYoon JslYoon commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

This is the documentation and e2e updates for a previous merged PR #2108

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: Claude Code
  • Generated by: Opus 4.6

Related Tickets & Documents

Related Issue # https://redhat.atlassian.net/browse/LCORE-2917
Closes # https://redhat.atlassian.net/browse/LCORE-2917

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • Documentation

    • Added comprehensive specifications for synchronous and streaming query APIs.
    • Documented attachments, streaming events, interruption, validation, errors, quotas, and usage examples.
    • Corrected the streaming query documentation heading and added links to the shared specification.
  • Bug Fixes

    • Improved image attachment validation to reject invalid, corrupted, or mismatched image content.
  • Tests

    • Added end-to-end and unit coverage for valid image attachments, invalid base64 data, incorrect content types, and mixed text/image attachments.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR replaces the query endpoint stub with a complete synchronous and streaming API specification, documents attachments, interruption, responses, errors, and examples, and adds image signature validation with unit and end-to-end coverage.

Changes

Query API documentation and attachment validation

Layer / File(s) Summary
Request contract and endpoint overview
docs/devel_doc/query_endpoint.md, docs/devel_doc/streaming_query_endpoint.md
Documents synchronous JSON and streaming SSE endpoints, shared request fields, attachment rules, image validation, and RAG configuration.
Responses, processing flow, and examples
docs/devel_doc/query_endpoint.md
Defines response schemas, SSE event ordering, interruption behavior, processing and quota rules, errors, and curl examples.
Image signature validation and coverage
src/models/common/query.py, tests/unit/models/requests/test_attachment.py, tests/e2e/features/query.feature, tests/e2e/features/streaming_query.feature
Validates decoded image signatures against declared MIME types and adds unit and end-to-end scenarios for valid, mixed, inconsistent, and invalid image attachments.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: ok-to-test

Suggested reviewers: tisnik

🚥 Pre-merge checks | ✅ 7
✅ Passed checks (7 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Performance And Algorithmic Complexity ✅ Passed No blocking perf regressions: the new image validator is one base64 decode plus a frozenset membership/prefix check; no new loops, N+1s, or unbounded growth.
Security And Secret Handling ✅ Passed Touched files add docs/tests and image validation; /query, /streaming_query, and interrupt endpoints are still protected by auth dependency + authorize, with no plaintext secrets found.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding image attachment support for /query and /streaming_query.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JslYoon JslYoon changed the title documentstion & e2e tests for query multimodal attachments LCORE-2917 Adding image attachment capabilities to /query and /streaming_query Jul 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/devel_doc/query_endpoint.md`:
- Line 181: Update the fenced code block containing the event payload example to
specify an explicit language, such as text, on its opening fence while
preserving the example content.

In `@tests/e2e/features/streaming_query.feature`:
- Around line 149-166: Update the streaming scenarios in
tests/e2e/features/streaming_query.feature at lines 149-166 and 206-228 to wait
for the SSE stream to complete after asserting HTTP 200, then verify a
successful terminal/result event or explicitly confirm no error event is
emitted. Apply the same completion assertion to both the valid image-query
scenario and the mixed-attachment scenario.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: df59433a-aeb1-4ed4-8701-9ccf8d2c3396

📥 Commits

Reviewing files that changed from the base of the PR and between 287072e and 9adc98a.

📒 Files selected for processing (4)
  • docs/devel_doc/query_endpoint.md
  • docs/devel_doc/streaming_query_endpoint.md
  • tests/e2e/features/query.feature
  • tests/e2e/features/streaming_query.feature
📜 Review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: mypy
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
  • GitHub Check: spectral
  • GitHub Check: Pylinter
  • GitHub Check: build-pr
🧰 Additional context used
📓 Path-based instructions (2)
**/*

📄 CodeRabbit inference engine (Custom checks)

**/*: Flag meaningful O(n^2)+ algorithms on non-trivial inputs, including handlers and Kubernetes list operations.
Flag N+1 patterns that list items and then query once per item, including Kubernetes API and database access.
Flag expensive work inside loops, including API calls, JSON parsing, and regex compilation.
Flag unbounded growth in caches, watchers, or buffers when eviction or limits are missing.
Flag missing pagination or limits on list operations and API endpoints.
Flag secrets or tokens logged in plaintext or hardcoded in source.
Flag API endpoints missing authentication or authorization.
Flag injection vulnerabilities, including SQL injection, command injection, and path traversal.
Flag sensitive data leaked in API responses, WebSocket messages, or logs.
Flag Kubernetes Secrets and Red Hat secrets missing OwnerReferences.

Never commit secrets or keys; use environment variables for sensitive data.

Files:

  • docs/devel_doc/streaming_query_endpoint.md
  • tests/e2e/features/streaming_query.feature
  • tests/e2e/features/query.feature
  • docs/devel_doc/query_endpoint.md
tests/e2e/**/*.feature

📄 CodeRabbit inference engine (AGENTS.md)

Write end-to-end tests using behave and Gherkin feature files.

Files:

  • tests/e2e/features/streaming_query.feature
  • tests/e2e/features/query.feature
🪛 markdownlint-cli2 (0.23.0)
docs/devel_doc/query_endpoint.md

[warning] 181-181: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (5)
tests/e2e/features/query.feature (1)

160-241: LGTM!

tests/e2e/features/streaming_query.feature (1)

168-205: LGTM!

docs/devel_doc/query_endpoint.md (2)

1-180: LGTM!

Also applies to: 182-247, 258-500, 504-525


248-257: 🗄️ Data Integrity & Integration

No change needed. The SSE end event contract includes available_quotas alongside data; EndStreamPayload also documents this by-name exception.

docs/devel_doc/streaming_query_endpoint.md (1)

1-5: LGTM!

Comment thread docs/devel_doc/query_endpoint.md
Comment thread tests/e2e/features/streaming_query.feature

@radofuchs radofuchs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in overall, just need a few updates

"system_prompt": "You are a helpful assistant"
}
"""
Then The status code of the response is 200

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing only for 200 is not enough here, add also the check for some more details, e.g. for some specific descriptive words in the response

"system_prompt": "You are a helpful assistant"
}
"""
Then The status code of the response is 200

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, but make sure that both parts are processed properly

"system_prompt": "You are a helpful assistant"
}
"""
Then The status code of the response is 200

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed with coderabbit here, also apply the same comments from query

Then The status code of the response is 200

Scenario: Check if query with shields returns 413 when question is too long for model context
Scenario: Check if LLM responds properly when a valid image attachment is sent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completely missing a test here for a case where you send a random base64 string. I tested this locally, lightspeed-stack returns generic 500 for this which needs a fix

Signed-off-by: Lucas <lyoon@redhat.com>
@JslYoon
JslYoon force-pushed the JslYoon-image-attachments branch from 9adc98a to 56eb60b Compare July 23, 2026 18:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/devel_doc/query_endpoint.md`:
- Around line 100-105: Update the image attachment documentation near the
existing base64 and MIME-type rules to state that decoded bytes must match the
declared image/jpeg or image/png file signature, as validated by
_validate_image_magic_bytes. Specify that valid base64 with a mismatched file
format is rejected with HTTP 422.
- Around line 92-95: Align the attachment documentation with actual runtime
behavior: either add explicit validation for the documented attachment_type and
content_type allowlists in the Attachment model and preserve the HTTP 422 claim,
or remove the allowlist and invalid-value 422 claims if no such validation is
intended. Ensure the documentation does not promise constraints that the model
does not enforce.
- Around line 179-183: Make the streaming_query SSE envelope consistent across
the generic schema and both end-event examples: either place available_quotas
inside the end event’s data object or update the schema description to
explicitly allow it at the top level, and apply the same shape to the additional
referenced examples.

In `@src/models/common/query.py`:
- Around line 18-20: Update the PNG entry in _IMAGE_SIGNATURES to use the
complete eight-byte PNG signature b"\x89PNG\r\n\x1a\n" instead of the four-byte
prefix, and adjust the existing PNG test fixture to include the complete
signature while preserving the JPEG behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 718e1ada-e0cb-453b-a77d-efbf8405aa75

📥 Commits

Reviewing files that changed from the base of the PR and between 9adc98a and 56eb60b.

📒 Files selected for processing (6)
  • docs/devel_doc/query_endpoint.md
  • docs/devel_doc/streaming_query_endpoint.md
  • src/models/common/query.py
  • tests/e2e/features/query.feature
  • tests/e2e/features/streaming_query.feature
  • tests/unit/models/requests/test_attachment.py
📜 Review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: list_outdated_dependencies
  • GitHub Check: build-pr
  • GitHub Check: bandit
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: mypy
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
🧰 Additional context used
📓 Path-based instructions (5)
**/*

📄 CodeRabbit inference engine (Custom checks)

**/*: Flag meaningful O(n^2)+ algorithms on non-trivial inputs, including handlers and Kubernetes list operations.
Flag N+1 patterns that list items and then query once per item, including Kubernetes API and database access.
Flag expensive work inside loops, including API calls, JSON parsing, and regex compilation.
Flag unbounded growth in caches, watchers, or buffers when eviction or limits are missing.
Flag missing pagination or limits on list operations and API endpoints.
Flag secrets or tokens logged in plaintext or hardcoded in source.
Flag API endpoints missing authentication or authorization.
Flag injection vulnerabilities, including SQL injection, command injection, and path traversal.
Flag sensitive data leaked in API responses, WebSocket messages, or logs.
Flag Kubernetes Secrets and Red Hat secrets missing OwnerReferences.

Files:

  • docs/devel_doc/streaming_query_endpoint.md
  • src/models/common/query.py
  • tests/unit/models/requests/test_attachment.py
  • docs/devel_doc/query_endpoint.md
  • tests/e2e/features/query.feature
  • tests/e2e/features/streaming_query.feature
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Use absolute imports for internal Python modules.
All modules must begin with descriptive docstrings explaining their purpose.
Use logger = get_logger(__name__) from log.py for module logging.
Use complete type annotations for function parameters and return types.
Use modern union syntax such as str | int; use Optional[Type] for optional values.
Use typing_extensions.Self for model validators.
Functions must use descriptive, action-oriented snake_case names such as get_, validate_, and check_.
Avoid modifying mutable parameters in place; return a new data structure instead.
Use async def for I/O operations and external API calls.
Handle APIConnectionError from Llama Stack.
All classes must have descriptive docstrings and complete type annotations for class attributes; use specific types instead of Any.
Use PascalCase for classes and descriptive standard suffixes such as Configuration, Error/Exception, Resolver, and Interface.
Use ABC and @abstractmethod for abstract interfaces.
Follow Google Python docstring conventions; document all modules, classes, and functions, including Parameters, Returns, Raises, and Attributes sections as applicable.
Never commit secrets or keys; use environment variables for sensitive data.

Files:

  • src/models/common/query.py
  • tests/unit/models/requests/test_attachment.py
src/models/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/models/**/*.py: Extend ConfigurationBase for configuration models and BaseModel for data models.
Use @model_validator and @field_validator for Pydantic model validation.

Files:

  • src/models/common/query.py
tests/unit/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

tests/unit/**/*.py: Use pytest for all unit tests; do not use unittest.
Use conftest.py for shared fixtures, pytest-mock for AsyncMock objects, and pytest.mark.asyncio for asynchronous tests.

Files:

  • tests/unit/models/requests/test_attachment.py
tests/e2e/features/**/*.feature

📄 CodeRabbit inference engine (AGENTS.md)

End-to-end scenarios must use behave’s Gherkin feature-file format.

Files:

  • tests/e2e/features/query.feature
  • tests/e2e/features/streaming_query.feature
🧠 Learnings (5)
📚 Learning: 2026-01-12T10:58:40.230Z
Learnt from: blublinsky
Repo: lightspeed-core/lightspeed-stack PR: 972
File: src/models/config.py:459-513
Timestamp: 2026-01-12T10:58:40.230Z
Learning: In lightspeed-core/lightspeed-stack, for Python files under src/models, when a user claims a fix is done but the issue persists, verify the current code state before accepting the fix. Steps: review the diff, fetch the latest changes, run relevant tests, reproduce the issue, search the codebase for lingering references to the original problem, confirm the fix is applied and not undone by subsequent commits, and validate with local checks to ensure the issue is resolved.

Applied to files:

  • src/models/common/query.py
📚 Learning: 2026-02-25T07:46:33.545Z
Learnt from: asimurka
Repo: lightspeed-core/lightspeed-stack PR: 1211
File: src/models/responses.py:8-16
Timestamp: 2026-02-25T07:46:33.545Z
Learning: In the Python codebase, requests.py should use OpenAIResponseInputTool as Tool while responses.py uses OpenAIResponseTool as Tool. This difference is intentional due to differing schemas for input vs output tools in llama-stack-api. Apply this distinction consistently to other models under src/models (e.g., ensure request-related tools use the InputTool variant and response-related tools use the ResponseTool variant). If adding new tools, choose the corresponding InputTool or Tool class based on whether the tool represents input or output, and document the rationale in code comments.

Applied to files:

  • src/models/common/query.py
📚 Learning: 2026-06-24T13:45:37.249Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 1971
File: src/utils/markdown_repair.py:31-36
Timestamp: 2026-06-24T13:45:37.249Z
Learning: In the lightspeed-stack repository, docstrings must use the section header name "Parameters:" (not "Args:") for function arguments, even if the project references Google Python docstring conventions. Ensure docstrings follow the project’s established "Parameters:" header format for any documented function parameters.

Applied to files:

  • src/models/common/query.py
  • tests/unit/models/requests/test_attachment.py
📚 Learning: 2026-07-06T15:26:18.398Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2071
File: src/models/config.py:2416-2422
Timestamp: 2026-07-06T15:26:18.398Z
Learning: In this repo’s Python code under src/**, don’t treat differences in string concatenation style as a style inconsistency when Black has effectively forced (or made clearer) use of explicit `+` string concatenation in multi-line logger/string expressions. If adjacent-literal implicit concatenation is avoided/changed specifically to accommodate Black’s formatting in these call sites, accept the `+` usage and don’t recommend converting it solely for consistency with nearby blocks that use implicit concatenation.

Applied to files:

  • src/models/common/query.py
📚 Learning: 2026-07-17T19:25:05.325Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2166
File: src/utils/saved_prompts.py:129-157
Timestamp: 2026-07-17T19:25:05.325Z
Learning: For any endpoint that handles saved prompts and calls `src/utils/saved_prompts.py::create_saved_prompt`, treat the endpoint as the validation boundary. Before calling `create_saved_prompt`, validate the incoming saved-prompt name and content, specifically using `validate_saved_prompt_name` and then persist (store) the normalized value it returns. Do not call `create_saved_prompt` with unvalidated/raw name/content.

Applied to files:

  • src/models/common/query.py
🪛 markdownlint-cli2 (0.23.0)
docs/devel_doc/query_endpoint.md

[warning] 181-181: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (8)
docs/devel_doc/query_endpoint.md (1)

181-181: Specify the fenced code-block language.

This is the same unresolved markdown-lint issue from the previous review; add text (or another suitable language) to the opening fence.

Source: Linters/SAST tools

docs/devel_doc/streaming_query_endpoint.md (1)

1-5: LGTM!

tests/e2e/features/query.feature (2)

160-182: Assert that the attachments were actually processed.

image and error are generic prompt/attachment terms; these assertions can pass when vision processing is unavailable or ignored. Assert a deterministic, attachment-specific result instead.

Also applies to: 240-268


183-239: LGTM!

Also applies to: 269-269

tests/e2e/features/streaming_query.feature (2)

149-172: Assert that the attachments were actually processed.

Stream completion is now awaited, but generic image and error fragments still allow a passing response that did not consume the supplied image.

Also applies to: 230-259


173-229: LGTM!

src/models/common/query.py (1)

100-100: LGTM!

tests/unit/models/requests/test_attachment.py (1)

109-128: LGTM!

Comment on lines +92 to +95
**Allowed `attachment_type` values:** `"alert"`, `"api object"`, `"configuration"`, `"error message"`, `"event"`, `"image"`, `"log"`, `"stack trace"`

**Allowed `content_type` values:** `"text/plain"`, `"application/json"`, `"application/yaml"`, `"application/xml"`, `"image/jpeg"`, `"image/png"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Align the documented attachment allowlists with runtime validation.

The supplied Attachment model declares attachment_type and content_type as plain str fields; its validator only checks image consistency, base64 validity, size, and magic bytes. Unless another validator enforces these lists, unsupported values are accepted despite this documentation claiming they are allowed values and return HTTP 422 when invalid. Add explicit validation or remove the allowlist/422 claims.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/devel_doc/query_endpoint.md` around lines 92 - 95, Align the attachment
documentation with actual runtime behavior: either add explicit validation for
the documented attachment_type and content_type allowlists in the Attachment
model and preserve the HTTP 422 claim, or remove the allowlist and invalid-value
422 claims if no such validation is intended. Ensure the documentation does not
promise constraints that the model does not enforce.

Comment on lines +100 to +105
Image attachments (`content_type` of `"image/jpeg"` or `"image/png"`) are handled differently from text attachments:

- `attachment_type` must be `"image"` when `content_type` is an image MIME type, and vice versa. Mismatches are rejected with HTTP 422.
- `content` must be valid base64-encoded image data. Invalid base64 is rejected with HTTP 422.
- Decoded image size must not exceed **100 MB** (104,857,600 bytes).
- Image attachments are **not** appended to the query text. Instead, they are passed as structured multimodal input to the LLM, each converted to a data URL (`data:{content_type};base64,{content}`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Document the required image signature validation.

Image content is also checked against its declared MIME type via _validate_image_magic_bytes(...) in src/models/common/query.py (Lines 42-102). State that decoded bytes must match the declared image/jpeg or image/png signature; valid base64 with the wrong file format is rejected.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/devel_doc/query_endpoint.md` around lines 100 - 105, Update the image
attachment documentation near the existing base64 and MIME-type rules to state
that decoded bytes must match the declared image/jpeg or image/png file
signature, as validated by _validate_image_magic_bytes. Specify that valid
base64 with a mismatched file format is rejected with HTTP 422.

Comment on lines +179 to +183
`POST /v1/streaming_query` returns an SSE stream. Each event is a line of the form:

```
data: {"event": "<event_type>", "data": {<payload>}}
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Make the SSE envelope consistent with the end event examples.

The generic format says all payload is inside data, but both end examples place available_quotas at the top level. Update the schema description or move available_quotas into data so clients have one unambiguous event shape.

Also applies to: 243-258, 503-503

🧰 Tools
🪛 markdownlint-cli2 (0.23.0)

[warning] 181-181: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/devel_doc/query_endpoint.md` around lines 179 - 183, Make the
streaming_query SSE envelope consistent across the generic schema and both
end-event examples: either place available_quotas inside the end event’s data
object or update the schema description to explicitly allow it at the top level,
and apply the same shape to the additional referenced examples.

Comment on lines +18 to +20
_IMAGE_SIGNATURES: dict[str, bytes] = {
"image/png": b"\x89PNG",
"image/jpeg": b"\xff\xd8\xff",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use PNG’s complete eight-byte signature.

b"\x89PNG" accepts payloads such as b"\x89PNGnot-an-image". Require b"\x89PNG\r\n\x1a\n" and update the existing PNG test fixture accordingly.

Proposed fix
-    "image/png": b"\x89PNG",
+    "image/png": b"\x89PNG\r\n\x1a\n",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_IMAGE_SIGNATURES: dict[str, bytes] = {
"image/png": b"\x89PNG",
"image/jpeg": b"\xff\xd8\xff",
_IMAGE_SIGNATURES: dict[str, bytes] = {
"image/png": b"\x89PNG\r\n\x1a\n",
"image/jpeg": b"\xff\xd8\xff",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/models/common/query.py` around lines 18 - 20, Update the PNG entry in
_IMAGE_SIGNATURES to use the complete eight-byte PNG signature
b"\x89PNG\r\n\x1a\n" instead of the four-byte prefix, and adjust the existing
PNG test fixture to include the complete signature while preserving the JPEG
behavior.

@JslYoon
JslYoon requested a review from radofuchs July 23, 2026 19:00

@radofuchs radofuchs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@asimurka asimurka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants