-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(cli): map rewind turns after compression #4242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
becf439
2d226b2
09d4888
66ce9c3
c24c8cc
293d377
f3f767b
3e03ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -74,7 +74,11 @@ import type { ApprovalModeValue } from './session/types.js'; | |||||||||||
| import { z } from 'zod'; | ||||||||||||
| import type { CliArgs } from '../config/config.js'; | ||||||||||||
| import { loadCliConfig } from '../config/config.js'; | ||||||||||||
| import { Session, buildAvailableCommandsSnapshot } from './session/Session.js'; | ||||||||||||
| import { | ||||||||||||
| Session, | ||||||||||||
| buildAvailableCommandsSnapshot, | ||||||||||||
| type HistorySnapshot, | ||||||||||||
| } from './session/Session.js'; | ||||||||||||
| import { | ||||||||||||
| formatAcpModelId, | ||||||||||||
| parseAcpBaseModelId, | ||||||||||||
|
|
@@ -1541,7 +1545,24 @@ class QwenAgent implements Agent { | |||||||||||
| 'Invalid or missing sessionId', | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
| if (!Array.isArray(history)) { | ||||||||||||
| const isHistorySnapshot = | ||||||||||||
| !!history && | ||||||||||||
| typeof history === 'object' && | ||||||||||||
| !Array.isArray(history) && | ||||||||||||
| Array.isArray((history as { history?: unknown }).history) && | ||||||||||||
| Number.isInteger( | ||||||||||||
| (history as { modelFacingUserTurnCount?: unknown }) | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Critical] 空历史快照被接受,可静默清空整个会话。
Suggested change
— DeepSeek/deepseek-v4-pro via Qwen Code /review |
||||||||||||
| .modelFacingUserTurnCount, | ||||||||||||
| ) && | ||||||||||||
| Number.isFinite( | ||||||||||||
| (history as { modelFacingUserTurnCount?: unknown }) | ||||||||||||
| .modelFacingUserTurnCount as number, | ||||||||||||
| ) && | ||||||||||||
| ((history as { modelFacingUserTurnCount?: unknown }) | ||||||||||||
| .modelFacingUserTurnCount as number) >= 0 && | ||||||||||||
| ((history as { modelFacingUserTurnCount?: unknown }) | ||||||||||||
| .modelFacingUserTurnCount as number) <= Number.MAX_SAFE_INTEGER; | ||||||||||||
| if (!Array.isArray(history) && !isHistorySnapshot) { | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: No upper bound validation for The validation checks If
Fix: Add an upper bound check, e.g.: && ((history as { modelFacingUserTurnCount?: unknown })
.modelFacingUserTurnCount as number) <= MAX_REASONABLE_TURN_COUNTOr validate against Reviewed by mimo-v2.5-pro
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: No upper bound validation for The validation checks If
Fix: Add an upper bound check, e.g.: && ((history as { modelFacingUserTurnCount?: unknown })
.modelFacingUserTurnCount as number) <= MAX_REASONABLE_TURN_COUNTOr validate against Reviewed by mimo-v2.5-pro |
||||||||||||
| throw RequestError.invalidParams( | ||||||||||||
| undefined, | ||||||||||||
| 'Invalid or missing history', | ||||||||||||
|
|
@@ -1555,7 +1576,7 @@ class QwenAgent implements Agent { | |||||||||||
| ); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| session.restoreHistory(history as Content[]); | ||||||||||||
| session.restoreHistory(history as Content[] | HistorySnapshot); | ||||||||||||
| return { success: true }; | ||||||||||||
| } | ||||||||||||
| case 'getAccountInfo': { | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Critical]
isHistorySnapshotguard acceptsNaN,Infinity,-Infinity, negative, and non-integer values formodelFacingUserTurnCount.typeof NaN === 'number'istruein JS. A malformed ACP client can send{history: [...], modelFacingUserTurnCount: NaN}which permanently poisons the session —Math.max(NaN, ...)propagatesNaNthrough all downstream arithmetic in#computeApiTruncationIndexForUserTurn, making every futurerewindToTurnfail silently.Number.isInteger()rejectsNaN,Infinity, floats, and the>= 0rejects negatives — matching the existing validation pattern fortargetTurnIndexat line 1004.— mimo-v2.5-pro via Qwen Code /review