Review the prerequisites
Suitable for: Backend developers learning Agent applications.
- Revoke memories, clean up derivatives, and prevent stale data from returning
- Deleting the text and prohibiting its reuse are separate steps. The authoritative revocation state must participate in reads and writebacks before the old replica, otherwise old checkpoints, backfills, or caches will reintroduce deleted facts.
How does the mechanism work?
Step-by-step explanation
- How should the product commitment be defined if the removal coincides with tool shipping?
After deleting copies, examine the race between revocation and dispatch.
- How to prevent tombstone loss during backup and restore?
Recovery may restore stale knowledge of revocations even after physical cleanup.
- What are the costs of the full-scope epoch and the itemized versions?
Move from preventing revoked memory from reappearing to implementable performance trade-offs.
Implementation · Build it
Implement the contract · Revoke memories, clean up derivatives, and prevent stale data from returning
Objectives of this level: Implement two unsolved pure functions and verify the submitted module, not the supplied observer.
Visual guide · Restore through current authority
Deleting one payload does not invalidate its copies. This local view checks dependencies; atomic cross-service revocation and cleanup are separate design work. Select the figure to open it at full size.
Your deliverable and complete input
Use a new practice directory and Python 3 standard library. Save revocation_lab.py as revocation_lab.py. This file contains fixtures and a grader, not the full solution. Implement the following signatures in revocation_student.py; scaffold emits these unsolved functions and refuses to overwrite an existing file:
def restore_context(authority, checkpoint):
raise NotImplementedError("implement restore_context")
def admit_write(authority, candidate):
raise NotImplementedError("implement admit_write")
{
"authority": {
"available": true,
"scope": [
"tenant-a",
"user-1",
"project-1"
],
"epoch": 2,
"sources": {
"s-email": {
"version": 2,
"revoked": true
},
"s-style": {
"version": 1,
"revoked": false
}
},
"memories": {
"m-email": {
"scope": [
"tenant-a",
"user-1",
"project-1"
],
"version": 1,
"source_id": "s-email",
"source_version": 1,
"body": "send email digests"
},
"m-style": {
"scope": [
"tenant-a",
"user-1",
"project-1"
],
"version": 1,
"source_id": "s-style",
"source_version": 1,
"body": "use short paragraphs"
}
}
},
"checkpoint": {
"scope": [
"tenant-a",
"user-1",
"project-1"
],
"epoch": 1,
"refs": [
{
"memory_id": "m-email",
"version": 1
},
{
"memory_id": "m-style",
"version": 1
}
],
"summary": {
"body": "send a short email digest",
"dependencies": [
{
"source_id": "s-email",
"version": 1
},
{
"source_id": "s-style",
"version": 1
}
]
}
},
"candidate": {
"scope": [
"tenant-a",
"user-1",
"project-1"
],
"epoch": 2,
"memory_id": "renamed-email",
"source_id": "s-email",
"source_version": 2,
"body": "send email digests"
}
}
Input validation is part of the contract
All displayed fields are required. Objects are dicts; scopes are lists of exactly three nonempty strings. IDs and bodies are nonempty strings; epoch and versions are positive Python ints, so True is invalid. available and revoked must be bools. Sources and memories are dicts keyed by nonempty IDs. Refs are lists of memory_id/version objects; an empty refs list is valid. summary alone may be None; a non-null summary has body and a nonempty list of source_id/version dependencies. The candidate fields match the displayed candidate. Validate the complete input first; missing fields, inappropriate nulls or wrong types raise exactly ValueError("shape"). Extra fields are ignored. A well-shaped unknown referenced ID is a data gap, not a shape error. Do not mutate inputs.
Restoration output and derivation rules
Return exactly {"memory_ids": [...], "bodies": [...], "summary": string_or_None}. Unavailable authority or a checkpoint scope mismatch returns empty lists and None. Otherwise deduplicate and lexicographically sort referenced memory IDs. Retain an ID only when the current memory exists in the authority scope, its version equals the ref, and its current source exists, is unrevoked and matches memory.source_version. Bodies come from current authority, not copied checkpoint text. Keep a summary only when the checkpoint epoch is current and every dependency has a matching unrevoked source; otherwise set it to None. Do not silently copy the remaining part of a mixed summary. The base output is {"memory_ids":["m-style"],"bodies":["use short paragraphs"],"summary":null}.
Write admission output and precedence
Return exactly status/reason. After shape validation, first matching rule wins: unavailable authority → deny/authority_unavailable; different scope → deny/scope_mismatch; different epoch → deny/epoch_changed; absent source → deny/source_missing; revoked source → deny/source_revoked; different source_version → deny/source_changed; otherwise allow/ok. The base candidate is denied even under a new ID. This is a pure decision, not a database write. It does not implement transactional compare-and-set, new explicit consent or physical deletion. Real candidate source IDs/versions must come from verified extraction lineage; this lab checks declared metadata, not whether a worker forged provenance or the body is semantically supported by that source.
A live first dependency does not authorize the whole summary
Run the following probe from the same practice directory after implementing your module. It reconstructs the complete base fixture above, then explicitly sets epoch 2, selects only m-style, and replaces the summary dependencies in order: live s-style/version 1 first, revoked s-email/version 2 second. A current epoch and the first live source are insufficient: summary must be None while the independent m-style record stays usable. Removing the second source also yields None. Only changing that second current source to unrevoked permits this declared two-source summary; this is a fixture control, not a production re-consent workflow or proof that its text is true.
from copy import deepcopy
from revocation_lab import fixture
from revocation_student import restore_context
authority, checkpoint, _ = fixture()
checkpoint.update(epoch=2, refs=[{"memory_id": "m-style", "version": 1}],
summary={"body": "mixed style and email preferences", "dependencies": [
{"source_id": "s-style", "version": 1},
{"source_id": "s-email", "version": 2}]})
safe = {"memory_ids": ["m-style"], "bodies": ["use short paragraphs"], "summary": None}
assert restore_context(authority, checkpoint) == safe
missing = deepcopy(authority)
del missing["sources"]["s-email"]
assert restore_context(missing, checkpoint) == safe
both_live = deepcopy(authority)
both_live["sources"]["s-email"]["revoked"] = False
assert restore_context(both_live, checkpoint) == dict(safe, summary="mixed style and email preferences")
print("all_summary_dependencies_checked")
The correct output is all_summary_dependencies_checked with exit 0. Save this as revocation-dependencies-probe.py. A first-dependency-only implementation should fail the first assertion; repair only your module and rerun the identical probe plus both seeds. The suite now has 40 cases, including these three dependency controls. Checking the first dependency or epoch alone is never an all-dependency gate.
After implementing your module and saving the probe, run it as a separate command:
python3 revocation-dependencies-probe.py
Run your own implementation
python3 --version
python3 revocation_lab.py scaffold --out revocation_student.py
python3 revocation_lab.py grade --module revocation_student.py --out revocation-before.json --seed 41
Scaffold exits 0. The unchanged template grade exits 1, with 0/40 checks passed; this expected failure is your starting evidence. Implement your functions without changing grader fixtures or expected labels, then run:
python3 revocation_lab.py grade --module revocation_student.py --out revocation-after.json --seed 41
python3 revocation_lab.py grade --module revocation_student.py --out revocation-variant.json --seed 9001
A conforming implementation exits 0 with 40/40 for each run. Reports contain the resolved imported module path, its SHA-256, per-case outputs and exceptions, seed and input-mutation checks. The suite includes positive restoration, stale checkpoint, changed source and memory versions, unknown references, strict null/bool handling, unavailable authority and renamed revoked-source writes. Seed changes produce reproducible IDs, scopes, versions and revocation inputs; the public rules and source are readable, so these are changed-input exercises, not secret unseen exams. An instructor may choose a seed after you freeze your code.
Submit your module, before/after/variant reports, personal diff and a short explanation of one rejected source. Guided output earns observation credit; passing this local mechanical contract does not prove summary truthfulness, remote erasure or learner mastery.
code example
Missing reference versus malformed input
A well-shaped ref to a missing memory is skipped. refs=null has no valid list meaning and raises ValueError("shape"). Silently treating both as an empty context hides a broken caller contract.
Acceptance task for this level
Implement restore_context and admit_write in your own module; deliver the failing template baseline, personal diff, fixed-input and changed-seed reports.
Reading this browser’s record…
Hide the answer and check your understanding
Why do bodies come from current records but IDs come from checkpoint refs?
Expand reference derivation
The checkpoint limits the recovery selection; it is not current authority for content or access. Current records and sources verify that selection and supply the body. A stale summary must be rebuilt rather than trusted because one valid ref survived.
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.