Reading notes on X's open-source For You algorithm (xai-org/x-algorithm), turned into equations, charts, and a spreadsheet model. Every claim cites a file and line in the pinned commit, and every artifact here can be regenerated from the scripts in this repo.
X open-sourced its For You recommendation code on 2026-08-13. Reading ranking code directly is useful, but some of the interactions (the score offset, the author-diversity decay, the out-of-network gates) are easier to reason about as equations and models than as Rust spread across files. So I wrote the scoring function out in full, verified every constant against the source, and built a spreadsheet where the formulas are live.
This is careful reading, not growth advice. If anything here disagrees with the code, the code wins; file an issue with the line number.
| File | What it is |
|---|---|
| ANALYSIS.md | Ten findings from the code, each with file:line citations: the mutual-follow reply boost, the out-of-network reply/retweet gates, author-diversity decay, cold start, thread collapse, quote-post treatment, the engagement-bait label chain, and a table of common advice the code contradicts |
| EQUATION.md | The complete ranking-stage scoring function written out: the weighted sum, the offset map, author diversity, the OON factor, cold start, the filter gates, and what is genuinely outside closed form |
| models/x-ranking-model.xlsx | Spreadsheet model, 6 sheets, all 214 calculations as live formulas (nothing flattened): mutual-reply component, diversity series, signal weights, cold-start gates |
| charts/ | The two charts: the equation card above and the mutual-follow reply comparison below |
| scripts/ | build_workbook.py regenerates the spreadsheet; cards/ regenerates both charts |
| sources/SOURCES.md | The exact upstream commit, every file referenced, and the citation policy |
S = γ · m(k) · φ( Σ wₐ Pₐ ) subject to surviving every filter
A weighted sum of model-predicted action probabilities, mapped to the non-negative reals, then multiplied by two penalties: one for repeating an author within a timeline load, one for being out of network or being a reply or repost. The full derivation, constants, and the order-of-operations subtlety are in EQUATION.md.
Read these before quoting anything.
- This is not a reconstruction of X's production system. It is an interpretation of the public repository at one commit. The public source does not necessarily reveal every production model, parameter override, experiment, feature, or serving behavior.
- The learned model dominates. The weights only blend probabilities predicted by a transformer (Phoenix). Its behavior is not inspectable from the repo, so no formula here predicts actual reach.
- Do not compare raw weights across action types. X's own code comment (
param.rs:279-281) says the weights combine action value with typical action base rates. A weight of 20 on one action and 0.5 on another does not mean the first "counts 40x more" in practice. - Values are runtime-configurable. X states the repo defaults are cron-synced from production, so they are representative, not guaranteed live for any given request.
- Line numbers are pinned to commit
a389166and will drift in later commits.
Claims in the documents are labeled: SOURCE FACT (code that was read), MATHEMATICAL DERIVATION (arithmetic on those facts, like the offset-map bounds), INFERENCE (my interpretation), UNKNOWN (flagged openly).
The spreadsheet (needs Python 3.9+ and openpyxl):
pip install openpyxl
python3 scripts/build_workbook.pyThe charts (needs Node 20+):
cd scripts/cards
npm install
npx playwright install chromium
npm run equation
npm run mutual-replyDerived from xai-org/x-algorithm @ a389166 (Apache-2.0). Upstream code is cited, not vendored; quotes are limited to parameter names, line references, and a few short excerpts for commentary. See sources/SOURCES.md.
The analysis, model, and scripts in this repository are MIT licensed. The MIT license covers my work only, not X's code.

