Repository navigation
fix: serialize credential writers and sync atomic state writes - #84
Merged
Merged
Conversation
OBenner
commented
Nov 16, 2026
OBenner
left a comment
Owner
Author
There was a problem hiding this comment.
dev review — ACCEPT.
Проверено по диффу (fefbfbd, base e25fa04) и прогону на ветке (worktree review-84): file-lock 2/2, credential-concurrency 3/3 (включая реальную 4-процессную гонку), atomic-durability 3/3, atomic-crash 1/1, atomic-file 1/1 — 13/13 PASS. CI 3/3 зелёный (run 43850126018). git merge-tree с текущим main — чисто.
Проверки по существу:
- Серилизация: единый lock на credentials.json покрывает read-modify-write + token-file update + audit record для issue/ensure/rotate/revoke. Рекурсивного лока нет — ensureCredential зовёт issueLocked внутри своего lock, а не issue (иначе self-EEXIST до timeout).
- Долговечность: writeTextAtomic теперь fsync файла до rename + directory sync на POSIX; пропуск dir-sync на Windows задокументирован в durability-заметке. Crash-тест kill'ит реальный child до rename — хвостов .tmp не остаётся, состояние консистентно.
- Fail-closed: stale lock → STORAGE_FAILURE через 10 с с явной инструкцией оператору; лок никогда не крадётся по PID/возрасту — осознанный cooperative-контракт, зафиксирован в limitations.
- authenticate остаётся lock-free read-only — верно, читатели не должны ждать writers.
- Без новых зависимостей; wire и спека не затронуты.
Неблокирующие замечания:
- В finally withFileLock unlink lock'а после throw из action может замаскировать исходное исключение при ошибке unlink — приемлемо для cooperative lock, но можно обернуть позже.
- docs/security/credential-durability-2026-11-16.md добавлен staff1 в зоне владения security — прошу security подтвердить документ при re-check (ниже).
Прошу security сделать re-check как владельца исходных находок L2/L3. После него передаю CTO на финал.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Concurrent credential writers could overwrite each other's hashes or issue multiple tokens during parallel init. All CredentialStore mutations now hold a per-project exclusive lock through read/modify/write, token-file updates and audit. Atomic state writes sync and close the temporary file before rename; POSIX also syncs the parent directory.
Closes #15.
Validation:
pnpm verifypassed (93 files / 808 tests, format/import checks/typecheck/build). Regression tests reproduced failures before the fix. Coverage includes independent stores, four real writer processes exercising issue/ensure/rotate/revoke, stale-lock refusal and exception cleanup, injected write/sync/rename failures, and a real child killed before rename retaining the previous valid JSON. Existing audit and permission diagnostics pass.Limits: the lock is cooperative, waits at most 10 seconds and deliberately never steals stale-looking locks. A killed writer requires the documented operator recovery after stopping all project writers. Windows has no directory fsync via Node; no guarantee of rename durability after power loss. Credential JSON and token files remain separate transactions. No dependencies, protocol changes or live credential mutations. Historical security review is preserved; L2/L3 closure evidence is in the new follow-up document.