Skip to content

Conversation

@tirthpatell
Copy link
Owner

CreateCarouselPost now polls each child container until it reaches FINISHED status before creating the carousel container. This fixes flaky integration tests where the API would reject carousel creation with "Invalid Carousel Children" errors due to children not being ready yet.

Removed unnecessary time.Sleep(1 * time.Second) workarounds from integration tests since the library now handles this properly.

CreateCarouselPost now polls each child container until it reaches
FINISHED status before creating the carousel container. This fixes
flaky integration tests where the API would reject carousel creation
with "Invalid Carousel Children" errors due to children not being
ready yet.

Removed unnecessary time.Sleep(1 * time.Second) workarounds from
integration tests since the library now handles this properly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@greptile-apps
Copy link

greptile-apps bot commented Jan 19, 2026

Greptile Summary

This PR fixes a race condition in carousel post creation by ensuring child media containers are fully processed before creating the carousel container. Previously, CreateCarouselPost would immediately attempt to create the carousel with child containers that might still be processing, causing intermittent "Invalid Carousel Children" API errors.

Key changes:

  • Added polling logic in CreateCarouselPost that waits for each child container to reach FINISHED status before proceeding
  • Leverages existing waitForContainerReady function with sensible defaults (30 attempts, 1-second intervals)
  • Provides clear error messages indicating which child container failed and why
  • Removed time.Sleep(1 * time.Second) workarounds from integration tests, as the library now handles synchronization properly

Impact:

  • Improves reliability of carousel post creation
  • Eliminates flaky integration tests
  • Better user experience with proper error reporting for failed child containers

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change follows existing patterns in the codebase (other post types already use waitForContainerReady), has clear error handling, uses well-defined constants for polling configuration, and removes workarounds from tests that prove the fix works correctly
  • No files require special attention

Important Files Changed

Filename Overview
posts_create.go Added polling for child container readiness before carousel creation to prevent "Invalid Carousel Children" errors
tests/integration/integration_test.go Removed unnecessary time.Sleep workarounds from tests since library now handles container readiness properly

Sequence Diagram

sequenceDiagram
    participant Test as Integration Test
    participant Client as Client.CreateCarouselPost
    participant API as Threads API
    
    Test->>API: CreateMediaContainer(image1)
    API-->>Test: container1 ID
    Test->>API: CreateMediaContainer(image2)
    API-->>Test: container2 ID
    
    Note over Test,Client: Before this PR: immediate carousel creation<br/>After this PR: wait for children to be ready
    
    Test->>Client: CreateCarouselPost([container1, container2])
    
    loop For each child container
        Client->>API: GetContainerStatus(childID)
        API-->>Client: status response
        alt Status = FINISHED
            Note over Client: Child is ready, continue
        else Status = IN_PROGRESS
            Note over Client: Wait 1 second, retry (max 30 attempts)
            Client->>API: GetContainerStatus(childID)
        else Status = ERROR/EXPIRED
            Client-->>Test: Error: child not ready
        end
    end
    
    Note over Client: All children ready
    Client->>API: createCarouselContainer(content)
    API-->>Client: carousel container ID
    
    Client->>API: GetContainerStatus(carouselID)
    API-->>Client: FINISHED
    
    Client->>API: publishContainer(carouselID)
    API-->>Client: post ID
    
    Client->>API: GetPost(postID)
    API-->>Client: post details
    Client-->>Test: Created Post
Loading

@tirthpatell tirthpatell merged commit d8392f2 into main Jan 19, 2026
9 checks passed
@tirthpatell tirthpatell deleted the fix/carousel-child-container-timing branch January 19, 2026 23:02
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