Write a quality incident report from logs.
Done by an agent. Checked twice.
An incident report with the timeline, cause, fix, product decisions and who was told, each fact tied to a log row.
Real files in
- cold_room_rules.md
The site's cold room rules: the limit, what counts as an excursion, when product must be held and who must be told by when. 17 lines, 729 bytes. - contacts.csv
Six people on site, their roles and other ways their names get written. 7 lines, 274 bytes. - cr2_stock.csv
The four lots in cold room 2 that night with their units. 5 lines, 234 bytes. - event_log.csv
49 rows from one night in a cold store: sensor readings, alarms, shift, maintenance and quality notes, typed in out of order, with one event logged twice and one name misspelled. 50 lines, 5 KB.
Sample data written by Atris. Not a real company.
Three steps
- 1.Put the log in order
- 2.Work out the facts from the rows
- 3.Write the timeline, list and report
Claude Sonnet 5.5, 1 min 16 s. No web. It never saw the check.
Checked twice
- Passed: 24 of 24 timeline lines carry the time of the log row they point to and the lines are in time order
- Passed: 16 of 16 key events from the log are in the timeline and 0 events logged twice are repeated
- Passed: 4 of 4 measured facts in the report match the sensor rows: start 00:30, end 03:15, 165 minutes, highest reading 8.9 C
- Passed: 6 of 6 notifications in the log are in notified.csv with the right person, role, time, way of telling and sender
- Passed: 4 of 4 lots are listed with their minutes exposed and the report gives the units on hold as 1,455, the sum from the stock list
- Passed: the cause is quoted word for word from log row E-033 and 2 of 2 repair rows are cited under Fix
- Passed: the report says the quality manager was told after 98 minutes against a limit of 60
- Passed: 208 of 208 times, dates, row numbers, readings and counts in the report are in the log, the stock list or the rules, or follow from them
- Passed: 24 of 24 timeline lines and 6 of 6 lines on who was told give the time of the log row they cite or of that person's own notification, with 15 of 15 times and readings set beside a row number agreeing with that row
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 7 ways on purpose. The check caught 7.
- CR2 air temperature went above the 5.0 C limit at 00:30 on 2026-11-15 (E-008, 5.4 C). It was back at the limit at 03:15 (E-029, 5.0 C). The excursion lasted 165 minutes. - The highest reading was 8.9 C at 01:45 (E-020). - The high temperature alarm was first raised at 00:32 (E-009, logged twice as E-009 and E-010, counted as one event). - Cause: a failed defrost termination sensor on evaporator 2 (E-033). A temporary fix was made at 02:05 (E-034) and a lasting fix at 09:40 (E-046). - Three lots (LOT-4471, LOT-4472, LOT-4480) were exposed for 165 minutes and had to be held: 1,455 units. LOT-4471 and LOT-4472 were rejected (1,000 units). LOT-4480 was released (455 units). LOT-4466 left CR2 after 50 minutes and did not need a hold. - One time limit was missed: the quality manager was told 98 minutes after the first alarm, against 60 allowed.
How this was run
An AI agent on Claude Sonnet 5.5 was given a folder with the files below and a three-step flow, and nothing else. It had no web access and never saw the check. The check was written before the run and made stricter after it. It works the answer out again from the input files. Then Claude Opus 5.5 reviewed the result against the inputs. The input files are sample data written by Atris, with the problems a real week has planted in them.
Run 1 of 1 on 1 December 2026. The agent took 1 min 16 s.
What the second review verified
- Excursion: the first reading above 5.0 C is E-008 at 00:30 (5.4 C) and the first reading back at or below the limit is E-029 at 03:15 (5.0 C). That is 165 minutes. The highest reading is 8.9 C at 01:45 (E-020). All match the report.
- Product: LOT-4466 left CR2 at 01:20 (E-025), giving 50 minutes, so no hold. The other three lots had 165 minutes each, over the 120-minute limit. Units on hold are 480+520+455=1,455 from the stock list, and the report notes that E-024 says 'About 1,500 units'.
- Notifications: all 6 notification rows (E-011, E-013, E-017, E-022, E-039, E-045) are in notified.csv with the right time. The two system texts list told_by 'system', and 'Jarek Molner' is corrected to the contacts spelling 'Jarek Molnar'.
- Rules: the quality manager was told 98 minutes after the first alarm (00:32 to 02:10), against 60 allowed, so not met. The site director was told at 06:30 the same day, so met. The cause quote matches E-033 word for word, the repairs E-034 (temporary) and E-046 (lasting) are cited, and the duplicate alarm E-009/E-010 is merged into one line. The supplied check.py passes all 7 checks.
What this run does not show
- The sample log names its cause in one row marked as a finding, so the report did not have to work out a cause.
- A time or row number changed to another real one from the log passes unless the two sit side by side or in the timeline.
- Whether the report reads well and lists the right open items is judged only by the second review.
Would the check catch a wrong answer?
A check that cannot fail proves nothing. After the run we took a copy of the output, broke it one small way at a time and ran the check again. It caught 7 of 7. The check was made stricter after the first try at this, and the same untouched output was graded again.
Open every file
flow.md · the three steps the agent followed
# Write a quality incident report from logs function: operations for: the person who answers for quality on site goal: One report says what happened, why, what was done and who was told, with every fact traced to a row in the log. ## 1. Put the log in order Read input/event_log.csv, the rules file in input/, input/contacts.csv and the stock list in input/. The log is in the order rows were typed in, which is not always the order things happened. Sort it by timestamp. When the same event was logged twice with the same time, source and detail, treat it as one event. A name in the log may be misspelled, so write every person's name as it is in contacts.csv. ## 2. Work out the facts from the rows Use the definitions in the rules file. Do the sums with a script. - When the excursion started and ended, its length in minutes and the highest reading with its time. - For each lot in the stock list, the minutes it was exposed and whether the rules say it must be held. Take units from the stock list. When a note in the log gives a different figure, use the stock list and say that the two differ. - The cause is in the row of type `finding`. The fix is in the rows of type `repair`. Say which repair was temporary and which was lasting. - Every row of type `notification` is one person being told. Record who, when, how and by whom. A message sent by a system with no person behind it is told by `system`. - For each time limit in the rules, work out the minutes it really took and say whether the limit was met. - When the log does not say who did something, write `not recorded`. Do not guess and do not add causes, times or names that are not in the files. ## 3. Write the timeline, list and report Write output/timeline.csv with columns time,event,source_rows. One row per event in time order. time is the timestamp of the log row, written the same way. source_rows holds the row_id it came from, or two ids joined by a semicolon for an event logged twice. Include the first reading above the limit, the highest reading, the first reading back at or below the limit and every row that is not a reading. Other readings may be left out. Write output/notified.csv with columns who,role,time,how,told_by,source_row. One row per notification row in the log. Write output/incident_report.md with these headings in this order: `## Summary`, `## Timeline`, `## Cause`, `## Fix`, `## Product`, `## Who was told`, `## Rules not met`, `## Open items`. Under Cause quote the finding row word for word and give its row_id. Under Fix give the row_id of each repair. Under Product give one line per lot with its minutes exposed, units and what was decided, then the total units put on hold. Under Who was told give one line per person told with the time. Under Rules not met give each limit that was missed with the minutes taken and the minutes allowed. Write times as HH:MM and lengths in minutes. ## Done looks like - Every line of the timeline points to a real log row with the same time. - The start, end, length and highest reading match the sensor rows. - Everyone the log says was told is in notified.csv with the right time.
input/cold_room_rules.md · 17 lines, 729 bytes
# Cold room rules, Kestrelmoor Fresh Foods ## Limit - Cold room 2 (CR2) air temperature limit: 5.0 C. ## What counts as an excursion - An excursion starts at the first reading above the limit. - It ends at the first later reading at or below the limit. - Its length is the minutes between those two readings. ## Product - A lot is exposed from the start of the excursion until the excursion ends or the lot leaves the room, whichever comes first. - Any lot exposed for more than 120 minutes must be put on quality hold until the quality manager decides. ## Who must be told - The quality manager must be told within 60 minutes of the first alarm. - The site director must be told on the same calendar day as the first alarm.
input/contacts.csv · 7 lines, 274 bytes
name,role,also_written Odile Ferrant,Night Shift Supervisor,O. Ferrant Jarek Molnar,Maintenance Technician on call,Jarek Molner; J. Molnar Priyanka Vale,Quality Manager,P. Vale Lorcan Reyes,Site Director, Hattie Brook,Customer Service Lead, Stellan Ord,Maintenance Manager,
input/cr2_stock.csv · 5 lines, 234 bytes
lot_id,product,units,in_cr2_since LOT-4466,Salted butter 250 g,300,2026-11-13 14:10 LOT-4471,Natural yoghurt 500 g,480,2026-11-13 16:40 LOT-4472,Double cream 250 ml,520,2026-11-14 09:05 LOT-4480,Soft cheese 200 g,455,2026-11-14 11:30
input/event_log.csv · 50 lines, 5 KB
row_id,timestamp,source,type,actor,detail E-001,2026-11-14 23:00,sensor CR2-T1,reading,,CR2 air temperature 3.6 C E-002,2026-11-14 23:15,sensor CR2-T1,reading,,CR2 air temperature 3.7 C E-003,2026-11-14 23:30,sensor CR2-T1,reading,,CR2 air temperature 3.5 C E-004,2026-11-14 23:45,sensor CR2-T1,reading,,CR2 air temperature 3.8 C E-005,2026-11-14 23:52,building system,note,,Scheduled defrost started on evaporator 2. E-006,2026-11-15 00:00,sensor CR2-T1,reading,,CR2 air temperature 3.9 C E-007,2026-11-15 00:15,sensor CR2-T1,reading,,CR2 air temperature 4.6 C E-008,2026-11-15 00:30,sensor CR2-T1,reading,,CR2 air temperature 5.4 C E-009,2026-11-15 00:32,building system,alarm,,CR2 high temperature alarm raised. Limit 5.0 C. E-010,2026-11-15 00:32,building system,alarm,,CR2 high temperature alarm raised. Limit 5.0 C. E-011,2026-11-15 00:34,building system,notification,,Alarm text message sent to on-call technician Jarek Molnar. No acknowledgement. E-012,2026-11-15 00:45,sensor CR2-T1,reading,,CR2 air temperature 6.3 C E-013,2026-11-15 00:50,building system,notification,,Alarm escalated. Text message sent to night shift supervisor Odile Ferrant. E-014,2026-11-15 01:00,sensor CR2-T1,reading,,CR2 air temperature 7.1 C E-015,2026-11-15 01:05,CR2 panel,ack,Odile Ferrant,Alarm acknowledged at the CR2 panel. E-016,2026-11-15 01:08,shift log,note,Odile Ferrant,CR2 door found closed. Evaporator 2 fans not running. Coil warm to the touch. E-017,2026-11-15 01:10,shift log,notification,Odile Ferrant,Phoned Jarek Molner at home. He answered and is coming in. E-018,2026-11-15 01:15,sensor CR2-T1,reading,,CR2 air temperature 7.8 C E-019,2026-11-15 01:30,sensor CR2-T1,reading,,CR2 air temperature 8.4 C E-020,2026-11-15 01:45,sensor CR2-T1,reading,,CR2 air temperature 8.9 C E-021,2026-11-15 02:00,sensor CR2-T1,reading,,CR2 air temperature 8.7 C E-022,2026-11-15 02:10,shift log,notification,Odile Ferrant,Emailed quality manager Priyanka Vale with the readings so far. E-023,2026-11-15 02:15,sensor CR2-T1,reading,,CR2 air temperature 7.9 C E-024,2026-11-15 02:20,shift log,hold,Odile Ferrant,"Put LOT-4471, LOT-4472 and LOT-4480 on quality hold in CR2. About 1,500 units." E-025,2026-11-15 01:20,stock system,action,,LOT-4466 moved from CR2 to CR1 for the 02:00 pick wave. E-026,2026-11-15 02:30,sensor CR2-T1,reading,,CR2 air temperature 6.8 C E-027,2026-11-15 02:45,sensor CR2-T1,reading,,CR2 air temperature 5.9 C E-028,2026-11-15 03:00,sensor CR2-T1,reading,,CR2 air temperature 5.2 C E-029,2026-11-15 03:15,sensor CR2-T1,reading,,CR2 air temperature 5.0 C E-030,2026-11-15 03:20,shift log,note,Odile Ferrant,CR2 back at the limit and falling. Hold stays on. E-031,2026-11-15 03:30,sensor CR2-T1,reading,,CR2 air temperature 4.4 C E-032,2026-11-15 01:40,maintenance log,note,Jarek Molnar,Arrived on site. E-033,2026-11-15 01:55,maintenance log,finding,Jarek Molnar,"Evaporator 2 defrost termination sensor has failed open. The defrost heater stayed on and the fans stayed locked out, so the room was being heated instead of cooled." E-034,2026-11-15 02:05,maintenance log,repair,Jarek Molnar,Isolated the defrost heater on evaporator 2 and forced the fans on. Room is pulling down. This is a temporary fix. E-035,2026-11-15 03:45,sensor CR2-T1,reading,,CR2 air temperature 3.9 C E-036,2026-11-15 04:00,sensor CR2-T1,reading,,CR2 air temperature 3.7 C E-037,2026-11-15 05:00,sensor CR2-T1,reading,,CR2 air temperature 3.6 C E-038,2026-11-15 06:00,sensor CR2-T1,reading,,CR2 air temperature 3.5 C E-039,2026-11-15 06:30,quality log,notification,Priyanka Vale,Phoned site director Lorcan Reyes and briefed him. E-040,2026-11-15 07:00,sensor CR2-T1,reading,,CR2 air temperature 3.6 C E-041,2026-11-15 07:10,quality log,note,Priyanka Vale,On site. Reviewing the readings and probing product. E-042,2026-11-15 08:00,sensor CR2-T1,reading,,CR2 air temperature 3.7 C E-043,2026-11-15 08:30,quality log,disposition,Priyanka Vale,"LOT-4471 and LOT-4472 rejected, to be destroyed. LOT-4480 released after a core probe of 4.1 C on 6 cases." E-044,2026-11-15 09:00,sensor CR2-T1,reading,,CR2 air temperature 3.6 C E-045,2026-11-15 09:00,quality log,notification,Priyanka Vale,Emailed customer service lead Hattie Brook: orders against LOT-4471 and LOT-4472 need a substitute. E-046,2026-11-15 09:40,maintenance log,repair,Jarek Molnar,Replaced the defrost termination sensor on evaporator 2. Ran one full defrost cycle and it ended normally after 22 minutes. E-047,2026-11-15 10:00,sensor CR2-T1,reading,,CR2 air temperature 3.5 C E-048,2026-11-15 10:15,maintenance log,action,Stellan Ord,Raised work order WO-2231 to replace the same sensor model on evaporators 1 and 3 by 2026-11-21. E-049,2026-11-15 10:30,maintenance log,note,Stellan Ord,The on-call text at 00:34 was not answered because the phone was on silent. The on-call procedure needs a review. No owner yet.
output/incident_report.md · written by the agent, 88 lines
# Quality incident report: Cold room 2 (CR2) high temperature, 15 Nov 2026 Source: input/event_log.csv (rows E-001 to E-049), sorted by timestamp. Rules from input/cold_room_rules.md. Units from input/cr2_stock.csv. Names are written as in input/contacts.csv. ## Summary - CR2 air temperature went above the 5.0 C limit at 00:30 on 2026-11-15 (E-008, 5.4 C). It was back at the limit at 03:15 (E-029, 5.0 C). The excursion lasted 165 minutes. - The highest reading was 8.9 C at 01:45 (E-020). - The high temperature alarm was first raised at 00:32 (E-009, logged twice as E-009 and E-010, counted as one event). - Cause: a failed defrost termination sensor on evaporator 2 (E-033). A temporary fix was made at 02:05 (E-034) and a lasting fix at 09:40 (E-046). - Three lots (LOT-4471, LOT-4472, LOT-4480) were exposed for 165 minutes and had to be held: 1,455 units. LOT-4471 and LOT-4472 were rejected (1,000 units). LOT-4480 was released (455 units). LOT-4466 left CR2 after 50 minutes and did not need a hold. - One time limit was missed: the quality manager was told 98 minutes after the first alarm, against 60 allowed. ## Timeline Full list with source rows is in timeline.csv. Times are 2026-11-15 unless stated. - 23:52 (14 Nov): Scheduled defrost started on evaporator 2 (E-005). - 00:30: First reading above the limit, 5.4 C (E-008). Excursion starts. - 00:32: High temperature alarm raised (E-009; E-010 is a duplicate of the same event). - 00:34: Alarm text sent to on-call technician Jarek Molnar. No acknowledgement (E-011). - 00:50: Alarm escalated by text to night shift supervisor Odile Ferrant (E-013). - 01:05: Odile Ferrant acknowledged the alarm at the CR2 panel (E-015). - 01:08: Odile Ferrant found the CR2 door closed, evaporator 2 fans not running, coil warm to the touch (E-016). - 01:10: Odile Ferrant phoned Jarek Molnar at home. He answered and was coming in (E-017). - 01:20: LOT-4466 moved from CR2 to CR1 (E-025). This row was typed in out of order. - 01:40: Jarek Molnar arrived on site (E-032). - 01:45: Highest reading, 8.9 C (E-020). - 01:55: Jarek Molnar recorded the finding (E-033). - 02:05: Temporary repair (E-034). - 02:10: Odile Ferrant emailed quality manager Priyanka Vale (E-022). - 02:20: Odile Ferrant put LOT-4471, LOT-4472 and LOT-4480 on quality hold (E-024). - 03:15: First reading back at or below the limit, 5.0 C (E-029). Excursion ends. - 03:20: Odile Ferrant noted CR2 back at the limit and falling, hold stays on (E-030). - 06:30: Priyanka Vale phoned site director Lorcan Reyes (E-039). - 07:10: Priyanka Vale on site, probing product (E-041). - 08:30: Priyanka Vale's decision on the held lots (E-043). - 09:00: Priyanka Vale emailed customer service lead Hattie Brook (E-045). - 09:40: Lasting repair (E-046). - 10:15: Stellan Ord raised work order WO-2231 (E-048). - 10:30: Stellan Ord noted why the 00:34 text went unanswered (E-049). ## Cause Row E-033 (maintenance log, Jarek Molnar, 01:55): > "Evaporator 2 defrost termination sensor has failed open. The defrost heater stayed on and the fans stayed locked out, so the room was being heated instead of cooled." The log also records at E-016 (01:08) that the door was found closed and the evaporator 2 fans were not running. The log gives no other cause. ## Fix - Temporary, E-034 (02:05, Jarek Molnar): isolated the defrost heater on evaporator 2 and forced the fans on. The row says the room was pulling down and that this is a temporary fix. - Lasting, E-046 (09:40, Jarek Molnar): replaced the defrost termination sensor on evaporator 2. One full defrost cycle ran and ended normally after 22 minutes. - Follow-up, E-048 (10:15, Stellan Ord): work order WO-2231 to replace the same sensor model on evaporators 1 and 3 by 2026-11-21. ## Product Exposure runs from 00:30 until the excursion ends (03:15) or the lot leaves the room, whichever is first. The hold limit is more than 120 minutes. Units come from the stock list. - LOT-4466, Salted butter 250 g: 50 minutes exposed (left CR2 at 01:20, E-025), 300 units. Not over 120 minutes, so no hold required. No hold was placed. Its condition after the move is not recorded. - LOT-4471, Natural yoghurt 500 g: 165 minutes exposed, 480 units. Hold required and placed (E-024). Rejected, to be destroyed (E-043). - LOT-4472, Double cream 250 ml: 165 minutes exposed, 520 units. Hold required and placed (E-024). Rejected, to be destroyed (E-043). - LOT-4480, Soft cheese 200 g: 165 minutes exposed, 455 units. Hold required and placed (E-024). Released after a core probe of 4.1 C on 6 cases (E-043). Total units put on hold: 1,455 (480 + 520 + 455). The hold note E-024 says "About 1,500 units". The stock list gives 1,455, so the two differ and 1,455 is used. Units rejected: 1,000. Units released: 455. ## Who was told - Jarek Molnar, Maintenance Technician on call: 00:34, text message from the system, no acknowledgement (E-011). - Odile Ferrant, Night Shift Supervisor: 00:50, text message from the system (E-013). - Jarek Molnar again: 01:10, phone call from Odile Ferrant (E-017). The log writes his name "Jarek Molner" here. - Priyanka Vale, Quality Manager: 02:10, email from Odile Ferrant (E-022). - Lorcan Reyes, Site Director: 06:30, phone call from Priyanka Vale (E-039). - Hattie Brook, Customer Service Lead: 09:00, email from Priyanka Vale (E-045). Details are in notified.csv. ## Rules not met - Quality manager told within 60 minutes of the first alarm: NOT MET. The first alarm was at 00:32 and Priyanka Vale was told at 02:10 (E-022). That took 98 minutes against 60 allowed, which is 38 minutes over. No earlier notification to the quality manager is in the log. Rules met: - Site director told on the same calendar day as the first alarm: MET. Told at 06:30 on 2026-11-15, 358 minutes after the alarm, on the same day as the alarm (E-039). - Quality hold for any lot exposed more than 120 minutes: MET. All three lots over 120 minutes were held (E-024). ## Open items - On-call procedure review: E-049 says the 00:34 text went unanswered because the phone was on silent and that the procedure needs a review. No owner is recorded. The first person reached by phone was at 01:10, 38 minutes after the alarm. - WO-2231 (sensors on evaporators 1 and 3) is due by 2026-11-21. Its completion is not recorded. - Why the quality manager was not told until 02:10: not recorded. - Who ordered the 02:20 hold, and who told the quality manager the lots were held: not recorded beyond Odile Ferrant being the actor on E-024. - Destruction of LOT-4471 and LOT-4472: not recorded as done. - LOT-4466: its temperature or condition after moving to CR1, and whether it was picked at 02:00, are not recorded. - Customer service: E-045 says orders against LOT-4471 and LOT-4472 need a substitute. Whether substitutes were arranged is not recorded. - The reading at 03:15 was exactly 5.0 C. By the rules (at or below the limit) this ends the excursion.
output/notified.csv · written by the agent, 7 lines
who,role,time,how,told_by,source_row Jarek Molnar,Maintenance Technician on call,00:34,text message,system,E-011 Odile Ferrant,Night Shift Supervisor,00:50,text message,system,E-013 Jarek Molnar,Maintenance Technician on call,01:10,phone call,Odile Ferrant,E-017 Priyanka Vale,Quality Manager,02:10,email,Odile Ferrant,E-022 Lorcan Reyes,Site Director,06:30,phone call,Priyanka Vale,E-039 Hattie Brook,Customer Service Lead,09:00,email,Priyanka Vale,E-045
output/timeline.csv · written by the agent, 25 lines
time,event,source_rows 2026-11-14 23:52,[note] Scheduled defrost started on evaporator 2.,E-005 2026-11-15 00:30,CR2 air temperature 5.4 C First reading above the 5.0 C limit; excursion starts.,E-008 2026-11-15 00:32,[alarm] CR2 high temperature alarm raised. Limit 5.0 C.,E-009;E-010 2026-11-15 00:34,[notification] Alarm text message sent to on-call technician Jarek Molnar. No acknowledgement.,E-011 2026-11-15 00:50,[notification] Alarm escalated. Text message sent to night shift supervisor Odile Ferrant.,E-013 2026-11-15 01:05,[ack] Alarm acknowledged at the CR2 panel.,E-015 2026-11-15 01:08,[note] CR2 door found closed. Evaporator 2 fans not running. Coil warm to the touch.,E-016 2026-11-15 01:10,[notification] Phoned Jarek Molnar at home. He answered and is coming in.,E-017 2026-11-15 01:20,[action] LOT-4466 moved from CR2 to CR1 for the 02:00 pick wave.,E-025 2026-11-15 01:40,[note] Arrived on site.,E-032 2026-11-15 01:45,CR2 air temperature 8.9 C Highest reading.,E-020 2026-11-15 01:55,"[finding] Evaporator 2 defrost termination sensor has failed open. The defrost heater stayed on and the fans stayed locked out, so the room was being heated instead of cooled.",E-033 2026-11-15 02:05,[repair] Isolated the defrost heater on evaporator 2 and forced the fans on. Room is pulling down. This is a temporary fix.,E-034 2026-11-15 02:10,[notification] Emailed quality manager Priyanka Vale with the readings so far.,E-022 2026-11-15 02:20,"[hold] Put LOT-4471, LOT-4472 and LOT-4480 on quality hold in CR2. About 1,500 units.",E-024 2026-11-15 03:15,CR2 air temperature 5.0 C First reading back at or below the limit; excursion ends.,E-029 2026-11-15 03:20,[note] CR2 back at the limit and falling. Hold stays on.,E-030 2026-11-15 06:30,[notification] Phoned site director Lorcan Reyes and briefed him.,E-039 2026-11-15 07:10,[note] On site. Reviewing the readings and probing product.,E-041 2026-11-15 08:30,"[disposition] LOT-4471 and LOT-4472 rejected, to be destroyed. LOT-4480 released after a core probe of 4.1 C on 6 cases.",E-043 2026-11-15 09:00,[notification] Emailed customer service lead Hattie Brook: orders against LOT-4471 and LOT-4472 need a substitute.,E-045 2026-11-15 09:40,[repair] Replaced the defrost termination sensor on evaporator 2. Ran one full defrost cycle and it ended normally after 22 minutes.,E-046 2026-11-15 10:15,[action] Raised work order WO-2231 to replace the same sensor model on evaporators 1 and 3 by 2026-11-21.,E-048 2026-11-15 10:30,[note] The on-call text at 00:34 was not answered because the phone was on silent. The on-call procedure needs a review. No owner yet.,E-049
check.py · the check, written before the run
"""Recomputes the incident facts from the event log and checks the timeline, the list of people told and the report against them."""
import csv, re, sys
from datetime import datetime
from pathlib import Path
root = Path(sys.argv[1]); ok = True
def say(passed, text):
global ok; ok = ok and passed; print(("PASS " if passed else "FAIL ") + text)
def flat(s): return " ".join((s or "").lower().replace("*", "").replace("’", "'").split())
def at(s): return datetime.strptime(s.strip()[:16].replace("T", " "), "%Y-%m-%d %H:%M")
def mins(a, b): return int((b - a).total_seconds() // 60)
log = list(csv.DictReader((root/"input/event_log.csv").open()))
byid = {r["row_id"]: r for r in log}
rules = (root/"input/cold_room_rules.md").read_text()
limit = float(re.search(r"limit:\s*(-?[\d.]+) C", rules).group(1))
hold_after = int(re.search(r"more than (\d+) minutes", rules).group(1)); tell_in = int(re.search(r"within (\d+) minutes", rules).group(1))
reads = sorted(((at(r["timestamp"]), float(re.search(r"(-?\d+\.\d+) C", r["detail"]).group(1)), r["row_id"]) for r in log if r["type"] == "reading"))
start = next(x for x in reads if x[1] > limit)
end = next(x for x in reads if x[0] > start[0] and x[1] <= limit)
peak = max((x for x in reads if start[0] <= x[0] <= end[0]), key=lambda x: x[1])
length = mins(start[0], end[0])
groups = {}
for r in log:
if r["type"] != "reading": groups.setdefault((r["timestamp"], r["source"], r["type"], r["detail"]), []).append(r["row_id"])
key = [[start[2]], [peak[2]], [end[2]]] + [ids for (_, _, typ, _), ids in groups.items() if typ in ("alarm", "ack", "notification", "hold", "finding", "repair", "disposition")]
tpath = root/"output/timeline.csv"
if not tpath.exists():
say(False, "output/timeline.csv was not written"); sys.exit(1)
tl = list(csv.DictReader(tpath.open()))
def cited(r): return [x for x in re.split(r"[;,\s]+", (r.get("source_rows") or "").strip()) if x]
def timed(r):
ids = cited(r)
try: return bool(ids) and all(i in byid for i in ids) and any(at(byid[i]["timestamp"]) == at(r["time"]) for i in ids)
except Exception: return False
true_rows = sum(1 for r in tl if timed(r))
try: ordered = all(at(a["time"]) <= at(b["time"]) for a, b in zip(tl, tl[1:]))
except Exception: ordered = False
say(len(tl) >= len(key) and true_rows == len(tl) and ordered, f"{true_rows} of {len(tl)} timeline lines carry the time of the log row they point to and the lines {'are' if ordered else 'are not'} in time order")
seen = {i for r in tl for i in cited(r)}
kept = sum(1 for ids in key if seen & set(ids))
twice = sum(1 for ids in groups.values() if len(ids) > 1 and sum(1 for r in tl if set(cited(r)) & set(ids)) > 1)
say(kept == len(key) and twice == 0, f"{kept} of {len(key)} key events from the log are in the timeline and {twice} events logged twice are repeated")
report = (root/"output/incident_report.md").read_text() if (root/"output/incident_report.md").exists() else ""
facts = [start[0].strftime("%H:%M") in report, end[0].strftime("%H:%M") in report, bool(re.search(rf"\b{length}\b", report)), bool(re.search(rf"(?<![\d.]){peak[1]}(?!\d)", report))]
say(all(facts), f"{sum(facts)} of 4 measured facts in the report match the sensor rows: start {start[0]:%H:%M}, end {end[0]:%H:%M}, {length} minutes, highest reading {peak[1]} C")
people = []; job = {}
for r in csv.DictReader((root/"input/contacts.csv").open()):
job[r["name"].strip()] = r["role"].strip()
people.append((r["name"].strip(), [r["name"].strip().lower()] + [a.strip().lower() for a in r["also_written"].split(";") if a.strip()]))
notes = [r for r in log if r["type"] == "notification"]
def told(r): return next(name for name, forms in people if name != r["actor"].strip() and any(f in r["detail"].lower() for f in forms))
npath = root/"output/notified.csv"
ngot = {(r.get("source_row") or "").strip(): r for r in csv.DictReader(npath.open())} if npath.exists() else {}
def same_time(a, b):
try: return at(a) == at(b)
except Exception: return a.strip()[-5:] == b.strip()[-5:]
def canon(s): return next((name for name, forms in people if s.strip().lower() in forms), s.strip())
ways = (("text", r"text|sms"), ("phone", r"phone|call|rang"), ("email", r"e-?mail"))
def way_ok(r, cell): return any(re.search(pat, r["detail"].lower()) and re.search(pat, (cell or "").lower()) for _, pat in ways) and sum(1 for _, pat in ways if re.search(pat, (cell or "").lower())) == 1
def row_ok(r):
g = ngot.get(r["row_id"])
return bool(g) and (g.get("who") or "").strip() == told(r) and same_time(g.get("time") or "", r["timestamp"]) and (g.get("role") or "").strip() == job[told(r)] \
and canon(g.get("told_by") or "") == (canon(r["actor"]) if r["actor"].strip() else "system") and way_ok(r, g.get("how"))
nrows = list(csv.DictReader(npath.open())) if npath.exists() else []
right = sum(1 for r in notes if row_ok(r))
say(right == len(notes) == len(nrows) and len(ngot) == len(notes), f"{right} of {len(notes)} notifications in the log are in notified.csv with the right person, role, time, way of telling and sender")
stock = list(csv.DictReader((root/"input/cr2_stock.csv").open()))
left = {}
for r in log:
m = re.search(r"(LOT-\d+) moved from CR2", r["detail"])
if m: left[m.group(1)] = at(r["timestamp"])
expo = {s["lot_id"]: mins(start[0], min(end[0], left.get(s["lot_id"], end[0]))) for s in stock}
held = [s for s in stock if expo[s["lot_id"]] > hold_after]
units = sum(int(s["units"]) for s in held)
lots = sum(1 for s in stock if any(s["lot_id"] in ln and re.search(rf"\b{expo[s['lot_id']]}\b", ln) for ln in report.splitlines()))
say(lots == len(stock) and bool(re.search(rf"\b{units:,}\b|\b{units}\b", report)), f"{lots} of {len(stock)} lots are listed with their minutes exposed and the report gives the units on hold as {units:,}, the sum from the stock list")
def part(name):
m = re.search(rf"(?ms)^## {name}\s*$(.*?)(?=^## |\Z)", report); return m.group(1) if m else ""
finding = next(r for r in log if r["type"] == "finding"); words = flat(finding["detail"]).split()
quoted = any(" ".join(words[i:i + 8]) in flat(part("Cause")) for i in range(len(words) - 7))
repairs = [r["row_id"] for r in log if r["type"] == "repair"]
fixed = sum(1 for i in repairs if i in part("Fix"))
say(quoted and finding["row_id"] in part("Cause") and fixed == len(repairs), f"the cause is quoted word for word from log row {finding['row_id']} and {fixed} of {len(repairs)} repair rows are cited under Fix")
alarm = min(at(r["timestamp"]) for r in log if r["type"] == "alarm")
qm = next(name for name, _ in people if "quality manager" in next(c["role"] for c in csv.DictReader((root/"input/contacts.csv").open()) if c["name"].strip() == name).lower())
took = mins(alarm, min(at(r["timestamp"]) for r in notes if told(r) == qm))
missed = part("Rules not met")
say(took > tell_in and bool(re.search(rf"\b{took}\b", missed)) and bool(re.search(rf"\b{tell_in}\b", missed)), f"the report says the quality manager was told after {took} minutes against a limit of {tell_in}")
# Every time, date, reading and count in the report must come from the log, the stock list or the rules, or be worked out from them.
iso = r"\d{4}-\d{2}-\d{2}"; clock = r"(?<![\d:])\d{1,2}:\d{2}(?!\d|:\d)"; tag = r"\b[A-Z]{1,4}\d*-[A-Z]?\d+\b"
months = "jan feb mar apr may jun jul aug sep oct nov dec".split()
source = " ".join(r["detail"] for r in log) + " " + rules + " " + " ".join(" ".join(s.values()) for s in stock)
stamps = {at(r["timestamp"]) for r in log}
days_ok = {d.strftime("%Y-%m-%d") for d in stamps} | set(re.findall(iso, source))
clocks_ok = {d.strftime("%H:%M") for d in stamps} | {c.zfill(5) for c in re.findall(clock, source)}
def bare(s): return re.sub(iso + "|" + clock + "|" + tag, " ", s)
def numbers(s): return [x.replace(",", "") for x in re.findall(r"(?<![\w.])\d[\d,]*(?:\.\d+)?(?![\w]|\.\d)", bare(s))]
moments = sorted({at(r["timestamp"]) for r in log if r["type"] != "reading"} | {start[0], peak[0], end[0]})
sizes = [int(s["units"]) for s in stock]
sums = {sum(x for i, x in enumerate(sizes) if pick >> i & 1) for pick in range(1, 2 ** len(sizes))}
points = {x for x in numbers(source) if "." in x}
whole = {float(x) for x in numbers(source) if "." not in x} | {float(x) for x in sums} | {float(x) for x in (length, took, took - tell_in, len(log), len(notes), len(stock), len(held), len(stock) - len(held), 0)}
whole |= {float(v) for v in expo.values()} | {float(mins(a, b)) for a in (start[0], alarm) for b in moments if b >= a}
seen = wrong = 0; odd = []
for ln in report.splitlines():
low = re.sub(r"^\s*\d+[.)]\s", "", ln)
for d in re.findall(iso, low):
seen += 1
if d not in days_ok: wrong += 1; odd.append(d)
for c in re.findall(clock, re.sub(iso, " ", low)):
seen += 1
if c.zfill(5) not in clocks_ok: wrong += 1; odd.append(c)
for i in re.findall(tag, low):
seen += 1
if i not in byid and i not in source: wrong += 1; odd.append(i)
rest = bare(low)
for y in re.findall(r"\b(?:" + "|".join(months) + r")[a-z]*,? (\d{4})\b|\b\d{1,2} (?:" + "|".join(months) + r")[a-z]* (\d{4})\b", rest.lower()):
seen += 1
if not any(str(d.year) in y for d in stamps): wrong += 1; odd.append("".join(y))
for a, b in re.findall(r"\b(\d{1,2}) (" + "|".join(months) + r")[a-z]*\b", rest.lower()) + [(y, x) for x, y in re.findall(r"\b(" + "|".join(months) + r")[a-z]* (\d{1,2})\b", rest.lower())]:
seen += 1
if not any(d.day == int(a) and months[d.month - 1] == b for d in stamps): wrong += 1; odd.append(a + " " + b)
rest = re.sub(r"(?i)\b\d{1,2} (?:" + "|".join(months) + r")[a-z]*(?: \d{4})?|\b(?:" + "|".join(months) + r")[a-z]* \d{1,2}(?:,? \d{4})?", " ", rest)
for x in numbers(rest):
seen += 1
if (x not in points) if "." in x else (float(x) not in whole): wrong += 1; odd.append(x)
say(seen > 0 and wrong == 0, f"{seen - wrong} of {seen} times, dates, row numbers, readings and counts in the report are in the log, the stock list or the rules, or follow from them" + (": not " + ", ".join(odd[:4]) if odd else ""))
def tied(name):
lines = [ln for ln in part(name).splitlines() if re.search(clock, ln)]
good = 0
for ln in lines:
ids = [i for i in re.findall(r"\bE-\d+\b", ln) if i in byid]
if ids: fine = {at(byid[i]["timestamp"]).strftime("%H:%M") for i in ids} | {c.zfill(5) for i in ids for c in re.findall(clock, byid[i]["detail"])}
else: fine = {at(r["timestamp"]).strftime("%H:%M") for r in notes if any(f in ln.lower() for f in dict(people)[told(r)])}
good += all(c.zfill(5) in fine for c in re.findall(clock, ln))
return good, len(lines)
# Where a time or a reading sits right beside a row number, the two must agree.
def hhmm(i): return {at(byid[i]["timestamp"]).strftime("%H:%M")} | {c.zfill(5) for c in re.findall(clock, byid[i]["detail"])}
pairs = agree = 0
for m in re.finditer(r"\(([^()]*)\)", report):
inside = m.group(1); ids = [i for i in re.findall(r"\bE-\d+\b", inside) if i in byid]
before = report[max(0, m.start() - 40):m.start()]
if not ids:
lead = re.search(r"\b(E-\d+)\s*$", before); ids = [lead.group(1)] if lead and lead.group(1) in byid else []
if not ids: continue
near = re.findall(clock, inside); temps = []
else:
lead = re.search(r"(" + clock + r")(?: on " + iso + r")?\s*$", before)
near = re.findall(clock, inside) + ([lead.group(1)] if lead else [])
temps = re.findall(r"(-?\d+\.\d+) ?C\b", inside)
for c in near:
pairs += 1; agree += any(c.zfill(5) in hhmm(i) for i in ids)
for x in temps:
pairs += 1; agree += any(x in byid[i]["detail"] for i in ids)
(g1, n1), (g2, n2) = tied("Timeline"), tied("Who was told")
say(n1 >= len(key) and n2 >= len({told(r) for r in notes}) and g1 == n1 and g2 == n2 and agree == pairs, f"{g1} of {n1} timeline lines and {g2} of {n2} lines on who was told give the time of the log row they cite or of that person's own notification, with {agree} of {pairs} times and readings set beside a row number agreeing with that row")
sys.exit(0 if ok else 1)
cold_room_rules.md: sample data written by Atris. Fingerprint 5f17c48262a2.
contacts.csv: sample data written by Atris. Fingerprint 3967d1a3e471.
cr2_stock.csv: sample data written by Atris. Fingerprint 934774dd3323.
event_log.csv: sample data written by Atris. Fingerprint 126905ffc626.
incident_report.md: written by the agent. Fingerprint eff90e17605a.
notified.csv: written by the agent. Fingerprint 12a5a272114c.
timeline.csv: written by the agent. Fingerprint f5d632c05a5b.