Repository navigation
feat(x): enforce daily and monthly X API cost limits - #165351
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed October 5, 2026, 5:26 AM ET / 09:26 UTC (Revision 5). ClawSweeper reviewWhat this changesThe X plugin adds persistent account spending limits, budget-aware reads and replies, resumable mention processing, and operator-visible spend totals. Merge readiness⛔ Blocked before merge - 3 items remain The work remains useful and is not implemented on main. No concrete introduced code defect was found, but the repository’s external-API proof requirement remains unresolved. Priority: P2 Review scores
Verification
How this fits togetherThe X plugin turns mentions into agent requests and posts public replies. Its API client now reserves estimated costs through a shared account ledger before dispatch, while its monitor preserves mentions during budget pauses. flowchart TD
A[X mentions and reply requests] --> B[X plugin API client]
C[Account spending limits] --> D[Persistent spend ledger]
B --> D
D --> E{Request affordable?}
E -->|Yes| F[X API and cost settlement]
E -->|No| G[Pause reads or refuse replies]
F --> H[Agent delivery and operator status]
G --> H
Decision needed
Why: The repository requires live external-API proof; accepting storage, UI, and controlled transport evidence instead requires explicit human authorization. Before merge
Agent review detailsSecurityNone. PR surfaceSource +971, Tests +1533, Docs +87, Generated 0. Total +2591 across 37 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one conservative spending ledger with clear operator-visible pauses and demonstrated bounded X requests for fresh and retained accounts. Do we have a high-confidence way to reproduce the issue? Not applicable to the spending-control feature; source confirms main lacks account budgets and requests up to 100 conversation results. Is this the best way to solve the issue? Yes, one plugin-owned reservation ledger is a maintainable approach; storage compatibility is supported, while the changed external contract still needs scoped proof or an exception. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 10080eaf91bc. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
5b98668 to
6a9d778
Compare
6a9d778 to
cedd352
Compare
|
Merged via squash.
|
69 upstream commits. Upstream's X cost limits (openclaw#165351) add 8 channel config entries. Upstream also reworked extensions/feishu/src/async.ts (openclaw#165340) and pruned Feishu tests in bot.*.test.ts and monitor.*.test.ts (openclaw#165438). This branch touches none of those files, and none of the 12 removed test names appears in the test files this branch adds. Three generated files conflicted, docs/.generated/config-baseline.counts.json, config-baseline.sha256 and src/config/bundled-channel-config-metadata.generated.ts. All three were regenerated from this merge rather than hand-merged. build:docker ran in a separate detached checkout of this commit. Counts are core 2505, channel 3874 and plugin 4490, which is upstream's counts plus this branch's two channel entries. The core and plugin hashes match upstream/main and the channel hash is new, as predicted. The three generated-file checks pass there. Feishu: 101 files and 1520 tests in the extension project, 17 files and 218 tests in the database-workers project, all passing. Both counts are lower than before this merge only because of upstream's pruning, which deletes bot.stripBotMention.test.ts and trims bot.test.ts. The merge leaves every Feishu test file this branch adds or changes untouched. The forwarder test and the routing guards pass, 503 tests. tsgo:core, tsgo:extensions, tsgo:extensions:test, tsgo:test:root, the line-cap, max-lines, assertion-safety, database-worker, test-timeout-race and test-mock-exports ratchets against upstream/main, oxlint and oxfmt on the 43 changed code files all pass.
What Problem This Solves
The X channel could make paid API calls without an account budget, including fetching 100 conversation posts when much less context was requested.
User Impact
Accounts default to $100 per UTC day and $1,000 per billing cycle, with inherited
costLimits.dailyUsd,monthlyUsd, andcycleStartDaysettings. Zero blocks paid calls. Channel status and the X replies page show spend, limits, and reset timing. Unaffordable polls pause, thread context degrades with an explicit notice, and unaffordable replies fail without retries.Activity streaming closes below a fixed $0.50 headroom and uses gated polling until reset. Already delivered events remain charged and admitted, so a provider burst can exceed a limit; headroom reduces that risk but is not a hard bound. Model tokens are outside these limits.
Why This Change Was Made
One plugin-owned SQLite ledger persists integer micro-dollar reservations before dispatch and serializes account mutations. Responses settle against returned resources; lost responses, 5xx, malformed successes, and interrupted reservations retain their maximum cost. Cross-midnight requests count toward both days but once within a shared cycle, including after restart.
Search respects the requested context allowance, and mentions use ten-post pages with a persisted continuation. Received mentions survive budget pauses and recoverable backfill, recipient, and pagination errors. Invalid continuations are cleared without advancing the cursor; uncertain recipients remain queued for verification.
Accounting deliberately ignores X's daily resource deduplication and counts expanded users, including Activity expansions, because their billing is unconfirmed. X's Activity and pricing pages disagree about
post.delete; allpost.*events are conservatively counted. Published rate inputs come from the maintainer's verified pricing facts and are documented in one module.Evidence
pnpm test extensions/x --maxWorkers=1). After final lint cleanup, all 46 affected transport/monitor tests passed again in 54.45 seconds. Both extension typechecks were rerun and passed.The full build passed before conflict integration (1 hour 19 seconds, mostly declaration generation); affected tests and static checks were rerun afterward. Conflicts were resolved while retaining Activity authentication/envelopes (#165337), guest mode (#165354), and periodic backfill/unparsed-event diagnostics (#165376). Only polls advance the cursor; an in-flight paid poll settles before stream teardown. Guest quota admission follows deferred-recipient verification. Generated config/UI metadata and guest-aware before/after screenshots were refreshed.
Fresh full-scope independent Codex review is scoped-clean at P2 and above. Replacement head:
cedd3524651ae14b2694928047ba2d1f5eede2d7. The exact-head native review checkout passed all 171 tests in 104.39 seconds. CI run 37289170037 passed in 489 seconds (43 jobs passed, 23 skipped), and Security Review 37288987038 passed. Native review artifacts validate with zero findings. Both final PR images render correctly.