Skip to content

feat(model): inspect GGUF and safetensors declarations - #5603

Merged
gensokyo-dev merged 9 commits into
mainfrom
feat/3323-model-artifacts
Oct 20, 2026
Merged

gensokyo-dev merged 9 commits into
mainfrom
feat/3323-model-artifacts

Conversation

@gensokyo-dev

@gensokyo-dev gensokyo-dev commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #3323.

Problem and outcome

Bundled model files previously reached an unsupported-binary result. inspect_model_artifact / inspect-model-artifact now exposes GGUF v2/v3 (both byte orders) and safetensors declarations through one local workflow: typed metadata, tensor identity/shape/type/ranges, and explicitly derived element/storage totals.

Default hash: "header" reads only the header/directory. It returns a scoped header digest, exact path/extent and bytes read; full-file SHA-256 and the Evidence subject remain null. Explicit hash: "full" streams every file byte for full SHA-256 without interpreting weights. Metadata arrays retain typed counts and eight-element previews with omissions recorded; scalar values, integer widths and negative zero survive JSON delivery.

Optional view returns selected rows plus model context in the initial call. Retained model-artifact views support batched names/keys/types/indices, fields, storage-validation states and pagination. Complete Evidence remains accessible. Unknown types keep their identity; declared ranges and unknown storage-size validation stay separate. Historical pages use validated positional indexes and unique names/keys/types, cached with immutable parent facts; they never reopen the file. Only the source-scoped index is mandatory: long labels obey field selection. Bounded view warnings link to complete parent Evidence.

Boundary and scope

The format readers own interpretation; application services own Evidence and delivery; CLI/MCP share both. One admitted descriptor/inspection, bounded prefix reads, a 100,000,000-byte GGUF prefix/safetensors JSON ceiling (excluding its 8-byte length field) and separate 32 MiB retained representation budget constrain work before expansion. File replacement/truncation, cancellation and failed-close ownership use existing filesystem/resource primitives. The EOF follow-up distinguishes concurrent truncation from initially malformed declarations.

This is built-in static format inspection within the supported contribution scope. Inspection reads existing local files. CLI compact delivery and explicit Evidence export create caller-selected output files through existing atomic publication. Model execution, target attachment, inference, external-file traversal and runtime network access are outside the operation; no new runtime dependency or installer behavior.

Executed validation

  • Final integration 62b640a60, tree 9a5a4d7a9, main 5b676ba9f: 54 reader tests + 5 public model CLI/MCP workflows passed. check:ci 8 tasks + architecture guards across 1,665 files passed, duplication 3.47%; generated docs and 5 README tests passed. No new test files; prior discovery found every test exactly once.
  • Shared-workflow coverage: 190 tests / 6 files passed at 85568378c, following 214 / 9 on the earlier main integration. After newer main, 21 generic MCP cases + 5 model workflows passed in isolation. One preceding constrained attempt hit two generic 30 s timeouts; deadlines were unchanged. New-main Apple producers passed 31 tests. Its evaluation helper suite passed 7 cases and failed one 1 s preparation deadline; the helper, test and process/filesystem/artifact dependencies are identical to main, with no model path involved. That single case then passed in isolation without changing deadlines. Failed attempts are retained; these are scoped passes, not a green full-suite claim.
  • Actual stdio SDK catalogs and replies validate through Ajv2020. Covered endian/quantized/scalar/empty/packed declarations, malformed headers/UTF-8/duplicate JSON keys, unsafe extents and preallocation, sparse 1 GiB input, overlaps/gaps, unknown storage, field/empty/batched selections, source removal, authenticated imported identities, Evidence portability, cancellation and failed-close retention/retry. Long unselected labels and warnings remain below 16 KB in the regression; full parent Evidence preserves source values.
  • Pre-fix regressions: two real truncation cases fail at 4f004f392; fourteen format cases, two imported/oversized-response MCP cases and two empty-GGUF cases fail at 49b016d1b. Independent official GGUFReader accepts five empty/quantized-empty/scalar declarations in each byte order; the old actual CLI refused them and the corrected CLI agrees on every shape/count/byte length.
  • Three real public models: all 161 tensors and 40 metadata entries match official gguf 0.19.0 / safetensors 0.8.0 readers, including ranges, shapes, types, element counts and scalar/array previews. Header/full scopes and independent whole-file SHA-256 pass. Final valid results exactly match their corresponding earlier header/full baselines. One verifier comparison initially mixed header/full limitations; the corrected corresponding-mode oracle passes, and the failed attempt is retained. No model was executed.

Pinned samples: stories15M Q4_0 (19,077,344 B, header 727,132 B, SHA-256 66967fbece6d…); stories260K big-endian (1,185,376 B, header 14,152 B, 276d6f9d9050…); MiniLM L3 (69,569,488 B, header 6,096 B, cf1e4e2d420c…). Reference packages and binaries stayed outside the repository.

Completed-task measurements and limits

Caller supplies two tensor names. Both strategies return the same format, scoped identity, selected metadata, declared totals and tensor facts, and export complete Evidence. 62b640a60, Linux / Node 24.18.0, fresh MCP processes; all steps include SDK, catalog/AJV, parsing, projection, serialization, token instrumentation, export and teardown.

Tokenx estimates count arguments and complete replies plus either used-tool input declarations or every input declaration. Wire estimates additionally count catalog output schemas, initialization and other messages. These are not actual model tokens or successful-agent/tool-selection measurements. Whole catalog cost remains visible.

Sample Delivery RPCs Used declarations + calls, tokens All input declarations + calls, tokens Whole wire, tokens Wall s Family CPU s Peak family RSS GiB
gguf complete 2 20,684 264,181 1,072,515 7.224 6.801 0.660
gguf direct 2 4,861 248,358 1,056,694 7.221 6.801 0.658
safetensors complete 2 18,877 262,374 1,070,708 7.772 7.475 0.662
safetensors direct 2 4,272 247,769 1,056,105 7.788 7.542 0.661
small complete 2 4,675 248,172 1,056,506 7.396 7.083 0.661
small direct 2 4,543 248,040 1,056,376 6.807 6.771 0.663

Historical measurements at 4f004f392 also covered both execution orders and all three samples; they are not cross-revision speed comparisons. The four-call summary-plus-generic-queries route took 7.13–7.55 s / 8.78–9.33 family CPU s / 0.89–0.93 GiB; direct selection used two calls. Complete versus direct cold timings were similar on real samples; tiny input had fixed-cost variance, so no universal speedup is claimed. Twelve historical GGUF probes per strategy gave 20.49 ms median for full tensor pages and 9.40 ms for selected pages; the first generic-query use took 1.79/1.62 s and is included in those probe sets, not presented as steady warm latency. No source was reopened for these probes.

Two-CPU affinity, 3 GiB V8 heaps and an 8 GiB process-family guard; all six final paired measurements passed first attempt without OOM or guard stops. Family RSS was sampled every 20 ms and can double-count shared pages or miss brief peaks. OS caches/host load, token-instrumentation overhead and engine-only costs were not isolated. There was no prior REA model-reader implementation; these compare equivalent delivery strategies. The small sample is authored, not real-model coverage.

Limits: Linux public workflows were executed; Windows/macOS were not. Storage sizes are derived from pinned ggml layouts or checked against safetensors declarations; runtime compatibility, weight values, model quality and effective/tied parameter counts are unverified. Array previews do not expose a complete vocabulary. Read guards detect observed filesystem changes, not adversarial changes that evade filesystem metadata. Generated catalogs/skills and all models remain ignored build/verification artifacts.

Author readiness

Human owner: @gensokyo-dev

The owner explicitly authorized the work, delegated technical review/validation to Codex and directed these declarations and ready submission. This records that instruction; it does not assert an independent human review.

  • 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; static format reading requires no execution/protection-recovery scope decision.
  • One focused outcome, Conventional Commit title and linked issue.
  • Tests cover changed behavior and meaningful failures; owning contracts, docs and generated metadata are current.
  • Final diff checked for credentials, unrelated changes and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T16:47:02.419800Z 62b640a Manual request
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49b016d1b8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/model/GgufHeader.ts Resolved
Comment thread src/model/ModelHeaderReader.ts Resolved
Comment thread src/model/GgufHeader.ts Resolved
@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking issue was found.

Summary

Adds local GGUF and safetensors declaration inspection through CLI and MCP.

  • Model files reveal their declared tensors and metadata.
  • Callers can choose a summary, a page, or complete model Evidence.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[CLI or MCP] --> B[ModelArtifactService]
  B --> C[ModelArtifactProvider]
  C --> D[GGUF or safetensors header reader]
  D --> E[Complete Evidence]
  E --> F[Complete delivery or export]
  E --> G[Retained summary or selected page]
  G --> H[Historical queries without reopening source]
Loading

Reviews (3) · Last reviewed commit: "chore: qualify model inspection with cur..." · Reviewed by Greptile

@gensokyo-dev

Copy link
Copy Markdown
Collaborator Author

@codex review

All five initial findings are addressed in a15c1af / 8556837; b8ae48f refreshes main and matches the pinned prospective merge tree. Please re-review the format boundary and retained-view identity/message fixes. Current validation and its scope are in the PR body; final integrated checks are running.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8ae48f89f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/model/GgufHeader.ts Resolved
@gensokyo-dev

Copy link
Copy Markdown
Collaborator Author

@codex review

097771f addresses the empty-GGUF finding at the reader boundary (zero extents and rank-zero scalars; original rank/block constraints retained), and closes the related compact-headline leak. 62b640a refreshes main and matches the pinned prospective merge tree. Reader54 and public model5 tests pass; final integrated gates and renewed real-model measurements are running. Please review the final diff for remaining actionable issues.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 62b640a605

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@gensokyo-dev
gensokyo-dev merged commit 98f4072 into main Oct 20, 2026
7 of 11 checks passed
@gensokyo-dev
gensokyo-dev deleted the feat/3323-model-artifacts branch October 20, 2026 16:50
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
3 tasks done
kangyishuai pushed a commit to kangyishuai/rea that referenced this pull request Oct 20, 2026
…ansition-view

Resolve the inspect_analysis_view description conflict with main's model
artifact view (morluto#5603). The description keeps main's text, including
inspect_model_artifact, and adds this branch's capture_browser_scenario
additions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto morluto added area: domain Domain logic, errors, and pure functions enhancement New feature or request labels Nov 23, 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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Inspect GGUF and safetensors model files without loading them

2 participants