Skip to content

fix(rewrite): reserve canonical-URL headroom for short-form platforms - #3

Open
ktherage wants to merge 1 commit into
queelius:masterfrom
ktherage:fix/rewrite-url-headroom
Open

fix(rewrite): reserve canonical-URL headroom for short-form platforms#3
ktherage wants to merge 1 commit into
queelius:masterfrom
ktherage:fix/rewrite-url-headroom

Conversation

@ktherage

Copy link
Copy Markdown

Problem

For short-form platforms (Bluesky, Mastodon, Twitter, Threads, LinkedIn), auto-rewrites are generated to exactly max_content_length characters, then _append_canonical_url() (base.py) appends the canonical URL on top. The final post exceeds the platform limit and the content-length check fails.

Bluesky (300-char limit) breaks on every publish. Example: a 268-char rewrite + canonical URL = 358 chars > 300. Mastodon only works because its 500-char limit happens to have enough slack. The same latent bug exists for Twitter (280), Threads (500), and LinkedIn (3000).

Fix

  • Add Platform.appends_canonical_url: bool = False class attribute.
  • Add Platform.rewrite_max_length(article) which returns max_content_length minus the canonical URL (plus the "\n\n" separator) for platforms that append it, floored at 1. Returns None for platforms with no limit.
  • Set appends_canonical_url = True on Bluesky, Mastodon, Twitter, Threads, LinkedIn.
  • Use rewrite_max_length() at every auto-rewrite call site: crier publish, publish --dry-run preview, crier audit update path, crier schedule run, and publishing.prepare_publish.

This leaves room for the URL so the final post fits exactly within the platform limit.

Tests

  • New TestRewriteMaxLength class covering: no-limit platforms, non-appenders (full budget), URL-headroom subtraction (final post fits exactly), no-URL and URL-already-in-body cases, floor-at-1 for tiny limits, and flag verification on all 5 platforms.
  • Updated test_publishing.py mocks to the new method.
  • Full suite: 1283 passed, 4 skipped (excluding test_mcp.py, which fails to collect due to the mcp dependency).

Verified live: after applying the same change locally, a Bluesky auto-rewrite publish that previously failed (Auto-rewrite failed ... 358 > 300) now succeeds.

Auto-rewrites are generated to exactly max_content_length characters, then
_append_canonical_url() appends the canonical URL on top, pushing the final
post past the platform limit and failing the content-length check. Bluesky
(300 chars) always broke this way; Mastodon only worked due to slack in its
500-char limit.

Add Platform.appends_canonical_url and Platform.rewrite_max_length(), which
return a reduced budget (limit minus URL plus "\n\n" separator) for
platforms that append the URL. Use it at every auto-rewrite call site
(publish, publish --dry-run, audit, schedule, and publishing.prepare_publish).

URL-appending platforms set appends_canonical_url: bluesky, mastodon,
twitter, threads, linkedin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant