Skip to content

fix(node): fail pin_git_object when the add response carries no Hash - #453

Closed
beardthelion wants to merge 3 commits into
Twigpine:mainfrom
beardthelion:fix/node-add-response-missing-hash
Closed

beardthelion wants to merge 3 commits into
Twigpine:mainfrom
beardthelion:fix/node-add-response-missing-hash

Conversation

@beardthelion

@beardthelion beardthelion commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A 200 from /api/v0/add with no parseable Hash no longer counts as a successful pin. The old fallback returned the locally computed raw CID, an address the backend never confirmed stored; above the chunk threshold that CID is not even a stored block, so every later cat on it failed permanently.

Motivation & context

pin_git_object took the last NDJSON line carrying a Hash and fell back to Cid::from_git_object_bytes(data) when none did. The add goes out with raw-leaves=true, so on Kubo a payload over 262144 bytes lands chunked under a dag-pb root and the whole-object raw CID is never a stored block. The fabricated CID landed in encrypted_blobs.cid, so get_encrypted_blob failed on every fetch of an affected envelope and mirrors retried it on each sync.

Closes #452

Kind of change

  • Bug fix
  • Feature
  • Security fix
  • Docs
  • Tests / CI
  • Refactor (no behavior change)
  • Breaking or protocol change (issue required first)

What changed

  • pin_git_object (gitlawb-node) errors on a 200 add response without a usable Hash, carrying a truncated body excerpt. The returned Hash stays authoritative and is not compared against the locally computed raw CID, since above-threshold adds legitimately return the dag-pb root.
  • The delaying_endpoint test fixture now returns a conformant NDJSON add response. It had been relying on the fallback by answering 200 with an empty body, so six budget/timing tests were unknowingly passing through the bug.
  • New regression test pin_git_object_rejects_a_200_without_a_hash.

How a reviewer can verify

DATABASE_URL=postgresql://gitlawb:changeme@localhost:5432/gitlawb \
  cargo test -p gitlawb-node --bin gitlawb-node ipfs_pin

The new test fails on main: pin_git_object returns Ok(<fabricated CID>) for a 200 carrying {"Name":"object","Size":"19"}. Against live Kubo v0.43.0, a 262145-byte add returns the dag-pb root as Hash while the whole-object raw CID 500s on cat, which is the failure mode the fallback hid.

Before you request review

  • Scope is one logical change; no unrelated churn
  • cargo test -p gitlawb-node passes locally (the workspace suite runs in CI via pr-checks.yml)
  • New behavior is covered by tests (required for fixes)
  • cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings are clean
  • Commit titles use Conventional Commits (feat(...), fix(...), docs(...))
  • Docs / .env.example updated if behavior or config changed (or N/A)
  • Checked existing PRs so this isn't a duplicate

Notes for reviewers

Open PRs touching ipfs_pin.rs (#382, #407, #408) all modify the pin-set selection and read-bounding paths, not the add-response parser, so no semantic overlap. If #452's direction is wrong and a Hash-less 200 is meant to be a supported shape, this should instead pin down what the parser is allowed to accept.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation of successful pinning responses.
    • Pinning now reports an error when the service returns a missing, unusable, or malformed content identifier.
    • Invalid identifiers returned by the pinning service are no longer replaced with a caller-computed identifier.
    • Error handling now more reliably distinguishes invalid pinning responses from successful operations, preventing malformed content identifiers from being accepted as successful pins.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crate:node gitlawb-node — the serving node and REST API kind:bug Defect fix — wrong or unsafe behavior subsystem:storage Blob/object store, Arweave, IPFS, archives

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pin_git_object records a fabricated CID when /api/v0/add returns no Hash

3 participants