Repository navigation
Resilience


Status: endpoint registry, failover, shape-based extraction and timeouts are built (M1). The Hunter and
healthare planned (M4, #5).
Pinterest has no public search API, and the web resources it does serve change without notice. botticelli plans for that. Each capability has an ordered list of ways to call it (Candidates). When the first fails, the next is tried, and the one that worked is remembered on disk. Pins are found by their shape, not by a fixed path, so small changes to the JSON do not break parsing. When every Candidate fails, a Hunter (planned) will look at how the real site does it now.
An Endpoint registry maps each Capability to an ordered list of Candidates.
src/sources/pinterest/endpoints.default.json holds the defaults:
| Capability | Candidates, in order |
|---|---|
search |
BaseSearchResource |
related |
RelatedPinFeedResource, then RelatedModulesResource
|
pin |
PinResource |
board_info |
BoardResource |
board |
BoardFeedResource |
RelatedPinFeedResource works logged out. RelatedModulesResource needs a login (measured 2026-12-02), so it is a fallback for a logged-in session.
A Candidate is one way to call a Capability:
{
"resource": "RelatedPinFeedResource",
"handler": "www/pin/[id].js",
"sourceUrl": "/pin/{pin}/",
"options": { "pin": "{pin}", "field_set_key": "unauth_react", "source": "unknown", "top_level_source": "unknown", "top_level_source_depth": 1 }
}| Field | Role |
|---|---|
resource |
The resource name in the URL: /resource/<resource>/get/
|
handler |
Sent as the X-Pinterest-PWS-Handler header |
sourceUrl |
The source_url query value. May hold placeholders |
options |
The options object in the data query value. May hold placeholders |
Placeholders are {name} inside any string, including nested values. They are filled from the call's variables. A placeholder with no variable stays as written.
| Placeholder | Filled with | Used by |
|---|---|---|
{query} |
The search text | search |
{query_uri} |
The search text, URL-encoded | search |
{pin} |
The numeric pin id |
related, pin
|
{username}, {slug}
|
Parts of the board URL | board_info |
{board_path} |
/<user>/<board>/ |
board_info, board
|
{board_id} |
The id returned by board_info
|
board |
-
candidates(capability)returns learned Candidates first, then the defaults, with no duplicates (a Candidate is the same when resource, handler, sourceUrl and options are all equal). - When a Candidate succeeds after an earlier one failed in the same call, it is promoted: it moves to the front and the registry is written to disk.
- File:
BOTTICELLI_ENDPOINTS_FILE, else~/.config/botticelli/endpoints.json. The folder is created if missing. - The file is a JSON object from Capability name to an array of Candidates. Entries with a bad shape are ignored. An unreadable file counts as empty.
- The file is read once when the Pinterest source is created. A running process does not re-read it.
-
promotenever throws. If it cannot write, it prints[botticelli] could not save endpoint registry to <file>: <reason>to stderr and carries on.
To fix a broken endpoint yourself, add a Candidate. See CONTRIBUTING.md.
These rules are in call() in src/sources/pinterest/pinterest.ts and are tested in test/pinterest/failover.test.ts.
-
Network errors never fail over. A
NetworkError(DNS, TCP, TLS, timeout, a stalled or cut body) ends the call at once. Another endpoint cannot fix your connection. -
Only a
SourceErrorfails over. That is an HTTP error status, a resource-level error in the JSON, or a body that is not JSON. - Only the first page fails over. A bookmark belongs to the resource that issued it. A call that carries a bookmark tries the first Candidate only.
-
A cursor pins the call to the first Candidate. A cursor with no bookmark (
{skip: N}) counts refs of the first Candidate's page, so another Candidate would give a different list. With any cursor, only the first Candidate is tried. - Promotion needs a failure first. Success on the first Candidate changes nothing.
-
The error says what was tried. It reads
Pinterest <capability> failed on every known endpoint: <each message>, or…on the endpoint that issued the cursor: …for rules 3 and 4. It carries the last HTTP status.
Before failover, the transport retries 429 and 5xx answers twice, waiting 1 s then 2 s. Image and video downloads retry once.
extractRefs walks the whole JSON body and treats any object as a pin when it has an id, a type that is absent or "pin", and at least one image under images whose URL is on https://*.pinimg.com/. It does not care which wrapper key held it (results, data, modules). The walk stops at depth 40.
- Promoted pins (ads) are dropped.
- Typed objects that are not pins (stories, boards, users) are skipped, and their inner pins are not results.
- The best image is the first of
orig,736x,564x,474x,236x. With none of those, it takes the widest rendition that has a usable URL. - The extractor also returns
raw, the count of items on the page, even those skipped. Paging stops onraw, not on how many Refs survived, so a page made only of ads does not look like the end of the feed. - Videos: it prefers a 720p MP4 and derives a single-file rendition from an HLS URL when it can.
- Long hashtag walls in descriptions are cut to the prose plus the first five tags.
Pinterest sometimes ignores the bookmark and replays page one marked -end-. The pager handles it:
- A page that adds nothing new is retried, up to 3 times, waiting 300 ms, 600 ms, 900 ms. Without a bookmark the session cookie is cleared first, because a degraded session keeps serving the same short feed.
- On a first call, an early
-end-is retried when the board's pin count says more should exist. - One call reads at most 12 pages.
| What | Value |
|---|---|
| Wait for response headers | 20 000 ms, or BOTTICELLI_TIMEOUT_MS
|
| Silence between body chunks | The same value. A long download is fine while bytes keep arriving |
| Failure | A NetworkError that names the host. It mentions BOTTICELLI_PROXY when no proxy is set |
Set BOTTICELLI_TIMEOUT_MS to a positive number. Zero or a non-number falls back to the default; a negative value is not rejected today.
Status: planned (M4, #5). Nothing here exists in
src/yet.
The Hunter runs when every Candidate of a Capability fails.
- It opens headless Chromium with
playwright-core, using an installed Chrome (channel: 'chrome') or the Playwright cache. It never downloads a browser on install (ADR 0003).playwright-coreis an optional dependency. - It loads the equivalent page of the real site.
- It captures the
/resource/*/get/responses that containpinimg. - It extracts
resource,X-Pinterest-PWS-Handler,source_urlandoptions, and replaces the known values (pin,query,board_id) with placeholders. - It repeats the call without the browser to validate it.
- If it works, it promotes the Candidate in the registry.
- Timeout: 30 seconds.
Health checks every Capability of every Source. A failure triggers the Hunter. The health tool returns what was checked and what was recovered. Health runs locally. A daily check in GitHub Actions is an automation and is out of scope unless the owner asks.
The planned acceptance test for M4: point the registry at a dead endpoint, run health, and see search answer again with no manual step.
Search suddenly fails with HTTP 4xx on every endpoint. Pinterest probably changed the resource. Open a "source broken" issue with the error text and date. Do not paste cookies.
I fixed an endpoint locally and it vanished. The learned file is ~/.config/botticelli/endpoints.json (or your env path). A fix meant for everyone goes into endpoints.default.json through a PR.
The registry keeps a bad Candidate first. Delete the learned file or remove the entry. A promoted Candidate stays first until a different one is promoted.
Why did related use the second Candidate? The first failed, and the second answered. That is failover.
Network error reaching www.pinterest.com: <reason> (if pinterest.com is blocked on your network, set BOTTICELLI_PROXY). The host is blocked or down. Failover does not apply. Use a proxy.
This wiki mirrors docs/ in the repository. Edit the docs there, not here. · MIT · Not affiliated with Pinterest or Are.na.
Use
Understand
Contribute
Project