Skip to content

[codex] Extract sun session store#458

Merged
elkimek merged 2 commits into
mainfrom
codex/extract-sun-sessions-store
May 30, 2026
Merged

[codex] Extract sun session store#458
elkimek merged 2 commits into
mainfrom
codex/extract-sun-sessions-store

Conversation

@elkimek
Copy link
Copy Markdown
Owner

@elkimek elkimek commented May 30, 2026

What changed

  • Extracted shared Sun session options and safety constants into sun-session-model.js.
  • Extracted persisted Sun session CRUD, pause/resume, hydration, stale rehydration, and atmosphere override logic into sun-sessions-store.js.
  • Kept sun.js as the public facade for existing imports/window bindings, with injected hooks for live active-session state.
  • Added the new modules to the service worker app shell and bumped version.js to 1.8.286.

Why

sun.js had accumulated storage, hydration, constants, UI facade, and aggregate logic in one large module. This separates the sensitive persisted session lifecycle from active UI/modal code while preserving the existing public API.

Validation

  • node --check js/sun.js
  • node --check js/sun-session-model.js
  • node --check js/sun-sessions-store.js
  • node --check js/sun-active-session.js
  • node --check tests/test-sun.js
  • node --check tests/test-correctness-phase2.js
  • node tests/test-sun.js
  • node tests/test-correctness-phase2.js
  • node tests/test-sun-context.js
  • node tests/test-sun-ai-analysis.js
  • node tests/test-light-devices.js
  • ./run-tests.sh

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

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

Project Deployment Actions Updated (UTC)
get-based Ready Ready Preview, Comment May 30, 2026 5:08pm

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 30, 2026

Greptile Summary

This PR extracts shared session constants and safety model into sun-session-model.js and all persisted-session CRUD, hydration, and stale-rehydration logic into sun-sessions-store.js, while keeping sun.js as a thin re-export facade. It also fixes a previously noted concurrency gap in rehydrateStaleSessions by introducing _runHydrateSession, which properly deduplicates concurrent callers via the _hydrateInFlight map.

  • sun-session-model.js — new module owning EXPOSURE_PRESETS, POSTURE_MULTIPLIERS, SURFACE_ALBEDO, PHOTOSENSITIVE_MED_TIERS, and the tier-normalization helpers; imported by both the active-session ticker and the store.
  • sun-sessions-store.js — new module owning startSession/stopSession/logCompletedSession/deleteSession/pause/resume/updateSession/hydrateSession/rehydrateStaleSessions; wired to live-UI state through configureSunSessionsStore.
  • sun.js — converted to a pure facade; re-exports all previously-public symbols; service-worker.js and test-correctness-phase2.js updated to precache the two new files.

Confidence Score: 5/5

Clean refactoring — no public API is removed or altered, and the new dedup logic for concurrent rehydration is correct and covered by new tests.

All previously-public symbols remain re-exported from sun.js with preserved object identity. The _runHydrateSession helper correctly gates concurrent rehydrateStaleSessions calls on the same session-id promise, and the new test in section 12 verifies exactly one fetchAtmosphere call fires per stale session under concurrency. The service-worker and phase-2 correctness test are kept in sync. No logic was changed — only moved.

No files require special attention.

Important Files Changed

Filename Overview
js/sun-session-model.js New file — extracts shared constants (EXPOSURE_PRESETS, POSTURE_MULTIPLIERS, SURFACE_ALBEDO, PHOTOSENSITIVE_MED_TIERS) and tier helpers into a single source of truth. Clean and self-contained.
js/sun-sessions-store.js New file — owns all persisted session lifecycle; introduces _runHydrateSession helper that correctly deduplicates concurrent rehydrateStaleSessions callers via _hydrateInFlight. Logic matches the removed sun.js implementation.
js/sun.js Converted to a re-export facade; all previously-public symbols remain available; configureSunSessionsStore correctly injects _setLiveState/_clearLiveState/_commitCurrentSlice/_formatElapsed. No public API breakage detected.
js/sun-active-session.js Imports POSTURE_MULTIPLIERS and SURFACE_ALBEDO from the new model module and re-exports them; comment in header updated to point at sun-sessions-store.js. Minor, correct change.
service-worker.js Adds /js/sun-session-model.js and /js/sun-sessions-store.js to the APP_SHELL precache list; consistent with test-correctness-phase2.js update.
tests/test-sun.js Adds re-export identity checks, pause/resume lifecycle tests, concurrent rehydrateStaleSessions dedup test (section 12), and module-boundary guardrails (section 13). Tests are accurate and cover the new behavior.
tests/test-correctness-phase2.js Adds the two new module paths to pwaAppShellAssets so the service-worker asset-list test stays in sync. Minimal, correct change.
version.js Patch bump from 1.8.285 to 1.8.286 to bust the service-worker cache, consistent with the new module files added to APP_SHELL.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    sunjs["sun.js\n(public facade)"]
    model["sun-session-model.js\nEXPOSURE_PRESETS\nPOSTURE_MULTIPLIERS\nSURFACE_ALBEDO\nPHOTOSENSITIVE_MED_TIERS\nphotosensitiveMedScale\n_normalizePSMTier"]
    store["sun-sessions-store.js\ngetSessions / getActiveSession\nstartSession / stopSession\nlogCompletedSession / deleteSession\npause / resume / updateSession\nhydrateSession\nrehydrateStaleSessions\n_applyAtmOverrides"]
    active["sun-active-session.js\n(live ticker + UI)"]
    ui["sun-session-ui.js\n(saved session rows + edit UI)"]
    consumers["sun-ai-analysis.js\nsun-correlations.js\nlight-devices.js\nlight-today-ai.js\n…"]

    model -->|"imports constants"| store
    model -->|"imports constants"| active
    model -->|"re-exports"| sunjs
    store -->|"re-exports"| sunjs
    active -->|"re-exports quickLog / modal helpers"| sunjs
    ui -->|"re-exports session row / detail"| sunjs
    sunjs -->|"import getSessions\nchannelTier, formatChannelUnit…"| consumers
    store -->|"storeDeps injected by"| sunjs
    active -->|"activeDeps injected by"| sunjs
Loading

Reviews (2): Last reviewed commit: "Deduplicate sun session rehydration" | Re-trigger Greptile

Comment thread js/sun-sessions-store.js
@elkimek elkimek merged commit 2147720 into main May 30, 2026
5 checks passed
@elkimek elkimek deleted the codex/extract-sun-sessions-store branch May 30, 2026 17:13
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