Skip to content

Commit 314842d

Browse files
authored
fix(data): keep sparse early days from breaking the new model user estimate (#66561)
1 parent 6f707fe commit 314842d

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

‎packages/data/app/src/lib/estimate-users.ts‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export function estimateUsersSinceLaunch(input: { daily: Day[]; weekly: Week[];
3434
: 1,
3535
)
3636
const fit = search(days, activity, targets)
37-
if (!fit) return fallback
3837
const total = fit.adopters.reduce((sum, value, index) => (days[index]!.date >= input.launch ? sum + value : sum), 0)
3938
return Math.round(Math.min(Math.max(total, floor), fallback))
4039
}
@@ -47,11 +46,8 @@ function search(days: Day[], activity: number[], targets: { start: number; end:
4746
const best = (regulars: number[], chances: number[]) =>
4847
regulars
4948
.flatMap((regular) => chances.map((chance) => simulate(days, activity, targets, regular, chance)))
50-
.reduce<
51-
ReturnType<typeof simulate>
52-
>((top, item) => (item && (!top || item.error < top.error) ? item : top), undefined)
49+
.reduce((top, item) => (item.error < top.error ? item : top))
5350
const coarse = best(grid(undefined, 0.05), grid(undefined, 0.05))
54-
if (!coarse) return undefined
5551
return best(grid(coarse.regular, 0.01), grid(coarse.chance, 0.01))
5652
}
5753

@@ -66,12 +62,14 @@ function simulate(
6662
// earlier[t]: adopters before day t, each weighted by the chance they are still around on day t.
6763
const earlier: number[] = []
6864
const adopters: number[] = []
69-
for (const [index, day] of days.entries()) {
65+
// Returning users the day can't hold. Small days are noisy (one user, then none), so a shortfall is a miss to fit
66+
// away rather than a reason to rule the parameters out.
67+
const shortfall = days.reduce((sum, day, index) => {
7068
earlier.push(index === 0 ? 0 : STAY * (earlier[index - 1]! + adopters[index - 1]!))
7169
const value = day.users - regular * chance * activity[index]! * earlier[index]!
72-
if (value < 0) return undefined
73-
adopters.push(value)
74-
}
70+
adopters.push(Math.max(0, value))
71+
return sum + Math.min(0, value) ** 2
72+
}, 0)
7573
const error = targets.reduce((sum, target) => {
7674
// Chance that a regular still around on the week's first day uses the model at least once that week.
7775
const back = Array.from({ length: target.end - target.start + 1 }, (_, offset) => target.start + offset).reduce(
@@ -82,9 +80,16 @@ function simulate(
8280
{ chance: 0, unseen: 1 },
8381
).chance
8482
const fresh = adopters.slice(target.start, target.end + 1).reduce((total, value) => total + value, 0)
85-
return sum + ((fresh + regular * back * earlier[target.start]! - target.users) / target.users) ** 2
83+
return sum + (fresh + regular * back * earlier[target.start]! - target.users) ** 2
8684
}, 0)
87-
return { error, regular, chance, adopters }
85+
// Misses are measured against all weeks together: per-week shares would let a near-empty early-access week, where
86+
// one user is a 100% miss, outweigh the weeks that hold the launch.
87+
return {
88+
error: (error + shortfall) / targets.reduce((sum, target) => sum + target.users ** 2, 0),
89+
regular,
90+
chance,
91+
adopters,
92+
}
8893
}
8994

9095
function isoAfter(date: string, days: number) {

‎packages/data/app/test/estimate-users.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ describe("estimateUsersSinceLaunch", () => {
4646
expect(users).toBeLessThanOrEqual(185_512)
4747
})
4848

49+
// LongCat-2.5 on opencode.ai/data at 2026-11-26: two users the week before real usage began.
50+
test("keeps a near-empty early week from deciding the fit", () => {
51+
const daily = [
52+
1, 0, 0, 0, 1, 0, 0, 3000, 6500, 6500, 5900, 6100, 5500, 5300, 5700, 5800, 5800, 5800, 6200, 5600, 4400,
53+
].map((users, index) => ({ date: new Date(Date.UTC(2026, 10, 2 + index)).toISOString().slice(0, 10), users }))
54+
const weekly = [
55+
{ week: "2026-11-02", users: 1 },
56+
{ week: "2026-11-09", users: 23000 },
57+
{ week: "2026-11-16", users: 23000 },
58+
]
59+
60+
const users = estimateUsersSinceLaunch({ daily, weekly, firstSeen: "2026-11-02", launch: "2026-11-02" })
61+
62+
expect(users).toBeGreaterThan(30_000)
63+
expect(users).toBeLessThan(40_000)
64+
})
65+
4966
test("adds up the weeks when no week lines up with the days", () => {
5067
expect(estimateUsersSinceLaunch({ ...hy4, daily: [] })).toBe(185_512)
5168
expect(estimateUsersSinceLaunch({ ...hy4, firstSeen: "2026-11-01", daily: hy4.daily.slice(2) })).not.toBeNaN()

0 commit comments

Comments
 (0)