Skip to content

Reliable Long-Session Recovery and Turn Cost Tracking / 可靠的长会话恢复与本轮费用统计#2299

Open
SivanCola wants to merge 2 commits into
esengine:mainfrom
SivanCola:codex/fix-2287-cost-guards
Open

Reliable Long-Session Recovery and Turn Cost Tracking / 可靠的长会话恢复与本轮费用统计#2299
SivanCola wants to merge 2 commits into
esengine:mainfrom
SivanCola:codex/fix-2287-cost-guards

Conversation

@SivanCola
Copy link
Copy Markdown
Contributor

Summary

  • Use AppendOnlyLog.totalLength when marking the start of a turn so discardCurrentTurn does not truncate long sessions after the log window is applied.
  • Add a regression test that aborts a turn after the in-memory window is exceeded and verifies prior history is preserved.
  • Split status bar cost display into current turn cost and cumulative session cost for desktop/dashboard.

Root-cause notes for #2287

The concrete correctness bug found in this area is the abort/discard index: after the windowed AppendOnlyLog change, this.log.length is only the retained window size, not the full persisted history length. If an explicit abort with discardCurrentTurn happens in a long session, the rewrite can slice at the wrong index and drop persisted history outside the current window. That changes future prompt prefixes and can damage cache behavior.

I did not find the proposed stripDroppableReasoningContent explanation to be the primary cause of every tool-call iteration becoming a full cache miss: the strip path skips assistant messages with tool_calls, and ordinary assistant messages stripped before their first inclusion in a later request do not invalidate a previously sent prefix that already contained them. Missing required reasoning_content for historical thinking-mode assistant messages would also be more likely to surface as a request-shape error than as a silent full-cache-miss loop.

Verification

  • npm run test -- tests/loop-user-persist.test.ts desktop/src/App.test.ts desktop/src/ui/context-panel.test.tsx tests/desktop-btw-status.test.ts tests/desktop-user-message.test.ts
  • npm run typecheck
  • npm --prefix desktop run build
  • npm --prefix dashboard run build
  • npm run lint (passes with existing PlanPanel.tsx import-type warning)
  • pre-push npm run verify: build, lint, typecheck, and full test suite passed (314 test files, 4042 tests passed, 9 skipped); the first push attempt failed only at the final GitHub TLS send-pack step and was retried with --no-verify after verification had completed.

Related to #2287.

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: d7a591aba9

ℹ️ 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".

Comment thread dashboard/src/App.tsx Outdated
@SivanCola SivanCola changed the title fix(loop): preserve long-session history on abort Reliable Long-Session Recovery and Turn Cost Tracking / 可靠的长会话恢复与本轮费用统计 May 29, 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.

1 participant