Skip to content
This repository was archived by the owner on Apr 17, 2026. It is now read-only.

feat: storage abstraction, PostgreSQL backend, and memo mirror contract (#69) - #143

Merged
yai-dev merged 2 commits into
masterfrom
feat/69-storage-abstraction
Apr 13, 2026
Merged

feat: storage abstraction, PostgreSQL backend, and memo mirror contract (#69)#143
yai-dev merged 2 commits into
masterfrom
feat/69-storage-abstraction

Conversation

@yai-dev

@yai-dev yai-dev commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • Completes the Pre-GA storage contract consolidation: AgentrailSessionStore gains optional memo-document and tool-result-artifact methods; all code paths that previously relied on sessionDir are refactored to use the new store API.
  • Ships @agentrail/storage-postgres as the first drop-in reference implementation (session, trace, orchestration, inspector — all without filesystem coupling), with a full test suite via @testcontainers/postgresql.
  • Enforces /workspace/memo/** as a read-only bind-mount inside sandboxes; Write/Edit tools call writeMemoBack to sync writes back to the store, and refreshMemoMirror / refreshUserMemoMirrorForAllSessions keep live containers up-to-date after host-side compaction or USER.md consolidation.

Changed packages

Package Change
@agentrail/core minor — new store optional methods, SessionRef in MemorySessionContext, MemoryIndex path semantics
@agentrail/capabilities minor — SandboxMemoProvider, read-only memo mounts, writeToolResultArtifact builder, orchestration agent history
@agentrail/app minor — InspectorDataSource, UserSessionLister, UserMemoMirrorRefresher, compactToolResults wired to store
@agentrail/storage-postgres minor — new package, full reference implementation

A changeset file (.changeset/storage-abstraction-postgres.md) is included; the skip-changeset CI label is applied because the changeset is already present in the branch and avoids the "no changeset" duplicate-check failure.

Test plan

  • pnpm build:packages passes
  • pnpm test passes (includes @agentrail/storage-postgres docker-based tests via @testcontainers/postgresql — the ubuntu-latest CI runner has Docker available)
  • pnpm typecheck passes
  • pnpm format:check passes
  • DCO sign-off present on all commits (Signed-off-by: yai-dev <sunzhenyucn@gmail.com>)

…ct (#69)

Core storage contract changes:
- `AgentrailSessionStore` gains optional memo document and tool-result
  artifact methods (read/write/append/list); required for non-filesystem
  backends to enable sandbox /workspace/memo/** access
- `AgentrailSessionStore` no longer exposes `getSessionDir`; removed from
  all host call sites and developer docs
- `MemoryIndex` paths use canonical /workspace/memo/... form only

SandboxManager memo mirror:
- New `SandboxMemoProvider` interface with bidirectional read/write methods
- At sandbox creation: snapshots memo docs + tool-result artifacts into a
  temp dir; bind-mounts read-only so Bash cannot bypass Write/Edit tools
- New `writeMemoBack(sessionId, containerPath, content)` — Write/Edit tools
  call this after every successful memo-path write to keep store in sync
- New `refreshMemoMirror` / `refreshUserMemoMirrorForAllSessions` — host
  calls these after compaction artifact writes or USER.md consolidation so
  live containers see updated content immediately
- `SandboxEntry` stores tenantId/userId/sessionId for write-back routing

UserMemoryConsolidationService:
- New optional `mirrorRefresher: UserMemoMirrorRefresher` constructor param;
  calls `refreshUserMemoMirrorForAllSessions` after every USER.md write

memoryContext capability:
- `MemorySessionContext` gains `sessionRef` field
- `MemoryContextBuilders` gains `writeToolResultArtifact` builder; wired
  through to `DefaultCapabilityContextOptions.writeToolResultArtifact` so
  compaction artifacts are actually persisted (previous `sessionDir` path
  was never populated and silently dropped all artifacts)
- `compactMessages` ctx type updated: `sessionDir` removed, replaced by
  `writeToolResultArtifact` callback

OrchestrationPersistence:
- Adds `loadAgentHistory` / `writeAgentHistory` for sub-agent message
  history across turn boundaries
- Worker process supports dynamic postgres persistence init via
  `storageConfig` in `WorkerInitMessage`

InspectorDataSource:
- New `InspectorDataSource` interface + `createFilesystemInspectorDataSource`
- `createInspectorRoute` accepts `InspectorDataSource` (string path deprecated)
- `createAgentApp` `inspector` option now takes `true | InspectorDataSource`

New package: @agentrail/storage-postgres:
- `PostgresSessionStore` — full store including memo docs and artifacts
- `PostgresSessionTraceStore`
- `PostgresOrchestrationPersistence` — includes agent history
- `PostgresInspectorDataSource`
- `buildSchemaDDL(schema?)` for idempotent table creation
- `createSqlClient(options)` connection pool helper
- Full test suite via @testcontainers/postgresql

playground-server example:
- Updated `compactMessages` to use `writeToolResultArtifact` + mirror refresh
- Stream route uses cached trace store (one per session, not one per event)
- Inspector route switched to `createFilesystemInspectorDataSource`

Docs:
- New guide: docs/guides/build-a-storage-backend.md covering all 6 contracts
  and mirror refresh responsibilities
- session-store.md, configure-sessions.md, inspector-route.md updated for
  new API; getSessionDir removed from public contract docs
- playground-server.md examples updated to new patterns
- docs/tools/bash.md + sandboxed-bash description: memo paths are read-only

Signed-off-by: yai-dev <sunzhenyucn@gmail.com>
@yai-dev yai-dev added the skip-changeset Skip changeset check for docs-only, CI-only, or internal changes label Apr 13, 2026
@yai-dev yai-dev self-assigned this Apr 13, 2026
Signed-off-by: yai-dev <sunzhenyucn@gmail.com>
@yai-dev yai-dev removed the skip-changeset Skip changeset check for docs-only, CI-only, or internal changes label Apr 13, 2026
@yai-dev yai-dev linked an issue Apr 13, 2026 that may be closed by this pull request
8 tasks
@yai-dev
yai-dev merged commit 27f7f44 into master Apr 13, 2026
6 checks passed
@yai-dev
yai-dev deleted the feat/69-storage-abstraction branch April 13, 2026 10:16
@github-actions github-actions Bot mentioned this pull request Apr 13, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive storage abstraction layer across the Agentrail ecosystem, enabling support for non-filesystem backends and providing a reference PostgreSQL implementation. Key changes include breaking updates to the session and orchestration persistence contracts, the introduction of the @agentrail/storage-postgres package, and a new InspectorDataSource abstraction to decouple the Inspector API from the local filesystem. Additionally, the SandboxManager was enhanced to support bidirectional memo synchronization for database-backed stores. Feedback primarily addressed inconsistencies in default token budget values between the core implementation and the new PostgreSQL store, which should be aligned to ensure predictable behavior.

@@ -512,67 +525,32 @@ export class SessionManager {
compressedCount: number;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The token budget is hardcoded to 40,000 in the implementation, but the previous code used 60,000 as a default. This inconsistency should be resolved to ensure predictable compaction behavior.

async loadMessagesWithBudget(
tenantId: string,
sessionId: string,
tokenBudget = 40_000,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The token budget default of 40,000 differs from the 60,000 used in other parts of the application. Please align this value with the rest of the system to maintain consistent compaction thresholds.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stabilize storage abstractions, memo FS, and PostgreSQL reference implementation

1 participant