Back to the curriculum

L3-M05 · Level 3 · ~13 h

State, Context and Session Testing

What you build: State and session test suite

lessons
4
lesson hours (estimate)
≈ 7.5 h
0/4 lessons marked done · Progress is saved in this browser only. No account, nothing is sent to a server.
In review. The curriculum, module overviews and Levels 1–3 lessons are drafts written with AI assistance and reviewed by AI. Human review is still pending. English translation: AI-assisted, not human-reviewed.

Levels 1–3 lessons, exercises and quizzes are published as drafts, in Vietnamese with an AI-assisted English translation. They may change after human review.

Module path

  1. Lesson 1 · L3-M05-L01≈ 2 h

    Kinds of state: conversation, task, environment, long-term memory

    What you build: State inventory for an agent

    Needs: L3-M04-L05

    Key terms (6)
    • State inventoryBản kê trạng thái: danh sách mọi mẩu trạng thái, mỗi mục có phạm vi, khóa, vòng đời, người ghi và test
    • Conversation / task / environment stateTrạng thái hội thoại / tác vụ / môi trường
    • Long-term memoryBộ nhớ dài hạn: sống qua nhiều phiên
    • Derived stateTrạng thái dẫn xuất: bản sao hay bản rút gọn (context, tóm tắt, cache)
    • ProbeCâu hỏi dò: câu hỏi bình thường gửi tới agent để đọc ra một mẩu trạng thái; khác probe đo thiên lệch (L2-M04-L03)
    • Control (check)Phép kiểm đối chứng: hỏi khi chưa đổi gì; probe trượt đối chứng là probe hỏng
  2. Lesson 2 · L3-M05-L02≈ 2 h

    Context growth, trimming and summarisation failures

    What you build: Tests for lost instructions after trimming

    Needs: L3-M05-L01

    Key terms (6)
    • Context managerBộ quản lý context: quyết định message nào của lịch sử tới agent ở mỗi lượt
    • Token budgetNgân sách token của context (ở lab là token xấp xỉ)
    • PinningGhim: không bao giờ cắt một số message
    • Compaction / summarisationTóm tắt: thay các lượt cũ bằng một message tóm tắt
    • Lost / changed / invented factDữ kiện bị mất / bị đổi / bị bịa trong context so với lịch sử
    • Softened negationPhủ định bị làm mềm: "không gợi ý X" thành "có nói về X"
  3. Lesson 3 · L3-M05-L03≈ 2 h

    Multi-turn conversation regression for agents (with a short note on long-term memory)

    What you build: Conversation regression suite

    Needs: L3-M05-L02

    Key terms (6)
    • Conversation regression suiteBộ hồi quy hội thoại: các kịch bản nhiều lượt cố định với check ở lượt dò
    • Golden transcriptTranscript vàng: bản ghi nguyên văn câu trả lời của baseline, so nguyên văn (golden file của L1-M05-L05 cho cả hội thoại)
    • Probe turnLượt dò: lượt có check
    • New fail / fixed / still failTrượt mới (hồi quy) / đã sửa / vẫn trượt (lỗi đã biết)
    • Simulated userNgười dùng mô phỏng: một mô hình đóng vai người dùng
    • Stale memoryBộ nhớ cũ: lời sửa không thay giá trị đã lưu
  4. Lesson 4 · L3-M05-L04≈ 2 h

    Session and user isolation

    What you build: Cross-user leak tests

    Needs: L3-M05-L03

    Key terms (6)
    • Session isolation / user isolationCách ly phiên / cách ly người dùng
    • Canary valueGiá trị canary: giá trị chỉ người dùng A có; khác "tập canary" (canary set) của L2-M04-L05
    • Probe planKế hoạch probe: các lượt người dùng B gửi qua từng đường vào
    • Way in (via)Đường vào: phiên của mình, phiên mới, mã phiên của người khác, mã phiên không tồn tại
    • Insecure direct object reference (IDOR)Tham chiếu trực tiếp không an toàn tới đối tượng
    • Unrequested actionHành động không được yêu cầu: tool tác động lên tài khoản của người không yêu cầu

A. Module overview

Field Value
Module ID L3-M05
Level 3 - AI Agent Quality Engineer
Description Testing what an agent keeps between turns, sessions and users: a state inventory (conversation, task, environment, long-term memory, and derived state such as the context, the summary and the cache) with the scope, key, lifetime and writers of each item, plus probes with a control that show what is left after a context trim, a new session or when another student asks; a deterministic context manager with a token budget, five trimming strategies and a summariser with four seeded failure modes, measured with lost_facts instead of a keyword check; a multi-turn conversation regression suite with per-turn checks, a comparison with a baseline and a gate that fails closed on missing or broken data, plus a short note on long-term memory; and cross-user leak tests with canary values, a probe plan through every way in, a scan of three places and an audit of loans nobody asked for. The module's lab is the simulated chat helper of the fictional product ThuVien Mini (a school library helper) with six seeded defective variants, deterministic and offline: no model calls, no real server, no API key; all state lives in one Python object. What is known about conversation state, context windows, compaction, multi-turn conversations and sensitive information disclosure is cited from 15 sources read on 2026-11-04: Anthropic documentation (context windows, compaction) and two Anthropic articles (agent evals, context engineering), OpenAI documentation (conversation state, Agents SDK sessions), LangGraph documentation (persistence, stores), Chroma's context rot report, three arXiv papers (Lost in the Middle, LLMs Get Lost In Multi-Turn Conversation, MT-Bench-101; abstract pages only), OWASP LLM02:2025 and LLM08:2025, and the OWASP WSTG guide to testing IDOR. How much of each source was read is stated in §12 of each lesson.
Why this module matters A chat helper does not live in one run: a student sets a rule at turn 2 and asks again at turn 30, reopens the app the next day, and another student uses the same service at the same moment. Each of those depends on a piece of state that lives in a different place, for a different time, and breaks in a different way. The one-turn, one-student tests of the earlier modules do not see an instruction cut out of the context, a correction that does not survive a new session, or one student's answer reaching another student. The module lays the ground for reliability (L3-M06) and agent safety (L3-M07).
Target professional competency Level 3: testing multi-turn, stateful agents, including conversation state, context limits, conversation regression and isolation between sessions and users. Long-term memory is cut back to a note (curriculum, 2026-10-31: none of the 30 verified job postings mentions memory testing). The module does not measure the context rot of real models, does not use an LLM-simulated user, and does not test the security of real systems.
Estimated duration 4 lessons (110 + 120 + 110 + 120 minutes) = 7 hours 40 minutes, plus the quiz (~0.5 hours) and the module assignment (~5 hours) = ≈ 13 hours for someone who has finished L3-M04. An estimate, not yet measured with real learners.
Prerequisites L3-M04 (the first lesson needs L3-M04-L05). The module reuses, and does not repeat: the agent loop (L3-M01-L02), checking the end state in the environment (L3-M03-L04), a sandbox with no real side effects (L3-M02-L04), tokens and context windows (L1-M01-L02), regression testing and baselines (L1-M06), why exact matching is brittle (L3-M04-L02). No API key needed.
Module deliverable A state and session test suite: an inventory and a survival table with controls, a table of the first turn that loses an instruction for 14 context configurations, a conversation regression suite with a baseline and a gate, leak tests on two pairs of users with the learner's own probe plan, a scorecard of 11 release candidates combining a regression layer and an isolation layer, and a golden table for mutation testing; plus the small product of each lesson
Cost 0

What learners build. Step by step, in code-labs/l3-m05: (L01) the inventory data/inventory.json, validate_inventory, survival with four events (control, trim, new_session, other_user), locate, snapshot; (L02) count_tokens, build_context with five strategies (keep_all, drop_oldest, keep_system, pin_rules, summarise), the five summariser modes, lost_facts and the naive mentions; (L03) conversation specs, six check kinds, validate_conversation, run_suite, compare, gate, golden_diff, five versions v1 to v5 and one memory case across two sessions; (L04) canaries, check_plan, run_plan, leak_scan in the reply, the context and the task state, unrequested_loans, audit, a gate that needs all four ways in, and matrix over the correct service and the five isolation bugs. The lab imports nothing from earlier labs and needs only pytest.

What the module does not do. It does not measure real models or agents, gives no price, speed or reliability of any model, agent or vendor, and does not rank or recommend any framework, tool or provider: every number of the lab describes a simulation, and the parameter names of LangGraph or the OpenAI Agents SDK come only from the documentation read. The lab's helper reads everything in its context perfectly, so the lab does not simulate context rot; tokens are a proxy. Nothing runs shell commands, the network or files outside the Python process. A probe that uses another person's session id is a deliberate test inside the sandbox; on a real system do it only in a test environment, with test accounts, when permitted. No automated workflow in the repository is created or changed. No legal claims. Every gate only marks, fails closed on missing or broken data and has no word for "approved"; a person chooses the baseline, the budgets, the canaries, the plan and every real action.

Terms reused with another meaning (each lesson has a sentence that separates them). A session is a run of turns with one shared history, unlike the context, the list of messages the helper gets on one turn (L01); the history is never changed, trimming removes messages from the context and summarisation replaces a group of messages with one message (L02); a version in L03 is a context configuration plus a reply style, not a software version; a canary value in L04 is a value only user A has, unlike the "canary set" of L2-M04-L05; session isolation is not user isolation (L04).

B. Learning objectives

ID Objective
MO1 Write a state inventory of an agent with scope, key, lifetime and writers, show what is left after each event with probes that have a control, and tell "the store has the data" from "the agent sees the data".
MO2 Compare context trimming and summarisation strategies, detect instructions that are lost, changed or invented with a fact comparison instead of a keyword check, and choose a configuration within a given budget.
MO3 Build a multi-turn conversation regression suite with per-turn checks, compare a version with a deliberately chosen baseline, use a gate that fails closed on missing or broken data, and test a memory correction in a new session.
MO4 Design cross-user leak tests with unique canaries, a user B chosen so the bug has a chance to show and every way in, scan the reply, the context, the task state and the environment, and state what a plan does not prove.

C. Lessons

ID Lesson Duration Prerequisite Concepts Practical output
L3-M05-L01 Kinds of state: conversation, task, environment, long-term memory 110' L3-M04-L05 four kinds of state and derived state, scope, key, lifetime, writers, probes and controls State inventory for an agent
L3-M05-L02 Context growth, trimming and summarisation failures 120' L01 token budget, five strategies, four summary failure modes, lost_facts, a keyword is not an instruction Tests for lost instructions after trimming
L3-M05-L03 Multi-turn conversation regression for agents 110' L02 golden transcripts and per-turn checks, fixed scripts, baselines, still_fail, the gate, a note on long-term memory Conversation regression suite
L3-M05-L04 Session and user isolation 120' L03 how state crosses a boundary, IDOR, canaries, ways in, probe order, a scan of three places, an action audit Cross-user leak tests

D. Practical exercises (module assignment)

Module assignment exercises.md: a state and session test suite for ThuVien Mini v2 on new data (a new script and seven probes for S0107, six edits of the inventory, four new conversations w01 to w04, two new pairs of users and 11 release candidates): state and probes, context, regression, isolation with the learner's plan, the scorecard, the golden table and mutation, reproduction; a fixed interface, acceptance criteria AC1-AC7 and a 100-point rubric; plus an independent challenge on the lab's data. The four independent exercises of the lessons are in code-labs/l3-m05/exercises/ and in §9 of each lesson: predict the survival table and where each value lives (L01), predict the lost facts and choose a configuration within 80 tokens (L02), golden diffs and checks for two new conversations (L03), predict what the lesson's plan catches on another pair and write a plan that catches every bug (L04).

E. Module assessment

Module quiz quiz.md (12 questions, 20 points, pass mark 70%), the module assignment with acceptance criteria and a rubric (exercises.md); the solutions and the instructor guide are for instructors only. The practice of each lesson is practice-01.md to practice-04.md, public and with reference solutions. The instructor's solutions and checks are in code-labs/l3-m05/instructor/ and are for instructors only.

F. References

The shared list is in references.md (15 sources fetched on 2026-11-04, with the access date and how much of each was read). Each lesson also has its own reference table in §12.

Objective ↔ assessment matrix

Objective Lesson Independent exercise (§9) Quiz items Module assignment criteria
MO1 L01 exercises/test_l01_state.py Q1, Q2 AC1 (and AC6, AC7 for the whole module)
MO2 L02 exercises/test_l02_context.py Q3, Q4, Q8, Q9 AC2 (and AC6, AC7 for the whole module)
MO3 L03 exercises/test_l03_regression.py Q6, Q10, Q12 AC3, AC5 (and AC6, AC7 for the whole module)
MO4 L04 exercises/test_l04_isolation.py Q5, Q7, Q11 AC4, AC5 (and AC6, AC7 for the whole module)