Merge branch 'fix/v2.6.1-threads-publish-retry' for v2.6.1 release
Build Container / build (push) Successful in 6s
Build Container / build (push) Successful in 6s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
0dd59fbc18
4 files changed
+45
-5
No files matched your search
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [2.6.1] - 2026-11-01
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Threads crossposts gave up after Meta's publish step returned a one-off `HTTP 400 Fatal`; publish errors are now retried (a retry checks for an existing post first, so nothing is posted twice). Only a bad token or missing permission stops retries
|
||||||
|
- Threads errors now include Meta's error code, subcode, user message and trace id, so the editor shows why a post failed
|
||||||
|
- Wait a moment before the first readiness check on a Threads post, since Meta can report it ready too early
|
||||||
|
|
||||||
## [2.6.0] - 2026-11-01
|
## [2.6.0] - 2026-11-01
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -464,5 +464,5 @@ def create_app(config=None):
|
|||||||
|
|
||||||
# Package version (Semantic Versioning 2.0.0)
|
# Package version (Semantic Versioning 2.0.0)
|
||||||
# See docs/standards/versioning-strategy.md for details
|
# See docs/standards/versioning-strategy.md for details
|
||||||
__version__ = "2.6.0"
|
__version__ = "2.6.1"
|
||||||
__version_info__ = (2, 6, 0)
|
__version_info__ = (2, 6, 1)
|
||||||
+18
-3
@@ -415,6 +415,7 @@ THREADS_IMAGE_LIMIT = 8_000_000
|
|||||||
THREADS_REFRESH_EVERY = 24 * 3600 # tokens last 60 days; Meta allows a refresh once one is a day old
|
THREADS_REFRESH_EVERY = 24 * 3600 # tokens last 60 days; Meta allows a refresh once one is a day old
|
||||||
# Graph API error codes that are temporary (rate limits, service hiccups)
|
# Graph API error codes that are temporary (rate limits, service hiccups)
|
||||||
_GRAPH_TRANSIENT = {1, 2, 4, 17, 32, 341, 613}
|
_GRAPH_TRANSIENT = {1, 2, 4, 17, 32, 341, 613}
|
||||||
|
_GRAPH_AUTH = {10, 190, 200} # bad token or missing permission: retrying won't help
|
||||||
|
|
||||||
|
|
||||||
def threads_length(text: str) -> int:
|
def threads_length(text: str) -> int:
|
||||||
@@ -536,13 +537,19 @@ class ThreadsClient:
|
|||||||
if response.status_code >= 400 or error:
|
if response.status_code >= 400 or error:
|
||||||
error = error if isinstance(error, dict) else {}
|
error = error if isinstance(error, dict) else {}
|
||||||
code = error.get("code")
|
code = error.get("code")
|
||||||
|
detail = " / ".join(str(error[k]) for k in ("error_user_title", "error_user_msg")
|
||||||
|
if error.get(k))
|
||||||
message = (f"{method} {path}: HTTP {response.status_code} "
|
message = (f"{method} {path}: HTTP {response.status_code} "
|
||||||
f"{error.get('message') or response.text[:200]}")
|
f"{error.get('message') or response.text[:200]}"
|
||||||
|
f" (code {code}, subcode {error.get('error_subcode')}"
|
||||||
|
f"{', ' + detail if detail else ''}, fbtrace {error.get('fbtrace_id')})")
|
||||||
if response.status_code == 404 or (code == 100 and error.get("error_subcode") == 33):
|
if response.status_code == 404 or (code == 100 and error.get("error_subcode") == 33):
|
||||||
raise RemoteGone(message, permanent=True)
|
raise RemoteGone(message, permanent=True)
|
||||||
permanent = (400 <= response.status_code < 500 and response.status_code != 429
|
permanent = (400 <= response.status_code < 500 and response.status_code != 429
|
||||||
and code not in _GRAPH_TRANSIENT)
|
and code not in _GRAPH_TRANSIENT)
|
||||||
raise SyndicationError(message, permanent=permanent)
|
exc = SyndicationError(message, permanent=permanent)
|
||||||
|
exc.code = code
|
||||||
|
raise exc
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def _me(self) -> str:
|
def _me(self) -> str:
|
||||||
@@ -555,6 +562,7 @@ class ThreadsClient:
|
|||||||
def _wait(self, container_id: str) -> None:
|
def _wait(self, container_id: str) -> None:
|
||||||
"""Wait until Meta has processed a container (images take a few seconds)"""
|
"""Wait until Meta has processed a container (images take a few seconds)"""
|
||||||
delay = 1
|
delay = 1
|
||||||
|
self.sleep(2) # Meta can report a container ready a moment too early
|
||||||
for _ in range(8):
|
for _ in range(8):
|
||||||
status = self._call("GET", container_id, fields="status,error_message")
|
status = self._call("GET", container_id, fields="status,error_message")
|
||||||
state = status.get("status")
|
state = status.get("status")
|
||||||
@@ -641,7 +649,14 @@ class ThreadsClient:
|
|||||||
return existing
|
return existing
|
||||||
container = self._container(uid, post)
|
container = self._container(uid, post)
|
||||||
self._wait(container)
|
self._wait(container)
|
||||||
media_id = self._call("POST", f"{uid}/threads_publish", creation_id=container)["id"]
|
try:
|
||||||
|
media_id = self._call("POST", f"{uid}/threads_publish", creation_id=container)["id"]
|
||||||
|
except SyndicationError as e:
|
||||||
|
if getattr(e, "code", None) in _GRAPH_AUTH:
|
||||||
|
raise
|
||||||
|
# Meta's publish step fails now and then ("Fatal") and works on a
|
||||||
|
# later try; the retry checks for an existing post first
|
||||||
|
raise SyndicationError(str(e))
|
||||||
try:
|
try:
|
||||||
url = self._call("GET", media_id, fields="permalink").get("permalink")
|
url = self._call("GET", media_id, fields="permalink").get("permalink")
|
||||||
except SyndicationError:
|
except SyndicationError:
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class FakeThreads:
|
|||||||
self.pending_polls = 0
|
self.pending_polls = 0
|
||||||
self.lose_next_publish = False
|
self.lose_next_publish = False
|
||||||
self.fail_next = None
|
self.fail_next = None
|
||||||
|
self.fail_next_publish = False
|
||||||
|
|
||||||
def _json(self, code, body):
|
def _json(self, code, body):
|
||||||
return httpx.Response(code, json=body)
|
return httpx.Response(code, json=body)
|
||||||
@@ -83,6 +84,9 @@ class FakeThreads:
|
|||||||
return self._json(200, {"data": [
|
return self._json(200, {"data": [
|
||||||
{"id": pid, "text": p["text"], "permalink": f"https://www.threads.com/@phil/post/{pid}"}
|
{"id": pid, "text": p["text"], "permalink": f"https://www.threads.com/@phil/post/{pid}"}
|
||||||
for pid, p in self.posts.items()]})
|
for pid, p in self.posts.items()]})
|
||||||
|
if path == f"{UID}/threads_publish" and self.fail_next_publish:
|
||||||
|
self.fail_next_publish = False
|
||||||
|
return self._error(400, "Fatal", 24, 4279009)
|
||||||
if path == f"{UID}/threads_publish":
|
if path == f"{UID}/threads_publish":
|
||||||
container = self.containers[params["creation_id"]]
|
container = self.containers[params["creation_id"]]
|
||||||
pid = f"p{len(self.posts) + 1}"
|
pid = f"p{len(self.posts) + 1}"
|
||||||
@@ -237,6 +241,19 @@ class TestErrors:
|
|||||||
assert len(api.posts) == 1
|
assert len(api.posts) == 1
|
||||||
assert row(app, note)["state"] == "synced"
|
assert row(app, note)["state"] == "synced"
|
||||||
|
|
||||||
|
def test_publish_fatal_is_retried(self, app, api):
|
||||||
|
api.fail_next_publish = True
|
||||||
|
note = publish(app)
|
||||||
|
r = row(app, note)
|
||||||
|
assert r["state"] == "pending" and "Fatal" in r["last_error"] and "subcode 4279009" in r["last_error"]
|
||||||
|
with app.test_request_context():
|
||||||
|
from starpunk.database import get_db
|
||||||
|
get_db(app).execute("UPDATE syndications SET next_attempt_at = datetime('now')")
|
||||||
|
get_db(app).commit()
|
||||||
|
process_due()
|
||||||
|
assert len(api.posts) == 1
|
||||||
|
assert row(app, note)["state"] == "synced"
|
||||||
|
|
||||||
def test_bad_token_fails_permanently(self, app, api):
|
def test_bad_token_fails_permanently(self, app, api):
|
||||||
api.token = "other"
|
api.token = "other"
|
||||||
note = publish(app)
|
note = publish(app)
|
||||||
|
|||||||
Reference in new issue
Block a user