Repository navigation
fix(ai): read long-context thresholds from models.dev tiers - #30141
etiennejouan merged 4 commits into
Conversation
|
👋 Thanks for contributing to Twenty! We're excited to have you on board. Your PR has been set to draft while you work on it. Once you're done, mark it as Ready for review and our automated checks will run. By submitting your Pull Request, you acknowledge that you agree with the terms of our Contributor License Agreement. |
[Medium impact] The PR appears safe to merge. SummaryReads long-context prices and thresholds from models.dev context tiers instead of assuming 200K tokens.
Reviews (3) · Last reviewed commit: "fix(ai): read long-context thresholds fr..." · Reviewed by Greptile |
The catalog sync gave every long-context model a 200K threshold taken from models.dev's deprecated context_over_200k field. OpenAI models switch at 272K and Claude Haiku 5.5 at 100K, which models.dev publishes only in cost.tiers. Take the threshold and rates from the lowest context tier, falling back to context_over_200k at 200K.
32d032b to
826787d
Compare
🤖 PR Review
🔍 Automated Pre-Review✅ No issues detected - This PR is ready for human review. 🧭 External PR Triage Review✅ Looks good — a maintainer can pick this up. Checks
Detailed findings (duplicate candidates, standards notes, summary) are in the workflow run logs. Automated pre-review — human approval still required. |
There was a problem hiding this comment.
LGTM. Hi @PavleProd congrats for your first contribution to twenty repo !
|
Thanks @etiennejouan, glad it was useful!!!!! :D |
|
Hey @etiennejouan, the server-integration-test failure is in application manifest sync (DEFERRED_WORKSPACE_MIGRATION_ACTIONS_IN_PROGRESS), which this PR doesn’t touch. Could you re-run the failed job when you get a chance? |
…0371) ## Summary The AI catalog sync has failed every day since 2026-10-23 at "Create pull request" with `GitHub Actions is not permitted to create or approve pull requests`. That repo setting is off on purpose (twentyhq#29028), and i18n moved to the Twenty PR app, but this workflow kept `GITHUB_TOKEN`. The last catalog sync merged was twentyhq#28593, so `ai-models.json` and `ai-providers.json` are three weeks stale and catalog builder fixes like twentyhq#30141 can't reach billing. ```diff sync-catalog # GITHUB_TOKEN, contents: write run catalog sync compose PR body - peter-evans/create-pull-request # pushes, then fails to open the PR - mint dispatcher token, trigger twenty-infra automerge + force-push chore/ai-catalog-sync +open-pull-request # permissions: {} + open-pull-request.yaml # Twenty PR app opens the PR, triggers automerge ``` The reusable `i18n-open-pull-request.yaml` becomes `open-pull-request.yaml`, since it now serves more than i18n. It gets an optional `body` input, defaulting to its current text, and refreshes the body of an already open PR, so the catalog PR keeps a current coverage report. Its CI-trigger commit is now `chore: run CI on the latest push`. The i18n callers only change the path. ## Evidence - **Before:** run 43375772095 (2026-11-13) pushes `chore/ai-catalog-sync`, then fails with `GitHub Actions is not permitted to create or approve pull requests.` **After:** oxfmt and YAML parsing pass. The push step, replayed against a bare repo holding a stale `chore/ai-catalog-sync`, force-updates it with a single commit touching only the catalog folder. The app step only runs on GitHub, so the real check is the first run after merge: a PR from `twenty-pr` with CI running. ## Merge Danger **Door:** two-way Reverting brings back the current, failing workflow. **Blast Radius:** small - Catalog PRs now come from the Twenty PR app, so they get CI and twenty-infra's automerge turns on auto-merge. Main still requires an approval and the review bot only auto-approves translations, so a human still approves each catalog PR. - The first PR carries three weeks of catalog drift. - The five i18n workflows call the renamed file and behave the same, apart from the CI-trigger commit message. Nothing outside this repo references the old name or message. - The `ai, automated` labels are dropped. Nothing reads them.
Fixes #30144
Problem
The catalog sync prices long context from models.dev's
context_over_200kand gives every model a 200K threshold (LONG_CONTEXT_THRESHOLD_TOKENS). models.dev deprecated that field on 2026-08-23 (anomalyco/models.dev#5335). The real threshold now comes fromcost.tiers[].tier.size, and it isn't always 200K:computeCostBreakdownswitches them at 200K, so a request of 200K–272K is debited at double the input rate.tiers, so the catalog has nolongContextCostfor it, and requests over 100K are debited at base rates.Debited by
computeCostBreakdowntoday, against the provider's price (90% of input cache-read, 1K output):Fix
extractCosttakes the lowestcontexttier fromcost.tiersand uses itssizeasthresholdTokens.context_over_200kat 200K when a model has no tiers.ModelsDevModelgains thetiersfield.Built against today's models.dev payload, the only catalog changes are:
Rates and the Google and xAI entries are unchanged.
ai-models.jsonandai-providers.jsonaren't regenerated here; the next daily sync rewrites them. The regenerated catalog can be added to this PR if preferred.Test plan
build-catalog.spec.ts: two new cases, a 272K tier quoted in both fields and a 100K tier quoted only intiers. Both fail onmain(200000 instead of 272000;longContextCostundefined) and pass with the fix.scripts/ai-catalog-syncandmetadata-modules/aipass, exceptbuild-front-component-shared-dependencies, which needs a localtwenty-uibuild.tsgoreports no errors in them.Written with Claude Code (Claude Opus 5.5).