cachetools: a public library
Red Rabbit also drilled a public library, cachetools. Four planted changes, each a bug that once shipped and broke a documented promise, went through the test gates and then through the Kiro reviewer agent, in a first and a second reviewer run.
Test gates, examples and full
4/4
AWAKE 360 tests ran clean first.
Kiro reviewer, run 1
3/4
DID_NOT_RUN 1 reply refused.
Kiro reviewer, run 2
4/4
AWAKE
Every answer
| Planted change | examples | full | Reviewer, run 1 | Reviewer, run 2 |
|---|---|---|---|---|
| Planted change 1.1 <redacted>.__setitem__ returns without storing an already expired value and leaves the earlier value readable. | examples CAUGHT | full CAUGHT | Reviewer, run 1 CAUGHT | Reviewer, run 2 CAUGHT |
| Planted change 2.1 Cache.__setitem__ tests the room for a replacement against the full new size, so a <redacted> value <redacted> an entry it did not need to. | examples CAUGHT | full CAUGHT | Reviewer, run 1 CAUGHT | Reviewer, run 2 CAUGHT |
| Planted change 3.1 <redacted>.popitem passes the empty key list to a custom choice function instead of checking for an empty cache first. | examples CAUGHT | full CAUGHT | Reviewer, run 1 DID_NOT_RUN the Kiro hook never fired (no heartbeat) | Reviewer, run 2 CAUGHT |
| Planted change 4.1 The cached wrapper copies the inner wrapper's __dict__ over its own cache attributes by calling <redacted> last. | examples CAUGHT | full CAUGHT | Reviewer, run 1 CAUGHT | Reviewer, run 2 CAUGHT |
The heartbeat refusal
3.1 <redacted>.popitem passes the empty key list to a custom choice function instead of checking for an empty cache first.
DID_NOT_RUN the Kiro hook never fired (no heartbeat)
The reviewer gate counts a reply only when a Kiro hook proves that the agent opened the changed file. That proof is the heartbeat. Without it the gate refuses the reply, whatever the reply says, and the verdict is DID_NOT_RUN. The record keeps the reply it refused, shown here as it is. The first record is kept unchanged; the second record is a separate run.
- Agent status in the record
did_not_answer- The reply the gate refused, as the record holds it
- AGENT: red-rabbit-reviewer ct-rabbit-3 CAUGHT: The change removes the `if not keys` guard, so `popitem()` on an empty cache now calls the custom `choice` with an empty sequence. That breaks the "SHALL NOT call the custom `choice` function" requirement. `KeyError` is raised only if `choice` happens to raise `IndexError`. A custom `choice` that raises something else, or returns a value, gives the wrong result.
The diffs
Planted change 1: 1.1 <redacted>.__setitem__ returns without storing an already expired value and leaves the earlier value readable.
<redacted>.__setitem__ returns without storing an already expired value and leaves the earlier value readable.
WHEN a key that is already in a<redacted>is assigned a value whose time-to-use has already expired, THE<redacted>SHALL NOT keep the earlier value readable under that key. Documented promise (tag <redacted>.1.4): "a *cache* is a <redacted> <redacted> of a fixed maximum size" (<path>), read with "Items that <redacted> because they have exceeded their time-to-use will be no longer accessible, and will be removed <redacted>." (<path>).
diff --git <path> <path>
index <redacted>..<redacted> 100644
--- <path>
+++ <path>
@@ -637,9 +637,7 @@ class <redacted>(<redacted>):
self.<redacted>(time)
expires = self.<redacted>(key, value, time)
if not (time < expires):
- # updating an existing item with an already expired
- # one should remove the existing item
- return self.<redacted>(key)
+ return # skip expired items
<redacted>(self, key, value)
# removing an existing item would break the heap structure, so
# only mark it as removed for now
Planted change 2: 2.1 Cache.__setitem__ tests the room for a replacement against the full new size, so a <redacted> value <redacted> an entry it did not need to.
Cache.__setitem__ tests the room for a replacement against the full new size, so a <redacted> value <redacted> an entry it did not need to.
WHEN a key already in a size-awareCacheis assigned a larger value and<redacted> - <redacted> + <redacted> <= maxsize, THECacheSHALL store the replacement without callingpopitem()or <redacted> any other entry. Documented promise (tag <redacted>.1.6): the cache documents "When a cache is full, :meth:Cache.__setitem__()calls :meth:self.popitem()repeatedly until there is enough room for the item to be added" (<path>). For<redacted>only: "deleting the item followed by an insert" (<path>).
diff --git <path> <path>
index <redacted>..<redacted> 100644
--- <path>
+++ <path>
@@ -87,7 +87,7 @@ class Cache(collections.abc.MutableMapping):
self.popitem()
else:
<redacted> = size - self.<redacted>[key]
- while self.<redacted> + <redacted> > maxsize:
+ while <redacted> > 0 and self.<redacted> + size > maxsize:
self.popitem()
if key not in self.<redacted>:
<redacted> = size
Planted change 3: 3.1 <redacted>.popitem passes the empty key list to a custom choice function instead of checking for an empty cache first.
<redacted>.popitem passes the empty key list to a custom choice function instead of checking for an empty cache first.
WHENpopitem()is called on an empty<redacted>, THE<redacted>SHALL raiseKeyErrorand SHALL NOT call the customchoicefunction. Documented promise (tag <redacted>.2.0): "The optional argumentchoicemay specify an alternative function that returns an arbitrary element from a non-empty sequence." (<path>).
diff --git <path> <path>
index <redacted>..<redacted> 100644
--- <path>
+++ <path>
@@ -357,11 +357,12 @@ class <redacted>(Cache):
def popitem(self):
"""Remove and return a random `(key, value)` pair."""
- keys = self.<redacted>
- if not keys:
+ try:
+ key = self.<redacted>(self.<redacted>)
+ except IndexError:
raise KeyError("%s is empty" % type(self).__name__) from None
- key = self.<redacted>(keys)
- return (key, self.pop(key))
+ else:
+ return (key, self.pop(key))
def clear(self):
Cache.clear(self)
Planted change 4: 4.1 The cached wrapper copies the inner wrapper's __dict__ over its own cache attributes by calling <redacted> last.
The cached wrapper copies the inner wrapper's __dict__ over its own cache attributes by calling <redacted> last.
WHEN one@cachedwrapper is applied on top of another, THE outer wrapper SHALL expose its owncache,<redacted>,<redacted>and<redacted>attributes and SHALL NOT expose those of the inner wrapper. Documented promise (tag <redacted>.2.2): "The decorator'scache,key,lockandconditionparameters are also available as :attr:cache, :attr:<redacted>, :attr:<redacted>and :attr:<redacted>attributes of the <redacted> wrapper function." (<path>).
diff --git <path> <path>
index <redacted>..<redacted> 100644
--- <path>
+++ <path>
@@ -277,4 +277,4 @@ def <redacted>(func, cache, key, lock=None, <redacted>=None, info=None):
wrapper.<redacted> = key
wrapper.<redacted> = lock if lock is not None else <redacted>
wrapper.<redacted> = <redacted>
- return wrapper
+ return functools.<redacted>(wrapper, func)