Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ surface; this store remembers the result.
> it is not ready for production use. Published versions are listed on
> [npm](https://www.npmjs.com/package/@pegma/sessions).

The `0.3.0` API adds `observe(sessionId, now?)`: a fresh liveness-checked read
without an idle touch or cleanup write. Hosts can keep `get` for initial
admission and use `observe` for closing checks that must not count as activity.
Both use the same expiry predicate and clock semantics. Each result is a
snapshot; later revocation or expiry is still possible. See the
[package README](packages/sessions/README.md) for usage.

The `0.2.1` change observes the default clock after awaited reads and sweeps.
With a consistent advancing clock, a concurrent touch observed in that snapshot
is no longer mistaken for a future timestamp merely because the operation
Expand Down Expand Up @@ -60,8 +67,8 @@ What it does own, it owns opinionatedly:
The hygiene sweep is the opposite — version-conditional, so a session that
came back to life mid-sweep survives. Keeping those two rules opposite is
the design.
- **Reads that garbage-collect and never resurrect** — a dead row found on
read is lazily purged; the idle-anchor touch declines to write back a
- **Activity reads that garbage-collect and never resurrect** — a dead row found
by `get` is lazily purged; the idle-anchor touch declines to write back a
session a concurrent destroy just removed, and a failed touch never fails
the request.

Expand Down
25 changes: 25 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# @pegma/sessions v0.3.0

Add `SessionStore.observe(sessionId, now?)` for fresh liveness and identity
checks that must not extend activity. It hashes the raw session id and performs
one keyed backend read, then applies the existing liveness predicate. It returns
the public record when live and null when missing, revoked, or rejected by the
shared timestamp and expiry checks. Those checks validate lifecycle timestamps,
not principal claims or host data. It never touches the idle anchor or lazily
deletes a dead row; backend read failures propagate.

The default clock is observed after the awaited read, matching `get`; explicit
instants retain their existing semantics. Use `get` for activity such as initial
request admission and `observe` for later closing checks. Each observation reads
the backend afresh, but its result is a snapshot, not a lock against subsequent
revocation or expiry. Hosts still own current identity and permission checks.

The `0.3.0` minor version reflects the public `SessionStore` interface expansion
under `0.x`. Existing `get`, revocation, expiry cleanup, storage schema, and
runtime dependency pins retain their behavior. Memory and real Azure Tables
tests cover read-only operation, exact expiry, clock observation, fresh
revocation, concurrent touches, and snapshot limits. On the initialized Azure
Tables adapter's no-retry path, the tests observe one physical GET per
observation, including dead and missing records. Adapter retries can issue
additional physical requests.

# @pegma/sessions v0.2.1

Fix default clock observation around awaited session reads and expiry sweeps.
Expand Down
20 changes: 13 additions & 7 deletions docs/PROJECT_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ same function, so the two can never disagree.
idle anchor through a decider that declines to resurrect a session a
concurrent destroy just removed; a failed touch never fails the request.
- `destroy(sessionId)` — delete; already-gone is success, not an error.
- `observe(sessionId, now?)` — one fresh keyed read with the same liveness and
clock semantics as `get`, without an idle touch or lazy delete. Use it for
closing checks after the activity-bearing admission read. Backend failures
propagate; the result is a snapshot, not a lock against later revocation.
- `destroyAllForPrincipal(principalId)` — sign out everywhere. Lists the
partition and filters on the record's principal; deletes are deliberately
**unconditional**, because a session touched concurrently must still die.
Expand Down Expand Up @@ -199,8 +203,8 @@ counts, revocation counts) report through the spine `Logger` port.

### In scope

- The session record store: create, liveness-checked reads with idle
touch, destroy, principal-wide revocation, expiry sweep.
- The session record store: create, liveness-checked activity reads with idle
touch, read-only observation, destroy, principal-wide revocation, expiry sweep.
- Mandatory id hashing, dual expiry, the single liveness predicate.
- The host data field with a host-supplied codec fragment.
- Conformance-style tests over `createMemoryStore()` and against the Azure
Expand Down Expand Up @@ -313,11 +317,13 @@ principal exists. `PrincipalId` would become nullable and
needs it yet, and nullable-principal is a one-way door better opened by a
real requirement.

**Touch write amplification.** Every live `get` writes the idle anchor. The
reference application accepts this (its traffic is modest); a busier host
might want a touch floor ("don't re-touch within N minutes"), trading idle
precision for writes. Cheap to add behind a config default of 0; decide when
a consumer measures it.
**Touch write amplification.** A live `get` attempts a best-effort idle touch.
Its decider keeps the existing anchor when the observed instant is no later
than the current `lastSeenAt`, including after a concurrent touch. The `0.3.0`
`observe` API supports hosts whose closing checks need fresh session liveness
without renewing activity. A host can retain `get` for initial admission and
use `observe` for later checks without changing idle precision. This is not a
touch floor or an authority cache.

## Near-term backlog

Expand Down
14 changes: 7 additions & 7 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pnpm run release:pack -- -- --output .release
```

After merge, create and verify the tag before creating the GitHub release.
For example, for the next patch release. The final command sends only the
For example, for the next release. The final command sends only the
current version's section to GitHub; older sections stay in the changelog:

```sh
Expand All @@ -139,13 +139,13 @@ git switch --detach origin/main
git config gpg.format ssh
git config user.signingkey ~/.ssh/pegma-release-signing-key
git config gpg.ssh.allowedSignersFile ~/.config/pegma/release-allowed-signers
git tag --sign v0.2.1 --message "Sessions v0.2.1" HEAD
git verify-tag v0.2.1
git push origin refs/tags/v0.2.1
git fetch origin tag v0.2.1 --force
git verify-tag v0.2.1
git tag --sign v0.3.0 --message "Sessions v0.3.0" HEAD
git verify-tag v0.3.0
git push origin refs/tags/v0.3.0
git fetch origin tag v0.3.0 --force
git verify-tag v0.3.0
node --input-type=module -e 'import { readFileSync } from "node:fs"; process.stdout.write(readFileSync("RELEASE_NOTES.md", "utf8").split("\n# @pegma/sessions ")[0]);' |
gh release create v0.2.1 --verify-tag --title "@pegma/sessions v0.2.1" --notes-file -
gh release create v0.3.0 --verify-tag --title "@pegma/sessions v0.3.0" --notes-file -
```

Do not let `gh release create` create a tag. Never move or recreate a release
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sessions",
"version": "0.2.1",
"version": "0.3.0",
"private": true,
"description": "Server-side session records for Pegma components.",
"license": "MIT",
Expand Down
40 changes: 40 additions & 0 deletions packages/sessions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,46 @@ thousands, not millions, of live sessions.
Session data must never contain IdP access tokens, refresh tokens, or any other
credential re-presentable to another service.

## Activity reads and read-only checks

Use `get(rawSessionId)` when the request should count as activity. It reads a
live session and attempts a best-effort idle touch; a dead row is lazily
deleted best-effort. The returned record describes the initial validated
snapshot and does not claim that the touch succeeded.

Use `observe(rawSessionId)` when a later check needs current session identity
and liveness without extending activity:

```ts
const admitted = await sessions.get(rawSessionId);
if (admitted === null) return refuseRequest();

// Before a later protected step, read current session state again.
const current = await sessions.observe(rawSessionId);
if (current === null) return refuseRequest();
// The host must also revalidate current identity and permissions.
```

`observe` hashes the id and performs one fresh keyed backend read per call. It
returns a `SessionRecord` when live or null when missing, revoked, or rejected
by the timestamp and expiry checks shared with `get` and the sweep. These
checks validate lifecycle timestamps, not principal claims or host data.
It does not touch the idle anchor, delete dead rows, or cache earlier results.
Backend read failures reject so the host can fail closed. Keep `get` for the
activity that should renew idle expiry; repeated observations alone will not
keep a session alive.

Both methods observe the default clock after the awaited storage read. An
explicit `now` is used unchanged; hosts seeking current liveness should omit
it. Absolute and idle boundaries are exclusive: a session is dead at either
boundary. Invalid timestamps and idle anchors ahead of the observing clock
fail closed, including clock rollback or host skew.

A returned record is a snapshot, not a lock or a cross-store transaction.
Revocation after that backend snapshot can overlap a successful result, and
the session may expire before later work completes. Hosts retain their
closing checks and any required identity, permission, and commit-time fences.

## Development

Node.js 22 or 24 is required for local development (the same versions CI
Expand Down
2 changes: 1 addition & 1 deletion packages/sessions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pegma/sessions",
"version": "0.2.1",
"version": "0.3.0",
"description": "Hashed server-side session records with absolute and idle expiry.",
"license": "MIT",
"type": "module",
Expand Down
Loading
Loading