Skip to content

feat(context-usage): persist usage across restarts - #616

Merged
ewen-poch merged 1 commit into
mainfrom
feat/context-window-session-persistence
Aug 2, 2026
Merged

feat(context-usage): persist usage across restarts#616
ewen-poch merged 1 commit into
mainfrom
feat/context-window-session-persistence

Conversation

@ewen-poch

Copy link
Copy Markdown
Member

Problem

Context-window usage currently lives only in the ACP runtime snapshot, so restarting Open Science removes the indicator even though the conversation Session is restored.

Proposed change

  • Persist the last known contextUsage as an optional, sanitized Session field.
  • Mirror live usage only for attached runtime Sessions; clear it when an attached context generation is invalidated.
  • Fall back to the persisted snapshot for restored, detached Sessions.
  • Keep New conversation unchanged: no Session means no Context window indicator.
flowchart LR
  A["ACP runtime usage"] --> B["Session store contextUsage"]
  B --> C["Existing Session JSON autosave"]
  C --> D["Restart hydration"]
  D --> E["Existing Context window UI"]
Loading

Scope and non-goals

No database, migration script, dependency, layout, or new user action is added. Older Session files remain valid because the field is optional.

Acceptance criteria and validation

All checks below ran after the final material edit.

  • Context usage round-trip and untrusted payload sanitization -> npm test -- src/shared/session-persistence.test.ts src/renderer/src/lib/acp/useWorkspaceAgentRuntime.test.ts -> passed (119 tests).
  • Context Window remains hidden without usage, including New conversation -> existing ComposerContextUsage coverage within the full suite -> passed.
  • Node and renderer types -> npm run typecheck equivalent (tsc against both project configs) -> passed.
  • Repository lint -> npm run lint equivalent -> passed with 0 errors and 19 pre-existing warnings.
  • Full regression suite -> npm test -- --maxWorkers=4 -> passed (670 files, 9,756 tests; 184 skipped).

Review focus

  • Last-known snapshot semantics across detached versus attached runtime Sessions.
  • Strict validation of restored breakdown category keys and token counts.
  • No-op equality guard preventing redundant Session writes.

Uncovered risks

The exact quit-and-relaunch Electron UI journey is not automated; persistence boundaries, hydration fallback, hidden-empty behavior, and the full unit/integration suite are covered.

@github-actions github-actions Bot added the enhancement New feature or request label Aug 2, 2026
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codex Review

Verdict: mergeable

No actionable findings.

Summary: Static inspection found no concrete merge-blocking defects in the pull request changes.

@github-actions github-actions Bot added the ready-to-merge All completed AI reviewers found this pull request mergeable. label Aug 2, 2026
@ewen-poch
ewen-poch merged commit 272d27a into main Aug 2, 2026
23 checks passed
@ewen-poch
ewen-poch deleted the feat/context-window-session-persistence branch August 2, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready-to-merge All completed AI reviewers found this pull request mergeable.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant