Skip to content

Fix ADE chat recovery and bound Codex usage scans#796

Merged
arul28 merged 2 commits into
mainfrom
ade/need-your-because-ade-chats-7a82978c
Jul 12, 2026
Merged

Fix ADE chat recovery and bound Codex usage scans#796
arul28 merged 2 commits into
mainfrom
ade/need-your-because-ade-chats-7a82978c

Conversation

@arul28

@arul28 arul28 commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Fixes the ADE runtime stalls that orphaned Claude turns and left the Stop UI stale. Claude restart, Stop, and idle-steer paths now reconcile missing terminal events and bound SDK control calls. Codex usage history now streams JSONL with hard line, file, byte, and entry limits while preserving exact all-time totals through read-only SQLite reconciliation.\n\nValidation: quality dual review clean; desktop Node 22 typecheck passed; affected CI shards 1 and 8 passed; usage suite 130/130; agent chat suite 562/562; internal docs validated.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Claude session recovery so interrupted or incomplete conversations are finalized consistently after restart or resume.
    • Added more reliable interrupt and subagent stop handling, including safeguards for hung operations and idle runtimes.
    • Improved steer behavior while Claude continues processing.
  • Usage Tracking

    • Improved Codex usage accuracy across lifetime and recent-period summaries.
    • Added safeguards for oversized or excessive log data and improved concurrent scan handling.

Greptile Summary

This PR improves Claude chat recovery and Codex usage accounting. The main changes are:

  • Claude idle steers now keep the returned steer id tied to the delivered turn.
  • Claude restart, Stop, and model-switch paths now repair missing terminal turn events.
  • Claude interrupt and subagent stop calls now use bounded control-call timeouts.
  • Codex usage scans now cap JSONL files, bytes, lines, and entries.
  • Codex all-time totals now reconcile against read-only SQLite state.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues found in the changed code.

T-Rex T-Rex Logs

What T-Rex did

  • The desktop typecheck proof was reviewed, and the log confirms the requested command, the working directory, that the process was killed, and EXIT_CODE: 137.
  • The desktop Vitest proof was reviewed, and the log confirms the focused command, the working directory, the test summary (Test Files 3 passed (3), Tests 893 passed (893)) and EXIT_CODE: 0.
  • The artifacts containing the desktop typecheck and Vitest proof logs were attached for reviewer access.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
apps/desktop/src/main/services/chat/agentChatService.ts Propagates steer ids through prepared Claude sends, repairs orphaned parent turns, and bounds Claude control calls.
apps/desktop/src/renderer/components/chat/chatTurnState.ts Updates parent user-message detection for delivered idle-steer turns.
apps/desktop/src/renderer/components/chat/AgentChatPane.tsx Uses the shared parent user-message predicate when selecting retry input.
apps/desktop/src/main/services/usage/ledgers/localUsageLedgers.ts Adds bounded Codex JSONL scanning, single-flight production scans, and SQLite lifetime reconciliation.
apps/desktop/src/main/services/usage/usageTrackingService.ts Keeps lifetime-only reconciliation entries out of daily buckets while preserving all-time totals.

Reviews (2): Last reviewed commit: "ship: iteration 1 — address chat lifecyc..." | Re-trigger Greptile

@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ade Ignored Ignored Preview Jul 12, 2026 8:56pm

@arul28 arul28 changed the title local-runtime-action-timeout -> Primary Fix ADE chat recovery and bound Codex usage scans Jul 12, 2026
@arul28

arul28 commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

@copilot review but do not make fixes

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Claude chat lifecycle handling now reconciles unsettled turns, bounds interrupt and stop operations, and refines steering behavior. Codex usage scanning adds bounded, coalesced parsing and lifetime reconciliation, while aggregation excludes lifetime-only entries from period buckets.

Changes

Claude chat lifecycle

Layer / File(s) Summary
Restart transcript reconciliation
apps/desktop/src/main/services/chat/agentChatService.ts, apps/desktop/src/main/services/chat/agentChatService.test.ts
Unsettled parent turns are detected and terminalized during restart, with expanded coverage for partial, ancient, and orphan transcript cases.
Bounded Claude control operations
apps/desktop/src/main/services/chat/agentChatService.ts, apps/desktop/src/main/services/chat/agentChatService.test.ts
Interrupt and subagent stop calls use shared timeouts, concurrent stopping, retry logging, and idle parent-turn terminalization.
Steer dispatch behavior
apps/desktop/src/main/services/chat/agentChatService.ts, apps/desktop/src/main/services/chat/agentChatService.test.ts
Steering awaits dispatch acceptance while delaying the final done event until the provider turn completes.

Local usage ledger scanning

Layer / File(s) Summary
Bounded Codex log scanning
apps/desktop/src/main/services/usage/ledgers/localUsageLedgers.ts, apps/desktop/src/main/services/usage/usageTrackingService.test.ts
Codex scans support configurable line and entry limits, shared in-flight scans, aggregate file-size budgets, and oversized JSONL-line skipping.
Bounded lifetime reconciliation
apps/desktop/src/main/services/usage/ledgers/localUsageLedgers.ts, apps/desktop/src/main/services/usage/usageTrackingService.test.ts
JSONL and SQLite Codex totals are reconciled within result capacity, with lifetime-only remainder entries preserving exact totals.
Lifetime-only aggregation
apps/desktop/src/main/services/usage/ledgers/localUsageLedgers.ts, apps/desktop/src/main/services/usage/usageTrackingService.ts, apps/desktop/src/main/services/usage/usageTrackingService.test.ts
Lifetime-only entries contribute exclusively to all-time totals and are excluded from daily and preset-period buckets.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • arul28/ADE#175: Related Claude session resume, teardown, and transcript reconciliation changes.
  • arul28/ADE#763: Related Claude lifecycle and reconciliation work.
  • arul28/ADE#791: Related Claude SDK turn lifecycle and steering changes.

Suggested labels: desktop, docs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main change areas: ADE chat recovery and bounded Codex usage scans.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ade/need-your-because-ade-chats-7a82978c

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@arul28
arul28 force-pushed the ade/need-your-because-ade-chats-7a82978c branch from 191ef0e to ae1946a Compare July 12, 2026 20:15
@arul28

arul28 commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: ae1946aa0e

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/desktop/src/main/services/chat/agentChatService.ts (1)

29936-29946: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant prepareSendMessage call for the Claude non-busy steer path.

steer() computes preparedSteer via prepareSendMessage({sessionId, text: trimmed, ...}) (without reasoningEffort/executionMode/interactionMode), but for the Claude non-busy branch that result is discarded entirely in favor of a fresh sendMessage({...}, { awaitDispatch: true }) call using the raw args (this time including those three fields). prepareSendMessage does non-trivial work (lane launch-context resolution, per-attachment path validation via resolvePathWithinRoot), so it runs twice for this path. Since preparedSteer isn't reused here, consider either building it with the full field set once and passing it through, or deferring prepareSendMessage/preparedSteer computation until after the branch decision is made.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/desktop/src/main/services/chat/agentChatService.ts` around lines 29936 -
29946, Avoid the duplicate prepareSendMessage work in steer() for the Claude
non-busy path. Either defer preparedSteer creation until after branch selection,
or construct it once with reasoningEffort, executionMode, and interactionMode
and reuse it for sendMessage instead of passing raw arguments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/desktop/src/main/services/chat/agentChatService.ts`:
- Around line 23753-23757: The unconditional reconcileClaudeSessionAfterRestart
call in ensureClaudeSessionRuntime can emit duplicate interrupted status/done
events during Claude model switches. Distinguish genuine host-restart recovery
from non-restart model-switch teardown by skipping the restart sweep for the
latter, or record the terminalized turnId in the existing duplicate-interrupt
guard so the new runtime suppresses it; add coverage for a mid-stream model
switch and verify only one interrupted pair is emitted.

---

Nitpick comments:
In `@apps/desktop/src/main/services/chat/agentChatService.ts`:
- Around line 29936-29946: Avoid the duplicate prepareSendMessage work in
steer() for the Claude non-busy path. Either defer preparedSteer creation until
after branch selection, or construct it once with reasoningEffort,
executionMode, and interactionMode and reuse it for sendMessage instead of
passing raw arguments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0deea6d0-cc1c-4221-aec0-d8fda5b08eba

📥 Commits

Reviewing files that changed from the base of the PR and between c76c075 and 191ef0e6e1bf56a98c020f243abefff0adb72316.

⛔ Files ignored due to path filters (4)
  • docs/features/chat/README.md is excluded by !docs/**
  • docs/features/chat/transcript-and-turns.md is excluded by !docs/**
  • docs/features/onboarding-and-settings/README.md is excluded by !docs/**
  • docs/features/onboarding-and-settings/usage-tracking.md is excluded by !docs/**
📒 Files selected for processing (5)
  • apps/desktop/src/main/services/chat/agentChatService.test.ts
  • apps/desktop/src/main/services/chat/agentChatService.ts
  • apps/desktop/src/main/services/usage/ledgers/localUsageLedgers.ts
  • apps/desktop/src/main/services/usage/usageTrackingService.test.ts
  • apps/desktop/src/main/services/usage/usageTrackingService.ts

Comment thread apps/desktop/src/main/services/chat/agentChatService.ts
Comment thread apps/desktop/src/main/services/chat/agentChatService.ts
@arul28

arul28 commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: bcb3854a0d

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

@arul28
arul28 merged commit 2a0af1b into main Jul 12, 2026
33 checks passed
@arul28
arul28 deleted the ade/need-your-because-ade-chats-7a82978c branch July 16, 2026 18:21
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