Skip to content

fix(host): use session.snapshotEvents() for dsh-session >= 0.1.2-rc.1 - #7

Merged
Max-Samson merged 2 commits into
Max-Samson:mainfrom
GImDX:fix/snapshot-events-api
Sep 8, 2026
Merged

fix(host): use session.snapshotEvents() for dsh-session >= 0.1.2-rc.1#7
Max-Samson merged 2 commits into
Max-Samson:mainfrom
GImDX:fix/snapshot-events-api

Conversation

@GImDX

@GImDX GImDX commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Problem

dsh-session 0.1.2-rc.1 removed the public events property on Session (replaced by snapshotEvents()). The /dsh-usage-chart/usage route still reads session.events, which is now undefined:

  • foldRounds(undefined) throws TypeError: events is not iterable
  • dsh-host-webserver wraps the uncaught handler error as a bare 400 empty response
  • the client falls back to the empty observed-rounds path, so the per-round usage chart disappears for every loaded session

Verified against a live deployment on dsh-session 0.1.2-rc.1: /usage?session=<loaded session> returns an empty 400, /usage?session=<unknown> returns the plugin 404 JSON, and folding the same session log offline succeeds — the crash only occurs on the new runtime API shape.

Fix

  • Prefer session.snapshotEvents() when present, with a legacy session.events fallback (?? [] so a missing API can never crash the route again)
  • Align the vendored SessionEventLike type in types/cordis.d.ts (add required time, mark events optional, add snapshotEvents?)

Verification

  • npm run typecheck clean
  • node --test tests/*.test.mjs → 39/39 pass
  • Replayed a real 13k-event session log through the patched fold path locally without errors

dsh-session removed the public \events\ property in 0.1.2-rc.1; the
/usage route crashed with 'events is not iterable' (400) and the
rounds chart disappeared. Prefer snapshotEvents() with a legacy
fallback, and align the vendored SessionEventLike type (add time).
@Max-Samson
Max-Samson self-requested a review September 7, 2026 15:19
…he new API is present, added to cover the snapshotEvents() branch introduced by commit c92e3f3

@Max-Samson Max-Samson left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@GImDX Thanks for the clean fix.
The feature detection (typeof session.snapshotEvents === 'function') and fallback to session.events ?? [] correctly handle the breaking change in dsh-session >= 0.1.2-rc.1 while preserving backwards compatibility.
I have added a dedicated unit test verifying both the snapshotEvents() preference and the fallback behavior under /usage. All 40 tests and typechecks pass.

@Max-Samson
Max-Samson merged commit 1ecc34f into Max-Samson:main Sep 8, 2026
Max-Samson added a commit that referenced this pull request Sep 8, 2026
…session >= 0.1.2-rc.1)

- fix(host): adapt /usage route to use session.snapshotEvents() for dsh-session >= 0.1.2-rc.1 with fallback to legacy session.events (#7)
- test: add coverage for snapshotEvents() preference and fallback under /usage
- docs: update README and CHANGELOG to 1.1.4
- chore: bump version to 1.1.4 in package.json and package-lock.json
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