Estimated time: ~5 hours for someone who has done the four independent exercises of L01-L04 (an estimate, not yet measured with real learners). Main tools:
lab.state,lab.context,lab.summariser,lab.conversation,lab.isolation,lab.appincode-labs/l3-m05. The helper, the summariser, the service, the six defective variants, the tokens and every result in the lab are simulated (deterministic programs written by the lab author): no model calls, no real server, no API key needed; all state lives in one Python object.
Main practical exercise
Business context
The ThuVien Mini team (fictional) is preparing to move the chat helper to ThuVien Mini v2: a release that may change the context strategy, the reply style, and may carry one of the isolation or memory bugs met in L04. A colleague's ticket says: "the one-student tests are all green, so the new release is safe". That line does not say which instructions the helper still remembers after the context is trimmed, whether a correction survives a new session, or whether another student can see this student's data. You need to build a state and session test suite for v2 with its reports, then answer: what does the suite catch in the helper's state, context and sessions, and what does it not yet prove?
Problem to solve
An inventory that passes the checker can still have the wrong scope; a probe that fails its control gives results that look like findings; a test that only counts tokens does not see a lost instruction; a regression suite compared with the wrong baseline hides bugs in still_fail; a probe plan that finds no leak does not prove the service is isolated; and a green scorecard does not yet say which layer was really tested.
Your job is to measure each layer separately with the fixed configuration below, combine them with a decision function that fails closed on missing or broken data, say clearly what each layer does not prove, and let a person record the final decision. Every gate only says HOLD or READY_FOR_REVIEW and has no word for "approved".
Input data
The lab's data is in code-labs/l3-m05/data/ and is fictional; do not change lab/, data/, tests/ or exercises/. You write every data file in the session_suite/ package yourself from the tables below (copy every sentence exactly: the helper understands a fixed set of sentence patterns only).
Fixed configuration (so that every submission is reproducible and comparable):
| Item | Value |
|---|---|
| State (Task 1) | state_v2.json: student S0107, other student S0042, a seven-sentence script, seven probes, seven values for locate, six edits of the lab's inventory (table 1) |
| Context (Task 2) | conversation w01 of table 2; 14 configurations: the five strategies of lab.context.STRATEGIES at budget 120 and at budget 160 (other values default), plus summarise at budget 120 with the four modes drops_rules, softens_negation, invents, keeps_stale |
| Regression (Task 3) | suite_v2.json: four conversations w01 to w04 with 10 checks (table 2); six versions: v1 to v5 of lab.conversation.VERSIONS plus fifo = {"config": {"strategy": "drop_oldest", "budget": 140}, "style": "v1"}; baseline v1 |
| Isolation (Task 4) | isolation_v2.json: two pairs of students P1 and P2 with the scripts and canaries of table 3, and one broken canary list; plan_v2.json: your plan |
| Scorecard (Task 5) | candidates_v2.json: 11 candidates r01 to r11 (table 4), baseline r01; regression layer: compare(run of r01, run of the candidate) on suite_v2.json; isolation layer: isolation.audit(the candidate's variant, plan_v2, the script and canaries of P1) |
| Reproduction (Task 7) | Six Markdown reports and table.json; no timestamps, no Python version |
Table 1. The state of S0107 (other student: S0042).
| Item | Content |
|---|---|
| Script | "My name is Sora.", "Never recommend books by Lan Huong.", "Only recommend math books.", "Remember that my class is T9M.", "Borrow B009.", "Tell me about B007.", "Tell me about B004." |
Probes (ask → expect) |
name: "What is my name?" → Sora; rule_b002: "Recommend a book." → B002; rule_b009: "Recommend a book." → B009; class: "What is my class?" → T9M; pending: "yes" → Done: B009; phone: "What is my phone number?" → 0900-222-107; loans: "What have I borrowed?" → not borrowed |
Values for locate |
Sora, Lan Huong, math, T9M, B009, B007, 0900-222-107 |
Six edits (each applied to a copy of state.load_inventory()) |
e1: reply_cache gets scope service and an empty key; e2: long_term_memory gets lifetime forever; e3: profile gets empty writers; e4: drop every item of kind derived; e5: pending_borrow gets an empty key and a test of two spaces; e6: loans gets kind environmental |
Table 2. The v2 regression suite (id, student, turns; a turn with checks lists them in brackets; new_session opens a new session before that turn).
id |
Student | title |
Turns |
|---|---|---|---|
w01 |
S0518 | A corrected rule and a rule in other words, then a long browse | 1 "My name is Hana."; 2 "Only recommend story books."; 3 "Please skip anything written by Lan Huong."; 4 "Tell me about B001."; 5 "Tell me about B004."; 6 "Tell me about B005."; 7 "Actually, only recommend science books."; 8 "Tell me about B002."; 9 "Tell me about B006."; 10 "Recommend a book." (category science; not_by Lan Huong); 11 "What is my name?" (contains Hana) |
w02 |
S0315 | A class corrected, then read in a new session | 1 "Remember that my class is M3K."; 2 "Tell me about B008."; 3 "Actually, my class is M3L."; 4 new_session, "What is my class?" (contains M3L; not_contains M3K) |
w03 |
S0042 | Two loans and the loan period in a long session | 1 "Borrow B005."; 2 "yes" (contains 7 days); 3 "Tell me about B001."; 4 "Tell me about B004."; 5 "Tell me about B007."; 6 "Tell me about B009."; 7 "Borrow B008."; 8 "yes" (contains 7 days); 9 "What have I borrowed?" (contains B005, B006, B008) |
w04 |
S0518 | A dislike in words the helper does not understand | 1 "Only recommend science books."; 2 "Please do not suggest books by Lan Huong."; 3 "Tell me about B009."; 4 "Recommend a book." (category science; not_by Lan Huong) |
Table 3. Two pairs of students for the leak tests.
| Pair | A | B | A's script | Canaries |
|---|---|---|---|---|
| P1 | S0042 | S0518 | "My name is Nami.", "Remember that my class is R2D.", "Borrow B007.", "yes", "What have I borrowed?", "Borrow B009." | Nami, R2D, B006, B007, B009, 0900-111-042, S0042 |
| P2 | S0315 | S0107 | "My name is Kim.", "Remember that my class is J5P.", "What is my phone number?", "Borrow B002." | Kim, J5P, B003, 0900-333-315, S0315 |
| Broken list | (pair P1) | Nami, R2D, An |
Table 4. Eleven release candidates (version, variant of lab.app.VARIANTS).
r01 |
r02 |
r03 |
r04 |
r05 |
r06 |
r07 |
r08 |
r09 |
r10 |
r11 |
|---|---|---|---|---|---|---|---|---|---|---|
| v1, correct | v3, correct | v4, correct | v5, correct | fifo, correct | v1, stale_memory | v1, shared_cache | v1, memory_by_name | v1, session_fallback | v1, no_owner_check | v1, global_task_state |
Fixed interface
The session_suite/ package must have exactly these names (the grader and your tests call them):
| Name | Contract |
|---|---|
mine.survival_findings(table) |
Reads a state.survival table. Returns a sorted list: broken:<fact> when control is False (and nothing else for that fact), lost:<fact>:<event> when trim or new_session is False, leak:<fact> when other_user is True. ValueError when the table is empty or not a dict, a row lacks or has an extra event, or a value is not a bool |
mine.first_lost_turn(conv, config) |
Runs the conversation in a fresh App (correct service) and returns (turn, lost_facts) for the first turn (from 1) where context.lost_facts(history of the current session, context of the turn) is not empty; None when no turn loses anything. ValueError when validate_conversation or check_config reports a problem |
mine.LAYERS |
("regression", "isolation") |
mine.decide(parts) |
parts = {"regression": a compare result, "isolation": an audit result, "plan": the plan}. Returns (decision, reasons): HOLD when conversation.gate or isolation.gate holds, or when parts is broken; READY_FOR_REVIEW when the list of reasons is empty. Each reason starts with regression: , isolation: or malformed: . A gate that holds always gives at least one reason of its layer |
mine.layers(reasons) |
The layers present in a list of reasons, in the order of LAYERS then malformed; ValueError for a reason with another prefix |
mine.diff_cards(before, after) |
The candidate ids (sorted) whose decision differs between two tables {id: (decision, reasons)}; ValueError when the two tables do not hold the same ids |
build_session_suite.build(out) |
Writes exactly seven files in out: state.md, context.md, regression.md, isolation.md, scorecard.md, mutation.md, table.json |
build_session_suite.check_card() |
The cells of the recomputed table.json that differ from expected_v2.json (as suite/<version> or card/<id>); [] when they match |
build_session_suite.check_gates() |
The names of the fixed cases of the three gates (conversation.gate, isolation.gate, mine.decide) that give a wrong result; [] when all are right |
build_session_suite.check_cases() |
The names of the hand-built cases (values worked out by hand) that give a wrong result; [] when all are right |
table.json |
{"suite": {version: [keys of failed checks]}, "card": {id: [decision, mine.layers(reasons), new_fail, number of audit findings, number of unrequested loans]}} |
Tasks
- State and probes (L01). Write
state_v2.jsonfrom table 1 andmine.survival_findings. Reportstate.md: a line checking the lab's inventory, a table of the six edits with the codes ofvalidate_inventory, a line saying what happens whensurvivalis called withoutother, the survival table of seven probes × four events (withotherS0042), aFindings: ...line, and alocatetable for the seven values. - Context (L02). Write
mine.first_lost_turn. Reportcontext.md: one row for each of the 14 configurations, with the first lost turn and the problems at that turn,lost_factsat turn 10, the book id recommended at turn 10, the results of the three checks ofw01(PorF), the largest token count of the context, and the number of turns whose context is over budget. - Regression (L03). Write
suite_v2.jsonfrom table 2 (validate_conversationmust be clean). Reportregression.md: a line with the number of conversations and checks, a table of the six versions (failed checks,new_failagainstv1,still_fail,passed, gate), a line with the golden diff ofv3againstv1for each conversation, a line comparingv4with the baselinev2, and a long-term memory line: thestale_memoryvariant withv1on the suite as written, then again when turn 4 ofw02does not open a new session. - Isolation (L04). Write
isolation_v2.jsonfrom table 3 andplan_v2.json: at most five steps, using all four ways in, such that on P1 all five defective variants are caught, on P2 every defective variant exceptmemory_by_nameis caught, the correct service is READY_FOR_REVIEW on both pairs, andglobal_task_stateleaves exactly one loan nobody asked for on each pair. Reportisolation.md: thecheck_canariesresults of the two pairs and of the broken list (pass A's script assetup=: a canary must occur in A's data, otherwise the lab returnsNOT_IN_A), then two tables (the lab's DEFAULT_PLAN andplan_v2) with one row per pair × variant: number of findings, steps, places, number of unrequested loans, gate. - Scorecard (L03 + L04). Write
candidates_v2.jsonfrom table 4,mine.decide,mine.layers,mine.diff_cards. Reportscorecard.md: a table of the 11 candidates (version, variant, decision, layers, reasons), a line with the number of candidates each layer holds, a line with the candidates held by one layer only, threediff_cardslines when switching to P2 withplan_v2, P2 with DEFAULT_PLAN, and P1 with DEFAULT_PLAN, and a line with the person's decision fromreview.json(ornonewhendecisionis empty). Inreview.jsonyou record the decision of a person (decision,reviewed_by), not of a test or CI. - Golden table and mutation. Produce
table.json(6suiterows, 11cardcells). Read every cell before pinning (every cell you did not predict correctly before running needs a sentence of explanation innotes/decisions.md), then write the table toexpected_v2.json. Writecheck_card,check_gates(at least: a run compared with itself is READY_FOR_REVIEW; onlystill_failis READY_FOR_REVIEW; anew_fail, a missing check, an extra check, a doubled check and a broken comparison all HOLD; a clean audit (whoseplanis the plan given to the gate) with all four ways in is READY_FOR_REVIEW; a result of another plan, a missing way in, an unrequested loan alone,problems, and a broken audit all HOLD;decidewith brokenpartsis HOLD; no approval word) andcheck_cases(at least eight hand-built cases, values worked out by hand: e1 and e4 pass the checker; the codes of e5; therule_b002probe fails its control; theclassandpendingrows of the survival table;first_lost_turnofkeep_system120 and ofsummarise120keeps_stale; alost_factscase withinvented:; a canary list that is refused; a shorter transcript is a difference forgolden_diff). Reportmutation.md. Innotes/decisions.md, sectionMutations, list at least ten broken versions (one per line starting with- `m_) ofbuild_context, the summariser,lost_facts,compare, the gates,evaluate,leak_scan,unrequested_loans,check_canaries,validate_inventory,survivalormine.decidethat you installed withmonkeypatch, which were killed (by the golden table, the gate cases or the hand-built cases) and which survived, with a reason. - Reproduction. Write
build_session_suite.py(every number comes fromlabandmine, none typed by hand) andtest_build_session_suite.pychecking AC1-AC7 on the text of the reports you produce. Writenotes/decisions.mdwith exactly five sections in this order:State and probes,Context and regression,Isolation and scorecard,Mutations,What the suite does not prove. The Vietnamese section names of the Vietnamese brief are also accepted.
Deliverables
session_suite/
__init__.py (file rỗng)
mine.py (survival_findings, first_lost_turn, LAYERS, decide, layers, diff_cards)
state_v2.json (Nhiệm vụ 1)
suite_v2.json (Nhiệm vụ 3: 4 hội thoại, 10 check)
isolation_v2.json (Nhiệm vụ 4: hai cặp và danh sách hỏng)
plan_v2.json (Nhiệm vụ 4: kế hoạch của bạn)
candidates_v2.json (Nhiệm vụ 5: 11 ứng viên)
expected_v2.json (Nhiệm vụ 6: bảng vàng)
review.json (Nhiệm vụ 5: quyết định của một người)
build_session_suite.py (chạy: python -m session_suite.build_session_suite <thư mục ra>)
test_build_session_suite.py (chạy: python -m pytest session_suite)
notes/
decisions.md (năm mục)
(The tree is kept identical to the Vietnamese version: "file rỗng" = empty file, "Nhiệm vụ" = Task, "hội thoại" = conversations, "hai cặp và danh sách hỏng" = two pairs and the broken list, "kế hoạch của bạn" = your plan, "ứng viên" = candidates, "bảng vàng" = golden table, "quyết định của một người" = a person's decision, "chạy" = run, "thư mục ra" = output folder, "năm mục" = five sections.)
Put the session_suite/ folder inside code-labs/l3-m05 so that import lab works, and run from the lab folder. Use relative imports inside the package (from . import mine). Do not create or change any file under .github/; delete every temporary file you create.
Acceptance criteria (required)
| # | Criterion | How it is checked |
|---|---|---|
| AC1 | state.md: the lab's inventory is clean; e1 and e4 give [], e2 ['BAD_LIFETIME'], e3 ['NO_WRITER'], e5 ['NO_KEY', 'NO_TEST'], e6 ['BAD_KIND']; calling survival without other gives ValueError; the rule_b002 row is "no" in control; Findings: has broken:rule_b002 and exactly six lost: items, and no leak:; locate of T9M is ['conversation', 'memory'] and of the phone number ['environment']; survival_findings raises ValueError at the edges of the interface table |
your test reads the report text; the grader runs it again |
| AC2 | context.md has 14 rows; keep_all at both budgets loses nothing but has turns over budget; keep_system 120 loses from turn 5 (lost:name, lost:only) and recommends B002 at turn 10; pin_rules at both budgets loses only lost:exclude:Lan Huong; the faithful summarise loses nothing at both budgets; keeps_stale gives 9 as the first lost turn; first_lost_turn raises ValueError on a broken spec or configuration |
the test reads the report text |
| AC3 | regression.md has Suite: 4 conversations, 10 checks.; v1 fails only w04/t4/1 and its gate is READY_FOR_REVIEW; v2, v4, v5, fifo HOLD, fifo fails w03/t8/0; v3 is READY_FOR_REVIEW although the golden diff flags turns 10 and 11 of w01 and turn 4 of w04; with baseline v2, v4 gives READY_FOR_REVIEW and w01/t10/1 is in still_fail; stale_memory fails two checks of w02 with the new session and none of w02 without it |
the test reads the report text |
| AC4 | isolation.md: both pairs have unique canaries, the broken list gives ['NOT_UNIQUE']; with DEFAULT_PLAN, P1 catches all five and P2 misses shared_cache and memory_by_name; plan_v2.json has at most five steps and meets every condition of Task 4 |
the test runs isolation.matrix with your plan |
| AC5 | scorecard.md: r01 and r02 are READY_FOR_REVIEW with no reason; r03 to r06 are held by the regression layer only (r06 by two checks of w02), r07 to r11 by the isolation layer only, and r11 has an unrequested-loan reason; switching to P2 with plan_v2 changes the decision of exactly r08; the person's decision line is none when review.json has an empty decision; no approval word in any report; the mine functions raise ValueError or return HOLD at the edges of the interface table |
the test compares cells with numbers worked out by hand (not with the function under test) |
| AC6 | table.json has 6 suite rows and 11 card cells, equal to expected_v2.json; check_card(), check_gates(), check_cases() all return []; mutation.md has No mismatch with the pinned table (17 cells)., Gate cases failing: none. and Hand-built cases failing: none.; changing one cell of the golden table makes check_card() return exactly that cell; the Mutations section has at least ten broken versions, each saying killed (by what) or survived, with a reason |
run the tests; the grader reads the section |
| AC7 | Running again gives exactly the seven files (byte for byte), no timestamps, Python version or CR characters; every report says it is simulated (SIMULATED) and names no vendor or model; python -m pytest session_suite passes; notes/decisions.md has all five sections in the right order, and no ranking words ("best", "you should use", "we recommend using") |
run twice and compare; the grader reads decisions.md against the rubric |
Grading rubric (100 points)
| Dimension | 0 | 1 | 2 | 3 | Weight |
|---|---|---|---|---|---|
| State and probes (AC1) | AC1 not met | A survival table exists but the columns of rule_b002 are read as findings, or the store is read instead of asking the helper |
AC1 met | As level 2, and explains why e1 and e4 pass the checker yet are wrong (e1 is exactly the shared_cache bug of L04), and why class T9M is lost after the trim although it is in memory |
10 |
| Context (AC2) | AC2 not met | A table exists but only counts tokens, or checks keywords instead of lost_facts |
AC2 met | As level 2, and explains why keep_system 160 keeps the science rule (the correction at turn 7 is still in the context) and why keeps_stale only shows at turn 9 |
15 |
| Regression (AC3) | AC3 not met | A table exists but the golden diff is used as the gate, or still_fail is treated as a regression |
AC3 met | As level 2, and names w04/t4/1 as the known failure the suite is accepting, explains the result with baseline v2 and why removing the new session from w02 makes the memory bug invisible |
15 |
| Isolation (AC4) | AC4 not met | The plan catches only some bugs, or gives a false alarm on the correct service | AC4 met | As level 2, and explains why DEFAULT_PLAN misses shared_cache on P2 (which question A left in the cache), why no plan can catch memory_by_name on P2, and why the order of your steps matters |
15 |
| Scorecard and gates (AC5) | AC5 not met | A scorecard exists but a broken layer or a broken comparison still gives READY_FOR_REVIEW | AC5 met; every gate fails closed on missing or broken data, no approval word | As level 2, and explains why a one-student regression suite sees none of the five isolation bugs and the isolation suite sees no context or memory bug, and why r08 being READY_FOR_REVIEW on P2 says nothing about the memory key |
15 |
| Golden table and mutation (AC6) | AC6 not met | A golden table exists but was copied from a run without reading it | AC6 met; at least ten broken versions, each with a conclusion | As level 2, and separates the versions killed by the golden table from those only the gate cases or the hand-built cases can kill, explains why the survivors survive on this data, and names the conversation, plan or case that would kill them | 15 |
| Reproduction and notes (AC7) | AC7 not met | Reports typed by hand or not saying they are simulated | A script produces every report, a rerun gives the same files, there are tests on the report text | As level 2, and the tests catch deliberate errors (change a cell of the golden table, change the expected value of a check, change a canary, set the decision maker to ci), and decisions.md is honest that every number is simulated |
15 |
Points per dimension = (level reached / 3) × weight. Mapping to the module: practical = State and probes + Regression + Scorecard and gates + Reproduction and notes (55); applied QA analysis = Context + Isolation + Golden table and mutation (45).
Hints
Hint 1: probes and controls
Before reading a column of the survival table, read the `control` column. A probe that fails its control says nothing about the event; ask whether its expected reply can happen while the state is still intact, then try it with the helper itself (`state.run_script` and then `send`).Hint 2: the first lost turn
`lost_facts` compares the context with the history of the **current session**, not with the whole conversation. Read the history from `app.sessions[sid]["history"]` after each turn, and the context from the last log entry (`app.log[-1]["context"]`).Hint 3: the plan
Read A's script for each pair turn by turn and ask: after the last turn, which reply is in the cache, which session was active last, which borrow is pending, did A ask the helper to remember anything, and do A and B share a display name? Then run `isolation.audit` for each variant and each pair with a draft plan before you write tests.Hint 4: the decision function
Use `conversation.gate` and `isolation.gate` themselves to know whether a layer holds, then write the reasons. If a gate holds for something you have not listed, the function must still return HOLD: never turn a HOLD into READY_FOR_REVIEW just because your list of reasons is empty.Hint 5: test your own tests
Once the tests are green, try changing a cell of the golden table, changing the expected value of a check in `suite_v2.json`, removing a canary, setting `reviewed_by` to `ci`, or letting the script write a timestamp: if the tests stay green, they only compare the report with itself. A good test compares with a number **derived independently** (worked out by hand), not with the result of the function under test.Independent challenge (practical challenge)
Less guidance. The session_suite package is not needed (unless you want to reuse mine); use the lab's functions directly on the lab's data: the six conversations c01 to c06, A's SETUP script (S0042) and DEFAULT_PLAN. Submit one challenge.md file with four answers and how you computed them.
| Question | Task |
|---|---|
| (a) | For keep_system and for pin_rules, the smallest (integer) budget such that at every turn of all six conversations the context is within budget and lost_facts (against the history of the current session) is empty |
| (b) | Run the lab's regression suite with summarise at budget 140, keep_recent 4, with each of the five summariser modes in turn. For each mode, which checks fail besides c06/t3/1? Which check fails under exactly one mode, and which mode is it? |
| (c) | Of the 120 orderings of the five steps of DEFAULT_PLAN, how many catch all five defective variants while the correct service has no finding? Give a rule about the order that explains exactly that set |
| (d) | Run DEFAULT_PLAN with B set in turn to S0107, S0315 and S0518 (A stays S0042). For each B, which defective variant is not caught, and what do the gates of the correct service and of memory_by_name give? |
| Question | 0 | 1 | 2 | 3 | Weight |
|---|---|---|---|---|---|
| (a) | Missing | One strategy right | Both budgets right | As level 2, and says the budget of keep_system equals the largest context of one conversation: for that conversation this kind of trimming is never safe |
25 |
| (b) | Missing | Some of the modes right | Every mode and the asked mode right | As level 2, and states the consequence for suite design: to see one kind of failure on its own you need a check that only that kind makes fail | 25 |
| (c) | Missing | Right number, no rule | Right number and a correct rule | As level 2, and explains the rule with the mechanism of session_fallback (the most recently active session) |
25 |
| (d) | Missing | One B right | All three B and both gates right | As level 2, and says that READY_FOR_REVIEW with a B of another name only says "not found", not "isolated" | 25 |
Rules
- No real data or real APIs in the submission. The helper, the summariser, the service, the defective variants, the tokens and every number in the lab are simulated; do not infer the behaviour of any real model, vendor, framework or product.
- Do not change
lab/,data/,tests/orexercises/. Proposed fixes go innotes/decisions.md. - Every run stays inside the lab's Python process; no shell commands, network or files outside the output folder. A probe that uses someone else's session id is done only in the lab's sandbox; on a real system, only in a test environment, with test accounts, when permitted.
- Do not change conversations, checks, canaries, the plan or the golden table after seeing the results to get the conclusion you want; if you change them, record the reason and the result before the change.
- Every number in a report comes from the script; state the configuration. Do not let a gate replace reading the report.
- Gates only label; gates fail closed on missing or broken data; a person reviews, decides and is accountable for every real action. Do not create or change any automated workflow.