Skip to content

Split Session change decisions from their PostgreSQL writes - #316

Merged
SaladDay merged 3 commits into
mainfrom
refactor/sessions-primitives
Sep 30, 2026
Merged

SaladDay merged 3 commits into
mainfrom
refactor/sessions-primitives

Conversation

@SaladDay

@SaladDay SaladDay commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1 (store layering), PR 11. Splits the Session change decisions from their PostgreSQL writes, so later Session PRs build on shared primitives.

Commits

  1. Prep: provisioning failure detail is sanitized by a store function.
  2. Vocabulary (script-generated rename): the SessionChange vocabulary moves to sessions. That covers Turn and its statuses, EnvironmentInputActivity, EnvironmentFailure and ProvisioningFailureDetail. Item merging and the ordered Item events move to items.
  3. Decide / apply:
    • sessions owns the Turn and Item change sets, EndTurn, measured usage, the terminal status and the retention bounds. When a Turn ends, unfinished Items become incomplete, artifacts are published or discarded, then the Turn event and the settled activity are written.
    • persistence/postgres/sessionpg loads facts and applies the decisions. It runs as free functions on the caller's transaction queries, allocates sequence numbers, IDs, positions and output indexes, and decides nothing.
    • The unstorable-text rejection becomes textvalue.ErrUnstorable.
    • Deleted from store: recordTurnChange, recordSessionChange, recordItemChange and settleTurnArtifacts.

Behaviour

  • Ordering, atomicity, rollback and the shared settlement time are unchanged. New PostgreSQL tests pin journal sequencing and pruning, Item positions and output indexes, and the Turn-end order.
  • Facts are now read before the writes rather than between them. This is equivalent, because the Session lock is held throughout.

Review and checks


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@SaladDay
SaladDay merged commit 66edf75 into main Sep 30, 2026
5 of 6 checks passed
@SaladDay
SaladDay deleted the refactor/sessions-primitives branch September 30, 2026 17:16
The detail type moves to sessions with the Session change vocabulary,
while the sanitizing rule uses store's provisioning step labels.
SessionChange, Turn with its status constants, EnvironmentInputActivity,
EnvironmentFailure and ProvisioningFailureDetail move verbatim from store to
the new sessions package. Every reference was rewritten by
rename-sessions-vocab.py; two store test locals named sessions were renamed
so they no longer shadow the package. No behaviour changes.
items decides each Item change and builds its ordered events; sessions
decides the public changes for Turn and Session transitions, what a Turn
that ends settles, measured usage and Session activity. sessionpg loads
the facts those decisions read and applies them in the caller's Session
transaction: event sequence and IDs, journal rows, Items, usage, Artifact
settlement and pruning. It parses IDs with pgunit.ParseID and returns
textvalue.ErrUnstorable for text PostgreSQL cannot store. Store scripts
call the decisions and apply functions directly; recordTurnChange,
recordSessionChange, recordItemChange and settleTurnArtifacts are gone.
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