Skip to content
Agent Field Notes
Course contentsExpand a topic to choose a lesson.

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

Semantic and authorization equivalence for cache reuse

Examine different caching tiers, permission versions, latency and real savings.

Learning objectives: The prerequisite for a cache hit is that the new request and the old result are still equivalent in terms of task semantics, data version, and authorization scope. Neither similar text nor short-term expiration can be independently proven to be safe for reuse.

Content checked: 2026-10-03 · Each level has independent explanations, tasks and inspections

Choose a starting point based on your familiarity with this topic. Current level: Debugging · Diagnose failures. After completing the task, continue to the next level. Reading and self-checks alone do not establish mastery.

On this level

Review the prerequisites

Suitable for: Backend developers learning Agent applications.

Semantic and authorization equivalence for cache reuse
The prerequisite for a cache hit is that the new request and the old result are still equivalent in terms of task semantics, data version, and authorization scope. Neither similar text nor short-term expiration can be independently proven to be safe for reuse.

How does the mechanism work?

Step-by-step explanation
  1. Is it enough to just put user_id into the key?

    The main question designs cache keys; explain why a user identifier alone is insufficient.

  2. What should I do if the permissions have changed but the cache has not expired?

    Cache versioning must also handle uncertainty in revocation propagation.

  3. How to verify when semantic cache encounters "contains" and "does not contain"?

    Semantic matching can miss decisive conditions, so provide concrete checks.

Debugging · Diagnose failures

Diagnose failures · Semantic and authorization equivalence for cache reuse

Objectives of this level: Find the first incorrect decision in a cache leak using paired inputs and a source repair.

Visual guide · A hit needs current equivalence

A hit needs current equivalence

A fresh TTL is only one test. Current authority comes first; write receipts require reconciliation rather than read-cache reuse. Select the figure to open it at full size.

Known faulty implementation

A helper that returns hit whenever expires>now omits current authorization, completeness and version binding. A second helper checks tenant/order/query but omits user from the entry key; it can reuse another user’s result under the same tenant. Neither fault is fixed by reducing TTL.

Same-input diagnosis

Use the foundation payload, then change principal.active=false without changing entry. Expected denied/revoked, faulty hit. Restore active and change entry.user=u2: expected miss/key_mismatch. Restore user and change request.policy=4: expected miss/version_mismatch. Record first wrong branch, expected/actual and input hash.

Repair and distinguish

Place identity/active/ownership checks before cache reuse; include user in the entry binding. Show the actual source diff, the original failure, both repaired reports and a new u3 entry. Keep input unchanged. The 20-case run is regression evidence; the added unseen-to-the-author condition and reviewer observation belong in a separate assessment record.

python3 lab_runner.py scaffold --course agent-cache-correctness --out cache_student.py
python3 lab_runner.py grade --course agent-cache-correctness --module cache_student.py --out cache-report.json

Runner · Cases · Source package

code example

One-field counterexamples

Change only entry.user from u1 to u2. A key missing user incorrectly hits; expected miss/key_mismatch. Restore user and change request.policy to 4; expected miss/version_mismatch. Show the different first failing branches.

Acceptance task for this level

Reproduce a TTL-only or user-omitting key bug, distinguish it from stale data, patch its source and rerun the same cases plus a new user variant.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

Both revoked and old-policy cases fail. How do you avoid treating them as one TTL problem?

Further explanations and practice

When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.

All linked explanations and exercises (1 )

Sources and verification scope

The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.