P0-G: Implement SalienceEngine — hotpath admission, promotion & eviction#44
P0-G: Implement SalienceEngine — hotpath admission, promotion & eviction#44
Conversation
Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
- Add PageActivity, HotpathEntry, TierQuotas, SalienceWeights, TierQuotaRatios to core/types.ts - Extend MetadataStore interface with hotpath/activity methods - Create core/HotpathPolicy.ts: computeCapacity, computeSalience, deriveTierQuotas, deriveCommunityQuotas - Create core/SalienceEngine.ts: computeNodeSalience, batchComputeSalience, shouldPromote, selectEvictionTarget, bootstrapHotpath, runPromotionSweep - Extend IndexedDbMetadataStore with hotpath_index and page_activity stores - Add 39 tests in tests/SalienceEngine.test.ts covering all requirements Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
…est, add clarity comments Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Introduces the “hotpath” salience policy + engine layer (Williams Bound) and wires it into storage via new MetadataStore capabilities, with accompanying unit tests to validate capacity/salience math and promotion/eviction behavior.
Changes:
- Add
core/HotpathPolicy.ts(capacity, salience, tier/community quota derivation) andcore/SalienceEngine.ts(salience computation + promotion/eviction lifecycle). - Extend
core/types.tsMetadataStorewith hotpath index + page activity APIs, and implement them instorage/IndexedDbMetadataStore.tswith an IndexedDB schema bump to v2. - Add comprehensive unit tests in
tests/SalienceEngine.test.tsfor policy math and lifecycle behavior.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
core/types.ts |
Adds PageActivity, HotpathEntry, quota/weight types, and new MetadataStore hotpath/activity methods. |
core/HotpathPolicy.ts |
Defines default hotpath policy and implements capacity/salience/quota derivation functions. |
core/SalienceEngine.ts |
Implements salience computation and hotpath promotion/eviction logic (including community-aware logic). |
storage/IndexedDbMetadataStore.ts |
Bumps IndexedDB schema to v2 and adds persistence for hotpath index + page activity. |
tests/SalienceEngine.test.ts |
Adds unit tests for policy + engine behavior and determinism. |
.gitignore |
Ignores package-lock.json. |
| // Tier is at quota — promote only if beats weakest in tier | ||
| const weakestId = await selectEvictionTarget(tier, communityId, metadataStore); | ||
| if (weakestId === undefined) continue; | ||
|
|
||
| const weakestEntry = tierEntries.find((e) => e.entityId === weakestId); | ||
| const weakestSalience = weakestEntry?.salience ?? 0; |
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
… cache entries, fix tests - Enforce tier quotas regardless of capacityRemaining (review comment 2) - Enforce community quotas regardless of capacityRemaining (review comment 1) - When tier is full, evict from full tier not scoped to communityId (review comment 3) - Treat candidate community as at least size 1 for quota derivation (review comment 4) - Cache hotpath entries in-memory during sweep loop (review comment 5) - Fix tautological test assertion to verify against actual tier quota (review comment 6) - Add new community condition: communityCount > 0 so new communities can earn first slot Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
All 6 review comments addressed in commit
|
|
@copilot There was apparently some overlap between this and another issue, as a result there was a merge conflict. I attempted to fix it manually but now there are checks failing and this is complex enough, it might be worth a top to bottom redraft of the effected files. While you're in there, please ensure all non-comment characters are called by name, not by greek math symbols. Gamma, beta, rho are much better variable names than their greek letter counterparts. |
…ith English names Clean redraft of HotpathPolicy.ts, types.ts, IndexedDbMetadataStore.ts to resolve broken merge artifacts (duplicate functions, interfaces, syntax errors). - core/HotpathPolicy.ts: unified HotpathPolicy interface with structured salienceWeights/tierQuotaRatios, computeCapacity with optional c param, computeSalience using named weights (alpha/beta/gamma not Greek letters), deriveTierQuotas, deriveCommunityQuotas with min-1 guarantee - core/types.ts: single set of PageActivity, HotpathEntry, TierQuotas, TierQuotaRatios, SalienceWeights; MetadataStore with removeHotpathEntry - storage/IndexedDbMetadataStore.ts: single applyUpgrade, single set of hotpath methods with removeHotpathEntry and deterministic eviction - tests/HotpathPolicy.test.ts: updated to structured DEFAULT_HOTPATH_POLICY - All Greek symbol variables and special Unicode chars replaced with ASCII equivalents (sigma, alpha, beta, gamma, ->, ~=) All 192 tests pass. Build and lint clean. Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
Done in All Greek/Unicode symbols replaced with English names throughout: |
SalienceEngine is the decision-making layer for hotpath admission, needed by ingest, query, and Daydreamer before any of those modules can be implemented.
New modules
core/HotpathPolicy.ts— Williams Bound policy foundation.computeCapacity(H(t)),computeSalience(sigma formula),deriveTierQuotas/deriveCommunityQuotas(largest-remainder allocation), and frozenDEFAULT_HOTPATH_POLICYwith structuredHotpathPolicyinterface containing nestedsalienceWeightsandtierQuotaRatiosobjects (c=0.5, alpha=0.5, beta=0.3, gamma=0.2, tier ratios).core/SalienceEngine.ts— Core salience computation (computeNodeSalience,batchComputeSalience), admission gating (shouldPromote), eviction targeting (selectEvictionTargetwith deterministic tie-breaking by entityId), and lifecycle helpers (bootstrapHotpath,runPromotionSweep) with community-aware quota enforcement. Tier and community quotas are enforced regardless of overall capacity remaining, preventing monopolization during ramp-up. Uses in-memory entry caching during sweep loops to avoid repeated store reads.Type & storage extensions
core/types.ts— AddedPageActivity,HotpathEntry,TierQuotas,TierQuotaRatios,SalienceWeights; extendedMetadataStorewith hotpath methods (includingremoveHotpathEntry) and page activity methods.storage/IndexedDbMetadataStore.ts— DB schema v2:hotpath_indexstore (keyed byentityId, indexed bytier) andpage_activitystore. Implements all newMetadataStoremethods includingremoveHotpathEntryandevictWeakestwith deterministic tie-breaking by entityId.Tests
tests/SalienceEngine.test.ts— 40 tests covering: H(t) monotonicity/sublinearity/edge-case safety, sigma formula correctness, bootstrap fills to exactly H(t), steady-state promotion only when candidate beats weakest, eviction targets exactly the weakest resident, community quotas prevent single-community monopolization, tier quotas prevent hierarchy-level domination (even when overall capacity has room), deterministic eviction under identical state.tests/HotpathPolicy.test.ts— Updated to use structuredDEFAULT_HOTPATH_POLICYinterface with nestedsalienceWeightsandtierQuotaRatios.Naming conventions
All variable names and comments use English names (
alpha,beta,gamma,sigma) instead of Greek letter Unicode characters. Unicode special characters (arrows, mathematical symbols) replaced with ASCII equivalents throughout.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.