Repository navigation
Description
Problem
Source audit during stage5b #746 confirms that DiaryRepositoryImpl.call classifies SignInRequired and calls parameterless DiarySessionStore.clearDiaryToken(). LessonsPreferences implements it with an unconditional DataStore dropDiaryToken(). Cache-generation barriers protect cache publication but do not protect this persistence write.
If a students/read/correction request is sent with diary bearer A, a new sign-in or address change may install B before the old structured DIARY_TOKEN_INVALID response arrives. The late refusal can then clear B. This finding was reproduced by the actual 24-case RED below and corrected only after qualified resource release.
Expected behaviour
Carry the actual sent diary request address/bearer through each consumed authenticated diary operation. Clear only a matching still-current diary token, atomically with the address/token comparison inside the DataStore write; a pre-write read followed by unconditional clear is insufficient. A replaced bearer, changed server or missing observed send must not clear another session. Retain the target/login/pupil, class membership and caches as existing rules require. Preserve cancellation and failure recovery; no lock spans network I/O.
Acceptance
- Deferred-response tests reproduce replacement-session and changed-server deletion before correction, using the real persistence boundary and actual binding/send identity where applicable.
- Matching current invalid diary credentials clear only that bearer; a replaced bearer/server or missing observed send retains the current session. Refusal classification keeps the approved reason-first and canonical-code fallback semantics.
- The comparison and token removal are one atomic DataStore transaction, including a second preferences instance over the same store where practical.
- Existing diary/upstream/cache/cancellation tests and REST/Connect/gRPC binding cases remain green.
- Full stage5b gates, independent whole-branch review, CI/dev/master and source-matched signed-native/production acceptance are recorded with Move the remaining Android remotes to v2 transports (stage 5b) #746.
No production account, password, sign-in, sign-out or token mutation is used for reproduction. Keep this issue open until its delivery gates actually pass.
Scope ruling from the approved design
Design section4 explicitly keeps unknown reasons by name and handles them by canonical code; reasonless responses retain status fallback. This fix guards which actual request may clear storage, rather than redefining DiaryFailure. An unknown authentication refusal may still mean SignInRequired under that accepted fallback, but may clear only matching actually sent credentials. Non-authentication refusals retain the session. Management's stricter DEVICE_TOKEN_INVALID-only membership removal is a separately accepted rule and is not blindly copied to diary classification.
Observed RED before producer correction
A newly admitted one-shot offline core:data command compiled the two new test files and freshly executed all24 parameterized cases over REST/Connect/gRPC in26.67s:15 AssertionError failures,9 passed controls, no errors/skips/compiler/framework failures. Each binding reproduces five failures: a late refusal deletes a replacement bearer written by another preferences facade; a server change does not protect the retained token; a replacement between the caller and the actual store transaction is deleted; a refusal with no observed send clears credentials; and cancellation of the persistence write becomes a normal sign-in failure. Current-token clearing, canonical fallback for an unknown authentication reason and non-authentication retention controls pass.
The fixture uses real selected network bindings, actual Authorization headers, LessonsPreferences/AES/MemoryStore and a write-boundary interleaving through another preferences instance. All118 source inputs/two absences remained frozen; a fresh JUnit report, original request/input bytes, raw output and owned-process identities/absence were retained. The READY request was withdrawn after actual normal tool completion as the coordinator requested; producer changes still await independently qualified resource release. No code fix, overall GREEN, native or delivery is inferred.
Focused correction verified
One conditional DataStore transaction now compares the actual sent address/diary bearer with the current store contents, across preferences facades, before dropping only the matching token. Authenticated read/correction remotes and the repository carry their per-call observation. Cancellation remains thrown; ordinary storage failures preserve the classified refusal. The initial combined candidate executed571 fresh cases with568 passes and three overstrong cancellation-reference assertions tracked transparently by #754; both fresh Detekt tasks passed. After that actual release, only the test contract changed to require CancellationException plus original-cause provenance, as the pinned coroutines1.11.0 recovery code requires.
The new one-shot affected-data validation then freshly passed467/467 cases, errors/skips0 and fresh data Detekt0, exit0 in39.79s. All24 ownership regressions pass over REST/Connect/gRPC. Exact130 inputs, original request, reports and process identities were retained; the coordinator independently qualified and released the run. Prior unchanged app84/model20 results remain separate. Full unfiltered suites, signed native, review and delivery remain pending; this issue stays open.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsNow
Activity