refactor(context): context双阈值预算预警实现#172
Conversation
internal/agent/runner.go
Outdated
| if compactErr != nil { | ||
| return "", compactErr | ||
| requestTokens := int(tokenusage.ApproximateRequestTokens(messages)) | ||
| compacted, compactErr := r.maybeAutoCompactSession(ctx, sess, promptTokens, requestTokens) |
There was a problem hiding this comment.
maybeAutoCompactSession now runs on every loop iteration (the previous step == 0 gate was removed). In tool-heavy turns, this can compact mid-run and summarize away structured tool_result messages, which risks changing tool-loop behavior before the final assistant answer. Consider restricting auto-compaction to pre-first-turn (or preserving latest tool-result context explicitly) to avoid semantic loss.
internal/agent/runner.go
Outdated
| requestTokens := int(tokenusage.ApproximateRequestTokens(messages)) | ||
| compacted, compactErr := r.maybeAutoCompactSession(ctx, sess, promptTokens, requestTokens) | ||
| if compactErr != nil { | ||
| retried, retryErr := r.retryAfterPromptTooLong(ctx, sess, out, compactErr, &reactiveRetries, maxReactiveRetries) |
There was a problem hiding this comment.
When preflight compaction returns local prompt too long (from promptTokens), this path still attempts reactive compaction/retry. Because the latest user message is preserved, retries often cannot reduce the offending token source and can add avoidable compaction round-trips. Consider bypassing reactive retry for locally generated prompt-too-long preflight errors.
|
|
||
| func IsContextTooLongMessage(message string) bool { | ||
| message = strings.ToLower(strings.TrimSpace(message)) | ||
| if message == "" { |
There was a problem hiding this comment.
IsContextTooLongMessage relies on broad substring hints (for example "context window", "too many tokens") over arbitrary error text. This can misclassify unrelated failures as context-too-long and trigger unnecessary reactive compaction/retry. Consider tightening classification order (provider code/status first, then narrower fallback matching).
Review Findings
Validation
SummaryReview completed with 3 findings above. No code changes were made. |
|
@xgopilot 所以现在这个pr需要大改吗,还是只需小修复让其通过ci合pr检测即可? |
结论不需要大改,属于小修复范围。 当前这版我本地跑了: 但为了避免合入后出现行为风险,建议至少补这 2 个关键点(都可定点修改,不是重构级):
另一个是低优先级改进:
回答你的问题
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
@xgopilot 现在能够合并了吗 还有什么大问题吗 |
结论可以合并,从代码风险角度看目前没有阻塞级大问题。 Review Findings
已核对项
|
No description provided.