fix(integrations): accept a github first sync that crosses a month's end

Open
#751 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

Read collectBilling and monthsToSync in src/lib/adapters/github/billing.ts, then follow the existing boundary test in src/lib/adapters/github/index.test.ts. First decide which month-boundary behavior to use and present the options as a table on the issue before coding. Add the reproduction test and verify the first sync stores a valid batch without an invalid_response retry.

Written by the indexing model from the issue text.

Description

area: integrations bug impact: low priority: P3 size: S

Context

Found while fixing #732. A GitHub account's first sync that starts before 00:00 UTC on a month's last day and reads that month's billing summary after 00:00 fails validation, and the job retries it.

How it happens, on main and on the #732 branch alike:

  • collectBilling (src/lib/adapters/github/billing.ts) picks the months to read from the clock at the start of the sync (monthsToSync(now)). A sync that starts at 2026-10-31T23:59:59Z reads October only, as the current month.
  • If the summary is read at 2026-11-01T00:00:01Z, October's month to date has a retrievedAt after its period ended (the period ends at 2026-11-01T00:00Z).
  • collectPastDays states the daily amounts up to 2026-10-31 against that reading, and validateAdapterMetrics (pastDayIssues in src/lib/adapters/metrics.ts) rejects every one: "a daily amount's live reading must be a running total: a period from the first day of a UTC month, still open when it was read".
  • The whole batch fails (InvalidResponseError in src/lib/jobs/sync-connection.ts, around line 222). invalid_response is not a permanent code, so the job retries after backoff, and the retry, after 00:00, reads both months and succeeds.

Reproduction: in src/lib/adapters/github/index.test.ts, copy the test "decides the past days against the day the month to date was read when the sync crosses 00:00 UTC (boundary: midnight)" and move the clock to 2026-11-01T00:00:01Z when the summary route is called instead of when /usage is. checkSyncResult then returns one issue per daily amount, all with the message above. Run on the #732 branch at 0d2255ac; not committed.

Impact: low. Only a first sync that reads its summary in the seconds just past midnight on a month's last day hits it. It records invalid_response on the connection, then succeeds on the retry, and no data is lost. A later sync is not affected: it states no daily amounts.

Plan

  1. Decide how a first sync should treat a month it reads after the month ended. For example: decide "current" per reading from its retrievedAt and read the new month too, or keep the clock at the start of the sync for every read. Present the options as a table on this issue before writing code.
  2. Add the reproduction above as a unit test.

Acceptance criteria

  • A first sync that reads its month's summary just after 00:00 UTC on the month's last day stores a valid batch, without an invalid_response failure and retry.
  • Unit test for that case in src/lib/adapters/github/index.test.ts.
  • Playwright: none needed, because the change is in a sync's stored rows.

Files and areas

src/lib/adapters/github/billing.ts (collectBilling, monthsToSync), src/lib/adapters/github/index.test.ts, src/lib/adapters/metrics.ts (read only). Non-goals: the 3 day grace window, later syncs, other providers.

Verification

  • npx vitest run src/lib/adapters/github src/lib/adapters/metrics.test.ts
  • npm run typecheck, npm run lint, npm test

Branch: <issue-number>-<slug>
Closes with a Closes #<issue-number> footer on the commit or pull request.

Model: anthropic/claude-opus-5-5 | Reasoning effort: max

Dominant language
TypeScript
Stars
13
Forks
2
Avg merge
5h 20m
Merged PRs (30d)
287

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from eddiejaoude/StackDash

All issues in eddiejaoude/StackDash

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.