Skip to content

fix(x): stream mentions through the Activity API instead of polling - #165337

Merged
steipete merged 2 commits into
mainfrom
steipete/x-activity-user-token
Oct 5, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/x-activity-user-token

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes X mention subscriptions being rejected with OauthAccessTokenRequired, forcing the plugin into polling with delays of up to a minute.

User Impact

Mentions can use the Activity stream instead of waiting for the polling interval. When X refuses Activity access, channel status includes its actual rejection reason with credentials redacted.

No configuration keys or migration are required. The bot's user OAuth grant must include tweet.read. Live delivery latency has not been measured after this fix.

Why This Change Was Made

X requires user OAuth for post.mention.create subscription creation. Create subscriptions with the refreshed user access token while retaining the app bearer for subscription listing and the persistent stream.

Successful subscription setup must also preserve delivery: consume X's documented data.event_type and data.payload envelope through the existing post validator and recipient checks. Other event types are ignored; reconnect backfill and polling fallback remain intact.

Evidence

  • Maintainer-reported live reproduction on 2026-10-05: X returned HTTP 400 OauthAccessTokenRequired when creating the mention subscription with the app bearer. This establishes the original failure, not a successful post-fix live stream.

  • X's Activity authentication documentation, stream quickstart, and event payloads define the token and envelope contracts used here.

  • Regression reproduced before the parser correction: both documented-envelope recipient-hydration cases failed because the event transport admitted no posts. The correction passes these cases and tests subscription creation followed by chunked live-stream input, recipient filtering, ignored non-mention events, keep-alives, cursor advancement, and reconnect backfill.

  • Corrected candidate: pnpm test extensions/x --maxWorkers=1 passed 71 tests in 8 files, 101.38 seconds wall time. Both extension typechecks, targeted typed lint, formatting, and diff checks passed. Individual file runs: 13 event tests in 11.34 seconds wall time; 15 API tests in 9.38 seconds. Native review checkout at 89144ec10520: 71 tests in 8 files passed, 107.91 seconds wall time. The supported SDK-build preparation timeout was increased; test deadlines were unchanged.

  • The original implementation passed the same 71 tests in 79.67 seconds, both extension typechecks, typed lint, formatting, git diff --check, and the full build. The build reported an existing advisory UI bundle overage of 49 bytes. CI run 37264606876 passed on the original authentication-only head; it is prior-head evidence, not validation of the parser correction.

  • ClawSweeper's initial P1 finding was accepted: authentication success could activate a parser that dropped documented events. The correction removes that incompatible parser path. The earlier scoped-clean review covered the authentication-only candidate; fresh review found no P0–P2 code defects in the complete working-tree candidate. Its sole index-only finding was resolved by staging the exact reviewed correction; no source bytes changed after review.

  • Final-head CI 37267188832 passed at 89144ec10520 in 373 seconds elapsed; its changed-test job took 107 seconds including setup. No CI reruns or inherited-red exception were needed.

  • ClawSweeper revision 2 confirms the delivery finding is resolved and reports no new actionable code defect. Its remaining request is authenticated live proof. Maintainer disposition: land within this work order’s non-deployment scope using the reported live rejection, published X contracts, failing-before/passing-after transport regression, local checks, and exact-head CI; retain the post-fix live-proof gap below.

Validation is at the real event-transport boundary with synthetic HTTP/stream inputs matching X's documented contract. No deployment or post-fix authenticated X subscription/delivery test has been performed. No UI layout changes or UI captures.

Keep the app bearer for listing subscriptions and opening the Activity stream. Create mention subscriptions with the refreshed user OAuth token, and report bounded, credential-redacted X error details when falling back to polling. Stream HTTP 401 and 403 also fall back with the detailed reason.

Document token ownership and fallback status. Validation: 71 X tests passed in 79.67 seconds wall time; extension production and test typechecks, typed lint, formatting, and diff checks passed. Autoreview was scoped-clean through P2.
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 5, 2026 04:41
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: x size: M labels Oct 5, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 5, 2026, 1:24 AM ET / 05:24 UTC (Revision 2).

ClawSweeper review

What this changes

The X plugin creates mention subscriptions with the bot’s user token, reads the documented Activity event envelope, and reports credential-redacted polling fallback reasons.

Merge readiness

⛔ Blocked before merge - 2 items remain

The prior delivery finding is resolved, and current main still needs this fix. No new actionable code defect was found; authenticated X contract validation remains outstanding.

Likely related people: steipete (high confidence, prior merged X plugin work).

Priority: P1
Reviewed head: 89144ec10520bc4f8c145b137a4ed8c151549251

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) PR readiness rating was derived from proof quality, review findings, security review, and reviewer confidence.
Proof confidence 🌊 off-meta tidepool Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 10 items Pinned introduced changes: Reviewed the merge-base-to-head changes in the five introduced paths, rather than attributing endpoint drift to this PR. The stale test merge was not used to claim removal of current-main behavior.
Prior finding resolved: The parser now accepts data.event_type and data.payload through the existing post validator. Stream delivery still verifies the numeric recipient before admission and cursor advancement, addressing the earlier documented-envelope delivery failure.
Authentication and diagnostics: Subscription creation uses the refreshed user token; listing and streaming retain the app bearer. Activity error bodies are bounded to 16 KiB, known credentials are redacted before truncation, and diagnostic output is limited to 512 characters.
Findings None None.
Security None None.

How this fits together

The X plugin receives mentions through Activity streaming or polling, verifies the recipient, and queues them for an allowlisted agent conversation. The agent’s answer becomes a public X reply.

flowchart TD
  A[Bot credentials] --> B[Activity subscription setup]
  B --> C[Activity stream]
  B --> D[Polling fallback]
  C --> E[Recipient checks]
  D --> F[Durable mention queue]
  E --> F
  F --> G[Allowlisted agent turn]
  G --> H[Public X reply]
Loading

Before merge

  • Resolve merge risk (P1) - Successful authenticated subscription creation followed by actual streamed mention delivery remains unverified. This matters because existing auto accounts can switch from working polling to the corrected stream path.
  • Complete next step (P2) - Add redacted after-fix authenticated X subscription and streamed mention-delivery evidence before merge.
Agent review details

Security

None.

PR surface

Source +47, Tests +140, Docs +19. Total +206 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 62 15 +47
Tests 2 159 19 +140
Docs 1 28 9 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 249 43 +206

Review metrics

Metric Value Why it matters
Production versus regression coverage production +47 net lines; tests +140 net lines Production growth primarily adds bounded, redacted diagnostics, while regression coverage exercises token selection and the corrected delivery envelope.

Merge-risk options

Maintainer options:

  1. Record authenticated X delivery (recommended)
    Provide redacted after-fix evidence that a missing subscription is created and a subsequent mention reaches the agent through the stream while polling fallback remains available.

Technical review

Best possible solution:

Keep one X transport owner with documented token selection, recipient filtering, reconnect backfill, and polling fallback, validated against authenticated X delivery.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current main sends an app bearer when creating a private mention subscription, contrary to X’s documented OAuth contract. The captured body also records the original live rejection; this review did not execute X requests.

Is this the best way to solve the issue?

Yes. Correcting token selection and the event envelope inside the existing transport is a focused repair that preserves recipient checks and fallback; authenticated contract validation is still needed.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 56acd8ce050e.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The reported authentication failure prevents the X channel from using its intended streaming workflow.
  • merge-risk: 🚨 message-delivery: Subscription success activates the corrected stream path, whose actual authenticated delivery has not yet been demonstrated.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

  • Pinned introduced changes: Reviewed the merge-base-to-head changes in the five introduced paths, rather than attributing endpoint drift to this PR. The stale test merge was not used to claim removal of current-main behavior. (89144ec10520)
  • Prior finding resolved: The parser now accepts data.event_type and data.payload through the existing post validator. Stream delivery still verifies the numeric recipient before admission and cursor advancement, addressing the earlier documented-envelope delivery failure. (extensions/x/src/events.ts:82, 89144ec10520)
  • Authentication and diagnostics: Subscription creation uses the refreshed user token; listing and streaming retain the app bearer. Activity error bodies are bounded to 16 KiB, known credentials are redacted before truncation, and diagnostic output is limited to 512 characters. (extensions/x/src/api.ts:538, 89144ec10520)
  • Independent X contract: X documents user-context OAuth with tweet.read for mention subscriptions, the data.event_type/data.payload envelope, and deletion of user-context subscriptions when OAuth access is revoked. These contracts support the implementation: https://docs.x.com/x-api/activity/introduction#event-privacy-and-authentication and https://docs.x.com/x-api/activity/event-payloads.
  • Still necessary on main: Fetched main still creates mention subscriptions with appOnly:true and uses the incompatible event parser. The latest release tree contains no extensions/x entry, so there is no verified shipped replacement for this work. (extensions/x/src/api.ts:503, 56acd8ce050e)
  • Boundary tests and live coverage: Inspected the changed authentication, diagnostic, documented-envelope, recipient-hydration, keep-alive, backfill, and fallback tests. They inject a fetch implementation and synthetic streams. The captured PR body reports 71 passing tests in 101.38 seconds and explicitly states that no post-fix authenticated X subscription or delivery test occurred; those reported runs were not executed by this review. (extensions/x/src/events.test.ts:84, 89144ec10520)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-05T04:47:00.833Z sha 070336c :: blocked before merge. :: [P1] Preserve mention delivery when subscription creation starts succeeding

Read mention posts and event types from the documented data envelope, reuse the existing post validator, and preserve recipient checks and reconnect backfill. This prevents successful subscription setup from replacing working polling with a stream that silently ignores mentions.

The documented-envelope regression failed on the old parser. All 71 X tests pass in 101.38 seconds wall time; extension typechecks and targeted lint pass. Independent review found no P0-P2 code defects in the final working-tree candidate; its index-only finding was resolved by staging the exact reviewed files.
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 5, 2026
@steipete
steipete merged commit 4bfec62 into main Oct 5, 2026
114 of 116 checks passed
@steipete
steipete deleted the steipete/x-activity-user-token branch October 5, 2026 05:32
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…penclaw#165337)

* fix(x): use user tokens for Activity subscriptions

Keep the app bearer for listing subscriptions and opening the Activity stream. Create mention subscriptions with the refreshed user OAuth token, and report bounded, credential-redacted X error details when falling back to polling. Stream HTTP 401 and 403 also fall back with the detailed reason.

Document token ownership and fallback status. Validation: 71 X tests passed in 79.67 seconds wall time; extension production and test typechecks, typed lint, formatting, and diff checks passed. Autoreview was scoped-clean through P2.

* fix(x): consume documented Activity event envelopes

Read mention posts and event types from the documented data envelope, reuse the existing post validator, and preserve recipient checks and reconnect backfill. This prevents successful subscription setup from replacing working polling with a stream that silently ignores mentions.

The documented-envelope regression failed on the old parser. All 71 X tests pass in 101.38 seconds wall time; extension typechecks and targeted lint pass. Independent review found no P0-P2 code defects in the final working-tree candidate; its index-only finding was resolved by staging the exact reviewed files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: x docs Improvements or additions to documentation merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant