fix(posting): cap stuck Instagram container polling and guard scheduled post create/update transitions
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, typescript
Research direction
Read apps/workers/src/services/db-job-poller.ts and apps/workers/src/services/instagram-api.service.ts to trace ContainerNotReadyError retries and job state updates, then inspect apps/api/src/instagram/services/instagram-posts.service.ts for create and update flows. Check the existing worker and service tests before changing behavior. Done means polling eventually fails with a clear error, post and job creation is atomic, and edits are rejected during PROCESSING.
Written by the indexing model from the issue text.
Description
Problem Description
-
Infinite reschedule loop on stuck Instagram media containers:
Inapps/workers/src/services/instagram-api.service.ts(waitForContainerAndPublish, lines 789-815), anIN_PROGRESSmedia container throwsContainerNotReadyError(containerId, 5).
Inapps/workers/src/services/db-job-poller.ts(lines 272-295), catchingContainerNotReadyErrorresetsattempts: candidate.attemptswith no maximum poll count or elapsed-time cap. If an Instagram container gets stuck inIN_PROGRESS(e.g., corrupt or rejected video), the worker polls Graph API indefinitely every ~6-12s while leavingInstagramScheduledPost.statusstuck inPROCESSING. -
Non-atomic post/job creation and unsafe edits during
PROCESSING:- In
apps/api/src/instagram/services/instagram-posts.service.ts(createScheduledPost, lines 226-264),instagramScheduledPost.createandbackgroundJob.createrun outside aprisma.$transaction; ifbackgroundJob.createfails, an orphaned post remains inSCHEDULED/PROCESSINGwithbackgroundJobId: null. updateScheduledPost(lines 278-356) only rejectsPUBLISHEDposts, allowing edits whilepost.status === 'PROCESSING'and resetting theBackgroundJobback toPENDINGmid-publish, risking duplicate publishes.
- In
Expected Behavior
- Container polling (
ContainerNotReadyError) must have a safe maximum cap (e.g., 15-20 minutes or max ~100 polls so large ~100 MB videos have plenty of time to process), after which bothBackgroundJobandInstagramScheduledPosttransition toFAILEDwith a clear timeout error. createScheduledPostmust create theInstagramScheduledPostandBackgroundJobatomically insideprisma.$transaction.updateScheduledPostmust continue allowing edits whileSCHEDULED, and reject edits whilestatus === 'PROCESSING'(in addition toPUBLISHED).
Where to Look
apps/workers/src/services/instagram-api.service.ts(waitForContainerAndPublish, lines 789-815)apps/workers/src/services/db-job-poller.ts(lines 272-295)apps/api/src/instagram/services/instagram-posts.service.ts(createScheduledPostlines 226-264,updateScheduledPostlines 278-356)
Solution / Implementation Guide
- Cap container polling (
db-job-poller.ts&publish-worker.ts):- Track
containerPollCountandfirstPolledAtinerr.updatedPayloadwhen handlingContainerNotReadyError. - Once
containerPollCount >= MAX_CONTAINER_POLLS(e.g.,100) orDate.now() - firstPolledAt > 20 * 60 * 1000, mark both theBackgroundJobandInstagramScheduledPostasFAILEDwith a descriptiveerrorMessageinstead of rescheduling.
- Track
- Atomic create &
PROCESSINGedit guard (instagram-posts.service.ts):- Wrap
instagramScheduledPost.create,backgroundJob.create, and linkingbackgroundJobIdinsidethis.prisma.$transaction(...)increateScheduledPost. - In
updateScheduledPost, reject requests with409 Conflict/400 BadRequestwhenexisting.status === 'PROCESSING'.
- Wrap
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 6m
- Merged PRs (30d)
- 27
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sumamakhan761/tryinstance
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#65 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
sumamakhan761/tryinstance#64 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
sumamakhan761/tryinstance#63 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#62 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#60 ·
Maintainers usually reply within 1 day
All issues in sumamakhan761/tryinstance
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day