carlos / platform Public

spec: pending logins are never deleted by another attempt (Paul)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 290434fa6a619243d77f723385e2d08568c7c0c1 parent 47eefde
3 files changed, +54 −13
  • docs/superpowers/reviews/CODEX-FINDINGS-agent-login-link-branch-R2.md +38 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-agent-login-link-branch.md +2 −2
  • docs/superpowers/specs/2026-11-07-agent-login-link-design.md +14 −11

Intent

Human

<task-notification> <task-id>banx8r3t5</task-id> <tool-use-id>toolu_01BeXXPbVLjRnEMUjkaHDtzF</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a1de5273-c148-49b8-8267-3dee9d49c9c1/tasks/banx8r3t5.output</output-file> <status>completed</status> <summary>Background command "Run Astra scoped re-review round 2" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 15.4 g CO₂e (1,972,100 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-agent-login-link, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-agent-login-link-branch-R2.md b/docs/superpowers/reviews/CODEX-FINDINGS-agent-login-link-branch-R2.md
new file mode 100644
index 000000000..3f4fb6665
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-agent-login-link-branch-R2.md
@@ -0,0 +1,38 @@
+Reviewed `d532ad9b..47eefded7a1a89803327365c7124e35f1e75bb6e`, branch round 2 of 3.
+
+- **Round-1 P1: partly resolved.** Exact-path waiter cleanup is safe, but concurrent writers can still erase the newest attempt.
+- **Round-1 P2: resolved.** Credential load/save failures after approval now return `terminalLoginError`, preserve the underlying error, explain that another login is needed, and trigger pending-file cleanup.
+
+**P1 — Concurrent `--no-wait` processes can delete both pending attempts.**
+
+Verified by source inspection at [authpending.go:75](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-agent-login-link/authpending.go:75). Each writer publishes its file, lists the directory, then unconditionally removes every other `.json` file.
+
+A valid interleaving is:
+
+1. A publishes its file.
+2. Newer B publishes its file.
+3. A and B each list both files.
+4. A deletes B; B deletes A.
+5. Both return success. A subsequent `--wait` reports no pending login.
+
+The new test runs saves sequentially, so it cannot catch this. An in-memory model of the publication, directory snapshot and removal steps confirmed the failing interleaving; this was not execution of the Go implementation.
+
+**Invariant / fault family:** Completing an older attempt must never erase its replacement; newest-wins must survive concurrent writers.
+
+**Fix direction:** Enforce publication and retirement through one cross-process ownership protocol, with a deterministic test forcing this interleaving. This is the second consecutive round in the same fault family, so stopping rule 2 applies before another fix. The choices are to refuse concurrent starts before creating an attempt, cut replacement support, or enforce the invariant centrally with a guard test. I recommend the third.
+
+No additional P2 or P3 findings in the scoped fixes.
+
+The census verdicts below concern root authority and do not waive the P1:
+
+| Census item | Verdict | Evidence and reason |
+|---|---|---|
+| `loadPendingLogin` | **Approve** | [authpending.go:94](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-agent-login-link/authpending.go:94): `ReadDir` and `ReadFile` remain within operator-selected CLI authentication state. `accepted-legacy` fits these reads. |
+| `savePendingLogin` | **Approve** | [authpending.go:45](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-agent-login-link/authpending.go:45): temporary-file creation and directory enumeration remain beside the credential store; no new root-service input or execution authority. |
+| Module-root envelope `.` | **Approve** | Reviewed the changed pending-file functions and [approval handling](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-agent-login-link/auth.go:762), including their callers. No expanded root authority or weakened root validation in this fix range. |
+
+Round-1 deferred-minors triage otherwise remains unchanged; its approved-then-storage-failure item is resolved.
+
+Targeted Go tests and Darwin/Windows build attempts all stopped before compilation because the sandbox denied creation of Go’s build directory. Cross-platform build and runtime behavior therefore remain unverified. Changed Go files pass formatting and whitespace checks; the full diff reports trailing whitespace in the recorded round-1 findings. No files were edited.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-agent-login-link-branch.md b/docs/superpowers/reviews/CODEX-FINDINGS-agent-login-link-branch.md
index a165329bf..f9bfbd6ef 100644
--- a/docs/superpowers/reviews/CODEX-FINDINGS-agent-login-link-branch.md
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-agent-login-link-branch.md
@@ -1,6 +1,6 @@
Reviewed `432135ae..d532ad9b`, branch review round 1. Two findings: one P1 and one P2. Evidence below is verified by source inspection. Targeted tests could not start because the read-only sandbox prevented Go from creating its build directory. Formatting and `git diff --check` passed.
-1. **P1 — An older wait can delete a newer pending login.**
+1. **P1 — An older wait can delete a newer pending login.**
Evidence: [authpending.go:82](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-agent-login-link/authpending.go:82), together with replacement at line 58.
`clearPendingLoginIf(A)` reads A, another process saves B through `os.Rename`, then A’s cleanup removes the path now holding B. B’s device code is lost, so its subsequent `--wait` cannot complete. The “two syscalls wide” comment acknowledges the window but does not protect it. The existing test replaces A before cleanup starts, so it misses this interleaving.
@@ -9,7 +9,7 @@ Reviewed `432135ae..d532ad9b`, branch review round 1. Two findings: one P1 and o
**Invariant / fault family:** Completing an older attempt must never erase its replacement.
-2. **P2 — Approval followed by a credential-storage failure leaves an uncollectable pending attempt.**
+2. **P2 — Approval followed by a credential-storage failure leaves an uncollectable pending attempt.**
Evidence: [auth.go:773](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-agent-login-link/auth.go:773) and [auth.go:842](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-agent-login-link/auth.go:842). The server consumes the attempt when returning the token: [authstore.go:593](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-agent-login-link/internal/console/authstore.go:593).
If approval succeeds but loading or saving credentials fails, `pollLogin` returns an ordinary error. Cleanup consequently retains the pending file, although the server has already consumed the attempt. Retrying cannot recover that token; it receives `unknown`.
diff --git a/docs/superpowers/specs/2026-11-07-agent-login-link-design.md b/docs/superpowers/specs/2026-11-07-agent-login-link-design.md
index 9467c9f2a..9d38cc0ac 100644
--- a/docs/superpowers/specs/2026-11-07-agent-login-link-design.md
+++ b/docs/superpowers/specs/2026-11-07-agent-login-link-design.md
@@ -111,17 +111,20 @@ Plain `carlos auth login` keeps today's behaviour (print, then wait).
`carlos auth login --help` and the docs page for agents say: agents use
`--no-wait`, show the person the link, then run `--wait`.
-The pending file records the console origin, the device code, its expiry
-and the label, so `--wait` polls the console that started it whatever
-`--console` or default is in force later. It is written with the
-credential store's atomic 0600 pattern (auth.go credentialFile.save). A second
-`--no-wait` replaces it (newest wins). `--wait` deletes the file only if it
-still holds the attempt that `--wait` just finished (compare the device
-code under the same lock or rename discipline), so finishing an old
-attempt never erases its replacement **(codex 7)**. Approved, denied,
-unknown and expired all end the attempt and delete its file on the same
-compare; a transient network failure keeps it. A plain `carlos auth login`
-leaves a pending file alone. The file name is the builder's.
+Each attempt gets its own pending file, in a directory beside the
+credentials file (`login-pending.d/`, 0700; files 0600, written with the
+credential store's atomic pattern). A file records the console origin, the
+device code, its expiry and the label, so `--wait` polls the console that
+started it whatever `--console` or default is in force later.
+
+**Paul's ruling, 2026-11-08 (after branch review rounds 1-2 found the same
+race twice):** a process never deletes another attempt's file. A file is
+removed only by its own `--wait` (approved, denied, unknown, expired,
+including an approved login whose token could not be saved), or by anyone
+once it has expired. `--wait` picks the newest unexpired attempt. Several
+unexpired attempts can sit side by side for up to the 10-minute login
+lifetime; that is the accepted cost. A transient network failure keeps the
+file. A plain `carlos auth login` never touches the directory.
### 3. The approval page acts on the code in the link