Skip to content

feat(content-store): store patch content in Neon Object Storage - #422

Merged
allisonmahmood merged 4 commits into
mainfrom
tier2/391-neon-object-storage
Oct 1, 2026
Merged

allisonmahmood merged 4 commits into
mainfrom
tier2/391-neon-object-storage

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Patchy needs to store deployed content in Neon Object Storage rather than Azure Blob Storage.

This replaces the unused Azure backend with a path-style S3 layer using explicit Neon credentials and a branch-scoped endpoint. It preserves the ContentStore contract, keeps filesystem storage for development and tests, and updates server configuration and storage documentation.

Stacked on tier2/390-admission; this PR targets that branch and contains only the issue #391 implementation. Part of #384. Closes #391.

Verification

  • Typecheck and lint passed.
  • 24 offline storage tests and eight live contract tests against the Neon spike bucket passed, including pagination beyond 1,000 objects.
  • A 2 MiB live round-trip, replacement and deletion smoke passed with run-scoped cleanup.
  • Full offline suite passed with four workers: 1,091 tests across 96 files. The initial default-concurrency run had one Postgres timeout; that test passed in isolation and in the bounded-concurrency run.
  • Standards and spec reviews found no issues.

Implemented with GPT-6 Astra through the omp coding-agent harness.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:xl Over 1,000 changed lines; review in multiple passes labels Sep 28, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Opus review

Reviewed origin/tier2/390-admission...ab00a6a against #391 and spec #384 (§18, the content-store row). Two findings, both about where the new PATCHY_S3_* settings reach. The layer itself looks right.

1. The packed e2e still strips the Azure settings but not the S3 ones (correctness, mirrored surface)

scripts/packed-cli-e2e.mjs:2706-2712: environment() starts from process.env (:4121) and unsets AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_CONTAINER and AZURE_STORAGE_CONNECTION_STRING. That was the guard that kept a real store out of the e2e server. Azure is gone and nothing unsets PATCHY_S3_*, so the guard no longer covers anything.

How it fails: a developer exports the five PATCHY_S3_* settings, which docs/DEVELOPMENT.md:951 tells them to configure "for a deployment or the live contract suite". Then they run pnpm test:all or pnpm test:packed-cli-e2e. Server.ts sees PATCHY_S3_BUCKET and selects S3ContentStore, so e2e publishes write into that real bucket and the PATCHY_STORAGE_DIR: objectDir at :2702 is ignored. The run then fails at :4115 (readFile(path.join(objectDir, version.objectKey))), and the test objects stay in the bucket. Fix: replace the three AZURE_* names with the five PATCHY_S3_* names.

2. The live suite's docs name settings the live suite doesn't read (correctness, dev loop)

packages/content-store/live/S3ContentStore.live.ts:218-231 maps every PATCHY_S3_* lookup to NEON_BUCKET, AWS_ENDPOINT_URL_S3, AWS_REGION, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. docs/DEVELOPMENT.md:642-643 says the suite uses "the dedicated S3 settings", and :951 says to configure all five PATCHY_S3_* settings for it. An agent that follows the docs and supplies PATCHY_S3_* gets a missing-config failure, because the mapping means those names are never read. :969-970 also says the layer never uses ambient AWS_* settings, yet the live tier reads exactly those.

The root test:content-store:live script (package.json:19) is a second entry point the docs don't mention, and it only works if those AWS_*/NEON_BUCKET names are already exported. Pick one route: either the live test reads PATCHY_S3_* directly (drop the mapping, and whoever runs it supplies those names), or the docs say plainly that the live tier reads the spike file's AWS_*/NEON_BUCKET names. In both cases, point the script at the documented invocation or remove it.

Checked, not blocking

  • Intent: path-style S3Client with explicit credentials from Config. Startup selects it by PATCHY_S3_BUCKET and fails when S3 settings are partial. The Azure layer and its deps are deleted because nothing selects them. The filesystem layer stays for dev and tests. The shared contract suite runs against the filesystem layer, s3rver in pnpm test, and the live tier outside it. CONTEXT.md, CONTEXT-MAP.md, README layout, ADR-0003 and DEVELOPMENT.md are updated.
  • "Streaming bodies": the existing ContentStore contract has no streaming API. Keeping getBytes buffered matches the contract the other layers satisfy, so this isn't a gap.
  • Error mapping: NoSuchKey maps to ObjectNotFound. AccessDenied, NoSuchBucket, 5xx and a truncated body map to StoreUnavailable. Delete is idempotent, and pagination is guarded against a continuation token that doesn't advance.
  • Keys: callers build keys from validated ids, definition names or checked archive filenames, so no user-controlled dot segments reach the path-style URL.
  • Dev runner: scripts/dev spawns the server with extendEnv: false, so it's already closed to ambient S3 settings.
  • Ran locally: vitest run packages/content-store (24/24), eslint on the changed files, and package tsc --noEmit, all clean. No live Neon or AWS calls.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed ab00a6a against origin/tier2/390-admission at 0c8c567, using git diff origin/tier2/390-admission...HEAD. Spec: #391 and the content-store requirements in #384. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings. The adapter uses the existing ContentStore contract and Effect configuration/layer patterns. The Azure implementation and dependencies are removed rather than retained behind compatibility code.

Spec

No merge-blocking intent findings. The change covers path-style requests, branch-specific endpoint configuration, explicit credentials, server selection with filesystem fallback, and shared offline/live contract coverage. The named documentation updates are present. No wire, CLI, migration, or UI contract changes were needed.

Verification performed:

  • pnpm exec vitest run packages/content-store/src: 24 tests passed across 3 files.
  • Separate loopback-only S3 smoke: a 2 MiB binary round-trip, prefix listing, UTF-8 replacement, idempotent deletion, and ObjectNotFound after deletion all passed.
  • The live Neon suite was not rerun; no external bucket was accessed.

Summary: Standards 0 blockers, worst none; Spec 0 blockers, worst none.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Standards

Effect service conventions: no findings. S3ContentStore is a concrete make and layer on the ContentStore port. Config and Redacted secrets come from the environment, and the barrel stays export * as S3ContentStore.

  1. Hard. docs/DEVELOPMENT.md describes a different live suite than the command it prints. AGENTS.md, under "Hit every surface", requires the dev-loop doc to match a new test tier. The live section says the suite uses the dedicated S3 settings, and that table is PATCHY_S3_BUCKET, PATCHY_S3_ENDPOINT, PATCHY_S3_REGION, PATCHY_S3_ACCESS_KEY_ID, and PATCHY_S3_SECRET_ACCESS_KEY. packages/content-store/live/S3ContentStore.live.ts lines 7-19 rewrite every lookup to NEON_BUCKET, AWS_ENDPOINT_URL_S3, AWS_REGION, AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY. The spike file at ~/.config/patchy-cloud/neon-spike.env already uses those names, and NEON_BUCKET is patchy-content, so the printed node --env-file command works today. A file filled in from the table misses every key the suite reads. package.json also adds pnpm test:content-store:live, which does not load the env file, and the doc never mentions the script. Document the spike names beside the command. The later sentence that the server layer ignores ambient AWS_* names is true of S3ContentStore.make and should stay.

  2. Small. packages/content-store/src/ContentStore.ts lines 32-34 still say the disk or the blob service refused. AGENTS.md says keep comments up to date, and the content-store glossary avoids "blob store". Say filesystem or object store.

Baseline smells: none. The text encode and decode pair in S3ContentStore.ts matches the filesystem store. AGENTS.md's YAGNI rule wins over a helper for those two lines.

Spec

Issue #384, for this PR, is the content-store row in §3 and the first bullet of §18: an S3 layer for Neon Object Storage, path-style and branch-scoped, the production store, buildable on its own.

(a) Missing or partial: none.

(b) Scope creep: none. No CDK, first deploy, object-key layout, or sweep.

(c) Implemented but wrong: none.

Met. forcePathStyle: true and the branch endpoint are the client, S3ContentStore.ts lines 24-40. The server uses that layer when PATCHY_S3_BUCKET is set and the filesystem otherwise, apps/server/src/Server.ts lines 83-86. list is a paginated prefix stream of { key, lastModified }, which is what a later sweep needs.

Issue 391

The ticket asks for that same store, plus a done-when and a surface list #384 does not spell out.

Met: the S3 layer in packages/content-store, path-style addressing, branch scope via the endpoint, credentials from Effect Config, production selection, the filesystem kept for dev and tests, Azure deleted (AzureContentStore, BlobContainer, and the Azure test), s3rver inside pnpm test, the live tier excluded from pnpm test, the CONTEXT-MAP line, the DEVELOPMENT.md key table, and ADR-0003.

Partial:

  • The live bucket. The suite reaches patchy-content because NEON_BUCKET in the spike file is that name. Leaving the name out of source is right. The doc mismatch above is what can make the next run miss the bucket.
  • packages/content-store/CONTEXT.md. The Azure avoid-words are gone. The glossary still does not say production bytes go to Neon Object Storage. The map line does.
  • Streaming bodies. put and get take a string and a Uint8Array, same as the filesystem layer. getBytes buffers with transformToByteArray inside the abortable call. That is the contract both layers already had. A stream-shaped body would be a new interface.

The README layout line, the s3rver patch, and the raw HTTP error tests are extra. They earn their place, below.

Method

One ContentStore contract, three runners: filesystem, patched s3rver, and an opt-in Neon client. Production uses @aws-sdk/client-s3 with path-style addressing, explicit credentials, and checksums only when the API requires them, S3ContentStore.ts lines 37-47. Neon documents that client and those two settings. The repo's Effect HTTP client has no SigV4 signer. Explicit credentials mean the SDK default chain is not consulted. A missing secret fails when the layer builds. pnpm dev uses a closed environment and sets PATCHY_STORAGE_DIR only, so ambient spike variables cannot select S3. Nothing creates a bucket.

The s3rver patch is the right local fix. s3rver 3.7.1 encrypts continuation tokens with DES, and current OpenSSL will not run DES, so the second list page throws before any assertion. The tokens are opaque. AES-256-CBC with a 16-byte IV is enough, and patchedDependencies will fail install if the version moves. s3rver accepts any request whose access key id is S3RVER and does not check SigV4. The offline suite cannot catch a signature or checksum Neon would reject. The live tier is that check, and it sits outside pnpm test on purpose.

Cleared against the code: pagination continues only with a new token and fails closed on a stuck one, the contract writes 1005 keys, the path-style URL is https://<branch-host>/bucket/key, the region comes from config, WHEN_REQUIRED adds no x-amz-checksum-* header on PutObject, NoSuchKey becomes ObjectNotFound, delete of a missing key succeeds, and a Uint8Array subarray is sent with its own byteOffset and byteLength. Secrets stay Redacted.

../ is a legal object key. The filesystem rejects it because the resolved path would leave the root. Callers already use files/<patchId>/....

YAGNI

Small, and the shape is right. One module does config, the client, put, get, delete, and a paged list. Azure is gone, with no shim.

Keep the spike-name remap. That file is shared with the rest of the Neon spike and already holds NEON_BUCKET and AWS_*. Pointing the suite at PATCHY_S3_* means copying those secrets under a second set of names. Fix the doc.

Worth deleting: AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_CONTAINER, and AZURE_STORAGE_CONNECTION_STRING in scripts/packed-cli-e2e.mjs around line 2709. Nothing reads them. That e2e already drops every PATCHY_* name.

Leave the 1005-key case in the shared suite. It is the test that makes a one-page list fail offline. Three keys do not.

Leave the pagination loop, the checksum flags, forcePathStyle, the s3rver patch, the HTTP status cases, and the live file. A NoSuchBucket 404 has to stay StoreUnavailable. s3rver's happy path never returns that status.

list in S3ContentStore.ts lines 103-144 is the one dense function. Stream.paginate wants a page plus an optional token, and the throw above NextContinuationToken is what makes that use safe. It reads correctly once you know that. I would not split it.

Summary

Standards: 2 findings. The worst is the live-suite doc naming PATCHY_S3_* while the suite reads the spike file's NEON_BUCKET and AWS_* names. Spec: 0 findings.

Reviewed with Grok 4.7 in the Grok harness.

@allisonmahmood

allisonmahmood commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner Author

Updated through 013c945.

Corrected the fake ownership decision

My previous justification for keeping the patched s3rver was wrong. Owning its multipart/XML dependencies and cipher patch was not justified by the four S3 operations this layer uses.

  • Replaced it with test/S3HttpFixture.ts: 111 lines including the listener/configuration setup shared with the existing HTTP error tests. A Map stores object bytes and timestamps behind node:http; the real AWS S3 client still serializes requests and parses responses over loopback HTTP.
  • Supports only PutObject, GetObject, DeleteObject, and ListObjectsV2, with XML escaping, prefix filtering, 1,000-key pages, continuation tokens, and missing-key errors. Existing HTTP tests retain access-denied, missing-bucket, service-unavailable, and truncated-body cases through injected response handlers.
  • Removed s3rver, its types, its 218-line patch, and both dependency overrides. The install pruned 114 packages and the lockfile lost 862 lines. No replacement dependencies or advisory exceptions.
  • Kept the production adapter, shared contract, and live Neon suite unchanged. The local fixture deliberately does not verify signatures or emulate unrelated S3 features; live Neon remains the provider-compatibility check.

Other review dispositions retained

  • Fixed Opus chore(deps): bump the minor-and-patch group with 11 updates #2 and Grok's live-suite documentation finding: documented the actual NEON_BUCKET/AWS_* inputs, their mapping to server PATCHY_S3_* settings, and both supported live-suite invocations.
  • Fixed Grok's terminology/glossary findings and removed obsolete Azure environment exclusions.
  • Kept the existing broad environment sanitizer for Opus chore(deps): bump github/codeql-action/upload-sarif from 4.37.4 to 4.37.8 #1: it removes every ambient PATCHY_* variable before applying test-owned settings, so the claimed S3 leak was not present. Explicit S3 poison settings remain in the packed CLI CI invocation.
  • Kept the live spike-name mapping, buffered byte contract, pagination, checksum settings, error distinctions, and 1005-object contract case. The AES patch is removed, not retained.
  • Astra reported no blockers; the original review-body and inline-comment lists were empty.

Verification for the replacement

  • All 24 offline content-store tests passed with the owned fixture.
  • A standalone real-SDK HTTP smoke passed: 2 MiB binary round-trip, escaped object key, overwrite, 1006-object pagination with timestamps, idempotent deletion, and missing-key error.
  • Workspace lint and typecheck passed; formatting passed.
  • Full pnpm audit: no known vulnerabilities.
  • No live Neon files or shared-contract tests changed; no live bucket operations were needed for this replacement.

All eight checks passed on 013c94557ec1388ce5655ecb13e851ae9488b4a3: test (22), test (24), postgres-concurrency, clerk-live, lint, cli-smoke, dependency-review, and label. CI run. Final feedback check found no new conversation comments, review bodies, or inline comments. GitHub reports CLEAN/MERGEABLE against the unchanged stacked base tier2/390-admission. No merge performed.

@allisonmahmood allisonmahmood linked an issue Sep 28, 2026 that may be closed by this pull request
Base automatically changed from tier2/390-admission to main October 1, 2026 01:01
Replace the unused Azure backend with path-style S3 storage configured for a Neon branch and private bucket. Preserve the ContentStore contract and keep filesystem storage for local use.

Share contract coverage across filesystem, local S3 and an opt-in Neon live tier. Patch s3rver continuation tokens to use AES because current Node/OpenSSL disables DES.

Verified 1091 offline tests with four workers, eight live Neon contract cases, a 2 MiB live round-trip smoke, workspace typecheck and lint. Standards and spec reviews found no issues.

Implements #391.
Document the live tier's spike environment names and both invocation paths. Clarify storage terminology and remove obsolete Azure environment exclusions.

Keep the packed runner's existing PATCHY_* sanitization and exercise it with poisoned S3 settings in CI. Replace s3rver's vulnerable busboy/dicer dependency with the compatible maintained Fastify parser.

Verified 24 offline and 8 live storage cases, packed CLI end-to-end with ambient S3 poison, and multipart upload plus malformed-header rejection on loopback.
@allisonmahmood
allisonmahmood force-pushed the tier2/391-neon-object-storage branch from 013c945 to c240955 Compare October 1, 2026 01:01
@allisonmahmood
allisonmahmood merged commit 29e4934 into main Oct 1, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the tier2/391-neon-object-storage branch October 1, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:server Touches the server area size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(content-store): the Neon Object Storage layer

1 participant