Skip to content

fix: 8 tuning session bugs — data loss, stale state, missing TF metrics#432

Merged
eddycek merged 2 commits intomainfrom
fix/tuning-session-bugs
Apr 11, 2026
Merged

fix: 8 tuning session bugs — data loss, stale state, missing TF metrics#432
eddycek merged 2 commits intomainfrom
fix/tuning-session-bugs

Conversation

@eddycek
Copy link
Copy Markdown
Owner

@eddycek eddycek commented Apr 11, 2026

Summary

Comprehensive review found 8 bugs in tuning session data flow. Fixes:

Data loss (main process):

  • archiveSession() now copies verificationTransferFunctionMetrics (Flash Tune TF verification was permanently lost)
  • archiveSession() now copies recommendationTraces (telemetry data was lost)
  • updateRecordVerification() + IPC handler accept TF metrics for history reanalysis
  • commitVerification() passes TF metrics to updateHistoryVerification() call

Stale state (renderer):

  • isReanalyze reset after use — prevented quality gate from showing on 2nd verification attempt
  • pendingVerification cleared on: wizard exit, session dismiss, session phase change
  • verificationPickerLogId cleared on session dismiss
  • All isReanalyze references use local snapshot to prevent reading stale React state

Test plan

  • 3111 unit tests pass, 0 TS errors
  • New test: archiveSession includes verificationTransferFunctionMetrics + recommendationTraces
  • Manual: complete Flash Tune → verify TF verification metrics in history JSON

🤖 Generated with Claude Code

Main process:
- archiveSession() now copies verificationTransferFunctionMetrics
  and recommendationTraces to history records (Flash Tune data was lost)
- updateRecordVerification() accepts TF metrics parameter
- TUNING_UPDATE_HISTORY_VERIFICATION handler passes TF metrics through

IPC/preload:
- updateHistoryVerification signature includes TF metrics parameter

Renderer:
- isReanalyze reset after use (prevented quality gate on 2nd attempt)
- pendingVerification cleared on: wizard exit, session dismiss, phase change
- verificationPickerLogId cleared on dismiss
- commitVerification passes TF metrics to history record updates
- All isReanalyze references use local snapshot (not stale state)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 11, 2026 13:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes multiple tuning-session data flow issues across renderer ↔ preload ↔ main so verification metrics (including Flash Tune transfer-function verification) and recommendation telemetry are preserved and can be re-applied during history reanalysis, while also reducing stale renderer state during verification flows.

Changes:

  • Extend updateHistoryVerification IPC/API to include transfer-function verification metrics end-to-end (renderer → preload → main → history storage).
  • Archive additional session fields into history (verificationTransferFunctionMetrics, recommendationTraces) and add a regression test.
  • Reset several renderer-side verification states on dismiss/phase changes and avoid stale React state reads during verification analysis.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/shared/types/ipc.types.ts Adds TF verification metrics parameter to updateHistoryVerification API type.
src/renderer/App.tsx Clears more verification UI state on certain transitions; passes TF metrics through history-update path; snapshots isReanalyze to avoid stale reads.
src/preload/index.ts Forwards new TF verification metrics arg through IPC invoke.
src/main/storage/TuningHistoryManager.ts Archives TF verification metrics + recommendation traces; supports updating TF verification metrics on a specific record.
src/main/storage/TuningHistoryManager.test.ts Adds regression test ensuring new fields are archived.
src/main/ipc/handlers/tuningHandlers.ts Extends IPC handler to accept and persist TF verification metrics for record updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/renderer/App.tsx
// Clear stale verification state when session changes (disconnect, reset, new session)
const sessionPhase = tuning.session?.phase;
useEffect(() => {
setPendingVerification(null);
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

The new sessionPhase effect only clears pendingVerification, but other verification-related UI state can remain set across session/profile changes (e.g., verificationPickerLogId keeps VerificationSessionModal open, and reanalyzeHistoryRecordId/isReanalyze can leak into the next flow). Consider clearing verificationPickerLogId, reanalyzeHistoryRecordId, and isReanalyze in the same effect so any session change fully resets verification UI state.

Suggested change
setPendingVerification(null);
setPendingVerification(null);
setVerificationPickerLogId(null);
setReanalyzeHistoryRecordId(null);
setIsReanalyze(false);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 3851eab — useEffect now clears all verification state together.

Comment thread src/renderer/App.tsx
setErasedForPhase(null);
setPendingVerification(null);
setVerificationPickerLogId(null);
setIsReanalyze(false);
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

In the 'dismiss' action you clear pendingVerification/verificationPickerLogId/isReanalyze, but reanalyzeHistoryRecordId is left intact. If the user previously started a history reanalysis (sets reanalyzeHistoryRecordId) and then dismisses/resets, the next verification analysis can incorrectly be treated as a history update and overwrite the wrong record. Clear reanalyzeHistoryRecordId here as part of the reset.

Suggested change
setIsReanalyze(false);
setIsReanalyze(false);
setReanalyzeHistoryRecordId(null);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 3851eab — reanalyzeHistoryRecordId added to dismiss cleanup.

Address CodePilot feedback:
- useEffect on sessionPhase clears verificationPickerLogId,
  reanalyzeHistoryRecordId, isReanalyze (not just pendingVerification)
- dismiss handler also clears reanalyzeHistoryRecordId

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@eddycek eddycek merged commit 35c6cdc into main Apr 11, 2026
1 check passed
@eddycek eddycek deleted the fix/tuning-session-bugs branch April 11, 2026 13:57
eddycek added a commit that referenced this pull request Apr 11, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants