carlos / platform Public

console: restore the purge-recovery test; note retirement reasons

The cleanup revert left TestDemoPurgeRecovery expecting retained rows;
it is back to main's expectation. Documents that a new retirement reason
needs demo_spent_tokens' CHECK first (Opus re-check note).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d2678aff18192341d18e2d09c566e127d588b38e parent a92358e
2 files changed, +6 −2
  • internal/console/demo_expiry.go +3 −0
  • internal/console/demo_expiry_test.go +3 −2

CI passed — run details

Intent

Human

<task-notification> <task-id>bskzs3ji6</task-id> <tool-use-id>toolu_01UcfLjQ1EUwKzniZEs6HWVi</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/bskzs3ji6.output</output-file> <status>completed</status> <summary>Background command "S=/home/paulca/.cache/tmp/dcx; sleep 10; until [ -f $S/done ]; do sleep 30; done; tail -1 $S/log2; cat $S/final2.md" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>aa105e0434c8649b8</task-id> <tool-use-id>toolu_017ng2QPYN1VbAK6GVb3H3t1</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/aa105e0434c8649b8.output</output-file> <status>completed</status> <summary>Agent "Opus review spent-link branch" 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>**Verdict: APPROVE.** I only read `git diff ac40eb5b a92358ee` and ran no tests, as asked. All five fixes are in and correct. - **Commit** (`demo_claim_transfer.go:680`): the spent hash is saved as 'kept' in the same transaction, before the live hash is cleared. Commit already requires a live hash, so a plain INSERT is safe. - **Retirement** (`demo_expiry.go:213`): it uses `INSERT OR IGNORE`, so the first reason wins. Once a demo is kept its live hash is gone, so a later expiry or takedown cannot overwrite 'kept'. Skipping 'claimed' is correct because the commit already wrote 'kept'. - **Lookup** (`demo_store.go:357`): it reads only the new table and returns errors only. A spent token still authorises nothing. - **Cleanup**: the `WipeDemoAbuse` and `pruneDemoClaims` changes are reverted to `main`. The comment is back to the original. Spent hashes are deleted after 30 days and then read as invalid. The table holds only the hash, reason and time, with nothing linking it to an account or host. - **Messages**: agents with an invalid token get DEMO-TOKEN again. The browser page still shows the "link is wrong" message. - **JavaScript**: the guard on the error response is in. - **Census**: `demo_spent_tokens` is registered in the claim SQL table list as a table that names no app. Two notes, neither blocking: 1. The table only allows the reasons 'expired', 'operator' and 'kept'. If a new retirement reason is added later, the retirement transaction will fail. A comment next to `retireDemoLocked` would warn whoever adds one. 2. If any dev database ran d1d84e19, it has two unused columns and an index on `demo_apps`. That code was not released, so this is probably moot.</result> <usage><subagent_tokens>89406</subagent_tokens><tool_uses>1</tool_uses><duration_ms>15502</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>byefds24d</task-id> <tool-use-id>toolu_013jR7kCjuStbTiLezVrANut</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/byefds24d.output</output-file> <status>completed</status> <summary>Background command "sleep 45; until amadan ci status carlos/platform -branch demo-claim-spent-link 2&gt;&amp;1 | head -1 | grep -q '@ a92358ee'; do sleep 30; done; while amadan ci status carlos/platform -branch demo-claim-spent-link 2&gt;&amp;1 | head -1 | grep -q 'running\|queued\|pending'; do sleep 60; done; amadan ci status carlos/platform -branch demo-claim-spent-link 2&gt;&amp;1 | head -3" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>bsmqsbasx</task-id> <tool-use-id>toolu_01NLfhas2QRAcYWrLHh5VqnL</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/bsmqsbasx.output</output-file> <status>completed</status> <summary>Background command "sleep 30; while amadan ci status carlos/platform -branch demo-claim-spent-link 2&gt;&amp;1 | head -1 | grep -q 'running\|queued\|pending'; do sleep 60; done; amadan ci status carlos/platform -branch demo-claim-spent-link 2&gt;&amp;1 | head -3" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 10.9 g CO₂e (1,319,794 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on demo-claim-spent-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/internal/console/demo_expiry.go b/internal/console/demo_expiry.go
index fc7310e83..eb761fb03 100644
--- a/internal/console/demo_expiry.go
+++ b/internal/console/demo_expiry.go
@@ -113,6 +113,9 @@ func (s *Server) expireDemoLocked(ctx context.Context, d DemoRow, now time.Time)
return s.retireDemoLocked(ctx, d, now, "expired")
}
+// retireDemoLocked's reason is "expired", "operator" or "claimed". Any other
+// reason must first be added to demo_spent_tokens' CHECK (demo_store.go), or
+// the spent-token insert fails the whole retirement transaction.
func (s *Server) retireDemoLocked(ctx context.Context, d DemoRow, now time.Time, reason string) error {
if reason != "expired" && reason != "operator" && reason != "claimed" {
return demo.ErrPolicy
diff --git a/internal/console/demo_expiry_test.go b/internal/console/demo_expiry_test.go
index 335c6b099..d702f189c 100644
--- a/internal/console/demo_expiry_test.go
+++ b/internal/console/demo_expiry_test.go
@@ -3,6 +3,7 @@ package console
import (
"bytes"
"context"
+ "database/sql"
"errors"
"net/http/httptest"
"strings"
@@ -125,8 +126,8 @@ func TestDemoPurgeRecovery(t *testing.T) {
if err = s.store.WipeDemoAbuse(t.Context(), now.Add(8*24*time.Hour)); err != nil {
t.Fatal(err)
}
- if row, err := s.store.demoByID(t.Context(), d.ID); err != nil || row.CreatingIP != "" || row.Client != "" || row.PurgedAt == 0 {
- t.Fatalf("spent tombstone lost or abuse history retained: %+v %v", row, err)
+ if _, err = s.store.demoByID(t.Context(), d.ID); !errors.Is(err, sql.ErrNoRows) {
+ t.Fatalf("history retained: %v", err)
}
in := demoTestAdmission(t, s.cfg.Demo)
in.AccountSqid = d.AccountSqid