Skip to content

fix(model): report malformed GGUF and Safetensors headers as invalid_format through ParseFailure - #10667

Merged
morluto merged 2 commits into
mainfrom
refactor/model-parse-failure
Nov 14, 2026
Merged

morluto merged 2 commits into
mainfrom
refactor/model-parse-failure

Conversation

@morluto

@morluto morluto commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

GGUF and Safetensors header parsing now reports failures through the shared ParseFailure algebra (format model). ModelFormatFailure, its format | unsupported | capacity kinds, and the TypeError guards that checked its constructor arguments are deleted.

  • Capacity refusals are ParseFailure limits. The limit name is the existing ModelCapacityLimit and the maximum is the producing allowance.
  • User-visible change: malformed and truncated model headers move from target_unavailable / unsupported_target (BinaryTargetError, constraint file_format_rejected) to invalid_request / invalid_input with issue { path: ["path"], reason: "invalid_format" }, through the shared parseFailureAnalysisError mapping. This follows the maintainer decision (2026-11-14) that approved admission and error-category changes, matching fix(gpu): report malformed GPU containers as invalid_format #10644 for GPU containers.
  • parser-json-parse drops by 2 for src/model/ModelFormat.ts.

#10652 (which added the guard) is merged; this branch is rebased on main. Sibling of #10664 and #10665. Part of plan W7 (parser kernel).

Problem and expected behavior

ModelFormatFailure restated the ParseFailure algebra with its own spellings: format for malformed and capacity for limit. A second field, limit, was valid only for one kind and was checked at runtime with plain TypeError throws.

Expected:

  • One algebra.
  • The kind and the limit name are carried in the typed failure, so they need no runtime check.
  • The provider reads the limit back through modelCapacityLimitOf.

Change and scope

  • src/model/ModelFormat.ts:
    • Adds MODEL_FORMAT.
    • modelCapacityFailure(limit, detail) builds the limit failure. Its maximum comes from modelCapacityReportedLimits, so the value has one owner.
    • modelCapacityLimitOf recovers the ModelCapacityLimit from a failure.
    • rejectModel and rejectPickle throw malformedInput and unsupportedInput.
  • GgufHeader.ts, SafetensorsHeader.ts, ModelHeaderReader.ts and ModelArtifactProvider.ts throw through those helpers.
  • ModelArtifactProvider.ts:
    • a model allowance (modelCapacityLimitOf) → resource_constraint with the same reported limits and recovery;
    • every other format failure → parseFailureAnalysisError: malformed/truncated → invalid_format on path; unsupported (PyTorch pickle) → unsupported_target, unchanged.
  • docs/model-artifacts.md states the new category.

Not included:

  • Any other provider's category. Other file_format_rejected producers are unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the model header parsers produce the failure. ModelArtifactProvider remains the one translation.

  • Contribution scope fit and linked maintainer decision: maintainer decision 2026-11-14 approved error-category changes where needed (malformed → invalid_format).

  • CLI and MCP/tool-catalog contract: malformed/truncated model headers change public code and category as above (CLI exit code stays 1). Unsupported and capacity refusals, their messages, reported limits and recovery are unchanged. Tool schemas unchanged.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: none.

  • Target selection, authority, upstream behavior, and cleanup details: partial-progress handling is unchanged.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests updated: tests/boundary/model/modelArtifact.test.ts (malformed cases assert AnalysisInputError with invalid_format on path; the header-allowance case asserts failure: { kind: "limit", format: "model", limit: { name: "header-bytes", maximum: 100_000_000 } }) and tests/acceptance/modelArtifactCli.test.ts (CLI and MCP malformed refusals).
  • User-visible CLI/MCP output, MCP inspect_model_artifact on a Safetensors file whose data offsets are outside the file:
    {"code":"invalid_request","category":"invalid_input","details":{"operation":"inspect_model_artifact","issues":[{"path":["path"],"reason":"invalid_format","message":"Selected artifact <path>: Declared extent is outside the file"}]}}
    (shape asserted by the acceptance test; before: {"code":"target_unavailable","category":"unsupported_target","details":{"constraint":"file_format_rejected", ...}}).
  • Remaining proof gaps: none known.

Validation performed

  • Earlier revision: npm run test:focused -- tests/boundary/model/modelArtifact.test.ts tests/acceptance/modelArtifactCli.test.ts tests/boundary/mcp/modelArtifactPartialReadFailure.test.ts tests/boundary/model/modelArtifactPartialCancellation.test.ts tests/process-global/modelHostReadFailure.test.ts tests/acceptance/formatSpecificCallerPathCli.test.ts: 6 files, 172 tests passed.
  • Category change: npm run test:focused -- tests/boundary/model/modelArtifact.test.ts (143 passed) and npm run test:focused -- tests/acceptance/modelArtifactCli.test.ts (16 passed); npm run docs:check passed; node scripts/verify/architecture-guards.mjs passed.
  • node scripts/verify/architecture-guards.mjs --shrink-baselines: passed and lowered both baselines.
  • npm run check:fast: typecheck and lint passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: callers matching target_unavailable / file_format_rejected for malformed model headers now see invalid_request / invalid_format. Approved category change; not marked breaking, consistent with fix(gpu): report malformed GPU containers as invalid_format #10644. ModelFormatFailure was internal.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no change.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-14T20:28:48.249123Z
We couldn’t complete this review. Comment @codex review to try again.
33b1da4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Base automatically changed from refactor/rust-auditable-parse-failure to main November 14, 2026 20:28
@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no actionable failures were found.

Summary

Replaces ModelFormatFailure with ParseFailureError for GGUF and Safetensors headers.

  • Model headers report failures through the shared parse-failure format.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[GGUF and Safetensors parsers] --> B[ParseFailureError]
  B --> C[ModelArtifactProvider]
  C --> D[Malformed: file_format_rejected]
  C --> E[Unsupported: unsupported_target]
  C --> F[Known model limit: resource_constraint]
Loading

Reviews (1) · Last reviewed commit: "refactor(model): report GGUF and Safeten..." · Reviewed by Greptile

…the shared mapping

Malformed and truncated GGUF and Safetensors headers now take the shared ParseFailure mapping (invalid_request, invalid_format on path) instead of the model provider's own BinaryTargetError file_format_rejected. Unsupported forms stay unsupported_target and model allowances keep their resource-constraint recovery.
@morluto
morluto force-pushed the refactor/model-parse-failure branch from 33b1da4 to baacee6 Compare November 14, 2026 20:33
@morluto morluto changed the title refactor(model): report GGUF and Safetensors format failures through ParseFailure fix(model): report malformed GGUF and Safetensors headers as invalid_format through ParseFailure Nov 14, 2026
@morluto
morluto merged commit a22fb6e into main Nov 14, 2026
51 of 53 checks passed
@morluto
morluto deleted the refactor/model-parse-failure branch November 14, 2026 23:59
@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant