carlos / platform Public

console: end the DPA acceptance when an account is reaped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev e5d666e150c1208d085910d68d1a963291517907 parent 2fa579b
2 files changed, +47 −6
  • internal/console/legal_store_test.go +43 −6
  • internal/console/store.go +4 −0

Intent

Human

<task-notification> <task-id>a4f37797b22525a8e</task-id> <tool-use-id>toolu_01Lbr44784UG6DJmjnXRR3QV</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/260ddc60-0dfc-4cf8-8857-7688d6275097/tasks/a4f37797b22525a8e.output</output-file> <status>completed</status> <summary>Agent "Implement Task 2: guarded fetch" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE Commit: 2fa579b7 "console: guarded fetch and canonical check for legal documents" Tests: `go test ./internal/console -run 'TestFetchLegal|TestCanonicalAgreement|TestAlert' -count=1` passes. Before the implementation, the same command failed to compile on the undefined `newGuardedHTTPClient` and `fetchLegalText`. Build checks: `go build ./...`, `go vet ./internal/console/` and `gofmt -l internal/console` are clean. The sandbox blocked the first build with a read-only file system, so I reran it with the sandbox disabled. Concerns: - **Git lock:** the `git commit` printed a `packed-refs.lock` "File exists" error (the stale lock the brief mentioned), but the commit landed. `git log` shows 2fa579b7 and the tree is clean. - **Extra refusals beyond the brief:** - An href containing whitespace, a control character or a backslash is refused, because browsers read `/\host` or `/&lt;tab&gt;/host` as `//host`. - A self-closing tag other than `&lt;br/&gt;` is refused. - Token names in error messages are cut to 24 characters. - **Unused function:** `newLegalHTTPClient`, which builds the 10 s legal client, has no caller until Task 3. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/.superpowers/sdd/2026-11-25-dpa-acceptance/task-2-report.md</result> <usage><subagent_tokens>54076</subagent_tokens><tool_uses>8</tool_uses><duration_ms>206603</duration_ms></usage> </task-notification>

Attributed to this commit: 25.0 g CO₂e (3,121,880 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on dpa-and-retention, 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/internal/console/legal_store_test.go b/internal/console/legal_store_test.go
index 2df9518d8..6975486c6 100644
--- a/internal/console/legal_store_test.go
+++ b/internal/console/legal_store_test.go
@@ -63,9 +63,7 @@ func TestLegalDocumentsAppendOnly(t *testing.T) {
func TestDPAAcceptanceOneLivePerAccount(t *testing.T) {
s := openTestStore(t)
- doc, _ := s.PublishLegalDocument(legalTestDoc("1"))
- lh, _ := s.SetLetterhead(Letterhead{Entity: "E", RegisteredOffice: "R", CompanyNumber: "1", Signatory: "S",
- PrivacyAddress: "p@example.com", CreatedBy: "op", CreatedAt: time.Unix(1, 0)})
+ doc, lh := legalTestDocAndLetterhead(t, s)
acct := testAccountID()
a := legalTestAcceptance(acct, doc, lh)
if _, err := s.AcceptDPA(a); err != nil {
@@ -91,9 +89,7 @@ func TestDPAAcceptanceOneLivePerAccount(t *testing.T) {
func TestEndDPAOnAccountDelete(t *testing.T) {
s := openTestStore(t)
- doc, _ := s.PublishLegalDocument(legalTestDoc("1"))
- lh, _ := s.SetLetterhead(Letterhead{Entity: "E", RegisteredOffice: "R", CompanyNumber: "1", Signatory: "S",
- PrivacyAddress: "p@example.com", CreatedBy: "op", CreatedAt: time.Unix(1, 0)})
+ doc, lh := legalTestDocAndLetterhead(t, s)
acct := testAccountID()
if err := s.CreateAccount(acct, "dpa-acct", "Shop", "owner@example.com", time.Now()); err != nil {
t.Fatal(err)
@@ -145,3 +141,44 @@ func TestLetterheadNewestIsCurrent(t *testing.T) {
t.Fatalf("first = %+v, %v", old, err)
}
}
+
+func legalTestDocAndLetterhead(t *testing.T, s *Store) (doc, lh int64) {
+ t.Helper()
+ doc, err := s.PublishLegalDocument(legalTestDoc("1"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ lh, err = s.SetLetterhead(Letterhead{Entity: "E", RegisteredOffice: "R", CompanyNumber: "1", Signatory: "S",
+ PrivacyAddress: "p@example.com", CreatedBy: "op", CreatedAt: time.Unix(1, 0)})
+ if err != nil {
+ t.Fatal(err)
+ }
+ return doc, lh
+}
+
+func TestEndDPAOnAccountReap(t *testing.T) {
+ s := openTestStore(t)
+ doc, lh := legalTestDocAndLetterhead(t, s)
+ acct := testAccountID()
+ if err := s.CreateAccount(acct, "dpa-reap", "Shop", "owner@example.com", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ id, err := s.AcceptDPA(legalTestAcceptance(acct, doc, lh))
+ if err != nil {
+ t.Fatal(err)
+ }
+ at := time.Unix(1_700_000_400, 0)
+ if err := s.ReapAccount(acct, at); err != nil {
+ t.Fatal(err)
+ }
+ if live, err := s.LiveDPA(acct); err != nil || live != nil {
+ t.Fatalf("still live: %+v, %v", live, err)
+ }
+ if rows, err := s.LiveDPAs(); err != nil || len(rows) != 0 {
+ t.Fatalf("live rows = %+v, %v", rows, err)
+ }
+ var ended int64
+ if err := s.db.QueryRow(`SELECT ended_at FROM dpa_acceptances WHERE id = ?`, id).Scan(&ended); err != nil || ended != at.Unix() {
+ t.Fatalf("ended_at = %d, %v", ended, err)
+ }
+}
diff --git a/internal/console/store.go b/internal/console/store.go
index a7734def0..6cb66fab7 100644
--- a/internal/console/store.go
+++ b/internal/console/store.go
@@ -1947,6 +1947,10 @@ func (s *Store) ReapAccount(accountID int64, now time.Time) error {
now.Unix(), accountID); err != nil {
return err
}
+ // Its live DPA acceptance ends with it (legal_store.go).
+ if err := endDPA(tx, accountID, now); err != nil {
+ return err
+ }
return tx.Commit()
}