Skip to content

[WRONG BRANCH] fix(server): bound remote catalog serialization - #383

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-data-plane-resource-exhaustion
Draft

[WRONG BRANCH] fix(server): bound remote catalog serialization#383
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-data-plane-resource-exhaustion

Conversation

@luvs01

@luvs01 luvs01 commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent a low-bandwidth attacker with a data-plane key from forcing synchronous materialization of very large catalogs on every GET/HEAD /v1/catalog request and exhausting CPU/memory or blocking the Bun event loop.
  • Apply a route-level defense for the remotely reachable catalog without changing the management-plane behavior or bytes emitted by the shared serializer.

Description

  • Add serializeRemotePersistedCatalog() in src/server/catalog-download.ts that preflights the on-disk file size via statSync, returns an immediate over-limit sentinel, and otherwise calls the existing shared serializer; the function caches the serialized body/ETag by a high-resolution file identity and coalesces concurrent cache misses behind a single promise.
  • Keep the original serializePersistedCatalog() unchanged so the management route still materializes and emits the same bytes; the remote path enforces the 256 MiB limit before materialization and rechecks after serialization as defense-in-depth.
  • Update the data-plane handler in src/server/index.ts to use serializeRemotePersistedCatalog(), to return 507 catalog_too_large for preflighted oversize files, and to preserve existing conditional-GET (If-None-Match) and HEAD semantics.
  • Add a focused regression test in tests/api-catalog-route.test.ts that verifies the remote serialization is cached and that an oversized sparse/truncated file is rejected from metadata before JSON parsing.

Testing

  • Ran typecheck with bun x tsc --noEmit which completed successfully.
  • Ran focused tests with the repository-bundled Bun: bun test tests/api-catalog-route.test.ts --test-name-pattern 'caches remote serialization|serves a supported large catalog' and both targeted tests passed.
  • Ran node_modules/bun/bin/bun.exe test tests/api-catalog-route.test.ts (bundled Bun 1.4.0) and observed the serializer-focused tests passed; system Bun 1.2.14 lacked node:zlib support referenced by some tests, so the bundled Bun was used for focused verification.
  • Attempted the full test run but the environment produced unrelated, platform-specific failures and HTTP 403 variations; the focused regression coverage for the changed subsystem passed as described above.

Codex Task

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-31T01:00:21.673757Z 12fc5cf PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 31, 2026
@github-actions github-actions Bot changed the title fix(server): bound remote catalog serialization [WRONG BRANCH] fix(server): bound remote catalog serialization Aug 31, 2026
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 610a7034-5acc-4493-8f65-2740e9f04ea2


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions
github-actions Bot marked this pull request as draft August 31, 2026 00:57

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12fc5cf0d4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +115 to +116
const after = catalogFileIdentity(path);
if (after?.key !== identity.key) return { body: null };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retry when the catalog changes during serialization

When a catalog sync atomically replaces this file after the initial identity check but before this post-serialization check, the new file is valid and present, yet this branch returns { body: null }, which /v1/catalog maps to 404 catalog_not_found. This race can occur during normal startup because src/cli/index.ts starts the listener at line 268 before running the startup catalog sync at lines 393–399, and it can also occur during a manual sync; retry serialization against the new identity instead of reporting that no catalog exists.

Useful? React with 👍 / 👎.

Comment on lines +98 to +100
const identity = catalogFileIdentity(path);
if (!identity) return { body: null };
if (identity.size > MAX_REMOTE_CATALOG_BYTES) return { body: null, error: "too_large" };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Invalidate the cache when the catalog becomes ineligible

When a previously cached catalog is later deleted, becomes unreadable, or is replaced by an oversized file, these early returns never clear remoteCache, so the old serialized body remains strongly referenced for the rest of the process unless another valid catalog is successfully serialized. Because one cached entry may be nearly MAX_REMOTE_CATALOG_BYTES (256 MiB), this can retain substantial heap even after the operator removes the problematic catalog; clear the stale cache whenever the current path or identity is missing or rejected.

Useful? React with 👍 / 👎.

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

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant