Skip to content

Fix module-loader cache expiry and concurrency - #1753

Open
Zetazzz wants to merge 3 commits into
mainfrom
agent/express-context-loader-bounds
Open

Fix module-loader cache expiry and concurrency#1753
Zetazzz wants to merge 3 commits into
mainfrom
agent/express-context-loader-bounds

Conversation

@Zetazzz

@Zetazzz Zetazzz commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Frequent cache hits could keep module configuration alive indefinitely by extending its TTL. Concurrent misses also started duplicate queries, and invalidation could be undone when an older query completed.

Use a hard TTL, coalesce concurrent misses for the same logical key, and prevent invalidated in-flight work from repopulating the cache or removing newer pending work. The existing default limit of 100 completed entries is retained.

Related: constructive-io/constructive-planning#1693 (F11). This PR targets main and has no dependency on #1716.

Design decisions

  • Retain the existing key: databaseId:apiId when an API ID is present, otherwise databaseId. Logical database IDs already distinguish tenant databases. Pool identities and routing schemas are not added; expanding cache identity is not required for these lifecycle improvements.
  • Retain invalidate(databaseId?). A database ID clears its plain key and all API entries; omitting it clears every entry. Registry invalidation forwards the same operation to each loader. Additional invalidation parameters are not needed.
  • Keep absence uncached. undefined and PostgreSQL 42P01 results remain uncached so later calls can discover new configuration. Concurrent callers can share an in-flight absence check. Other errors propagate without being cached; negative caching is not needed.
  • Existing callers can still receive a result that was invalidated while running, but it cannot repopulate the cache. Its cleanup cannot remove a newer pending resolution.

The README records these deliberate scope decisions. The changes stay within the express-context loader cache and its documentation/tests.

Validation

  • Frozen-lockfile install with pnpm 10.34.5 passed.
  • Express-context and its workspace dependencies built successfully (CJS and ESM).
  • All express-context tests passed: 120 tests across 8 suites.
  • Targeted ESLint and git diff --check passed.
  • Full CI on 724b4400183a: 17/17 jobs passed, including Linux, Windows, PostgreSQL, MinIO integration, and Ollama. The cloud run also confirmed all 120 express-context tests passed.

Owner tests cover logical database/API isolation on shared pools, reuse and concurrent coalescing for the same logical key across contexts, plain-key/API invalidation while preserving other databases, hard TTL, the default 100-entry bound, both completion orders for invalidated in-flight queries, uncached absence/42P01 rediscovery, propagated errors, and registry forwarding.

@Zetazzz
Zetazzz force-pushed the agent/express-context-loader-bounds branch from e8438de to d5dac4d Compare September 6, 2026 01:51
@Zetazzz
Zetazzz force-pushed the test/performance-harness-core branch from 45cbb07 to 658736e Compare September 6, 2026 01:51
@Zetazzz
Zetazzz force-pushed the test/performance-harness-core branch from 658736e to f7c63ec Compare September 7, 2026 03:22
@Zetazzz
Zetazzz changed the base branch from test/performance-harness-core to main September 7, 2026 03:23
@Zetazzz
Zetazzz marked this pull request as ready for review September 7, 2026 03:23
@tenki-reviewer

tenki-reviewer Bot commented Sep 7, 2026

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR introduces two new capabilities: an LRU-cached, coalescing module loader in packages/express-context and a new packages/perf-harness package for spawning benchmark workers, collecting metrics, and producing reports.

Files Change
packages/express-context/src/loaders/* + cache-lifecycle test Adds a bounded LRU loader with hard TTL, concurrent-miss coalescing, and exact/logical invalidation.
packages/perf-harness/src/process.ts, run.ts, index.ts, stock-worker.ts Implements the worker spawn CLI protocol, base64url envelope, and secret handling.
packages/perf-harness/src/metrics.ts, report.ts, types.ts Adds metrics collection and report aggregation with median/min/max and percent-change math.
packages/perf-harness/src/fixture.ts Generates a seeded PostgreSQL fixture schema with identifier quoting and bounds checks.
packages/perf-harness/src/schedule.ts Provides seeded deterministic benchmark case ordering.
.github/workflows/run-tests.yaml + perf-harness tests/config Wires the new package into CI and adds unit tests across process, run, report, schedule, and fixture.

Reviewed commit: d5dac4d

@Zetazzz
Zetazzz force-pushed the agent/express-context-loader-bounds branch from d5dac4d to ca37b7c Compare September 7, 2026 03:23
@Zetazzz Zetazzz changed the title Isolate and bound control-plane loader caches Fix module-loader cache expiry and concurrency Sep 7, 2026
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.

2 participants