Edge Thumbnail Store accepts a store that does not refresh a key on overwrite

オープン
#869 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@BOBOGUAGUA428 がすでに取り組んでいます。

2026年11月26日 から。

評価

この issue はまだ評価されていません。

説明

Observed behavior

Edge Thumbnail Store (lru-cache) accepts a ThumbnailStore whose put overwrites an existing key without marking it most recently used. Such a store passes all five built-in cases, even though the scenario requires an overwrite to refresh recency.

The case labeled "put updates refresh recency" (capacity 2: put(1,1) put(2,2) put(1,10) get(1) get(2)) never inserts a new key after the overwrite, so nothing is evicted and the order of keys 1 and 2 never affects the result.

Expected behavior

A store that does not refresh a key on overwrite should fail at least one case. A correct LRU store should still pass. The contract in problem-bank/variants.json states that put(key, value) "inserts or overwrites the key and marks it most recently used".

Reproduction
  1. Use a source checkout at revision e30d6284d0f1cf8d4777d455e94c95e40e69156b.
  2. Load the judge specification for lru-cache from problem-bank/judges.json.
  3. Run each case's operation sequence against the incorrect store below, and grade the returned outputs with checkAnswer from web/lib.js. Observe that all five cases pass.
  4. Run the sequence put(1,1) put(2,2) put(1,10) put(3,3) get(2) get(1) get(3) on a capacity-2 store. A correct store returns -1, 10, 3, because the overwrite makes key 1 most recent and put(3,3) evicts key 2. The incorrect store returns 2, -1, 3, because key 1 keeps its old position and is evicted.

The incorrect JavaScript store used in step 3:

class ThumbnailStore {
  constructor(capacity) {
    this.capacity = capacity;
    this.map = new Map();
  }
  get(key) {
    if (!this.map.has(key)) return -1;
    const value = this.map.get(key);
    this.map.delete(key);
    this.map.set(key, value);
    return value;
  }
  put(key, value) {
    if (this.map.has(key)) {
      // Map.set on an existing key keeps its old insertion order.
      this.map.set(key, value);
      return;
    }
    if (this.map.size === this.capacity) {
      this.map.delete(this.map.keys().next().value);
    }
    this.map.set(key, value);
  }
}
CodeTrial version

Not built: neither codetrial --version nor cargo run -- --version was run. Reproduced from a source checkout at e30d6284d0f1cf8d4777d455e94c95e40e69156b (Cargo.toml version 0.1.0); the bug is in judge data, so no binary is involved.

Environment

OS: macOS arm64
Browser: Not used; runner-level reproduction
Language: JavaScript (the judge cases are shared by every language)
Interview loop: Not applicable
Problem: Edge Thumbnail Store (lru-cache)
REACTO or STAR step: Not applicable
Reconnect: Not applicable

Node.js v24.22.1.

Sanitized evidence

The stale-recency store passed all five built-in cases:

PASS capacity 2, classic eviction sequence
PASS capacity 1, immediate eviction
PASS put updates refresh recency
PASS new cache
PASS missing key

I plan to add the sequence above as a case in problem-bank/judges.json, regenerate web/judges/edge-thumbnail-store.json with scripts/gen-problems.py, and add a test in tests/browser/compiler-explorer.test.js that checks every expected value against a reference store and requires the new case, looked up by label, to reject the stale-recency store. The test fails against the five cases on main. Please assign this issue to me.

Public data confirmation
  • I removed credentials, session tokens, candidate recordings, and personal interview content from this public report.
主要言語
Rust
スター
236
フォーク
153
平均マージ
1日 9時間
マージ済み PR(30日)
187

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sysprog21/codetrial のほかの issue

sysprog21/codetrial の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。