Skip to content

feat(kit): tags as Marfa tags, delete and archive holds, request pacer and thumbnails - #486

Merged
aicayzer merged 51 commits into
mainfrom
kit/connector-kit
Dec 3, 2026
Merged

aicayzer merged 51 commits into
mainfrom
kit/connector-kit

Conversation

@aicayzer

@aicayzer aicayzer commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Connector kit work that every connector can use, needed first by the Raindrop connector:

  • Tags and favorites as Marfa tags. A kind declares tags and favorite; its entries carry the service's tags and favorite beside their fields, and the kit keeps them as Marfa tags and the favorite tag both ways, merging tag by tag against what both sides last held. A tag is agreed only when both sides hold it, a change of the kind's tag choice starts from a union, and the smaller agreement is saved before either side loses a tag, so a stop at any point can at worst re-add a tag, never remove one. It follows the mapping's tags ("marfa", "none" or { field }) and favorite choices.
  • A confirmable hold on a large batch of deletes, lifted from Google Calendar's preflight. The confirmation value binds the exact deletes, their operation (a trash never releases a purge) and what each cascade takes. Google Calendar now uses it.
  • An opt-in hold on a run that would archive a large share of a kind, with gathered and held archives kept across runs as hashes, so a deletion a service reports once is never lost. Marfa has no atomic archive of a set, so a confirmed batch is saved and finished first by the next run.
  • A request pacer with a budget a minute, rate-limit headers, and 429 waits (Retry-After first) through the durable wait. Every Readwise request goes through it.
  • A thumbnail helper that makes the small data URI Marfa's thumbnail field holds, with no native code: JPEG through mozjpeg in WebAssembly, CMYK JPEG through jpeg-js up to 16 million pixels, PNG, GIF and WebP, 25 million pixels at most.
  • Remakes carry the row's tags and favorite, and rows that come back from the bin with their parent are remade after it, under its new link.

Generated plugins now need marfa 0.0.123.

Closes #470, closes #471, closes #472, closes #473, closes #474.

Changes

  • kit/src/tags.ts, kit/src/run.ts, kit/src/agreement.ts, kit/src/store.ts, kit/src/define.ts; scripts/connector-plugins.ts writes tags and favorite on a kind.
  • kit/src/holds.ts: context.holdDeletes(...) in preflight; holdArchives: true on a kind; settings <connector>_confirm_deletes and <connector>_confirm_archives. A used value is recorded as spent, since a connector key cannot clear a setting.
  • kit/src/pacer.ts (@withmarfa/connector/pacer); Readwise's own limiter and Retry-After parsing removed.
  • kit/src/thumbnails.ts (@withmarfa/connector/thumbnails), kit/src/codec-wasm.ts; scripts/bundle-connectors.ts carries the codecs' WebAssembly inline.
  • kit/src/connections.ts: Connections.above(); preflight, onChange and remake share one context.
  • Google Calendar on holdDeletes, keeping google_calendar_confirm_deletes and its limit of 10.
  • Proof groups tags and holds; kit/README.md for each piece.

Testing

  • Build, typecheck, lint, format, connectors:check: pass.
  • Whole suite after scripts/monorepo.sh (marfa-server 0.0.123): 4,039 of 4,043; the four failures are the macOS sandbox tests, which cannot start Homebrew's Node on the machine used, and run in CI on the pinned Node.
  • Proof against 0.0.123: holds 5, tags 8 (including a real process crash mid-merge with both sides changing), readwise 9, readwise-with-reader 13, parent-of 4, todoist 34 statements.

Notes for reviewers

Checklist

  • The title is a scoped Conventional Commit.
  • New behavior has a test that was seen failing first, or no test was needed and the reason is above.
  • Docs, comments and the contract still say what is true after this change.

preflight gains context.holdDeletes, which holds a batch deleting more than 20 and a quarter of a whole, cascades counted, until <connector>_confirm_deletes names it. A kind with holdArchives keeps its archives until the run has read the vendor and holds more than 20 and a quarter of its active rows until <connector>_confirm_archives names them. A confirmation is spent in kit state before any write, so it releases one batch.

Closes #470, closes #471.
…to kit/connector-kit

# Conflicts:
#	kit/src/define.ts
…imits

A held thumbnail is kept only when Marfa takes it and the caller's maxBytes
and the 16 KiB cap allow it. The pixel limit falls to 12 million so the worst
decode peaks near 0.5 GB resident.
Count the archives that settle inbound retries and gather in delivery runs only the rows a delivery named. A held batch keeps no keys; a released batch is kept as key hashes and finished first at the next run's start, since Marfa has no atomic set archive. The delete value covers every whole and what each cascade takes, and both conditions lead with the value.
The export, Reader list and Reader write requests take their 429 wait, the
Retry-After parsing and the budget from the kit's Pacer, one per token and
limit. A missing or malformed Retry-After waits the pacer's default instead
of failing the run, and one 429 holds the token's later requests to its
deadline. The copies of the Retry-After logic in the HTTP client and the
Reader write client are gone.
A remake now carries the row's tags and favorite, and the agreement after it is what the vendor answered, or what was sent, so the next read keeps them in Marfa. Rows a cascade took come back offered to remake after the rows above them, handed every connection, and are only returned where the vendor still has them.

@aicayzer aicayzer left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review: ready to merge

Summary. Kit support for tags and favorites as Marfa tags, confirmable delete and archive holds, a request pacer, thumbnails and remakes with their tags and children; safe to merge after five review rounds fixed every blocking finding.

First draft: 1/5. The first round found fifteen blocking problems, including ways to lose tags and to archive or delete past the holds, and a regression in Readwise Reader's writes; all were fixed, and later rounds found and fixed six, one, two and two more.

Checked.

  • Keep what people made: tag agreement only when both sides hold a tag; smaller agreement saved before a removal; mapping-choice changes start a union; waiting rows retried; a remake carries its tags and favorite.
  • Every path: inbound retries and delivery-scoped runs count toward the archive hold; in kinds never send tags; children remade only after their parent's remake is settled.
  • Check and write are one step: confirmation values bind the exact set, its operation and cascades; a trash value never releases a purge.
  • Real conditions: state under 512 KiB at 14,000 to 16,000 held keys; quadratic scans removed; thumbnail decode memory bounded; CMYK JPEGs refused above 16 million pixels before a heap-bound decode.
  • Done: proof groups holds, tags, readwise, readwise-with-reader, parent-of, todoist against marfa 0.0.123.

Found.

  • Reader lost its preflight approval. preflight got a copy of the context. Fixed in 87f22bd. Every path
  • Tags agreed from a service answer alone, then deleted at the service. Fixed in e953ff8. Keep what people made
  • A mapping change resurrected or removed tags. Fixed in e953ff8 and c312a74. Keep what people made
  • Crash recovery undid a fresh tag edit. Fixed in e953ff8. Check and write are one step
  • Tag work lost behind a checkpoint or a failed write. Fixed in e953ff8. Keep what people made
  • Archive hold bypassed by a retry or a delivery, and confirmations not binding the set. Fixed in 7463229 and 63d42a3. Every path
  • Held or gathered archives lost after a failed run. Fixed in 4751408. Real conditions
  • Hold state and messages past Marfa's limits. Fixed in 7463229. Real conditions
  • Retry-After lost to a reset header; cached thumbnails skipping the cap. Fixed in 0bce5b8 and 91bc678. Done
  • A trash confirmation released purges. Fixed in 2e6080a. Check and write are one step
  • mozjpeg refused CMYK and harmless-warning JPEGs. Fixed in 4dee7eb and 5f9c118. Real conditions
  • A waiting create lost after a cascade restore; a child remade under its parent's deleted link. Fixed in f5073d2 and 595f7bd. Every path
  • A confirmed archive batch can be half written by a stop. Declined as specified: Marfa has no atomic archive of a set, so the batch is saved and finished first by the next run; #471 amended. Done

Quick fixes. 6 applied by reviewers.


Reviewed by withmarfa-reviewer on gpt-6.2-astra (round 1) and claude-opus-5-5 and claude-sonnet-5-5 (rounds 2 to 5). This review may contain mistakes.

@aicayzer
aicayzer marked this pull request as ready for review December 3, 2026 21:32
@aicayzer
aicayzer enabled auto-merge (squash) December 3, 2026 21:33
Comment thread kit/test/pacer.test.ts
describe("when the vendor's clock differs from this one", () => {
const ahead = 10 * 60_000;
const vendorDate = (): string =>
new Date(start + ahead).toUTCString().replace(/ GMT$/, " GMT");
@aicayzer
aicayzer merged commit 65485bb into main Dec 3, 2026
32 checks passed
@aicayzer
aicayzer deleted the kit/connector-kit branch December 3, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants