Skip to content

Move Item, Subagent and Artifact reads and Artifact staging into sessions and sessionpg - #331

Merged
SaladDay merged 1 commit into
mainfrom
refactor/sessions-items-artifacts
Sep 30, 2026
Merged

SaladDay merged 1 commit into
mainfrom
refactor/sessions-items-artifacts

Conversation

@SaladDay

@SaladDay SaladDay commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Item, Subagent and Artifact reads, and Artifact staging, move out of store into sessions and sessionpg. This PR also introduces the public Session skeleton that the remaining Session PRs extend.

What changes

  • sessions skeleton:
    • Service{storage Storage} with NewService.
    • Storage, which embeds ArtifactStorage.
    • Reader, which embeds ArtifactReader, ItemReader and SubagentReader.
  • sessionpg:
    • Store{units} with New(units).
    • It implements the Artifact, Item and Subagent reads and the staging transaction.
    • LoadPublicSubagent and LoadChildTurn are shared participants.
  • Artifact staging:
    • sessions.Service.StageTurnArtifacts is a pooled use case.
    • Inside one transaction it runs these steps in order:
      1. Authorize the Environment.
      2. Stream the export into large objects.
      3. Take the Session lock and recheck that the Turn is still running.
      4. Record the private Artifacts.
    • CompleteExecution stays the only fence that publishes or discards them.
    • The staging rules (the export shape and the running-Turn recheck) are tested against strict fakes.
  • execution.Dispatcher gains the required fields Sessions and SessionsReader, and StartWorker validates both.
  • api:
    • The Items, Subagents and Artifacts handlers read through sessionpg.Store and delete through sessions.Service.
    • These handlers map errors with writeSessionsError.
  • Removed from store: item_reads.go, session_artifacts.go, artifact_capture.go, subagent_reads.go, subagent_item_reads.go and list_cursors.go.
  • IMPLEMENTATION.md names the new owners.

Behavior

Public behavior is unchanged: pagination, ordering, visibility, the cursor errors and the export shape. There are small internal differences:

  • A missing Turn during staging is ErrNotFound instead of a raw driver error.
  • A stored Environment type that cannot be read is rejected as invalid input.
  • The Environment is loaded inside the staging transaction.

Checks

  • go build ./... and go vet ./services/core/....
  • sessions and sessionpg in full.
  • api Artifact, Item and Subagent tests, plus every test in the changed api test files.
  • execution -run 'StartWorker|Artifact|WorkerRun|Owner'.
  • cmd/server in full, and providers -run Configuration.
  • Store: exact-name runs of the 71 tests in the 31 changed test files. The official-client and native-daemon cases ran with the pinned SDK and a daemon built from this head.
  • make openapi produces no diff.
  • scripts/check-names.py.

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 4929939 into main Sep 30, 2026
1 check passed
@SaladDay
SaladDay deleted the refactor/sessions-items-artifacts branch September 30, 2026 21:00
…ions and sessionpg

The pooled sessions.Service and sessions.Reader skeleton lands with the
Artifact family: StageTurnArtifacts and DeleteSessionArtifact are Service
use cases on sessionpg.Store, and the Item, Subagent and Artifact reads are
sessionpg.Store methods behind sessions.Reader. Execution stages a Turn's
export through the required Dispatcher.Sessions; StartWorker also requires
Dispatcher.SessionsReader. cmd/server builds one sessionpg.Store for the
Dispatcher and the api Items, Subagents, Artifacts and ArtifactsReader
fields.

Staging keeps its single pooled transaction: the Environment is authorized
before the export is read, content streams into large objects that roll back
with a rejected or failed export, and the Session lock is taken through
sessionpg.LockSession only after the transfer to recheck the Turn.
LoadPublicSubagent and LoadChildTurn move to sessionpg/subagents.go with
their store signatures. The store read, capture and cursor files are
deleted, and the capture rejection test moves to sessionpg.
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