fix(jobs): stop a sync inside the tick's time limit, resume with the accounts it did not reach, and fail the connection on a cut-off
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 44/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- next.js, playwright, supabase, typescript
Hướng nghiên cứu
Start with src/lib/jobs/sync-connection.ts and src/lib/jobs/runner.ts to trace the sync deadline and failure handling, then review account ordering in src/lib/jobs/store.ts and the lease expiry migration. Run the listed job unit tests and npm run test:db; acceptance requires slow-adapter and clock tests, pgTAP coverage for repeated overruns, and updated docs/operations/jobs.md.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Context
Found by the Fable pre-production review on 2026-12-02 (main at cedc1914; every line reference below re-checked on main at cde5aa3b). Sources: deploy readiness report new issue 2, product triage report new issue 1, and provider connect readiness report N4, merged here.
A sync has no deadline, and a sync cut off by the function limit leaves no trace on the connection:
- The tick dies at 120 s (
src/app/api/jobs/tick/route.ts:14), the claim lease is 120 s (TICK_LEASE_SECONDS,src/lib/jobs/runner.ts:38), and a job may start up to 50 s in (TICK_BUDGET_MS,runner.ts:39-41). The GitHub adapter says so: "a sync has about 70 seconds" (src/lib/adapters/github/repositories.ts:49-52). Only GitHub budgets its time (repositories.ts:58-66). syncConnectionreads every included account in sequence with no time check (src/lib/jobs/sync-connection.ts:206-288), and writes the connection only afterwards (:111-112,:290-300). Accounts are read in fixed id order, first 200 (src/lib/jobs/store.ts:601-611), so a cut-off sync restarts from the same first account. New accounts are included by default (src/lib/connections/connect.ts:184-185).- One Supabase connection holds one account per project (
src/lib/adapters/supabase/index.ts:788-810) and syncs every 15 minutes (pollIntervalSeconds: 900,:726). Sentry makes 4 to 5 requests per project (docs/providers/sentry.md:173) and PostHog up to 20 sequential queries per sync (provider report). At the 0.5 to 1.3 s per request measured on GitHub (docs/providers/github.md:330), 100 requests take 50 to 130 s. Real latency for the other providers is unmeasured. - After the last attempt, a cut-off job is set
failedwithlease_expiredon the job row only (supabase/migrations/20261201120100_sample_data_build.sql:130-138). The connection staysactivewith a pastnext_sync_at, soenqueue_due_syncsqueues it again on the next tick (supabase/migrations/20261031100000_sync_engine.sql:121-137).
Impact: a user whose connection reaches more accounts than fit in about 70 s sees an active connection whose later accounts never sync, with no timeline event and no error. The provider is called again every couple of minutes without end, each stuck job holds a worker, and the operator sees only lease_expired job rows. Longer first syncs (62 days of events, #724) make this more likely.
Plan
- Pass a deadline into
syncConnectionfrom the runner: the lease end minus a stated margin of at least one adapter timeout (ADAPTER_TIMEOUT_MS, 15 s,src/lib/adapters/registry.ts:41). - Before each account, stop starting accounts once the deadline is near; keep everything already stored and end the job as succeeded with a "partial" outcome that is logged.
- Order the next job's accounts by the oldest last sync first (a column or the existing
first_synced_atand an account level sync time), so every account is reached across consecutive jobs. - When a job ends
lease_expired, mark its connection: record the overrun, and after repeated overruns set itfailedwithlast_error_code, onestackdash.sync_failedevent, andnext_sync_atan hour out (the same path ashandleFailure,sync-connection.ts:377-460). This needs a migration on the lease expiry function. - Jobs a dying tick never started are released without losing an attempt.
- Document the limit and the behavior in
docs/operations/jobs.md"Failures and retries".
Acceptance criteria
- No account starts once less than the stated margin is left; the job keeps what it stored.
- The next job starts with the accounts synced longest ago; a unit test with 60 accounts on a slow fake adapter syncs all of them across consecutive jobs.
- A clock test: three accounts, the second overruns, the third syncs on the next run.
- A job that ends
lease_expiredleaves its connection recorded as overrun; repeated overruns reachfailedwithlast_error_code, onestackdash.sync_failedevent, and the hourly retry (pgTAP test). - Jobs a dying tick never started do not lose an attempt.
-
docs/operations/jobs.mdstates the time limit and what happens at it. - Playwright e2e: none needed unless the connection page copy changes; say so in the pull request.
Files and areas
src/lib/jobs/sync-connection.ts, src/lib/jobs/runner.ts, src/lib/jobs/store.ts, a new migration for the lease expiry and account order, their unit and pgTAP tests, docs/operations/jobs.md.
Non-goals: per-account failure handling (separate issue, same files, do after this one), raising maxDuration as the only fix, adapter specific budgets beyond GitHub's.
Verification
npm run typecheck, npm run lint, npx vitest run src/lib/jobs, npm run test:db.
Branch: <issue-number>-sync-time-limit
Model: anthropic/claude-opus-5-5 | Reasoning effort: unknown
- Ngôn ngữ chính
- TypeScript
- Star
- 13
- Fork
- 2
- Merge trung bình
- 5 giờ 20 phút
- Pull request đã merge (30 ngày)
- 287
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của eddiejaoude/StackDash
-
area: integrations documentation priority: P2 size: XS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
eddiejaoude/StackDash#798 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: ops documentation priority: P3 size: XS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
eddiejaoude/StackDash#796 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: docs documentation impact: low priority: P3 size: XS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
eddiejaoude/StackDash#790 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: ops bug impact: low priority: P3 size: XS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
eddiejaoude/StackDash#785 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: connections enhancement impact: low priority: P3 size: XS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
eddiejaoude/StackDash#768 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của eddiejaoude/StackDash
Issue tương tự
-
bot:ai-assisted component:midnight-js status:untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
midnightntwrk/midnight-js#1790 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:vscode bug has repro platform:macos platform:vscode regression
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
anthropics/claude-code#113502 ·
-
Add: Rajdhani TV HDĐang mởcheck:passed streams:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
effort/l priority/p1 risk/high triage/core
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
iflytek/skillhub#1188 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày