[PR #261·263] When You Don't Know Whether a Save Went Through: Resending Only the Same Content, and Writes That Arrive After Logout
These two PRs fix how the customer app saves. PR 261 fixes the three customer-app items among the candidates left over from an earlier review, and PR 263 fixes one gap found while reviewing PR 261. On 2026-11-22 I approved PR 261 with “go with the recommendations” and PR 263 with “fix this now.”
| PR | What was wrong | What changed |
|---|---|---|
| 261 | Fields could still be changed while saving, so the screen and the server disagreed | While saving, every field, choice, and button is locked |
| 261 | After a failure, an edited value went out with the same request number and was dropped, yet the screen said “Recorded” | Failures with an unknown result are now told apart from definite failures |
| 261 | Skipped records had an edit button that only said “This can’t be edited” | The button is hidden |
| 263 | Input-screen drafts survived logout and could be seen by the next user | They are cleared at logout, and late writes are discarded |
Who did what:
- PR 261: The Claude lead session on my Windows computer (Claude Opus 5.5) handled checks, planning, tests, work instructions, and documents. Codex (
gpt-6.1-terra) did six rounds of implementation and four runs ofcodex exec review(Codex’s code review command). One side writes the tests first and the other implements. - PR 263: A Claude session on the same computer (Claude Opus 5.5) wrote both the tests and the implementation. Codex was not used.
PR 261: Locking during saves, and request numbers
1. Input is locked while saving
Only the save button was disabled; fields and choices stayed open. If a value changed while the request was in flight, the screen showed the new value while the server stored the old one. On eight screens — input record, after-input check, material preparation, input edit, plan change, device input, refill, and count change — every field, choice, and button is now locked while saving. An open iOS date or time picker is also closed when the lock starts.
2. Edited values dropped after a failure
When the server receives a request number it has already seen (clientRequestId, a number attached so one request is never stored twice), it returns what it stored the first time. So if sending failed and the user edited the value and sent again, the edit was dropped while the screen said “Recorded.” This was found on the material preparation screen, and five other save screens behaved the same way.
The fix changed three times.
- Round 1 — a new number if the value changed after a failure: The review pointed out that re-tapping an option already chosen also produced a new number.
- Round 2 — the same number if the content matches the failed request, a new one if it differs: If only the response had been lost and the first request was actually stored, the edited value would go out with a new number and create a second record (flagged by the review at its highest level).
- Round 3 — split failures in two (I chose option ‘2’):
- A failure with an unknown result (network drop, timeout, server 5xx error) may have been stored. Input is locked, and the screen shows only “It may have been saved, so you can only resend the same content” with a resend button. Same number, same content: whether the server returns the first record or stores a new one, there is only one record. To change the value, the user edits it after it is saved.
- A definite failure (4xx error) was not stored, so the user can edit and resend. The number stays the same.
Following further review, the unknown-result state is written to the phone before sending. If the user leaves the screen or the app dies mid-request, the screen reopens locked with the same content. Device input and refill remember this per device. If the phone can’t store it, the request is simply sent without it.
Input edit, count change edit, and plan change don’t use this. Those screens prevent overlaps with a standard version (the server rejects with 409), so they reopen after a failure.
3. A late read that re-locked the screen
The full check run by the Stop hook (a check that runs automatically when work ends) failed twice, so the cause was tracked down. When reading the “remembered send” at screen open finished late, it mistook the record left by the user’s own save in the meantime for an old one and locked the screen again. It only showed up in the heavily loaded full check, but it is a race condition (a result that depends on which of two jobs finishes first) that could happen on a real phone too.
Five screens now discard a late read result once that screen has sent anything. A test helper that deliberately delays the read was added. While building it, a mistake on the test side was fixed too: using spyOn and mockRestore (test tools that watch a function and then restore it) on the fake store wiped its fake implementation and broke the next test.
Alternatives dropped
- Having the server reject a known number with different content: The most robust, but it changes the request shape. I decided to add it during the next detail’s development.
- Blocking the screen until the remembered send is read: The review suggested it, but the read takes a few milliseconds and it didn’t fit the existing tests, so it was dropped.
PR 263: Clearing input drafts at logout
What was wrong
Logout clears record drafts and the photo folder with a single draftStore.clearAll(). But drafts on the input plan change, input record, and input edit screens were stored under different names and stayed behind. On a shared phone, the next user opening those screens could see the amounts and notes the previous user was writing.
What was chosen
- One place that clears:
draftStore.clearAll()now clears input drafts too. Logout already calls this one function, so no new clearing spot is added. - Blocking late writes: Clearing the keys was not enough. Logging out closes the open screen, and on closing it writes the draft it hadn’t written yet (one waiting 300 ms). That write lands after the clear, so the draft comes back. So input drafts now follow the “session number” rule record drafts already used (a number that goes up by one at every logout). The screen remembers the number when it opens and skips the write if the number has changed. If logout happens mid-write, the draft just written is removed.
Alternatives dropped
- A separate function for input drafts, called from logout: Two places would clear, and the late-write problem would remain.
- Putting the user ID into draft names: Every screen would need the user ID, and old users’ drafts that were never cleared would stay on the phone.
The “remembered send” from PR 261 was placed under the same name as record drafts from the start, so it was already cleared at logout. It was not touched this time.
How it was checked
PR 261
- In each round, Claude committed the tests first and confirmed they failed for the right reason before implementation. A shared helper checks whether a screen is locked.
- After Codex’s implementation, 290 tests in the six changed suites (groups of tests) passed, along with the app type check and lint (a code rule check, 0 errors).
- The full
npm run verifyfirst passed in 6 min 10 s, then failed twice under the Stop hook (the race in section 3). After the fix it passed in 11 min 44 s (customer app 827, admin web 492, server 862). The six changed suites passed 295 tests twice in a row. - Fixed through four
codex exec reviewruns: a new number even when nothing changed, forgetting after leaving the screen, forgetting when the app died mid-request, open iOS pickers, and phone storage failures. - Not fixed: if a request with an unknown result is still being processed on the server and the resent request gets a 4xx, the app treats it as a definite failure and unlocks. The app alone can’t tell these apart, so this will be blocked on the server side (rejecting a known number with different content).
- The admin web didn’t change, so
npm run e2ewas not run. The customer app e2e was not run either, since the request shapes are the same.
PR 263
- Claude wrote three tests first, and all three failed before the fix.
- Logout clears input plan, record, and edit drafts.
- A late draft write from a screen opened before logout is discarded.
- Logging out mid-write also removes the draft just written.
- After the fix, the 24 tests in that file, the app type check, and 225 tests in 10 input-screen and login suites passed.
- The full
npm run verifyresult isn’t in the devlog, so it is unverified (the devlog only says it goes in the PR description).
What wasn’t checked
- Locking during saves, and reopening locked after saving in airplane mode and leaving the screen, haven’t been seen on a real Android phone yet.
- Writing an input record, logging out, and opening the same screen under another account to see empty fields hasn’t been checked on a real phone either.
- PR 263 was a small fix, so one session wrote both the tests and the implementation instead of splitting the roles.
Lessons
- When request numbers prevent duplicates, tell “failures with an unknown result” apart from “definite failures.” The first may have been stored, so only the same content is resent. The app alone can only go so far; to close the gap completely, the server has to compare the content too.
- A clearing fix has to account for “writes that arrive after the clear.” Record drafts already handled this, but input drafts, built later, didn’t follow the same rule. The late read in PR 261 was the same shape of problem.