Skip to content

feat: add experimental on-demand pinning - #11252

Open
ihlec wants to merge 22 commits into
ipfs:masterfrom
ihlec:master
Open

feat: add experimental on-demand pinning#11252
ihlec wants to merge 22 commits into
ipfs:masterfrom
ihlec:master

Conversation

@ihlec

@ihlec ihlec commented Mar 26, 2026

Copy link
Copy Markdown

Summary

Automatically pin content when DHT provider counts fall below a configurable replication target, and unpin once
replication has been above target for a grace period.

Helps keeping critical data around, without wasting storage on overly replicated CIDs.

The feature is described in this draft: ipfs/specs#532
The feature is gated behind Experimental.OnDemandPinningEnabled.

CLI commands for ipfs pin ondemand:

  • add -- register CIDs for on-demand pinning
  • rm -- deregister and unpin
  • ls -- list registered CIDs

Design

  • Pin partitioning: the checker needs to distinguish its pins from user
    pins to avoid accidental deletion. This implementation uses boxo's pin name
    field ("on-demand") for that.
  • Storage budget: skips pinning when repo usage exceeds
    StorageMax * StorageGCWatermark.
  • Idle timeout: DAG fetches timeout after 2 minutes
    without receiving new blocks (allows large downloads while skipping dead records).
  • Provide after pin: the checker publishes a DHT provider record after pinning.
  • Sybil limitation: provider counts come from DHT queries, which are
    susceptible to Sybil manipulation. Documented as a known limitation.

Configuration Parameters (TBD)

Option Default Description
OnDemandPinning.ReplicationTarget 5 Minimum providers in DHT (excluding self)
OnDemandPinning.CheckInterval "10m" How often the checker runs
OnDemandPinning.UnpinGracePeriod "24h" How long above target before unpinning

Tests

Unit tests for the checker and store in ondemandpin/.

Visualization of Feature

(out of scope for this CLI PR, but helpful to get the idea)
UI-flow

@ihlec
ihlec requested a review from a team as a code owner March 26, 2026 11:06
@ihlec
ihlec force-pushed the master branch 2 times, most recently from 48a25c8 to 8802724 Compare March 31, 2026 11:29
@ihlec

ihlec commented Mar 31, 2026

Copy link
Copy Markdown
Author

Please focus the review on:

1. Core logic — ondemandpin/

  • ondemandpin/store.go (143 lines) — Datastore with CRUD to manage on-demand pinning CIDs.
  • ondemandpin/checker.go (282 lines) — Frequently queries the DHT for provider counts and pins/unpins accordingly.

2. Kubo integration — wiring and CLI

  • core/node/ondemandpin.go (168 lines) — translates Kubo's pinning system into a simple interface for checker.go.
  • core/commands/pin/ondemandpin.go (280 lines) — Standard cmds boilerplate for on-demand pinning.

*The rest of the files are configuration, glue code, and documentation.

@guillaumemichel guillaumemichel mentioned this pull request Mar 31, 2026
40 tasks
@ihlec

ihlec commented Apr 1, 2026

Copy link
Copy Markdown
Author

@guillaumemichel Please re-run the checks. I addressed the failing ones for overfull lines , typos, and changelog.

Comment thread core/commands/pin/ondemandpin.go Outdated
@lidel

lidel commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Triage note: we run out of time to review this in 0.41 iteration, but we've added it to 0.42. Thank you for your contribution and patience. 🙏

@lidel lidel added the need/maintainers-input Needs input from the current maintainer(s) label Apr 10, 2026
@gammazero gammazero added exp/expert Having worked on the specific codebase is important status/blocked Unable to be worked further until needs are met labels May 12, 2026
@gammazero

Copy link
Copy Markdown
Contributor

Triage: need careful review and testing.

@lidel lidel mentioned this pull request May 25, 2026
59 tasks
@lidel

lidel commented May 25, 2026

Copy link
Copy Markdown
Contributor

Triage: short on review bandwidth for v0.42, so we'd like to land this in v0.43 instead. I've rebased on latest master and moved the changelog entry to docs/changelogs/v0.43.md. Nothing for you to do; we'll continue review against v0.43 once the time comes.

@ihlec

ihlec commented Jul 10, 2026

Copy link
Copy Markdown
Author

Hi @lidel , just checking in on this. Please let me know if there’s any additional documentation, context, or testing steps I can provide to help ease the review.

@lidel lidel 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.

Thanks for waiting @ihlec. This deserved a real review a lot sooner than it got one.

Being straight with you: maintainer time on Kubo is a small shared budget this quarter, and this is a lot of code. A new package, new config, new commands, and a loop that pins and unpins on its own. That is not something I can skim, and a feature that deletes pins by itself really shouldn't be skimmed. I kept not finding the hours, and the release ran out first.

So I'm moving it to draft and off v0.43. That is not a rejection. I believe the idea is good and could be added to future Kubo, but pin ownership, the pin and unpin loop, and the name all need a decision before more code goes in. The inline comments say where I would take each one to be less brittle and respect user config. Feel free to push back on any of it, this is a first-pass set of comments, possible I misunderstood something.

Comment thread core/commands/pin/ondemandpin.go Outdated
Comment thread ondemandpin/checker.go Outdated
Comment thread config/ondemandpin.go Outdated
Comment thread ondemandpin/checker.go
Comment thread ondemandpin/checker.go Outdated
Comment thread ondemandpin/store.go
Comment thread core/commands/pin/ondemandpin.go
Comment thread core/commands/pin/ondemandpin.go Outdated
Comment thread config/ondemandpin.go
Comment thread ondemandpin/checker.go Outdated
@lidel
lidel marked this pull request as draft July 14, 2026 13:15
ihlec and others added 12 commits July 22, 2026 08:58
Add a background checker that automatically pins content when DHT provider counts fall below a configurable replication target and unpins once enough providers exist again after a grace period.

Gated behind Experimental.OnDemandPinningEnabled.
New CLI commands: ipfs pin ondemand {add,rm,ls}

Safety measures:
- storage budget check (respects StorageMax/GCWatermark)
- idle timeout on recursive DAG fetches (2 min without progress)
- pin partitioning via pin name to distinguish on-demand pins from persitent pins.
On-demand pinning is not landing in v0.43. Review is open and the design
needs changes first, so park the highlight in vFUTURE.md and restore
v0.43.md to the upstream skeleton.
@ihlec
ihlec marked this pull request as ready for review July 22, 2026 07:17
Comment thread core/commands/pin/ondemandpin.go Outdated
Comment thread ondemandpin/store.go
ihlec and others added 3 commits August 4, 2026 08:57
checkAll looked up CIDs one by one and blocked the sweep on Pin, so a
slow fetch delayed every other CID. Successful checks also cleared
NextCheckAt, so stable CIDs were DHT-queried again every CheckInterval.

Run due checks concurrently, set NextCheckAt from the outcome so
deadband/grace CIDs wait longer, and stop FindProviders once the
decision is known. Enqueue no longer drops when busy.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ihlec

ihlec commented Aug 4, 2026

Copy link
Copy Markdown
Author

Hi @lidel, I pushed the CI fixes.

@lidel
lidel marked this pull request as draft August 4, 2026 14:25
Comment thread ondemandpin/checker_test.go Outdated
Resolves fakeClock error in unit test (format mismatch)
@ihlec
ihlec marked this pull request as ready for review August 4, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exp/expert Having worked on the specific codebase is important need/maintainers-input Needs input from the current maintainer(s) status/blocked Unable to be worked further until needs are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants