Skip to content

Define session status model#14

Merged
qyinm merged 3 commits into
mainfrom
session-state-model
May 4, 2026
Merged

Define session status model#14
qyinm merged 3 commits into
mainfrom
session-state-model

Conversation

@qyinm
Copy link
Copy Markdown
Owner

@qyinm qyinm commented May 4, 2026

Summary

Defines a product-level session status model for MirrorNote notes and normalizes listener metadata plus STT chunk ledger state into that model.

Why

The app needs a stable session-state contract before building user-facing recovery UX. Listener metadata and chunk retry state were available separately, but there was no single app-level state for recording, degraded, finalizing, transcribing, failed, completed, or recoverable sessions.

Changes

  • Added AppSessionState and AppSessionStatus types to the desktop renderer contract.
  • Added normalizeAppSessionStatus() in the desktop main process to derive app-level session status from listenerSession metadata and latest STT chunk states.
  • Included sessionStatus on note summaries and note details.
  • Added node contract tests covering recording, degraded, finalizing, transcribing, failed, completed, and recoverable mappings.

Validation:

  • node apps/desktop/main/native-launch.node-test.cjs
  • npm run desktop:check
  • git diff --check -- apps/desktop/main.cjs apps/desktop/main/native-launch.node-test.cjs apps/desktop/src/types.ts

Summary by CodeRabbit

  • New Features

    • Notes now include a computed session status showing current app session state (recording → transcription → completion) attached to note data.
  • Improvements

    • Enhanced visibility into transcription lifecycle with detailed chunk metrics (retryable, failed, running) and clearer recovery/error details.
  • Tests

    • Added coverage to validate session-status derivation across recording, recovery, error and completion scenarios.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: bc5c547e-5cdf-4da3-809c-635991c80c2f

📥 Commits

Reviewing files that changed from the base of the PR and between fc40a8c and 6e6a15b.

📒 Files selected for processing (2)
  • apps/desktop/main.cjs
  • apps/desktop/main/native-launch.node-test.cjs
✅ Files skipped from review due to trivial changes (1)
  • apps/desktop/main/native-launch.node-test.cjs

📝 Walkthrough

Walkthrough

Derives a normalized application-level session status from persisted listener session state and the STT chunk ledger, persists it on snapshots, exposes it in reads, adds types, a schema migration, and test coverage for the mappings.

Changes

App Session Status Normalization

Layer / File(s) Summary
Type Definitions
apps/desktop/src/types.ts
Adds AppSessionState union, AppSessionStatus interface, and extends NoteSummary with `sessionStatus: AppSessionStatus
Database Schema
apps/desktop/main.cjs (migration)
Bumps NOTES_DATABASE_SCHEMA_VERSION to 4 and adds migration that alters notes to include session_status_json TEXT.
Core Normalization Logic
apps/desktop/main.cjs (lines ~1361–1430)
Adds normalizeAppSessionStatus(input = {}) to derive state, detail, and chunk counts from listenerSession and sttChunks. Adds normalizeStoredAppSessionStatus(value) to parse persisted JSON.
Snapshot Loading / Persistence
apps/desktop/main.cjs (lines ~1880–2012, 2521–2542)
loadBundleSnapshot loads STT chunk ledger and sets sessionStatus via normalization. upsertNoteSnapshot persists session_status_json. noteSummaryFromRow reads stored session_status_json and readNote recomputes and attaches live sessionStatus.
Tests / Test Exports
apps/desktop/main/native-launch.node-test.cjs, apps/desktop/main.cjs (export)
Exports normalizeAppSessionStatus under test-only exports and adds tests asserting mapping across recording, degraded, finalizing, failed, recoverable, transcribing, and completed scenarios with chunk-count metrics.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DB
    participant Normalizer as Normalizer(Service)
    participant Ledger as STT_Ledger
    Client->>DB: request note (readNote)
    DB-->>Client: row with metadata + sttChunks path
    Client->>Ledger: load latest stt-chunks.jsonl
    Ledger-->>Client: sttChunks
    Client->>Normalizer: normalizeAppSessionStatus({listenerSession, sttChunks})
    Normalizer-->>Client: AppSessionStatus (state, detail, counts)
    Client-->>DB: (on save) persist session_status_json
    Note right of Normalizer: derives state from listenerSession + sttChunks
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I count the chunks and listen close,
States converge where whisper goes,
From starting, stuck, to fully done—
Each note now knows the session spun,
Hoppity-hop, the status sings: well done!


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Review rate limit: 1/3 review remaining, refill in 37 minutes and 30 seconds.

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

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a status normalization system for application sessions, aggregating listener states and transcription chunk progress into a unified sessionStatus field. While the logic is supported by new unit tests, the implementation relies on synchronous file I/O within the Electron main process, which can lead to UI freezes—especially in noteSummaryFromRow where it creates an N+1 I/O bottleneck. Feedback also identifies redundant ledger parsing in readNote, suggesting a move toward asynchronous operations or database persistence for session metadata.

Comment thread apps/desktop/main.cjs Outdated
Comment thread apps/desktop/main.cjs
Comment thread apps/desktop/main.cjs Outdated
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: fc40a8c79c

ℹ️ 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 apps/desktop/main.cjs Outdated
Comment thread apps/desktop/main.cjs Outdated
@qyinm qyinm merged commit 5545623 into main May 4, 2026
2 checks passed
@qyinm qyinm deleted the session-state-model branch May 4, 2026 05:24
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