Skip to content

DeepSeek: add web-session usage and cost summary#1166

Open
Yuxin-Qiao wants to merge 1 commit into
steipete:mainfrom
Yuxin-Qiao:feature/deepseek-usage-cost-summary
Open

DeepSeek: add web-session usage and cost summary#1166
Yuxin-Qiao wants to merge 1 commit into
steipete:mainfrom
Yuxin-Qiao:feature/deepseek-usage-cost-summary

Conversation

@Yuxin-Qiao
Copy link
Copy Markdown
Contributor

Summary

Add a DeepSeek web-session usage/cost summary alongside the existing DeepSeek balance display.

This uses the DeepSeek dashboard endpoints observed from the web console:

  • https://platform.deepseek.com/api/v0/usage/amount?month=<month>&year=<year>
  • https://platform.deepseek.com/api/v0/usage/cost?month=<month>&year=<year>

The existing balance endpoint remains unchanged on https://api.deepseek.com/user/balance.

What changed

  • Adds defensive DeepSeek amount/cost response models and aggregation parser.
  • Fetches usage/cost summary only as an optional dashboard/session enhancement.
  • Shows compact DeepSeek usage dashboard data:
    • Today tokens/cost
    • This month tokens/cost
    • Request count
    • Top model
    • Cache-hit input, cache-miss input, and output token breakdown
  • Keeps the existing DeepSeek balance display unchanged.
  • Silently hides the usage/cost section on 401/403/network error/schema drift/parse failure.

Safety

  • Does not persist raw usage rows.
  • Does not log or render Authorization headers, cookies, bearer tokens, x-ds-trace-id, account IDs, emails, or raw credential material.
  • Test fixtures use synthetic redacted data only.

Testing

  • swift build — passed
  • swift test --filter "DeepSeekUsageCostParserTests" — passed
  • swift test --filter "DeepSeekUsageFetcherTests" — passed
  • swift test --filter "MiniMax" — passed
  • swift test — passed, 2956 tests
  • ./Scripts/lint.sh lint — passed, 0 violations

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 26a4ffed37

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Try to fetch usage summary, but don't fail if it errors - balance display takes priority
var usageSnapshot = usage
do {
let usageSummary = try await DeepSeekUsageFetcher.fetchUsageSummary(apiKey: apiKey)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Return balance result without awaiting optional summary

The summary fetch is optional, but this await makes the whole DeepSeek fetch path block on two extra network calls before returning any result. Because fetchUsageSummary performs fetchAmount and fetchCost sequentially and each request uses a 15s timeout, a slow or degraded platform.deepseek.com can delay a successful balance response by up to ~30s, which contradicts the stated “balance display takes priority” behavior and makes the provider appear hung.

Useful? React with 👍 / 👎.

Comment on lines +294 to +296
let summary = try DeepSeekUsageFetcher._parseUsageSummaryForTesting(
amountData: Data(amountJSON.utf8),
costData: Data(costJSON.utf8))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Make date-sensitive DeepSeek aggregation tests deterministic

These assertions depend on today matching the fixture date (2026-05-26), but the test call does not inject a fixed clock, so parsing uses Date() and will fail as soon as the real date changes. This introduces a time-based CI failure that is unrelated to code correctness; pass an explicit now/calendar into the parser path used by this test.

Useful? React with 👍 / 👎.

@Yuxin-Qiao Yuxin-Qiao force-pushed the feature/deepseek-usage-cost-summary branch from 26a4ffe to c0651d9 Compare May 26, 2026 13:10
@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented May 26, 2026

Codex review: needs real behavior proof before merge. Reviewed May 26, 2026, 1:33 PM ET / 17:33 UTC.

Summary
Review failed before ClawSweeper could summarize the requested change.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Review metrics: none identified.

Merge readiness
Overall: 🌊 off-meta tidepool
Proof: 🌊 off-meta tidepool
Patch quality: 🌊 off-meta tidepool
Result: rating does not apply to this item.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • No close action taken because the review did not complete.

Maintainer options:

  1. Decide the mitigation before merge
    Retry the Codex review after fixing the execution failure.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge
Review did not complete, so no work-lane recommendation was made.

Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

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

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 8fccb454acbb.

Label changes

Label changes:

  • add rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🌊 off-meta tidepool, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status no longer selects a status label.
  • remove P2: Current review triage priority is none.
  • remove merge-risk: 🚨 security-boundary: Current PR review selected no merge-risk labels.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.

Label justifications:

  • rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
Evidence reviewed

What I checked:

  • failure reason: timeout.
  • codex failure detail: Codex review failed for this PR: spawnSync codex ETIMEDOUT.
  • codex stdout: Per-item Codex failure; continuing with the rest of the shard.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels May 26, 2026
@Yuxin-Qiao Yuxin-Qiao force-pushed the feature/deepseek-usage-cost-summary branch 4 times, most recently from 7e3fc62 to e4570be Compare May 26, 2026 17:05
@Yuxin-Qiao Yuxin-Qiao force-pushed the feature/deepseek-usage-cost-summary branch from e4570be to 6ec5719 Compare May 26, 2026 17:22
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P2 Normal priority bug or improvement with limited blast radius. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant