Skip to content

fix(common): honor DeepSeek Beijing weekend boundaries - #1096

Closed
c8dhjp4tyv-bit wants to merge 9036 commits into
CodebuffAI:mainfrom
c8dhjp4tyv-bit:fix/deepseek-beijing-weekend-boundary
Closed

fix(common): honor DeepSeek Beijing weekend boundaries#1096
c8dhjp4tyv-bit wants to merge 9036 commits into
CodebuffAI:mainfrom
c8dhjp4tyv-bit:fix/deepseek-beijing-weekend-boundary

Conversation

@c8dhjp4tyv-bit

Copy link
Copy Markdown

Fixes #1090

Summary

  • Export and directly test the Beijing weekend predicate at the Friday/Sunday UTC boundary.
  • Apply DeepSeek's weekend off-peak rule only from its effective instant, 2026-08-22T16:00:00Z.
  • Keep historical pricing and expensive-window checks from retroactively treating pre-change weekends as off-peak.

Why

The existing weekend tests used instants where UTC and Beijing were already on the same weekend day, so removing the +8 hour conversion left the suite green. The new boundary cases pin Friday 16:00Z and Sunday 16:00Z, where the calendars diverge.

Verification

  • bun test common/src/__tests__/freebuff-peak-hours.test.ts — 26 passed
  • bun run --cwd common typecheck — passed
  • Prettier check and git diff --check — passed

The full common test command cannot pass in this public checkout because several existing tests reference private/web files absent from the mirror; the changed test file passes independently.

@xyzs996

ghost commented Aug 23, 2026

Copy link
Copy Markdown

Ran the two functions from this PR, copied verbatim, against our dated vector table for the live DeepSeek schedule. 15 of 15: 12 phase vectors and 3 next-change vectors, including both effective instants and both weekend edges. Over the week beginning 2026-08-24T00:00Z it yields 35 peak hours (5 days × 7), which is the shape the vendor footnote describes.

Mutation results, since #1090 was about tests staying green:

removed vectors broken
the >= DEEPSEEK_WEEKEND_OFFPEAK_EFFECTIVE_AT_UTC gate 2 of 122026-08-22T01:30Z and 2026-08-22T09:59:59Z, the pre-rule Saturday that must still bill peak
the + 8 * 60 * 60 * 1000 Beijing shift 0 of 12

That second row is the interesting one, and I think this PR gets it right for a reason worth writing down. With the current windows the weekend rule can only change the answer during 01:00-10:00 UTC — everywhere else the hour check already returns off-peak, so the weekend branch is a no-op. And 01:00-10:00 UTC is entirely inside the region where the UTC date and the Beijing date agree. So no vector expressed as a billing outcome can distinguish getUTCDay() from the Beijing-shifted day. Not ours, not any that can be written from the published card. That is precisely why both of the old tests stayed green.

Exporting isBeijingWeekend and asserting on it directly is the way out, and the four instants chosen here are the right four — 2026-08-28T16:00Z and 2026-08-30T16:00Z are exactly the two edges where the calendars diverge. Two of those four fail if the shift is removed. Our own answer to the same problem was to carry a synthetic schedule with a peak window past 16:00 UTC; testing the exported predicate is simpler and needs no fixture, and I would rather have it this way round.

One note, not a request: the +8 is safe here because China has observed no DST since 1991, so a fixed offset and Asia/Shanghai cannot diverge. That is a property of this one zone rather than of the code, so it may be worth a word in the comment next to the constant — the same function pointed at a zone with DST would be wrong twice a year.

Vectors are CC0 if they are useful in the suite: https://github.com/xyzs996/deepseek-peak-hours. Thanks for picking this up so quickly.

@c8dhjp4tyv-bit
c8dhjp4tyv-bit force-pushed the fix/deepseek-beijing-weekend-boundary branch from 43861e6 to b00d9e9 Compare August 23, 2026 21:30
@codebuff-team

ghost commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

The Beijing-weekend boundary tests are a genuine improvement — the old test data (e.g. 2026-08-29T02:00:00Z) never actually exercised the +8h conversion since UTC and Beijing agreed on the day-of-week, so the new Friday-16:00Z / Sunday-16:00Z cases in freebuff-peak-hours.test.ts catch a real gap. Exporting isBeijingWeekend for direct testing is also reasonable.

The part that needs work is DEEPSEEK_WEEKEND_OFFPEAK_EFFECTIVE_AT_UTC = Date.parse('2026-08-22T16:00:00Z'). This is a brand-new piece of business logic — it changes production pricing/availability behavior for every timestamp before that instant — and nothing in the PR or the doc comment cites where this date comes from. The existing doc comment only references api-docs.deepseek.com for the peak-hour windows; there's no equivalent source for "the weekend rule took effect on 2026-08-23 Beijing time." Before this lands anywhere, that constant needs a link to the actual DeepSeek announcement, changelog, or issue #1090's description that establishes the date — otherwise this is inventing pricing policy rather than fixing a bug in existing policy.

Also: deepseekPricingWindow and isDeepSeekExpensiveWindow now both gate on the same effective-date check independently. If this constant is legitimate, it'd be worth extracting a single isWeekendOffPeakEligible(at) helper instead of duplicating the >= EFFECTIVE_AT && isBeijingWeekend(at) condition twice.

Please link the source for the effective date, or explain in the PR body what #1090 actually reported (was pricing wrongly applied retroactively? did DeepSeek publish a change date?). Without that, this can't be safely ported into a billing-adjacent codepath.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written labels Aug 24, 2026

ghost commented Aug 24, 2026

Copy link
Copy Markdown
Author

Addressed the review points in 28179bc.

  • The effective instant is now explicitly sourced in the code comment: issue Both weekend tests stay green if the Beijing shift is removed #1090 records the DeepSeek Models & Pricing notice stating the weekend rule becomes effective at 00:00 Beijing time on 2026-08-23, and the comment links the current vendor pricing page (https://api-docs.deepseek.com/quick_start/pricing/) for the resulting Monday-Friday peak rule.
  • Extracted isWeekendOffPeakEligible(at) so the effective-date + Beijing-weekend condition has one source of truth instead of being duplicated in both pricing/availability functions.
  • Kept the direct Beijing boundary tests and the historical effective-date coverage unchanged.

codebuff public sync bot added 22 commits August 24, 2026 22:14
Source: CodebuffAI/freebuff-private@241f8bfa8a8a97867900b2f71754638efa2cbe86
Source: CodebuffAI/freebuff-private@cfc7760af31f29f1acc7153a7e9fcb48d35f730b
Source: CodebuffAI/freebuff-private@6965ea40dbf54a44c932ca4df63b0dd6377bfec5
Source: CodebuffAI/freebuff-private@ecf4fa2e98fcefcec1a96cbd596b5b16bccd97e3
Source: CodebuffAI/freebuff-private@ce96ca2455d9c6a027d6e41048e8f2520f78754f
Source: CodebuffAI/freebuff-private@890653e2610c57c22298d532cae0129efb26f862
Source: CodebuffAI/freebuff-private@d60d93125f90cdca18e1fc97819b91997081a97f
Source: CodebuffAI/freebuff-private@70ba2a57ab1e48c9f799107675dfb6029dc6d54f
Source: CodebuffAI/freebuff-private@9c2be6595fa98153b9ec0474caed5ec3a58ec116
Source: CodebuffAI/freebuff-private@c1db5271ba86e1c89c3c9fc0c6e6a2a857d3b5dd
Source: CodebuffAI/freebuff-private@2846f67777f75ee23da1e3a3047176d66953d906
Source: CodebuffAI/freebuff-private@f5329a11c8431d6f5c98581c2bfc67fb2d1829ba
Source: CodebuffAI/freebuff-private@e319a9e3de31d8c4cd1d0a9285dfd5360eebb7a1
Source: CodebuffAI/freebuff-private@9cbbba39efda2071b8325bf2779b39170e35348c
Source: CodebuffAI/freebuff-private@8470da01520ea7c273efb6eca943fd37fb265189
Source: CodebuffAI/freebuff-private@884e8a41dd02bb5c0be09d8da8e465c994a6c6a4
Source: CodebuffAI/freebuff-private@b550c712e828f5211de07c5699a643fe0fa8f22e
Source: CodebuffAI/freebuff-private@ddfa6c89a27176e4e1afef0bd597077698e3d9e3
Source: CodebuffAI/freebuff-private@9b8fb92689a45c3d52b65f6d4177bb8b0e4a29db
Source: CodebuffAI/freebuff-private@e20dcb5811c89bc349a283c8fb8b474f03857eaa
Source: CodebuffAI/freebuff-private@1a9bb08ef45331c94cfa616a7e5f91dbc3375e7b
Source: CodebuffAI/freebuff-private@2204d7f013215d4a9746f87ccadb88422bdbf0ce
codebuff public sync bot and others added 26 commits August 30, 2026 08:34
Source: CodebuffAI/freebuff-private@efe3fc4ffa4cceb2138f390c606e0ed843ca13b1
Source: CodebuffAI/freebuff-private@1b7d009da0f5d71624799fb56e47503c02d66ffe
Source: CodebuffAI/freebuff-private@c7eb55ee90b22d1963385f259958535b311dd7af
Source: CodebuffAI/freebuff-private@bb7cd6f516db0f13b8a4805f6ffe45d58e108465
Source: CodebuffAI/freebuff-private@b377dd73a9a3c03ddf1d2ac30aa31041ef41c26e
Source: CodebuffAI/freebuff-private@ebefe1ed757533292b4020b6242e2e7ce3a3e7e8
Source: CodebuffAI/freebuff-private@6681195eefb64fbce00fd6c3174ea1b9c07bb101
Source: CodebuffAI/freebuff-private@3652cdfb84c76cbfd6eaf0285588958c2e9e863d
Source: CodebuffAI/freebuff-private@4c569a6b8a413f2a7ed24ccc46e1bd6d18f4def9
Source: CodebuffAI/freebuff-private@97525b97891db562584728271a39c5ffa4f88a83
Source: CodebuffAI/freebuff-private@968cf83760c8f77a39a5aedaedc04d5f7fe2c98b
Source: CodebuffAI/freebuff-private@976b89df4e302612e31320d886053088882265fa
Source: CodebuffAI/freebuff-private@d7dc76f31a8a09229134d88ad4c4e209f052808b
Source: CodebuffAI/freebuff-private@f9c01eea0ce77cd368249f7c5d74ec024a7baf91
Source: CodebuffAI/freebuff-private@3e9ad036c6f9b7f71c2127403a89ce605c53c004
Source: CodebuffAI/freebuff-private@a98e28b9a11c0e821d5171d4fed11136ddfda460
Source: CodebuffAI/freebuff-private@5de60102491d5f19108aec59ab7a0bb41f3de60a
Source: CodebuffAI/freebuff-private@ade37e50551c2230d76dffc3fd29ca7ad02bdbfc
Source: CodebuffAI/freebuff-private@2d04668b529a04c2a90806272993d5f67a1afa1f
Source: CodebuffAI/freebuff-private@2f358ebf68b79b05acb81f18ee42ef4295edee17
Source: CodebuffAI/freebuff-private@e411009a76fbd9f689550bd51bc3b938209ec6f8
Source: CodebuffAI/freebuff-private@70a710b1d0941b7bd3a742dbc8e18f276b602850
@victorxheng

ghost commented Aug 31, 2026

Copy link
Copy Markdown

Apologies — this PR was auto-closed by GitHub when we force-pushed a history rewrite of this repository (repository maintenance; every commit SHA changed). That was not a judgment on this PR, and GitHub does not allow us to reopen it because the commits it was based on no longer exist in the new history.

If you'd like to continue with this change: rebase your branch onto the new main (or recreate it from a fresh clone) and open a new PR — feel free to link back to this one for context, and we'll pick up the review there.

Sorry for the churn, and thanks for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Both weekend tests stay green if the Beijing shift is removed

4 participants