From 522683e74687ad358c1081ce359d1b07b53831b2 Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Wed, 26 Nov 2025 12:28:55 -0600 Subject: [PATCH] fix(blocks): clamp Twitter search start_time to 10 seconds before now MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Twitter API requires start_time to be at least 10 seconds prior to the request time. When users provide a future time or a time too close to now, the API returns a 400 error. Changes: - Clamp start_time to max(start_time, now - 10s) in TweetDurationBuilder - Update input description to document this behavior - Fix serialize_list to handle None data gracefully Affected blocks: - TwitterSearchRecentTweetsBlock - TwitterGetUserMentionsBlock - TwitterGetHomeTimelineBlock - TwitterGetUserTweetsBlock Fixes BUILDER-3PG 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../backend/backend/blocks/twitter/_builders.py | 8 +++++++- .../backend/backend/blocks/twitter/_serializer.py | 4 +++- autogpt_platform/backend/backend/blocks/twitter/_types.py | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/autogpt_platform/backend/backend/blocks/twitter/_builders.py b/autogpt_platform/backend/backend/blocks/twitter/_builders.py index 6dc450c2474f..5f396b11ad6c 100644 --- a/autogpt_platform/backend/backend/blocks/twitter/_builders.py +++ b/autogpt_platform/backend/backend/blocks/twitter/_builders.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timedelta, timezone from typing import Any, Dict from backend.blocks.twitter._mappers import ( @@ -237,6 +237,12 @@ def __init__(self, param: Dict[str, Any]): def add_start_time(self, start_time: datetime | None): if start_time: + # Twitter API requires start_time to be at least 10 seconds before now + max_start_time = datetime.now(timezone.utc) - timedelta(seconds=10) + if start_time.tzinfo is None: + start_time = start_time.replace(tzinfo=timezone.utc) + if start_time > max_start_time: + start_time = max_start_time self.params["start_time"] = start_time return self diff --git a/autogpt_platform/backend/backend/blocks/twitter/_serializer.py b/autogpt_platform/backend/backend/blocks/twitter/_serializer.py index 906c52445686..bb570d995dc6 100644 --- a/autogpt_platform/backend/backend/blocks/twitter/_serializer.py +++ b/autogpt_platform/backend/backend/blocks/twitter/_serializer.py @@ -51,8 +51,10 @@ def serialize_dict(cls, item: Dict[str, Any]) -> Dict[str, Any]: return serialized_item @classmethod - def serialize_list(cls, data: List[Dict[str, Any]]) -> List[Dict[str, Any]]: + def serialize_list(cls, data: List[Dict[str, Any]] | None) -> List[Dict[str, Any]]: """Serializes a list of dictionary items""" + if not data: + return [] return [cls.serialize_dict(item) for item in data] diff --git a/autogpt_platform/backend/backend/blocks/twitter/_types.py b/autogpt_platform/backend/backend/blocks/twitter/_types.py index 8236297d5dab..88050ed54573 100644 --- a/autogpt_platform/backend/backend/blocks/twitter/_types.py +++ b/autogpt_platform/backend/backend/blocks/twitter/_types.py @@ -408,7 +408,7 @@ class ListExpansionInputs(BlockSchemaInput): class TweetTimeWindowInputs(BlockSchemaInput): start_time: datetime | None = SchemaField( - description="Start time in YYYY-MM-DDTHH:mm:ssZ format", + description="Start time in YYYY-MM-DDTHH:mm:ssZ format. If set to a time less than 10 seconds ago, it will be automatically adjusted to 10 seconds ago (Twitter API requirement).", placeholder="Enter start time", default=None, advanced=False,