Skip to content

fix: restore x-client-transaction-id bootstrap on current X pages - #93

Open
c4nc wants to merge 2 commits into
jackwener:mainfrom
c4nc:fix/ct-home-bootstrap
Open

c4nc wants to merge 2 commits into
jackwener:mainfrom
c4nc:fix/ct-home-bootstrap

Conversation

@c4nc

@c4nc c4nc commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Restores the x-client-transaction-id header on current X pages. Since X's Sept 2026 web rebuild, the root path serves a stripped logged-out shell without the ondemand.s bundle, so ClientTransaction init fails and the header is never generated. Every header-gated GET 404s as a result:

  • SearchTimeline — twitter search (HTTP 404)
  • Followers / Following / Likes (HTTP 404)

Tracking: #69, #73, #78, #88 (all same root cause, still open).

Related PRs #74/#84/#86/#89/#90/#91 target the same bootstrap; this one is the variant verified end-to-end against the live API (2026-09-29), including the point the others miss:

Root cause — verified empirically

Request Page size ondemand.s present?
GET / no cookie 35 KB ✗
GET /home no cookie 17 KB ✗ (stripped shell)
GET /home + session cookie 305 KB ✓ (index 59924, hash map, anim frames)

Two changes are therefore both required:

  1. Bootstrap from https://x.com/home with the session cookie sent (it is the cookie that makes the page un-stripped — not just the path change).
  2. Bump xclienttransaction floor to >=1.0.3: the pinned 1.0.1 expects the old "ondemand.s": "<hash>" name→hash map; the current page uses a webpack numeric module map (59924:"ondemand.s" + separate index→hash map), which only 1.0.3 (released 2026-06-26) parses. Verified: 1.0.1 → get_ondemand_file_url returns None → AttributeError; 1.0.3 resolves the bundle and generates a valid id.

Security note: the generated id is derived from public page data (site-verification key + bundle animation frames). The bootstrap cookie is only what distinguishes the full page from the stripped shell — it does not weaken the id.

Changes

  • client.py: CT bootstrap fetches /home with Cookie: auth_token=…; ct0=… (full browser cookie string when available)
  • pyproject.toml / uv.lock: xclienttransaction >=1.0.1 → >=1.0.3
  • graphql.py: extend the queryId bundle scan to the new abs.twimg.com/x-web/x-web/* layout (entry bundle + relative ./assets/*.js chunks) — the old responsive-web/client-web-only regex matches nothing now, silently killing live queryId re-resolution
  • tests/test_client.py: offline regression tests — bootstrap hits /home with the cookie, resolves the ondemand URL, real-parser resolution of the current layout
  • tests/test_smoke.py: live smoke tests for the CT-gated reads (followers, following)

Verification

  • ruff check . — clean
  • mypy twitter_cli — clean
  • pytest -q — 245 passed (includes new CT tests; run under 1.0.1 the new parser test fails with AttributeError, under 1.0.3 it passes)
  • pytest -m smoke -v — 8/8 live API tests pass (search, feed, followers, following, user, user-posts, whoami, status) — run with a real browser cookie session
  • Manual: twitter search, followers, following, likes all return data after the fix (previously 404/422)

Note: main already routes SearchTimeline through POST (0.8.6, May), which works without the header — that's why search "half-worked" while followers/following/likes stayed broken. This fix restores the GET path and the header for all endpoints, and the bundle-scan fix restores the live queryId re-resolution fallback.

The root path now serves a lightweight logged-out shell without the
ondemand.s bundle, so the ClientTransaction bootstrap (and therefore the
x-client-transaction-id header) silently stopped working. Every
header-gated GET 404s as a result: SearchTimeline, Followers, Following,
Likes (GitHub issues jackwener#69, jackwener#73, jackwener#78, jackwener#88).

Fix, verified end-to-end against the live API on 2026-09-29:
- bootstrap from https://x.com/home instead of the root path
- send the session cookie on the bootstrap request: /home WITHOUT a
  cookie is also a stripped 17KB shell; with a cookie it is the full
  305KB page carrying the numeric module map + hash map (the header is
  derived from public page data, so the cookie does not weaken it)
- require xclienttransaction>=1.0.3: 1.0.1's regex expects the old
  '"ondemand.s": "<hash>"' name->hash layout and cannot resolve the
  current numeric module index (get_ondemand_file_url returns None ->
  AttributeError); 1.0.3 uses ',<index>:"ondemand.s"'

Adds offline regression tests for the bootstrap (route + cookie +
resolved ondemand URL) and live smoke tests for the CT-gated reads.
SearchTimeline was additionally moved to POST in 0.8.6+ (already in
main); with this fix the GET form works again too.
X moved the web build from abs.twimg.com/responsive-web/client-web/* to
abs.twimg.com/x-web/x-web/* (entry bundle + relative ./assets/*.js
chunks). The queryId bundle scan only matched the old path, so live
queryId resolution was silently dead. Match both layouts and follow the
x-web entry bundle's ./assets/*.js chunks. (The current build no longer
embeds queryId/operationName pairs, so this restores future-proofing
rather than today's queryIds — those come from the community
twitter-openapi file.)
c4nc added a commit to c4nc/twitter-cli that referenced this pull request Sep 29, 2026
…s, upstream stance)

- Banner + badges: 'Maintained fork of public-clis/twitter-cli by c4nc', CI/version
- 'About this fork': why (X Sept-2026 rebuild broke the CT header), what's in it
  (CT bootstrap, xclienttransaction>=1.0.3, x-web bundle scan, 5 cherry-picked
  community fixes), version 0.8.6
- Credits: original jackwener (Apache-2.0), xclienttransaction author, and the
  three community authors of the cherry-picked PRs; our jackwener#93 contribution
- Upstream stance: not forking to fork; archive if original resumes + ships the fix
- Install + skills sections (EN + 中文): fork = working version, upstream = PyPI
  (missing the fix); install/clone/skill commands point at c4nc
@axsddlr

axsddlr commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

I independently re-verified this PR's two central claims while triaging all 29 open PRs, and both hold up. Sharing the evidence in case it helps a maintainer decide, since this is the one PR that unblocks every header-gated read.

1. The signed-out page really has no ondemand.s. Live probes from a clean client (no credentials, since the bootstrap itself is unauthenticated):

GET https://x.com          200, 45,615 bytes, external <script src>=0  -> get_ondemand_file_url() -> None
GET https://x.com/home     200, 28,468 bytes, external <script src>=0  -> None   (stripped shell)
GET /explore, /search      200, 28,468 bytes, ext=0                    -> None

The root page is now a Vite/TanStack-Router SPA (x-web/x-web/entry-client-logged-out-*.js); the signed-out entry bundle is 18 KB of dynamic chunk imports containing zero ondemand/queryId/operationName strings. So the cookie-on-/home requirement is real, and every PR that only changes / → /home without sending the cookie (#91) still gets the stripped shell.

2. The xclienttransaction floor bump is necessary, and this PR's test actually proves it. 1.0.3's get_ondemand_file_url() has no None guard, so on a stripped page it raises AttributeError rather than returning None — caught by _ensure_client_transaction's outer except, so it degrades instead of crashing.

I forced the venv back to 1.0.1 and re-ran this PR's own suite (using --no-sync, because uv run silently re-syncs and masks it):

1.0.3 → 3 passed
1.0.1 → 2 failed:  assert None == '.../ondemand.s.38289b77fa31a72ca.js'

That is the only negative-control test in the whole cluster — the version bump is load-bearing, not cosmetic.

On CI: the red status on this PR is not a code failure. gh run view 36592386140 reports "This run likely failed because of a workflow file issue", and the run sat at 720h (GitHub's 30-day ceiling on a hung run). Locally the tree is ruff-clean, mypy-clean, and 242 passed (the 3 failures being pre-existing Windows-only browser-path tests).

Two small things that would help it land, both in #102 (independent of this PR): a job timeout-minutes so a hung CI run fails fast instead of pinning the PR for a month, and a Windows-portability fix for those browser-path tests so pytest is fully green on every host.

Caveat I could not close: no decryptable X session exists on this machine, so the 305 KB authenticated /home claim is corroborated indirectly (the library's own handle_x_migration() now targets https://x.com/home) rather than directly observed. The signed-out side and the 1.0.1-vs-1.0.3 parser delta are both directly proven.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants