Skip to the lesson
CivOps AI Academy · M09SPC and Inspection: Charts, Run Rules, Capability, Gauges and First Articles
0%

Chapter 1 · Sessions 1 and 2

What the old SPC tool holds, and the tables that replace it

Before you chart anything, you count what the old SPC and inspection tool holds and costs, and you find out how it really computes its limits and its Cpk. Then one careful prompt adds the thirteen SPC tables to your platform, joined to the characteristics and inspections your Foundation already records, with tests that refuse bad data.

25 min4 stepsAbout 7 hours hands-on across six sessionsSessions 1 and 2

By the end of this chapter you can

  • Inventory the old tool from its own reports and invoice, and record how it sets limits and which sigma its Cpk uses.
  • Map the specification's spine names to your platform, and decide how the Foundation's characteristics and inspections join the module.
  • Have Claude Code write the thirteen spc_ tables, their rules and their tests in one pull request.
  • Write the module's made-up seed, supabase/seeds/spc.sql, with the 36 reference readings shifted onto today, and keep the same readings as a test fixture.

What this module replaces

The module collects characteristic data at the right frequency, charts it in real time with run rules, forces a documented reaction to every signal, computes capability correctly, and manages inspection and sampling plans, gauge studies and first-article inspection. It replaces InfinityQS ProFicient or Enact, Minitab Real-Time SPC, WinSPC, SQCpack, 1factory, High QA or DataLyzer [1][2], or the spreadsheet beside the gauge. Laboratory samples (M10) and the NCR and CAPA workflow (M08) belong to other modules.

The edge of SPC and inspectionInside: characteristics and control plans, sampling and inspection plans, data capture and control charts, run rules and required reaction, capability and gage R&R studies, and first article inspection. Outside, each with its owner: laboratory samples in M10, the NCR and CAPA workflow in M08, and digital forms in M01, which send readings in. INSIDE SPC AND INSPECTION (M09)Characteristicsand control plansSampling andinspection plansData captureand control chartsRun rules andrequired reactionCapability andgage R&R studiesFirst articleinspection (AS9102)OUTSIDE, WITH ITS OWNERLaboratory samplesowned by M10NCR and CAPA workflowowned by M08Digital formsM01 sends readings in
The edge of the module. Inside: characteristics, control plans, sampling and inspection, charts and the required reaction, capability, gauge studies and first articles. Outside: laboratory samples (M10) and NCR and CAPA (M08).
StandardUsed in this module for
AIAG SPC Reference Manual (2nd ed.)Chart choice, subgrouping, control limits and their constants, capability
AIAG MSA Reference Manual (4th ed.)Gage R&R, bias, linearity, stability, attribute agreement
ISO 7870-2:2023Shewhart control charts
ISO 22514 seriesProcess capability and performance
ANSI/ASQ Z1.4 and Z1.9, ISO 2859-1Acceptance sampling by attributes and by variables
SAE AS9102C [3]First article inspection, Forms 1 to 3
Western Electric (1956) and Nelson (1984)Run rules for patterns random variation rarely makes [4]
Step 1

Session 1: Count what the old SPC tool holds and costs, and how it computes

60 minutes

Why

The module is worth building only if it replaces real charts, real gauges, real users and a real bill, and the inventory is what Session 6 is checked against. Two questions matter as much as the counts: does the old tool recalculate limits by itself, and which sigma does its Cpk use? If either answer is wrong, your capability reports have been wrong too, and the new module will disagree with the old one for a good reason.

Do this

With the quality engineer, read from the tool's own reports, its settings and the vendor's account page (no customer names):

  • Characteristics charted, by part and press; charts by type; gauges in use and their last gauge study.
  • Users by what they do: measure, inspect, set or approve limits, answer signals, read reports.
  • The bill: amount, period, renewal date, notice period, paid users, as printed.
  • How limits are set: fixed after approval, or recalculated automatically (look in each chart's settings).
  • For one characteristic, the tool's Cpk and the help page or setting that says which sigma it uses.
  • What it can export: characteristics, specification limits, history, limits, violations and their responses.
  • Workarounds: readings typed on paper first, charts printed for audits, signals answered by email.
Paste into Claude Code, after replacing the <...> part
On a new branch spc/inventory, write docs/spc-inventory.md from what I give you below. Use only my numbers: where I wrote "unknown", write "unknown" and who can find out. Never estimate, round or fill a gap.

Tables:
1. Tools: name, owner, bill per year, renewal date, notice period, export available, source of each figure.
2. Characteristics, charts by type, gauges and their last study, with the report each count came from.
3. Users by role (measure, inspect, set limits, approve limits, answer signals, read).
4. How limits are set (fixed after approval or recalculated automatically), per chart type, with where I saw it.
5. One characteristic's Cpk as the tool shows it, and which sigma the tool says it uses.
6. What can be exported, and for how long after cancelling.
7. Workarounds, who, how often.
8. The first slice to replace (one part, its characteristics, its gauges), why, and the quality engineer and approver who will test it.

My notes:
<paste your notes here>

Open a pull request titled "SPC inventory" and show me the link.

You will see recreated screen

claude — acme-platform
⏺ Write(docs/spc-inventory.md)
+## How limits are set
+| X-bar R | recalculated every 25 subgroups automatically | chart settings, Limits tab |
+## One characteristic's Cpk
+| Flange height, part 4410 | Cpk 1.41 | help page: "Cpk uses the overall standard deviation" |
1
⏺ Pull request #91 adds docs/spc-inventory.md. Two findings to discuss: the X-bar R charts recalculate limits by themselves, and the tool's Cpk uses overall sigma, which is what the module calls Ppk. The export window after cancelling is unknown.2
Claude Code writes the inventory from your notes, including what the old tool gets wrong.
  1. The second pitfall, found in the old tool's own settings.
  2. The first pitfall: the old Cpk is really a Ppk. Expect the new module's Cpk to differ, and say why in Session 6.

Check it worked

Pull request SPC inventory holds the eight tables, every figure with its source, and answers to the limits and sigma questions.

If it goes wrong

Claude Code filled in a count or a price you did not give it

Say: Remove every figure I did not give you and write unknown. We hit this on our own platform: screens showed numbers nobody had measured, and one chart said "In control" on 87 screens from twelve made-up points.

Nobody knows which sigma the tool uses

Write unknown. Session 5's rehearsal recomputes Cpk and Ppk from the exported history, and the old figure will match one of them.

Your platform's names, and the characteristics you already have

The specification points at core_item, core_uom, core_equipment, core_lot, core_person, core_reason_code, core_data_tag and core_e_signature. Your Foundation already has parts, equipment and lots, and something closer still: a characteristics table with each part's limits, and an inspections table of first-piece and gauge results that the quality lead's hold decisions read. The module must not create a second home for the same limits or the same reading: two homes drift apart, and then the chart and the hold decision disagree.

Specification or moduleOn the stamping plant's platformDecision
core_item, core_equipment, core_lotparts, equipment, lotsPoint at them
spc_characteristiccharacteristics (lower_mm, upper_mm)One row each, pointing at the Foundation row; lsl and usl must equal its limits, enforced by a trigger
spc_measurementinspections (value_mm)Each new inspection is copied once into spc_measurement (source form), keeping the inspection's id, so every reading charts and the hold workflow is untouched
core_uom, core_reason_code, core_data_tag, core_e_signaturemissing unless another module added themAdd them in the spine migration
tenant_id on every rowsite_idOne company; site is the scope
Step 2

Session 2: Map the spine and join the characteristics you already have

20 minutes

Why

Your plant's limits and readings already live in the Foundation tables, and the quality lead's hold decisions read them. Joining the module to them, rather than copying them, keeps one set of limits and one record of each reading. The shared spine tables (units, reason codes, signatures) go in their own migration, merged first, because other modules use them too.

Do this

Terminal or PowerShell
cd ~/code/acme-platform && git switch main && git pull && claude
Paste into Claude Code
Read docs/SCHEMA-PLAN.md, docs/naming-standard.md, every file in supabase/migrations, and docs/spine-map.md if it exists. Do not change any existing table or migration.

On a new branch spine/spc-prerequisites:
1. Create or extend docs/spine-map.md: for core_item, core_uom, core_equipment, core_lot, core_person, core_job_role, core_reason_code, core_data_tag, core_e_signature, core_status_history and core_event_outbox, the table here that plays that role, or "missing". Record our scope column (site_id) and id type.
2. Record in docs/spine-map.md how the module joins the Foundation: spc_characteristic will point at our characteristics table (one each) and its lsl and usl must equal that row's limits; each new inspections row will be copied once into spc_measurement with source "form" and the inspection's id in ext. Ask me before choosing anything else.
3. For every "missing" item, write ONE new migration (npx supabase migration new spine_for_spc) with this platform's conventions: primary key, site_id, created and updated columns, row_version, archived_at, ext jsonb, timestamptz; row-level security on with no policies; signatures, status history and outbox append-only. Add each new table to docs/matrix.json with no rights yet.
4. pgTAP tests for every new table.

Push, open a pull request titled "Spine for SPC", wait for every check to finish, and tell me the result in plain words. If a check fails, fix it and wait again before reporting.

You will see recreated screen

claude — acme-platform
⏺ Read(supabase/migrations/20261016091500_create_first_tables.sql)
⎿ Read 112 lines
⏺ Write(docs/spine-map.md)
+| spc_characteristic | one per characteristics row; lsl = lower_mm, usl = upper_mm (trigger) |
+| spc_measurement | each new inspections row copied once, source form, ext.inspection_id |
+| core_reason_code | already created by spine_for_scheduling |
+| core_data_tag | missing: created in spine_for_spc |
1
⏺ Bash(gh pr checks --watch)
⎿ schema / test pass 2m02s
⏺ Pull request #92 is green. One new spine table (core_data_tag); reason codes and signatures already existed from other modules. No existing table changed.
Claude Code records how the module joins what you already have, and creates only what is missing.
  1. One set of limits, one record of each reading: the module joins the Foundation instead of copying it.

Check it worked

Pull request Spine for SPC is green, docs/spine-map.md records both joins, and no older migration is edited.

If it goes wrong

Claude Code proposes moving inspections into spc_measurement and dropping the old table

Refuse. Records of what happened are never dropped, and the hold workflow reads that table. Say: Keep inspections as it is; copy new rows once, as written in docs/spine-map.md.

It renamed characteristics to spc_characteristic

Say: Revert the rename; names are forever. A half-done rename breaks every query that used the old name; we hit exactly that on our platform.

It reports success but a check is red

Say: A check is red. Read the failed log, fix it and wait for green before you report. Trust the check, never the summary.

The thirteen tables

Thirteen tables in four groupsDefine: characteristic, control plan and control plan line. Plan the inspection: sampling plan, inspection plan and inspection lot. Chart and react: chart, subgroup, measurement and violation. Prove: capability study, MSA study and first article report. DEFINE WHAT TO MEASUREspc_characteristicfeature, limitsspc_control_planplan headerspc_control_plan_linehow, how oftenPLAN THE INSPECTIONspc_sampling_planscheme, AQLspc_inspection_plantype per itemspc_inspection_lotdecisionCHART AND REACTspc_charttype, rules, limitsspc_subgroupstatisticsspc_measurementone readingspc_violationsignal and responsePROVEspc_capability_studyCp, Cpk, Pp, Ppkspc_msa_studygage R&R, biasspc_fai_reportAS9102 forms
Thirteen tables in four groups. What to measure, how to inspect, chart and react, and the studies.

Five columns are soft links: plain uuid columns that will point at another module's table (MES operations, the FMEA, quality events) with no foreign key, because that module may not be installed yet. Readings are one row each with a numeric value; JSON only where the shape really varies.

TableHoldsColumns
spc_characteristicMeasured or counted characteristiccode text req, unique; item_id → core_item; operation_ref uuid (soft link to mes_operation_definition); name text req; char_type text req: variable, attribute; uom_id → core_uom; nominal num; lsl num; usl num; special_class text req: none, cc, sc, key; gauge_type text; data_tag_id → core_data_tag; decimals int
spc_control_planControl plan headerplan_no text req, unique; item_id → core_item req; revision text req; phase text req: prototype, pre_launch, production; status text req: draft, approved, superseded; fmea_ref uuid (soft link to qms_fmea)
spc_control_plan_lineControl plan line (AIAG format)control_plan_id → spc_control_plan req; process_step text req; characteristic_id → spc_characteristic req; evaluation_method text; sample_size int; frequency text; control_method text; reaction_plan text
spc_sampling_planSampling scheme definitioncode text req, unique; scheme text req: fixed, z14_aql, z19, skip_lot, c_zero, hundred_pct; aql num; inspection_level text; params json
spc_inspection_planInspection plan per item and typeitem_id → core_item req; inspection_type text req: receiving, in_process, final, first_article, audit, source; sampling_plan_id → spc_sampling_plan; characteristics json; active bool req
spc_inspection_lotInspection instance with decisioninspection_plan_id → spc_inspection_plan req; lot_id → core_lot; lot_qty qty; sample_size int; status text req: open, in_progress, decided; decision text req: pending, accept, reject, conditional; inspector_id → core_person; decided_at ts; quality_event_ref uuid (soft link to qms_quality_event)
spc_chartControl chart configuration and current limitscharacteristic_id → spc_characteristic req; equipment_id → core_equipment; chart_type text req: xbar_r, xbar_s, imr, p, np, c, u, ewma, cusum, short_run; subgroup_size int req; rules json req; ucl num; cl num; lcl num; ucl_r num; lcl_r num; limits_basis text req: historical, standard, manual; limits_set_at ts; limits_set_by → core_person; limits_approval_signature_id → core_e_signature
spc_subgroupSubgroup statisticschart_id → spc_chart req; seq int req; ts ts req; n int req; mean num; range_val num; stdev num; defects num; defectives num; inspected num; lot_id → core_lot; operation_run_ref uuid (soft link to mes_operation_run)
spc_measurementIndividual measurement or attribute observationcharacteristic_id → spc_characteristic req; subgroup_id → spc_subgroup; inspection_lot_id → spc_inspection_lot; value num; attribute_result text: pass, fail; defect_count int; measured_at ts req; measured_by → core_person; gauge_equipment_id → core_equipment; source text req: manual, gauge, tag, form, import
spc_violationRun-rule signal and the required responsechart_id → spc_chart req; subgroup_id → spc_subgroup req; rule_code text req; detected_at ts req; acknowledged_by → core_person; acknowledged_at ts; assignable_cause_code_id → core_reason_code; corrective_action text; escalated_event_ref uuid (soft link to qms_quality_event); status text req: open, acknowledged, closed
spc_capability_studyCapability result over a periodcharacteristic_id → spc_characteristic req; period_start ts req; period_end ts req; n int req; mean num; sigma_within num; sigma_overall num; cp num; cpk num; pp num; ppk num; distribution text; normality_p num; expected_ppm num; stable bool
spc_msa_studyMeasurement system analysisstudy_no text req, unique; gauge_equipment_id → core_equipment req; characteristic_id → spc_characteristic; study_type text req: grr_crossed, grr_nested, bias, linearity, stability, attribute_agreement; method text req: anova, average_range, kappa, other; operators int; parts int; trials int; data json; pct_grr num; ndc int; result text: acceptable, marginal, unacceptable; performed_at date
spc_fai_reportAS9102 first-article inspection reportfai_no text req, unique; item_id → core_item req; part_revision text; serial_no text; form1 json; form2 json; form3 json req; status text req: draft, complete, approved, rejected; approved_signature_id → core_e_signature
Step 3

Session 2: One prompt: the thirteen tables, their rules and their tests

25 minutes

Why

A rule kept in the table protects every screen, gauge feed and import. A characteristic whose lower limit is above its upper limit, or a violation closed with no cause, would quietly corrupt every chart and report built on it. Giving Claude Code the exact column list stops it inventing or dropping a column, and the two governance rules (limits change only with an approval, a violation closes only with a coded response) are written into the database from the start.

Do this

Paste into Claude Code
On a new branch spc/tables, add this module's own section to docs/spine-map.md, the one shared map (never a separate tables file), with exactly this content, then use it.

## M09 SPC and inspection tables (from the module specification M09)
Every table also has the standard columns recorded above in this map. "req" means not null. A list after a colon is a check constraint. "→ core_x" means a foreign key to the table docs/spine-map.md maps core_x to. "soft link" means a plain uuid column with a comment naming the table, and no foreign key. Types: ts = timestamptz, num and qty = numeric, json = jsonb.

### spc_characteristic
Measured or counted characteristic.
- code text req, unique
- item_id → core_item
- operation_ref uuid (soft link to mes_operation_definition)
- name text req
- char_type text req: variable, attribute
- uom_id → core_uom
- nominal num
- lsl num
- usl num
- special_class text req: none, cc, sc, key
- gauge_type text
- data_tag_id → core_data_tag
- decimals int

### spc_control_plan
Control plan header.
- plan_no text req, unique
- item_id → core_item req
- revision text req
- phase text req: prototype, pre_launch, production
- status text req: draft, approved, superseded
- fmea_ref uuid (soft link to qms_fmea)

### spc_control_plan_line
Control plan line (AIAG format).
- control_plan_id → spc_control_plan req
- process_step text req
- characteristic_id → spc_characteristic req
- evaluation_method text
- sample_size int
- frequency text
- control_method text
- reaction_plan text

### spc_sampling_plan
Sampling scheme definition.
- code text req, unique
- scheme text req: fixed, z14_aql, z19, skip_lot, c_zero, hundred_pct
- aql num
- inspection_level text
- params json

### spc_inspection_plan
Inspection plan per item and type.
- item_id → core_item req
- inspection_type text req: receiving, in_process, final, first_article, audit, source
- sampling_plan_id → spc_sampling_plan
- characteristics json
- active bool req

### spc_inspection_lot
Inspection instance with decision.
- inspection_plan_id → spc_inspection_plan req
- lot_id → core_lot
- lot_qty qty
- sample_size int
- status text req: open, in_progress, decided
- decision text req: pending, accept, reject, conditional
- inspector_id → core_person
- decided_at ts
- quality_event_ref uuid (soft link to qms_quality_event)

### spc_chart
Control chart configuration and current limits.
- characteristic_id → spc_characteristic req
- equipment_id → core_equipment
- chart_type text req: xbar_r, xbar_s, imr, p, np, c, u, ewma, cusum, short_run
- subgroup_size int req
- rules json req
- ucl num
- cl num
- lcl num
- ucl_r num
- lcl_r num
- limits_basis text req: historical, standard, manual
- limits_set_at ts
- limits_set_by → core_person
- limits_approval_signature_id → core_e_signature

### spc_subgroup
Subgroup statistics.
- chart_id → spc_chart req
- seq int req
- ts ts req
- n int req
- mean num
- range_val num
- stdev num
- defects num
- defectives num
- inspected num
- lot_id → core_lot
- operation_run_ref uuid (soft link to mes_operation_run)

### spc_measurement
Individual measurement or attribute observation.
- characteristic_id → spc_characteristic req
- subgroup_id → spc_subgroup
- inspection_lot_id → spc_inspection_lot
- value num
- attribute_result text: pass, fail
- defect_count int
- measured_at ts req
- measured_by → core_person
- gauge_equipment_id → core_equipment
- source text req: manual, gauge, tag, form, import

### spc_violation
Run-rule signal and the required response.
- chart_id → spc_chart req
- subgroup_id → spc_subgroup req
- rule_code text req
- detected_at ts req
- acknowledged_by → core_person
- acknowledged_at ts
- assignable_cause_code_id → core_reason_code
- corrective_action text
- escalated_event_ref uuid (soft link to qms_quality_event)
- status text req: open, acknowledged, closed

### spc_capability_study
Capability result over a period.
- characteristic_id → spc_characteristic req
- period_start ts req
- period_end ts req
- n int req
- mean num
- sigma_within num
- sigma_overall num
- cp num
- cpk num
- pp num
- ppk num
- distribution text
- normality_p num
- expected_ppm num
- stable bool

### spc_msa_study
Measurement system analysis.
- study_no text req, unique
- gauge_equipment_id → core_equipment req
- characteristic_id → spc_characteristic
- study_type text req: grr_crossed, grr_nested, bias, linearity, stability, attribute_agreement
- method text req: anova, average_range, kappa, other
- operators int
- parts int
- trials int
- data json
- pct_grr num
- ndc int
- result text: acceptable, marginal, unacceptable
- performed_at date

### spc_fai_report
AS9102 first-article inspection report.
- fai_no text req, unique
- item_id → core_item req
- part_revision text
- serial_no text
- form1 json
- form2 json
- form3 json req
- status text req: draft, complete, approved, rejected
- approved_signature_id → core_e_signature

Then write ONE migration (npx supabase migration new spc_tables) that creates all thirteen tables exactly as listed, and:
- codes and numbers unique per site; spc_characteristic also points at our characteristics table as docs/spine-map.md says, with lsl below usl and a trigger keeping lsl and usl equal to that row's limits;
- the trigger that copies each new inspections row once into spc_measurement (source form, ext.inspection_id);
- subgroup_size, n and sample_size above 0; one subgroup seq per chart;
- a trigger refusing any change to ucl, cl, lcl, ucl_r, lcl_r, limits_basis, limits_set_at, limits_set_by except together with a new limits_approval_signature_id by someone other than the proposer;
- a trigger refusing a violation status of acknowledged or closed without assignable_cause_code_id and corrective_action, and a close by the person who acknowledged it;
- measurements and violations append-only apart from the response columns; row-level security on every table with no policies; touch-row and audit triggers; each table in docs/matrix.json with no rights yet.

pgTAP tests in supabase/tests/spc.test.sql proving the database refuses: lsl above usl, an unknown chart_type, a change to ucl without an approval signature, closing a violation with no cause code, and a close by the acknowledger. Show me each failing before its rule exists and passing after.

Do not connect to any Supabase project. Push, open a pull request titled "SPC tables", wait for every check, and tell me the result in plain words.

You will see recreated screen

claude — acme-platform
⏺ Edit(docs/spine-map.md)
⎿ Added the section M09 SPC and inspection tables, 176 lines
1
⏺ Write(supabase/migrations/20261103121500_spc_tables.sql)
+create trigger spc_limits_need_approval before update of ucl, cl, lcl, ucl_r, lcl_r
+ on public.spc_chart for each row execute function public.spc_refuse_unapproved_limits();
+create trigger spc_violation_needs_response before update of status
+ on public.spc_violation for each row execute function public.spc_require_coded_response();
2
⏺ Bash(npx supabase test db)
⎿ spc.test.sql .. 5 of 5 failed (rules removed on purpose) spc.test.sql .. ok (rules restored)
⏺ Pull request #93 is green. Thirteen tables; limits change only with an approval by another person; a violation cannot be acknowledged or closed without a cause code and a corrective action.
The reference file, the migration from it, and each governance rule proven by breaking it.
  1. The column list now lives in the one shared map, in its own section.
  2. The specification's compliance note, written as two triggers: limits are controlled, responses are coded.

Check it worked

Pull request SPC tables is green; you saw the five tests red then green; no older migration is edited.

Fastest path

Asking for red-then-green in the prompt saves the round trip where you discover a test that could never fail.

If it goes wrong

A screen fails later with "column does not exist"

Say: Rebuild the local database from supabase/migrations only, run supabase db diff, and write any difference as a new migration. We merged ten columns without a migration once; the fresh-database check catches it.

The check went green after a test or CI file changed

Say: Undo every change to tests and CI. Never weaken a check to get to green; stop and explain. On our platform an agent that was refused one command used another to do the same thing.

A soft link was made a real foreign key, and the migration fails

Say: Make operation_ref, operation_run_ref, fmea_ref, quality_event_ref and escalated_event_ref plain uuid columns with a comment; the other modules may not be installed.

36 readings on an individuals chartThirty-six synthetic readings with centre line 10.00 and limits 9.70 and 10.30, drawn to scale. Point 13 is 10.34, beyond the upper limit (Nelson rule 1). Points 21 to 29 are nine in a row above the centre line (Nelson rule 2). No other rule fires. UCL 10.30+2 sigma+1 sigmaCL 10.00-1 sigma-2 sigmaLCL 9.70Rule 1: point 13 beyond the upper limitRule 2: nine in a row above the centre line, signal at point 2915101520253035
The 36 reference readings on an individuals chart. Centre 10.00, limits 9.70 and 10.30, one sigma 0.10. Point 13 is beyond the upper limit (rule 1); points 21 to 29 are nine in a row above the centre (rule 2). Nothing else fires. Made up for the lab.
The 36 synthetic reference readings, in order, 12 to a line (they add up to 360.65)
10.03 9.88 10.06 10.12 9.95 9.91 10.05 9.86 10.08 9.97 10.13 9.92
10.34 10.08 9.98 9.89 10.07 10.01 10.02 9.90 10.05 10.09 10.03 10.14
10.02 10.06 10.01 10.11 10.04 9.96 9.87 10.10 9.93 9.99 10.08 9.92
Step 4

Session 2: A small made-up seed with the reference readings, on the development project

20 minutes

Why

Session 4's rules engine is tested against an answer you can find with a ruler: rule 1 at point 13, rule 2 at point 29. Keeping those readings as a test fixture, and loading the same readings as made-up, marked seed rows shifted onto today, means every later step has a known answer. Pushing to the development project yourself proves the migrations and seed work on a real project before the deploy pipeline applies the migrations to production on merge.

Do this

Paste into Claude Code
On the branch spc/tables, write supabase/seeds/spc.sql and list it under [db.seed] sql_paths in supabase/config.toml, after the Foundation seed. Never append to supabase/seed.sql, and never seed production. Every row is made up and marked SYNTHETIC: codes start SYN-, names start "SYNTHETIC · ". Times are shifted onto today, relative to one clock reading at seed time; safe to run twice (a second run leaves the same rows).

One part SYN-4410 with characteristic SYN-FLANGE-H (variable, mm, nominal 10.00, specification 9.60 to 10.40, special_class sc), joined to a SYNTHETIC characteristics row as docs/spine-map.md says. One press SYN-P-03 and one gauge SYN-G-07. An approved control plan with one line (sample 1, every hour, reaction plan "stop, contain, call quality"). One I-MR chart with all eight Nelson rules on, limits_basis standard, cl 10.00, ucl 10.30, lcl 9.70, approved by the quality approver. The 36 readings below as 36 subgroups of one, one hour apart, ending one hour before seed time; no violations yet (Session 4 evaluates them). One person per role: operator, inspector, quality engineer, quality approver, supervisor, manager. Three assignable cause codes (SYN-TOOL-WEAR, SYN-MATERIAL, SYN-SETUP).

Readings:
10.03 9.88 10.06 10.12 9.95 9.91 10.05 9.86 10.08 9.97 10.13 9.92
10.34 10.08 9.98 9.89 10.07 10.01 10.02 9.90 10.05 10.09 10.03 10.14
10.02 10.06 10.01 10.11 10.04 9.96 9.87 10.10 9.93 9.99 10.08 9.92

Also write the same 36 readings, with fixed times on a fixed day, centre 10.00, sigma 0.10 and the expected signals (rule 1 at point 13, rule 2 at point 29, nothing else), to tests/fixtures/spc-reference.json; the rules and capability tests read that fixture, never the seed rows. Add a test that runs the seed twice on an empty database, checks the 36 readings add up to 360.65, and checks the counts above. Push to the same pull request and wait for the checks.

When it is green, push to the development project yourself, in a terminal (not inside Claude Code), with the password from Supabase: acme-platform-dev database password:

Terminal or PowerShell
cd ~/code/acme-platform && git fetch && git switch spc/tables && npx supabase link --project-ref tsrqponmlkjihgfedcba
Terminal or PowerShell
npx supabase db push --include-seed
Open

https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/editor

The development project's Table Editor: open spc_measurement.

That is the first load. After it, reload the made-up rows with npm run seed:dev, never with supabase db reset. Then owner two approves and you merge; the deploy workflow applies the migrations (never the seed) to production.

You will see recreated screen

supabase.com/dashboard/project/tsrqponmlkjihgfedcba/editor
spc_chartspc_characteristicspc_measurementspc_violation
spc_measurement
1
characteristicvaluesourcemeasured_at
SYN-FLANGE-H10.03manual36 h ago
SYN-FLANGE-H10.34manual24 h ago
SYN-FLANGE-H9.92manual1 h ago
The reference readings in the development project, marked as made up.
  1. Point 13, 10.34, is here; nothing has flagged it yet.
  2. Correct for now: the rules engine does not exist until Session 4.

Check it worked

acme-platform-dev shows 36 SYN-FLANGE-H readings and one approved chart; the pull request is merged; the deploy run on main is green.

If it goes wrong

A week later the chart's "last 24 hours" view is empty

The seed used fixed dates. Say: Make every seeded time relative to one clock reading at seed time; fixed-date examples belong in tests/fixtures/spc-reference.json. Then reload with npm run seed:dev. We hit this: eleven days after seeding, every recent-hours panel was blank.

The readings add up to something other than 360.65

One was typed wrong. Say: Compare the seed's readings and tests/fixtures/spc-reference.json with the list in the M09 section of docs/spine-map.md one by one. Fix the seed, not the check.

Claude Code offers to run db push for you

Refuse; the deny rule from Session 1 stops it anyway. You run it, on the development project.

Someone suggests supabase db reset --linked to start again

Do not. To start the made-up rows again on the development project, run npm run seed:dev.

Knowledge check

Your old tool's help page says its Cpk uses the overall standard deviation. What is that number really?

Knowledge check

Your Foundation already has a characteristics table with each part's limits. What does the module do?

References

  1. Advantive: SPC tools and ProFicient. https://www.advantive.com/?p=1379
  2. Advantive: ProFicient by InfinityQS. https://www.advantive.com/brands/infinity-qs/
  3. SAE International: AS9102C, Aerospace First Article Inspection Requirement. https://www.sae.org/standards/content/as9102c/
  4. NIST/SEMATECH e-Handbook of Statistical Methods: What are control charts?. https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc31.htm
  5. Supabase Docs: Testing your database. https://supabase.com/docs/guides/database/testing

Chapter 2 · Session 3

Who may measure, react and approve limits, and their screens

Control limits are part of the controlled process, and every signal needs an answer, so who may do what is the heart of the module. You write six roles and three rules for two people into the role matrix, generate the access rules from it, prove every refusal, and build the screens: capture at the press, the chart, the signal answer and the limits approval.

20 min2 steps6 roles, 3 two-person rules

By the end of this chapter you can

  • Add the module's roles, scopes, rights and two-person rules to docs/matrix.json and regenerate the access rules and route list.
  • Prove that nobody approves limits they proposed and nobody closes a signal they answered.
  • Build the operator's capture screen with limits feedback, the live chart, the violation answer and the limits approval.
Who may do whatA grid of six roles by six actions. Operator and inspector measure and acknowledge. Quality engineer acknowledges, closes, proposes limits and reads the board. Quality approver approves limits and reads the board. Supervisor acknowledges, closes and reads the board. Manager only reads the board. MeasureAcknowledgeClosePropose limitsApprove limitsRead boardOperatorYesYesInspectorYesYesQuality engineerYesYesYesYesQuality approverYesYesSupervisorYesYesYesManagerYesA person never closes what they acknowledged, and never approves limits they proposed.
Who may do what. Operators and inspectors measure and answer; the quality engineer proposes limits and owns the studies; a different person, the quality approver, approves; supervisors answer and close in their area; managers only read.
Two-person ruleWhy
Whoever proposed new limits may not approve themLimits are part of the controlled process; one person must not move the goalposts alone
Whoever acknowledged a violation may not close itA second person checks the cause and the action really fit the signal
An inspector may not approve their own first article reportAS9102 evidence is signed by someone independent
Step 5

Session 3: The roles in the matrix, rules generated, refusals proven

30 minutes

Why

Rights written by hand drift; rights generated from docs/matrix.json keep the database, the routes and the menus in step. The two-person rules are this module's controls, so each must be proven by a test that tries to break it and is refused.

Do this

Paste into Claude Code
Read docs/matrix.json, scripts/gen-policies.mjs, scripts/gen-routes.mjs, lib/access/routes.ts and docs/spine-map.md with its M09 section. Before writing any route code, read the relevant guide in node_modules/next/dist/docs/ (this Next.js version keeps request middleware in proxy.ts).

On a new branch spc/access, add to docs/matrix.json:
1. Roles operator, inspector, quality_engineer, quality_approver, supervisor, manager; machine accounts spc_importer and spc_gauge (gauge and tag feeds). In a separate migration create both as database logins with NOLOGIN, no BYPASSRLS, owning nothing; I set their passwords myself on each project, and you list them by name (never a value) in docs/KEYS.md.
2. Scopes: operator and supervisor by area; inspector, quality_engineer, quality_approver and manager by site.
3. Rights from nothing: operator and inspector insert measurements and read the charts of their area or site, acknowledge violations with a cause code and action; inspector also runs inspection lots and drafts first article reports; quality_engineer owns characteristics, control plans, charts (proposing limits), sampling and inspection plans, studies; quality_approver approves limits, control plans and first article reports with a signature; supervisor acknowledges and closes violations in their area and escalates; manager reads only. spc_importer only inserts characteristics, charts and imported measurements (source import), and never reads, updates or deletes; spc_gauge inserts measurements (source gauge or tag) only. Nobody gets delete.
4. The three two-person rules as rules on the cells.
5. Screens and routes: /spc/capture (operator, inspector), /spc/charts (all roles, read), /spc/violations (operator, inspector, supervisor, quality_engineer), /spc/limits (quality_engineer proposes, quality_approver approves), /spc/inspection (inspector), /spc/studies (quality_engineer), /spc/board (manager, quality_engineer), /api/spc/measurements, /api/spc/violations, /api/spc/limits/approve (quality_approver only). No import page or route: real records arrive only through the import workflow in Session 6.

Run node scripts/gen-policies.mjs and node scripts/gen-routes.mjs (it writes lib/access/routes.ts). Write docs/spc-rights-walk.md listing every right Sessions 4 to 6 need, with a test that fails if any is not allowed. Add to supabase/tests/access.test.sql: one allowed and one refused per role and table; each two-person rule refused; a supervisor of another area cannot answer this area's violation; the manager cannot write anything; for every permitted update the row really changed; a signed-out request to every new screen and route is refused.

Push, open a pull request titled "SPC access", wait for every check, and tell me the result in plain words. If a check fails, fix the matrix or the code, never the test.

You will see recreated screen

claude — acme-platform
⏺ Write(docs/matrix.json)
+"quality_approver": { "scope": "site", "spc_chart": { "update": ["ucl", "cl", "lcl", "limits_approval_signature_id"] },
+ "rules": ["not_proposer"] },
1
⏺ Bash(npx supabase test db)
⎿ access.test.sql .. 212 tests, ok ok approver who proposed the limits is refused ok acknowledger cannot close their own violation
2
⏺ Pull request #94 is green. All three two-person rules are refused when one person tries both halves. I changed no test.
The matrix is the file you decide; every two-person rule has a test that tries to break it.
  1. The approver touches only the limits and the signature, never limits they proposed.
  2. Each control proven by a refusal.

Check it worked

Pull request SPC access is green, docs/spc-rights-walk.md passes, and each two-person rule has a refused test.

If it goes wrong

Acknowledge reports success but the violation stays open

The role's read rule does not cover the row after the change, so the update finds nothing. Say: Make each role's read rule cover violations before and after the change, and test that the row really changed. We hit this in three of our modules.

A signed-in manager can approve limits

Signed in is not allowed. Say: Add a refused-role test for every role on /api/spc/limits/approve. On our platform any signed-in user could delete a whole site.

Step 6

Session 3: Capture at the press, the live chart, the answer and the approval

45 minutes

Why

Readings are only as good as the moment they are taken: an operator typing at the press needs to see at once whether a value is in specification and whether it made a signal. The chart, the answer to a signal and the limits approval are where the module's controls become visible. Building them against the seed lets an operator and the quality engineer try them before the rules engine is wired behind them.

Do this

Paste into Claude Code
Read the operator, supervisor and manager screens from Foundation Sessions 12, 13 and 15, and follow their layout, offline handling and tests. Read node_modules/next/dist/docs/ before adding routes; check proxy.ts still denies every route not in lib/access/routes.ts.

On a new branch spc/screens, against the seed on the development project:
1. /spc/capture (operator, phone first): pick part, characteristic and gauge; type the value with the characteristic's decimals; see at once in or out of specification; queued with no signal and sent once (a row id made on the phone); measured_by from the session on the server, never from the page.
2. /spc/charts: the chart with centre line and limits, zones at 1 and 2 sigma, specification limits drawn differently from control limits, and open violations marked. A chart with no approved limits says "Collecting: no approved limits", and never draws invented ones.
3. /spc/violations: open signals with rule, time and point; Acknowledge needs a cause code from the list and a corrective action; Close is offered only to someone other than the acknowledger.
4. /spc/limits: the quality engineer proposes limits with their basis and period; the quality approver sees the proposal beside the current limits and signs with their password typed again.

44 px targets, 16 px fields, 15 px text, no sideways scroll at 360 and 390 px. Screen tests for each role, a refused role per screen. Push, open a pull request titled "SPC screens", wait for every check including the preview, and give me the preview address and demo logins.
Open

https://github.com/acme-ops/acme-platform/pulls

Open the pull request and its Vercel preview; try capture on your phone.

You will see recreated screen

acme-platform-git-spc-screens-acme-ops.vercel.app/spc/capture
SYN-4410 · Flange height (mm)
GaugeSYN-G-07 ▾
Value10.361
Save reading
Capture at the press: the operator sees the answer before they put the gauge down.
  1. Typed with the characteristic's decimals.
  2. Two different questions: the part is good, but the process has signalled.

You will see recreated screen

acme-platform-git-spc-screens-acme-ops.vercel.app/spc/charts/SYN-FLANGE-H
SYN-FLANGE-H · I-MR · limits approved (standard)
UCL / CL / LCL10.30 / 10.00 / 9.70
The chart before Session 4: no rules evaluated yet, and it says so.
  1. Honest about what it does not yet do: no made-up "In control".

Check it worked

The preview opens on your phone; a reading taken in flight mode arrives once; specification and control limits look different on the chart; an operator sent to /spc/limits is refused.

If it goes wrong

The chart says "In control" before the rules engine exists

Say: Remove every status the code does not compute from stored readings; show Not evaluated instead. On our platform 87 screens graded a hard-coded twelve-point array and called it In control.

Every reading shows the same operator

The page sent the person and the server trusted it. Say: Take measured_by from the signed-in session on the server. We hit this: every record said it was created by the founder.

A link from the chart opens a blank 404

Say: Start the build, sign in as each role, visit every page and link on the four screens, and report every 404. We once had 130 links pointing nowhere.

Knowledge check

The quality engineer proposed new limits. Who may approve them?

Knowledge check

A reading of 10.36 has specification 9.60 to 10.40 and control limits 9.70 to 10.30. What is true?

References

  1. Supabase Docs: Row Level Security. https://supabase.com/docs/guides/database/postgres/row-level-security
  2. eCFR: 21 CFR Part 11, Electronic records and electronic signatures. https://www.ecfr.gov/current/title-21/chapter-I/subchapter-A/part-11
  3. W3C: Web Content Accessibility Guidelines (WCAG) 2.2. https://www.w3.org/TR/WCAG22/

Chapter 3 · Session 4

The chart and its required reaction, end to end

A reading arrives, the chart updates, every run rule is evaluated on every point, a signal opens a violation that cannot close without a coded answer, and limits never move by themselves. Then capability computed correctly, a gauge study, and a receiving inspection. Three tests are the module's definition of done.

30 min3 stepsThe three checks that define done

By the end of this chapter you can

  • Have Claude Code build a rules engine that reproduces the reference readings exactly: rule 1 at point 13, rule 2 at point 29.
  • Make every violation need a coded response before closing, and keep limits fixed until an approved change.
  • Compute Cp, Cpk, Pp and Ppk and match a second calculation to three decimals; run a gage R&R and a receiving inspection.
Choosing a control chartThree starting points. A measured number: individuals and moving range for one reading at a time, X-bar and R for small subgroups, X-bar and S for larger ones. Units counted pass or fail: np for a constant sample size, p when it varies. Flaws counted on a unit: c for the same area, u when it varies. EWMA and CUSUM catch small steady drifts. What do you have?A measured numberOne reading at a timeI-MRSmall subgroupsX-bar RLarger subgroupsX-bar SUnits: pass or failSample size constantnp chartSample size variesp chartFlaws on a unitSame area or countc chartArea or count variesu chartSmall, steady drifts: add EWMA or CUSUM on the same data.
Choosing a chart. Measured numbers: I-MR, X-bar R or X-bar S by subgroup size. Counted: p or np for defective units, c or u for flaws.
Nelson ruleThe patternUsually means
1One point more than 3 sigma from the centreA sudden change or an outlier
2Nine in a row on one side of the centreA shift of the average
3Six in a row steadily rising or fallingA trend, such as tool wear
4Fourteen in a row alternating up and downTwo alternating causes
5Two of three more than 2 sigma out, same sideA shift beginning
6Four of five more than 1 sigma out, same sideA smaller shift
7Fifteen in a row within 1 sigmaToo little variation: mixed streams
8Eight in a row more than 1 sigma out, either sideTwo streams, or overcontrol

The rules come from the Western Electric handbook (1956) and Nelson (1984) [1][2]. On a p or u chart the limits move with each sample size, so rules written for fixed zones do not carry over unchanged: decide which apply to each counted chart and write the reason down.

Step 7

Session 4: Capture, chart and a rules engine that reproduces the reference readings

35 minutes

Why

A rules engine that is nearly right is worse than none, because people trust it. Testing it against readings you have checked with a ruler, and the chart constants against your copy of the manual read by a second person, is the first check that defines done. Evaluating the rules in the same transaction as the reading means a point and its signal always exist together.

Do this

Type the X-bar R and I-MR constants (A2, D3, D4, d2 for n = 2 to 10) from your copy of the AIAG SPC manual or ISO 7870-2 into docs/spc-constants.csv, and ask a second person to check every value against the printed table. On paper, with a ruler: rule 1 fires at point 13, rule 2 at point 29, and nothing else.

Paste into Claude Code
Read the M09 section of docs/spine-map.md, docs/spc-constants.csv and tests/fixtures/spc-reference.json. On a new branch spc/rules:

1. lib/spc/rules.ts: one pure function that takes the points, the centre line, sigma and the rules switched on, and returns every rule that fires with the point number. All eight Nelson rules. Chart statistics (subgroup mean, range, moving range) and limits computed with the constants from docs/spc-constants.csv, which you must not edit.
2. /api/spc/measurements: inserts the reading, updates its subgroup, evaluates the chart's rules, and inserts any spc_violation with rule code and detected_at, all in one transaction. A chart without approved limits stores the reading and evaluates nothing. Write spc.violation.detected to the outbox.
3. Tests: on the 36 readings in tests/fixtures/spc-reference.json with centre 10.00 and sigma 0.10, the engine returns exactly rule 1 at point 13 and rule 2 at point 29 and nothing else; one hand-made case for each of rules 3 to 8 that fires exactly that rule; the constants file gives the limits of a small X-bar R example worked by hand in the test.

Show me the reference test failing with rule 2 switched off, then passing. Push, open a pull request titled "SPC rules engine", wait for every check, and tell me the result in plain words.

You will see recreated screen

claude — acme-platform
⏺ Bash(npx vitest run tests/spc/rules.test.ts)
⎿ ✓ reference readings: rule 1 at point 13, rule 2 at point 29, nothing else ✓ rules 3-8: each hand-made case fires exactly its rule ✓ X-bar R limits from docs/spc-constants.csv match the worked example
1
⏺ Bash(gh pr checks --watch)
⎿ ci / test pass 1m48s schema / test pass 2m35s
⏺ Pull request #95 is green. With rule 2 switched off, the reference test failed at point 29; switched on, it finds exactly the two signals you found on paper. Replaying the seed opened two violations on the development chart.
The first check that defines done: the engine finds exactly what your ruler found.
  1. Exactly the two signals, and nothing else: a rule that fires too often is as wrong as one that never fires.

Check it worked

Pull request SPC rules engine is green, the reference test was shown red then green, and the development chart shows two open violations.

If it goes wrong

Rule 2 fires at point 28 or 30 instead of 29

Count again on paper: points 21 to 29 are the nine above 10.00. Then say: Rule 2 must fire at the ninth point of the run, point 29; show me how the engine counts the run. Fix the engine, never the test.

Claude Code edits docs/spc-constants.csv to make a test pass

Say: Restore the constants file. If a test fails, show me which value disagrees with the worked example. Never loosen a check to get to green.

A test was green from the start

Say: Switch the rule off and show me the test fails, then restore it. Our page-presence check reported 350 present and 0 absent for weeks because it could only ever say yes.

One violation from signal to closeA point breaks a run rule and an open violation is made. It becomes acknowledged once an assignable cause code and a corrective action are recorded. A different person closes it. A serious one can be escalated to an action item or an NCR in M08. A point breaksa run ruleopendetected_at setacknowledgedcause and actionclosedby someone elseNeeds a cause codeand a corrective actionA different personcloses itEscalate if neededaction item, or NCR in M08Signal response time = minutes from detected_at to acknowledged_at.
One violation from signal to close. Acknowledged with a cause code and an action; closed by someone else; escalated to an NCR in M08 when it needs a hold.
Step 8

Session 4: The required reaction, and limits that never move by themselves

30 minutes

Why

A signal nobody answers is just a red dot. Requiring a coded cause and an action before a violation can close, checked by a second person, is the second check that defines done and what an auditor will ask for. Limits that recalculate with every point drift with the process and hide the shift they exist to catch, so they change only by an approved proposal.

Do this

Paste into Claude Code
On a new branch spc/reaction:
1. /api/spc/violations: acknowledge (cause code from the list and corrective action, both required), close (someone other than the acknowledger), escalate (a supervisor creates an action item linking back; if a qms_quality_event table exists, store its id in escalated_event_ref, otherwise leave it empty). Write spc.violation.closed to the outbox.
2. Limits: the quality engineer proposes new limits computed from a stated stable period (basis historical) or a standard; the quality approver signs with their password typed again (a core_e_signature row, meaning approved); only then do ucl, cl and lcl change, with limits_set_at and limits_set_by.
3. Tests: closing with no cause code is refused; closing by the acknowledger is refused; a query for closed violations with no cause code returns no rows; replaying 100 new readings leaves ucl, cl and lcl exactly where they were; a limits change without a signature is refused; the signal response time (median minutes from detected_at to acknowledged_at) is computed from the rows.

Show each test failing before its rule and passing after. Push, open a pull request titled "SPC reaction and limits", wait for every check, and tell me the result in plain words.

Then on the preview: answer one of the two seeded violations as the operator, and close it as the supervisor.

You will see recreated screen

acme-platform-git-spc-reaction-acme-ops.vercel.app/spc/violations
Rule 2 · nine in a row above centre · point 29
Assignable causeSYN-TOOL-WEAR ▾1
Corrective actionDie D-112 reground; first piece re-measured 10.01
Acknowledge
Answering a signal on the preview: no cause code, no acknowledgement.
  1. Chosen from the list, never typed: causes can be counted.
  2. The two-person rule, shown in plain words.

Check it worked

Pull request SPC reaction and limits is green; on the preview, one violation is acknowledged by one person and closed by another; the 100-point replay test leaves the limits unchanged.

If it goes wrong

Acknowledge shows success but the violation is still open

Say: After saving, read the violation back from the database; if the status did not change, show an error. On our platform a button reported success while nothing had happened.

Claude Code proposes recalculating limits automatically "to stay current"

Refuse. That is the second pitfall. Limits change only by an approved proposal.

Two people answer the same signal at once and one answer disappears

Say: Include updated_at in the update's where clause so a stale save is refused, and test two saves from the same copy. We lost records this way before we added that check.

Cp and Cpk on a bell curveTwo normal curves with sigma 0.10 between a lower specification limit of 9.70 and an upper limit of 10.30, drawn to scale. Centred on 10.00, Cp and Cpk are both 1.00. Shifted to a mean of 10.05, Cp stays 1.00 and Cpk falls to 0.83. LSL 9.70USL 10.309.609.709.809.9010.0010.1010.2010.3010.40Centred, mean 10.00: Cp 1.00, Cpk 1.00Shifted, mean 10.05: Cp 1.00, Cpk 0.83Both curves: sigma 0.10, so six sigma fills the whole 0.60 specification width.
Cp and Cpk. Sigma 0.10, specification 9.70 to 10.30 (made up for the arithmetic). Centred: both 1.00. Mean at 10.05: Cp 1.00, Cpk 0.83.
IndexFormulaSigma
Cp(usl − lsl) ÷ (6 × sigma within)Within subgroups
Cpkthe smaller of (usl − mean) and (mean − lsl), ÷ (3 × sigma within)Within subgroups
Pp(usl − lsl) ÷ (6 × sigma overall)Overall
Ppkthe smaller of (usl − mean) and (mean − lsl), ÷ (3 × sigma overall)Overall
Reading a gage R&R resultA scale from 0 to 40 percent drawn to scale: under 10 percent is acceptable, 10 to 30 percent is marginal, over 30 percent is not acceptable. A gauge at 12 percent falls in the marginal band. Under 10%10% to 30%: marginalOver 30%0%10%20%30%40%acceptablenot acceptableA gauge at 12% is marginal%GRR is the share of the variation that belongs to the gauge and its operators.ndc, the number of distinct categories the gauge tells apart, should be at least 5.
Reading a gage R&R. Under 10% acceptable, 10% to 30% marginal, over 30% not acceptable; ndc at least 5.
Step 9

Session 4: Capability done right, a gauge study and a receiving inspection

35 minutes

Why

Customers read capability reports, so Cpk computed with the wrong sigma, or reported for an unstable process without a flag, is a broken promise in writing. Matching a second calculation to three decimals is the third check that defines done. A gauge study first tells you whether the readings can be trusted at all, and a receiving inspection shows the same tables deciding about a lot.

Do this

Ask a second person to compute Cp, Cpk, Pp and Ppk for the 36 readings (specification 9.60 to 10.40, sigma within from the average moving range ÷ d2 for n = 2) in a spreadsheet or the free R language, and save the four numbers to three decimals in docs/spc-capability-check.csv. Type the Z1.4 rows your receiving inspection uses from your copy of the standard into docs/z14.csv.

Paste into Claude Code
On a new branch spc/capability:
1. A capability study for a characteristic over a period: n, mean, sigma_within and sigma_overall in separate columns, Cp, Cpk, Pp, Ppk, a normality test result, expected ppm. stable is true only if the rules engine found no signal in the period; otherwise the screen shows "Unstable: capability is indicative only". Below the target in ext (1.33, or 1.67 for special characteristics) writes spc.capability.below_target.
2. Tests: on the 36 readings in tests/fixtures/spc-reference.json, the four indices match docs/spc-capability-check.csv to 3 decimals (you must not edit that file); the study is marked stable false, because the period has two signals; Cpk is never computed from sigma_overall.
3. A crossed gage R&R by ANOVA (10 parts, 3 operators, 3 trials) storing pct_grr, ndc and result (under 10 acceptable, 10 to 30 marginal, over 30 unacceptable), tested on a made-up study with a hand-checked answer.
4. A receiving inspection lot: the plan picks the scheme; for z14_aql the sample size and accept number come from docs/z14.csv only; the decision accept, reject or conditional; a reject writes spc.inspection_lot.rejected.

Push, open a pull request titled "SPC capability, MSA, inspection", wait for every check, and tell me the result in plain words.

You will see recreated screen

claude — acme-platform
⏺ Bash(npx vitest run tests/spc/capability.test.ts)
⎿ ✓ Cp Cpk Pp Ppk match docs/spc-capability-check.csv to 3 decimals ✓ stable = false: 2 signals in period ✓ cpk uses sigma_within only
1
⏺ Bash(npx vitest run tests/spc/msa.test.ts tests/spc/inspection.test.ts)
⎿ ✓ gage R&R: pct_grr 12.4, ndc 6, marginal ✓ z14 sample and accept number read from docs/z14.csv
⏺ Pull request #96 is green. The capability study for the reference readings is saved as unstable, with a flag on the screen, because the period has two signals: the numbers are shown, labelled indicative.2
The third check that defines done: two independent calculations agree to three decimals.
  1. Your colleague's spreadsheet and the module agree; the old tool's figure will match Pp or Ppk if it used overall sigma.
  2. Stable first: capability on an unstable period is shown, but flagged.

Check it worked

Pull request SPC capability, MSA, inspection is green, and the reference study shows four indices matching the second calculation, marked unstable.

If it goes wrong

Cpk and Ppk come out identical

Sigma within was not used. Say: Show me sigma_within and sigma_overall and how each is computed; Cpk must use sigma within. That mix-up is the first pitfall.

A capability number appears on the board with no stable flag

Say: Show the stable flag beside every capability figure, and Unstable when it is false. A figure without its condition is a number nobody measured.

You do not have Z1.4 or the AIAG manuals

Do the rest of the step now and the table-driven parts when the copies arrive. Never type a table from memory or an unofficial copy.

Knowledge check

Why must replaying 100 new readings leave ucl, cl and lcl exactly where they were?

Knowledge check

What must be recorded before a violation can be acknowledged?

References

  1. NIST/SEMATECH e-Handbook: Process or product monitoring and control. https://www.itl.nist.gov/div898/handbook/pmc/pmc.htm
  2. ASQ: Control chart. https://asq.org/quality-resources/control-chart
  3. NIST/SEMATECH e-Handbook: Measurement process characterization. https://www.itl.nist.gov/div898/handbook/mpc/mpc.htm
  4. The R Project for Statistical Computing. https://www.r-project.org/

Chapter 4 · Sessions 5 and 6

Move the history, and switch the old tool off

Characteristics, specification limits and measurement history come from the old tool's export. The import is proven on made-up data and rehearsed on the development project with a copy IT has approved, where limits and capability are recomputed and compared with the old tool's own figures. Then it runs into production through the pipeline, both tools run side by side, and the old one is switched off.

30 min5 stepsEnds with the module gate

By the end of this chapter you can

  • Build an import that is safe to run twice and replays history through the rules engine in report-only mode.
  • Rehearse on the development project with a copy IT approved in writing, explain every difference from the old tool's limits and capability, and remove the rehearsal the same day.
  • Import into production through import-spc.yml, started by a person from main for an approved export, run a week side by side, cut over and record the saving.

Imported history is replayed through the rules engine in report-only mode: last year's signals appear in a report, never as open violations that page the floor today. Limits and capability are then recomputed from the history and compared with the old tool's own figures; that comparison is the validation, and every difference must have a reason (most often, the old tool's Cpk used overall sigma).

Key or secretWhat it unlocksWhere it livesWho holds itNever
spc_importer password (development)Signing in as the insert-only import login on acme-platform-dev; listed by name in docs/KEYS.mdPassword manager; GitHub secret SPC_IMPORTER_PASSWORD_DEVpat@acme.com, sam@acme.comNever in a file, a chat or Claude Code
spc_importer password (production)Signing in as the insert-only import login on acme-platform-prod, until it is set to NOLOGIN at cut-over; listed by name in docs/KEYS.mdPassword manager; GitHub secret SPC_IMPORTER_PASSWORD_PRODpat@acme.com, sam@acme.comNever on a laptop outside the password manager
The old SPC exportCharacteristics, limits and every historical reading, with operator namesA private folder, then the private Storage bucket imports; its sha256 and counts in docs/imports/spc-approved.mdThe quality engineerNever in the repository, a test, or a chat
Step 10

Session 5: The import, built and tested on a made-up export

35 minutes

Why

History is what lets you recompute limits and capability and check them against the old tool: the validation that proves the module computes correctly. An import that runs twice without duplicating, writes nothing in a dry run, refuses a file nobody approved, and replays history without paging the floor, means the real readings only ever meet code that has been reviewed and proven.

Do this

First, with the quality engineer, write docs/spc-import-map.md: the export's counts (characteristics, charts, readings per characteristic, oldest and newest dates), how old chart types, rules and cause codes map to the module's, and the old tool's own limits and Cpk for the characteristics in the first slice.

Paste into Claude Code
Read docs/spc-import-map.md, the M09 section of docs/spine-map.md and docs/matrix.json. On a new branch spc/import:

1. scripts/import/spc-import.mjs: reads one export file (a zip), connects as the database login spc_importer with the password from the environment variable SPC_IMPORTER_PASSWORD (never printed), and inserts characteristics (joined to our characteristics table as docs/spine-map.md says; a part or characteristic not in the spine stops the import with a list), charts with the old limits (limits_basis manual, the old values kept in ext.legacy_limits), and readings with source import and their original times. It only inserts: existing rows (same code; same characteristic, time and value) are skipped with on conflict do nothing, so a second run adds nothing. Every row carries ext.import_run.
2. Report-only replay: imported readings are run through the rules engine and the signals written to the run's report, never as spc_violation rows.
3. A comparison report per characteristic: limits and Cp, Cpk, Pp, Ppk recomputed from the history beside the old tool's figures from docs/spc-import-map.md.
4. --dry-run changes nothing. supabase/snippets/spc-remove-run.sql, for the development project only, deletes only the rows whose ext.import_run is the run id I type in; I paste it into that project's SQL editor myself.
5. tests/import/ on a made-up export (SYN- names): dry run changes nothing; counts match; second run adds nothing; replay opens no violation; an export whose sha256 is not approved is refused; a count that differs from the approved counts fails the run; the removal snippet removes only its own run.
6. .github/workflows/import-spc.yml: started by hand only (workflow_dispatch) and refusing to run from any branch but main; inputs target (development or production) and dry_run. It downloads the export from the private Storage bucket imports of the target and computes its sha256; it refuses unless that sha256 and the expected counts (characteristics, charts, readings) are recorded for that target in docs/imports/spc-approved.md on main; it runs with SPC_IMPORTER_PASSWORD_DEV or SPC_IMPORTER_PASSWORD_PROD; it fails on any count mismatch (the export must equal the approved counts, and imported plus skipped must equal the export); it uploads both reports as artifacts. No GitHub environment with required reviewers. Never print a secret.

Push, open a pull request titled "SPC import", wait for every check, and tell me the result in plain words. Do not run the workflow.

You will see recreated screen

claude — acme-platform
⏺ Bash(npx vitest run tests/import)
⎿ ✓ dry run changes nothing ✓ counts match ✓ second run adds 0 rows ✓ replay: 14 signals in report, 0 violations opened ✓ unapproved sha256 refused ✓ count mismatch fails the run
1
⏺ Pull request #97 is green. The workflow is manual only, runs only from main, and I did not run it. It refuses any export whose sha256 and counts are not in docs/imports/spc-approved.md on main. It needs SPC_IMPORTER_PASSWORD_DEV and SPC_IMPORTER_PASSWORD_PROD, typed by you on GitHub.
The import proven on made-up data; the history never pages the floor.
  1. Last year's signals go into a report, not onto today's violation list.

Check it worked

Pull request SPC import is green and merged; the workflow's only trigger is workflow_dispatch, it refuses any branch but main, and it reads the approved sha256 and counts from docs/imports/spc-approved.md.

If it goes wrong

Claude Code wants a sample of the real export in tests/

Refuse. Real readings never go into the repository; fixtures are made up and marked SYN-.

The replay opens violations on the development chart

Stop: the floor would be paged for last year. Say: Replay must write signals to the report only; add a test that the replay opens no violation.

Claude Code suggests a GitHub environment with required reviewers

Say: No environments with required reviewers; the reviewed pull request that records the sha256 is the approval. On the Team plan they are not available for private repositories.

Step 11

Session 5: Rehearse on the development project, and compare with the old tool

30 minutes

Why

This is the validation the specification asks for: limits and capability recomputed from your real history and set beside the old tool's own figures. Doing it on the development project, with a copy IT has approved in writing, means differences are explained before anything reaches production; removing the rehearsal the same day keeps that project made-up only.

Do this

Ask IT to approve one copy of the export for the rehearsal, in writing, redacted where it holds personal data (operator names on readings). Work out its fingerprint in a terminal (on Windows, Get-FileHash in PowerShell):

Terminal (Mac)
shasum -a 256 ~/private/spc-export.zip
Paste into Claude Code, after filling the <...> parts
On a new branch spc/import-approval-dev, create docs/imports/spc-approved.md with a section "development rehearsal": export file spc-export.zip, sha256 <paste the value>, expected counts <characteristics, charts, readings>, IT's written approval for one rehearsal on acme-platform-dev given on <date> by <role>, redacted where it held personal data, and a line "removed on:" left empty. Open a pull request titled "SPC: approve rehearsal export".

Owner two approves the pull request and you merge it. On the development project, set the import login's password yourself in the SQL editor (alter role spc_importer login password '…', the value from the password manager), then:

Open

https://github.com/acme-ops/acme-platform/settings/secrets/actions

If missing: new secret SPC_IMPORTER_PASSWORD_DEV, the value only.

Open

https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/storage/buckets

Upload the approved copy to the private bucket imports.

Open

https://github.com/acme-ops/acme-platform/actions/workflows/import-spc.yml

Run workflow from main: target development, dry_run true; read both reports; then dry_run false.

The same day: paste supabase/snippets/spc-remove-run.sql with the run id into the development project's SQL editor, delete the file from the bucket, and record the date on the "removed on:" line through a pull request.

You will see recreated screen

github.com/acme-ops/acme-platform/actions/workflows/import-spc.yml
import-spc · target development · comparison
1
CharacteristicOld UCLNew UCLOld CpkNew CpkNew Ppk
Flange height10.3110.311.411.581.41
Hole position0.0520.0491.121.151.06
ExplainedFlange height: old Cpk equals new Ppk; the old tool uses overall sigma (docs/spc-inventory.md).2
The comparison report from the rehearsal: the module's figures beside the old tool's.
  1. Two calculations from the same history, side by side.
  2. A difference with a reason. One without a reason means you are not ready.

Check it worked

The sha256 matched and the counts agree with docs/imports/spc-approved.md; every limit and capability difference in the comparison report has a written reason; the same day the rehearsal rows are removed with the snippet, the file is deleted from the bucket, and the date is recorded.

If it goes wrong

The run refuses: sha256 not approved

The file in the bucket is not the one recorded on main (a re-export changes it). Record the new value through a pull request owner two approves, or upload the approved file.

The run fails at sign-in although the secret exists

The value is probably wrong: on our Academy a key's value was its own name, pasted by mistake. Paste the value only, never NAME=value.

A limit differs and nobody can say why

Check the period and subgroup size the old tool used, and whether it recalculated automatically (Session 1). Do not go to production with an unexplained difference.

One inspection lotA lot arrives and the inspection plan picks a sampling scheme. A sample is drawn and measured, and the lot is decided: accept, conditional or reject. A rejected lot raises an action item and the event spc.inspection_lot.rejected. A lot arrivescore_lotPlan and schemespc_inspection_planDraw and measurespc_measurementDecidespc_inspection_lotacceptlot releasedconditionalnamed conditionrejectlot heldAction and eventspc.inspection_lot.rejectedScheme: fixed, z14_aql, z19,skip_lot, c_zero or hundred_pct.Sample sizes come from thestandard's tables, not memory.
One inspection lot. The plan picks the scheme, a sample is measured, and the lot is accepted, conditionally accepted or rejected.
Step 12

Session 6: Import into production through the pipeline, and run a week side by side

25 minutes, then a week

Why

Real history reaches production only through reviewed code that a person starts from main, for an export whose fingerprint and counts were approved in a reviewed pull request, never from a laptop, an upload page or an agent. A week where readings go into both tools shows whether operators, gauges and the rules engine behave on real days, and gives you the side-by-side figures the cutover rests on.

Do this

Take a fresh export, work out its sha256, and add a "production" section to docs/imports/spc-approved.md (file, sha256, expected counts, date) through a pull request; owner two approves and you merge. Set spc_importer's password on production yourself in its SQL editor. Then:

Open

https://github.com/acme-ops/acme-platform/actions/workflows/deploy.yml

Check the latest deploy on main is green, so production has every migration.

Open

https://github.com/acme-ops/acme-platform/settings/secrets/actions

If missing: SPC_IMPORTER_PASSWORD_PROD, the value only.

Open

https://supabase.com/dashboard/project/abcdefghijklmnopqrst/storage/buckets

Production Storage: upload the export to the private bucket imports.

Open

https://github.com/acme-ops/acme-platform/actions/workflows/import-spc.yml

Run workflow from main: target production, dry_run true, then false, then false once more (it must add nothing).

Then the quality engineer proposes limits for the first slice from the history, the quality approver approves them, and for one week every reading in that slice goes into both tools.

You will see recreated screen

github.com/acme-ops/acme-platform/actions/workflows/import-spc.yml
import-spc · target production · dry_run false
2
KindApprovedIn exportImportedSkipped
Characteristics4242420
Readings61,88061,88061,8800
The production run: same script, same reports, the real history.
  1. Started by a person on GitHub, from main, for the approved file.
  2. The counts that go into docs/cutover.md; any mismatch fails the run.
  3. Safe to run twice.

Check it worked

The run's sha256 matched the approved production entry, production counts equal the approved counts, a second run added nothing, the first slice's limits are approved in the module, and the side-by-side week has started.

If it goes wrong

The run fails with "relation does not exist"

Production is missing a migration. Check the deploy run and the daily freshness check from Session 11; never apply by hand. Our production database once fell nine migrations behind main.

The run fails on a count mismatch

Do not edit the approved counts to make it pass. Read the report, find which rows are missing or extra, and record a corrected export through a reviewed pull request.

Operators stop entering readings in one of the tools

Restart the count from the day both were used again; a partial week compares nothing.

Step 13

Session 6: Compare the week, cut over, and cancel with the saving written down

35 minutes

Why

The week's side-by-side figures are the evidence for switching, and the definition-of-done checks run on the deployed address are the proof the module computes correctly. The module is finished when the old tool stops costing money; the saving written as arithmetic from invoices proves the work paid for itself.

Do this

At cut-over, set the import login to NOLOGIN on production and development (alter role spc_importer nologin in each project's SQL editor). Then:

Paste into Claude Code, after replacing the <...> parts
On a new branch spc/cutover, write docs/cutover.md and update docs/spc-inventory.md from what I give you:
1. The week side by side: readings, signals by rule, chart limits and Cp, Cpk, Pp, Ppk per characteristic, old against new, with every difference explained (where I wrote "unexplained", say we are not ready).
2. Signal response time and the closed-without-cause query (must be zero rows) from the module.
3. The three checks that define done on the deployed demo address, with date and who ran them: the reference readings reproduce exactly; capability matches the second calculation to 3 decimals; every violation needs a coded response before closing.
4. The cutover date, where the old tool's final export is stored and its sha256, the retention period the quality engineer set, the old annual cost from invoice <number>, the cancellation or end date, and the saving as arithmetic from the invoices I give you, never an estimate; each tool and workaround marked replaced, retired or still in use; and, in docs/KEYS.md, spc_importer set to NOLOGIN on both projects with the date.
Then add this module's checks to docs/testing-protocol.md and open a pull request titled "SPC cutover".

My figures:
<paste the old tool's and the module's figures, the check results, dates and invoice figures>

You will see recreated screen

github.com/acme-ops/acme-platform/blob/spc/cutover/docs/cutover.md
docs/cutover.md
1
MeasureOld toolModuleNote
Readings1,2041,204none
Signals3 (rule 1 only)7old tool had rules 2-8 off
Cpk, flange height1.411.58old Cpk = module Ppk (overall sigma)
Closed without causenot recorded0query in testing protocol
Definition of doneReference readings exact · capability to 3 decimals · coded response before close2
The evidence the cutover rests on, on GitHub.
  1. Every difference has a reason; more signals is the module seeing what the old settings hid.
  2. The three checks, on the deployed address, dated.

Check it worked

docs/cutover.md is merged with no unexplained difference and the three checks passing; spc_importer is NOLOGIN on both projects; the old tool is cancelled or has an end date; its export is stored with its fingerprint; the saving is written from invoices; docs/testing-protocol.md lists the module's checks.

If it goes wrong

The module shows many more signals than the old tool

Usually the old tool had rules switched off or recalculated limits. Write which, and agree the rules per chart with the quality engineer; do not switch rules off to match the old count.

Someone wants to keep the old tool for its reports

Ask which report. Build it from the module's tables, or find why the import missed the data, before cancelling.

Before you go on · The module is done whenTick each one

Knowledge check

Why is imported history replayed in report-only mode?

Knowledge check

In the rehearsal, the old tool's Cpk equals the module's Ppk. What does that tell you?

References

  1. GitHub Docs: Manually running a workflow. https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
  2. GitHub Docs: Using secrets in GitHub Actions. https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions
  3. Supabase Docs: Storage. https://supabase.com/docs/guides/storage
  4. ISO: the standards catalogue (search ISO 22514 and ISO 2859-1). https://www.iso.org/

Chapter 5 · 12 questions · 80% passes

Final assessment

Twelve questions across the module. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.

15 min12 questions≈ 15 minutesRetake allowed

Choose one answer for each question, then submit. You will see the right answer and why for every question.

1. Which sigma does Cpk use?
2. A capability study covers a period in which the rules engine found signals with no known cause. How is it saved?
3. Who may close a violation in this module?
4. How may control limits on a chart be changed?
5. How does the measurement history reach production?
6. On the 36-reading reference data (centre line 10.00, limits 9.70 and 10.30), with all eight Nelson rules on, what fires?
7. A gage R&R study gives %GRR of 22%. How is the gauge judged?
8. You count defective units in samples whose size varies. Which chart do you use?
9. What is the difference between control limits and specification limits?
10. Your Foundation already records first-piece results in inspections. How does the module get those readings onto a chart?
11. Which AS9102 form records each numbered (ballooned) characteristic with its result?
12. How is history from the old SPC tool used during migration?