[PR #246·247·248·252·253·256] Turning Head Office Answers into Code: Table Ends, Keeping Edited Values, and Showing It on Screen
The head office (the side that runs the service) sent answers to questions we had asked. We compared those answers with the current code and moved the ones we could act on right away into the code. The six PRs are one continuous piece of work from 2026-11-19 to 2026-11-21, so they share one post. The head office’s original wording, question numbers and standard values are not in this post; it only covers the principles we kept while turning the answers into code.
All of it ran on my Windows computer. A Claude Code session (Claude Opus 5.5) that leads the head-office-answer work compared the answers with the code and wrote the plans and work instructions. PRs #246 and #247 were each implemented by another Claude Code session (Claude Opus 5.5), and PRs #252, #253 and #256 were implemented by the lead session itself. Codex (gpt-6.1-terra) wrote most of the tests. In PR #252 Codex stalled both times, so a Claude subagent of the lead session (Claude Opus 5.5) wrote the tests; in PRs #253 and #256 the same subagent also fixed places where Codex’s tests missed something or clashed with a rule. The final review was done by the lead session and codex exec review. In every case, the rule that the implementing side does not write its own tests was kept.
At a Glance
| PR | What was done | Principle kept | Rejected option |
|---|---|---|---|
| #246 | Calculate the rate even when the temperature is outside the table | Use the table’s ends instead of hard-coded numbers | Filling gaps in the middle with neighboring values |
| #247 | Apply the reading input ranges and the minimum count for weighing several at once | Do not overwrite values admins already edited | Changing every row unconditionally |
| #248 | A difference table of answers versus code, and tidying the records | Answers that change the structure wait for the follow-up answers | Changing the database structure right away |
| #252 | Change the empty draft’s default, and plan the reduction rule | Do not silently change approved standards | Changing existing versions too with a migration |
| #253 | Add pause and reduce to the server calculation | Do not put calculation inputs in customer responses | Not calculating when a reading is missing |
| #256 | Show the pause reason and reduction rate in the admin web and customer app | A server calculation is done only when it shows on screen | Sending the two average temperatures to customers too |
First, Checking the Premise of the Task
The lead session’s first task was “put the head office answers recorded in a certain PR into the code”. But that PR had no answers, only a record of questions sent. The real answers were in two other records. Claude built a difference table comparing each answer with the current code, and I picked and approved the ones we could do right away.
At that point we decided not to do several answers that would change the database structure (the shape of the tables that hold the data). They could change again depending on the answers to questions we had asked the head office again, so building them now could lock in the wrong structure.
PR #246: Using the Ends of the Table Instead of Hard-Coding Numbers
What changed
When calculating the daily input amount, the server looks up the rate for that day’s temperature in a table (a rate table by temperature range, one per standard version). Until now, if the temperature was outside the table’s range, the calculation was blocked. The head office answered that it should still calculate outside the table, and I decided on 2026-11-19 to apply that.
- If a matching range exists, it is used as is.
- If the temperature is below the table’s lowest range, the lowest range’s rate is used.
- If the temperature is at or above the table’s highest range, the value given in the head office answer is used as written.
- If there is a gap in the middle of the table, or the table is empty, it still does not calculate.
Chosen approach and rejected options
- Chosen: the temperatures from the head office answer are not written into the code. Instead, the code works from the lower and upper ends of each standard version’s table. If the head office builds the table with the same range as its answer, the behavior matches the answer exactly, and if the table changes later, the code stays the same.
- “The lowest range” is the row with the lowest starting temperature, not the table’s first row. Codex’s tests shuffle the row order to check this.
- Rejected: using the top range’s value at or above the upper end. The head office answer gave a separate value, so that value is used word for word. This reading went into the PR as something for me to confirm.
- Rejected: filling gaps in the middle with neighboring values. The head office answer only talked about the two ends, and a gap in the middle is most likely a mistake when entering the standard, so it stays blocked.
PR #247: Not Overwriting Values Admins Have Already Edited
What changed
The head office answered two things.
- Allowed input ranges for readings: the upper-end values of the range accepted when a customer enters readings. These ranges live in a database table, not in code, so we updated the file that fills in the initial values (the seed file) and added a migration (a file that changes database values in order) for databases that already exist.
- Minimum count for records that weigh several at once: both the server and the app block counts under 5. It is one shared constant, and no new error code was made; it reuses the one used for a similar case.
I approved the plan’s recommended options on 2026-11-19.
Chosen approach and rejected options
- The migration only changes rows still at their original values. It changes a row to the new value only if the item name matches and its lower and upper ends equal the old initial values. Values an admin already changed in the admin web are left alone.
- Rejected: changing every row unconditionally. The admin’s edits would be lost.
- Rejected: changing nothing. A newly created database and an existing one would have different values.
- The rollback (
down) uses the same condition and only returns rows holding the new value to the old one.
- Migration files that were already applied were not edited. A new database runs the old file (old values) and then the new file (new values), ending with the same values.
- The order of checks was set. If the count is not a whole number, is 0 or less, or the total weight is wrong, it is first refused as “invalid value”, and only then are counts under 5 refused. This order keeps someone who entered a wrong value such as 2.5 from getting the misleading message “please enter 5 or more”.
- One point raised by
codex exec reviewwas not fixed. On rollback, a row that an admin happened to set to exactly the new value also goes back to the old value. Fixing it would need a table or column to remember which rows changed, which grows the database structure, so we accepted it.
PR #252: Not Silently Changing Approved Standards
What changed
The head office answered: “treat a record as stale after a certain number of days, and let admins change it.” The field for admins to change this value already existed, so only the default for newly created empty drafts was changed from 7 days to 3 days. I picked this task, along with a plan draft for the reduction rule in the next section, on 2026-11-20.
Chosen approach and rejected options
- Existing standard versions, and drafts copied from them, stay as they are. Changing existing versions to 3 days with a migration would mean changing an already approved standard without anyone knowing, so that option was rejected. An admin who wants the change can make a new version.
- Parts with no answer stay as they are. Another time limit in the same feature has no head office answer yet, so it was not changed.
- For the reduction plan, we recommended keeping the standard values as columns of the standard version. Fixed values in code would need a new deployment every time a value changes, so that was not recommended. Since it changes the database structure, Claude asked me about it separately.
- When Codex stalled: both times, file reads and commands inside Codex’s sandbox (a separate, isolated environment for running) timed out, so Codex could not write the tests. We stopped before reaching the rule of stopping after three identical failures, and had a Claude subagent that was not implementing write the tests. The cause was not found; Codex ran normally that same afternoon.
PR #253: Adding the Reduction Rule to the Server Calculation
What changed
The reduction rule from the head office answer went into the daily input calculation. I set all five choices raised in the plan to the recommended options (2026-11-20).
- If any of the day’s latest readings crosses a pause threshold, no plan is issued for that day and the reason is sent instead (pause).
- Each time the average temperature over a recent period drops by a set amount compared with the same-length period before it, the input amount is reduced by a set rate (reduce, up to a maximum number of steps).
- The six standard values are columns of the standard version (a new migration). Every existing standard version got the head office’s default values. A pause threshold left empty turns that check off.
Chosen approach and rejected options
- An item with no reading that day skips its check. That was my decision. The option of not calculating when a reading is missing was rejected because a plan would only come out if every item were measured every day.
- The new columns can be left out of the API (the server’s entry point for sending values) that saves standards. Leaving them out keeps the current values. This lets the current admin web keep saving as is until the next PR changes the screens.
- The existing rule of not putting calculation inputs in customer responses was kept. Codex’s tests tried to read calculation inputs from the customer response and clashed with this rule; the subagent changed the tests to read the stored calculation inputs from the database.
- How the new columns were filled on approved versions: approved versions are protected by a database lock (a trigger, which makes the database itself block changes to values). So only the single change that fills the new columns turns the lock off and back on inside the same transaction (a group of changes that all succeed or are all undone). The migration test written by the subagent caught this problem. Without it, the migration would have failed on any database that already had an approved version.
- One mistake in the plan was corrected. Claude had written in the plan that “if today’s plan already exists, the blocking reason is not shown”, then confirmed in the code that the server already sends the plan and the reason together, and corrected it. A test now locks in that the same happens for the pause reason.
PR #256: A Server Calculation Is Useless if It Is Not on Screen
What changed
Even if the server calculates a pause or a reduction, people on site will keep inputting as usual unless they see it. So three screens changed.
- Admin web standards screen: fields to edit the three pause thresholds (empty means off) and the reduction drop, rate and averaging time; for approved versions, it shows the values and “off”.
- Admin web plan basis screen: shows the pause reason and “reduced by some % because the temperature dropped (earlier average → recent average)”.
- Customer app today’s input screen: if input is paused but a plan remains, rounds not yet done show “Don’t input while paused” and the record button is hidden. If the amount was reduced, “Reduced by some % because the temperature dropped” appears under the total.
- Server: only one value, the reduction rate, was added to today’s input response.
Chosen approach and rejected options
- Only the reduction rate was added to the customer response, to keep the rule of not sending calculation inputs. Sending the two average temperatures as well was rejected because the customer screen does not use them.
- Even while paused, viewing records for rounds already done and “input record outside a round” stay. Amounts already put in before the pause need to be recordable.
codex exec reviewpointed out a problem with the first approach. At first the rate from the day’s last calculation was sent. But if the customer is using a changed plan and a new suggestion comes out, the suggestion’s rate would appear under the total of the plan actually in use. So it was changed to send the rate from “the most recent calculation that is not a suggestion”.- If blocked for another reason (such as no reading) while a plan remains, the record button stays, as before. A test locks this in.
- The new fields come pre-filled with draft values, so the admin web’s existing browser tests (create draft, approve) keep running without changes.
How it was checked
- In every PR, the new tests were first seen failing only for the expected reasons before implementation. PR #246 had 2 of 30 failing, PR #253 had 12 calculation tests failing, and PR #247 failed only for expected reasons such as the missing new migration file, a range refusal, counts under 5 being saved, and app wording. The lead session reran the same failures on the test commit and used
git diff --name-onlyto check that the implementation commit did not touch the test files. - After implementation, all changed tests passed: 30 calculation tests in PR #246; 21 server unit, 104 server e2e and 46 app tests in PR #247; 9 in PR #252; 90 in PR #253; and 95 admin web, 24 server and the app screen tests in PR #256.
- In PR #247, the full set of migrations was run on an empty database, a temporary test checked that the new range values were there, and the test was then deleted. The test database is refilled from the seed every time, so the existing tests cannot see values created by a migration.
- In PR #253, the first full verification failed on the test that checks “entities (the code’s table definitions) and migrations match” because of a default value written differently (
'2'versus2.0), so the migration’s default was fixed. - In PR #246’s full
npm run verify(about 764 seconds), all 819 server tests passed, and 3 admin web and app tests that this work did not touch failed. All three passed when rerun on their own, so we treated it as a timing problem when the computer was busy running verification at the same time. The full verification results for the other PRs are in each PR description. - PRs #253 and #256 also ran the admin web browser tests (
npm run e2e). codex exec review: no findings for PR #246, the rollback point above for PR #247, and the rate point above for PR #256.
Lessons
- Working from the ends of the table instead of numbers keeps the code the same when the table changes. Because the tests came first, they caught the risk of wrongly treating “the lowest row” as the table’s first row.
- A value-changing migration that only touches “rows still at their original values” preserves admins’ edits. And when the test database is refilled from the seed, values created by migrations are invisible to tests, so check once separately on an empty database.
- Approved standards change only through a new version. Changing a default and changing an already approved value are different things.
- If an answer is ambiguous or seems to conflict with another answer, put it off instead of building it. Building it now could lock in the wrong structure. Where we built on our own reading, we decided to ask the head office whether that reading is right.
- A server calculation is only done when it shows on screen. If the pause reason and the reduction rate are not on screen, things on site carry on as before.
- Write existing rules and the list of files to change into the work instructions in advance. Without “what does not go into customer responses”, the test-writing side writes tests that clash with that rule; with only “add the new field to fixed test data”, it misses some files. It is better to extract the list of files a type check would find and hand it over in advance.