Skip to content

[WRONG BRANCH] fix(server): share stable dashboard asset snapshots - #382

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-unauthenticated-memory-amplification
Draft

[WRONG BRANCH] fix(server): share stable dashboard asset snapshots#382
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-unauthenticated-memory-amplification

Conversation

@luvs01

@luvs01 luvs01 commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The previous change fixed a package-replacement race by eagerly snapshotting non-HTML GUI assets, but it allocated a full per-request byte buffer which enables unauthenticated aggregate memory amplification and blocks the event loop.
  • The goal is to preserve the stable snapshot and Content-Length semantics while avoiding one full-copy-per-request allocation and allowing concurrent requests to share a single immutable asset representation.

Description

  • Add a StaticAssetSnapshot structure and a process-wide staticAssetSnapshots cache keyed by file path and an inode/mtime fingerprint to detect replacements and reuse snapshots.
  • Implement staticAssetSnapshot(path, contentType) which stat-guards the file, returns a cached Blob when the fingerprint matches, and otherwise creates and caches one immutable Blob from the file bytes.
  • Replace the eager per-request readFileSync(filePath) response body with a shared Blob returned from staticAssetSnapshot, while preserving Content-Type and browserSecurityHeaders and leaving HTML handling unchanged.
  • Update the test tests/gui-static.test.ts to assert that an already-created response retains the original bytes while a subsequent request after replacement receives the refreshed asset.

Testing

  • Ran the focused regression test with bun test tests/gui-static.test.ts, which passed.
  • Ran type checking with bun run typecheck, which passed.
  • Ran git diff --check / repository checks (no whitespace or check errors).
  • Attempted a full bun run test; the full suite run exposed unrelated pre-existing failures (an api-catalog-route auth assertion expecting 401 returned 403, and a chat-completions test timed out) so the long full-suite run was stopped after those unrelated failures.

Codex Task

@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: 368c3ae0-90ae-48e5-be2f-02fd7e39cd58


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

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@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-31T00:51:58.238151Z 053e403 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 github-actions Bot added the bug Something isn't working label Aug 31, 2026
@github-actions github-actions Bot changed the title fix(server): share stable dashboard asset snapshots [WRONG BRANCH] fix(server): share stable dashboard asset snapshots 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.

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

@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: 053e403fd4

ℹ️ 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 thread src/server/gui-static.ts
// Blob owns one immutable copy that every response can share. This keeps a response
// stable across package replacement without allocating the asset again per request.
const blob = new Blob([readFileSync(path)], { type: contentType });
staticAssetSnapshots.set(path, { fingerprint, blob });

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 Evict snapshots for obsolete asset paths

When a running source checkout rebuilds the dashboard—or a live package update replaces it—Vite gives changed JS/CSS bundles new content-hashed paths. Each subsequently requested bundle is retained by this process-wide map, while entries for the now-deleted paths are never removed and their full Blob contents remain reachable. Repeated dashboard rebuilds or updates therefore accumulate roughly one GUI bundle per version for the lifetime of the proxy, undermining the memory-amplification fix; bound the cache or purge entries that no longer belong to the current gui/dist snapshot.

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