InferenceAI

Enter at least two characters to search.

Start free
Repository challenges

Isolate a multi-request KV cache

Debugging · Intermediate · AI engineering · 35 minutes

Engineering ticket

Two request streams share a cache. Implement process(events, capacity). Each event is [request_id, token]. Return the retained token list after each event. Keep an independent newest-token window per request. Capacity <= 0 retains no tokens. Do not mutate events. Example: [["a",1],["b",2],["a",3]], capacity 2 returns [[1],[2],[1,3]].

Review rubric

  • Correctness on documented inputs
  • Tests and edge cases
  • Clear explanation of trade-offs

Reading the ticket and starter files is public. Sign in to save edits, run tests and submit evidence. Code-review quality requires human review.

Starter repository

cache.py
def process(events, capacity):
    cache = []
    result = []
    for request_id, token in events:
        cache.append(token)
        result.append(cache[-capacity:])
    return result
README.md
# InferenceAI engineering lab

Read the ticket, inspect the files, reproduce the issue and implement the contract. Run visible tests while working. Submit checks protected cases. Explain your changes and limitations.
tests/test_cache.py
import unittest
from cache import *

class ContractTest(unittest.TestCase):
    def test_example(self):
        self.assertEqual(process([["a",1],["b",2]], 2), [[1],[2]])