Skip to content

Comments

Increase server robustness on invalid underlying data#668

Merged
jviotti merged 1 commit intomainfrom
robust-handling
Feb 24, 2026
Merged

Increase server robustness on invalid underlying data#668
jviotti merged 1 commit intomainfrom
robust-handling

Conversation

@jviotti
Copy link
Member

@jviotti jviotti commented Feb 24, 2026

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

@augmentcode
Copy link

augmentcode bot commented Feb 24, 2026

🤖 Augment PR Summary

Summary: Makes server actions fail with runtime errors (instead of debug-only asserts) when metapack/schema inputs are missing or malformed.

Key changes:

  • JSON Schema evaluate/trace: replace several precondition checks with std::runtime_error.
  • Schema search: throw on missing/unreadable search index rather than asserting.
  • Metapack reader: validate required metadata fields/types and throw on unknown encodings.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

// TODO: Cache this across runs?
const auto locations{sourcemeta::one::read_json(locations_path)};
assert(locations.defines("static"));
if (!locations.defines("static")) {
Copy link

Choose a reason for hiding this comment

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

sourcemeta::core::JSON::defines() asserts is_object(), so if locations isn’t an object this can still assert/UB (especially in release builds where assert is compiled out). If the goal is robustness on invalid data, consider guarding locations.is_object() (or using try_at) before calling defines/at.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

const auto base_dialect_result{sourcemeta::core::to_base_dialect(
current_location.at("baseDialect").to_string())};
assert(base_dialect_result.has_value());
if (!base_dialect_result.has_value()) {
Copy link

Choose a reason for hiding this comment

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

This has_value() check won’t help if malformed current_location causes current_location.at("baseDialect") (and later at("dialect")) to assert/UB before to_base_dialect() is called. If these fields can be missing/invalid, consider validating presence/type without at() first.

Severity: high

Other Locations
  • src/server/action_jsonschema_evaluate.h:103

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

static auto search(const std::filesystem::path &search_index,
const std::string_view query) -> sourcemeta::core::JSON {
assert(std::filesystem::exists(search_index));
if (!std::filesystem::exists(search_index)) {
Copy link

Choose a reason for hiding this comment

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

If this PR’s intent is to avoid debug-only enforcement, note the remaining assert(search_index.is_absolute()) below will be a no-op in release builds (potentially allowing unexpected relative paths). Consider making that invariant a runtime check too.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 3 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/server/action_schema_search.h">

<violation number="1" location="src/server/action_schema_search.h:25">
P2: The new runtime_error thrown here is uncaught in action_schema_search, so it falls back to dispatch’s generic handler and returns HTTP 405 "method-not-allowed" for missing/failed search indexes. That status is misleading for an internal/index error; handle the error locally and return an appropriate 404/500 response instead.</violation>
</file>

<file name="src/server/action_jsonschema_evaluate.h">

<violation number="1" location="src/server/action_jsonschema_evaluate.h:36">
P1: `JSON::defines()` internally asserts `is_object()`, so if the parsed `locations` value is not a JSON object (e.g., malformed file), this will still assert/UB before the `defines("static")` check can throw. Add a `locations.is_object()` guard before calling `defines()` to fully cover the robustness goal.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti jviotti merged commit 6b961ac into main Feb 24, 2026
8 of 9 checks passed
@jviotti jviotti deleted the robust-handling branch February 24, 2026 20:18
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