Skip to content

fix(session-import): separate budget accounting failures - #4444

Closed
7Sageer wants to merge 1 commit into
mainfrom
fix/session-import-accounting
Closed

7Sageer wants to merge 1 commit into
mainfrom
fix/session-import-accounting

Conversation

@7Sageer

@7Sageer 7Sageer commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Requirement or Bug

区分导入时「预算不够」和「装完再称仍超预算」两种失败,并去掉会被覆盖的图片块计数。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

 renderHistory
   if reserve or no turn fits
     throw INSUFFICIENT_TOKEN_BUDGET
   assemble message
-  if estimate exceeds budget
-    throw Error without code  → CONVERSION_FAILED
+  if estimate exceeds budget
+    throw BUDGET_ACCOUNTING_FAILED

 makeSteps
-  image or document block: increment imageBlocks or documentBlocks
+  document block: increment documentBlocks
+  image block: do not increment
 readClaudeSession
   imageBlocks = imageReferences.contentReferences

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
装完再称仍超预算时 convertSession 的 error.code 无码,落成 CONVERSION_FAILED BUDGET_ACCOUNTING_FAILED 按这个码分支的 convertSession 调用方。CLI 导入页只显示原句,不看码 无。失败句子不变
导入页失败行 Rendered import exceeded its token budget. 同一句 使用 /import-sessions 或 kimi import-sessions 的人 无变化
stats.imageBlocks 遍历加一后被 contentReferences 覆盖 只赋值为 contentReferences 读完整历史附件里该字段的脚本。现有测试断言的就是覆盖后的数 无。发布出去的数不变

受影响模块:packages/session-import。pnpm --filter @moonshot-ai/session-import test,195 项通过。没有能打中 BUDGET_ACCOUNTING_FAILED 的现有用例,这次也不新写。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Give the post-fit over-budget check its own error code. Image block
counts stay on content references.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 13:13
@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a23920d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@7Hanrui

7Hanrui commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T13:16:28.282922Z a23920d Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: a23920d0e7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@7Sageer 7Sageer closed this Oct 26, 2026
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.

3 participants