console: dpaInForce no longer depends on slice order
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
internal/console/dpainforce.go+4 −9internal/console/dpainforce_test.go+5 −0
CI cancelled — superseded by a newer push — run details
CI log
=== gate === go: downloading go1.26.10 (linux/arm64) go version go1.26.10 linux/arm64 opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1 tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz tofu: downloaded, digest verified aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip aws: downloaded, digest verified archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip archive: downloaded, digest verified installed in /tmp/carlos-opentofu-BMMxeU .amadan/test-gate.sh go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0 go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5 go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.105.0 go: downloading github.com/benbjohnson/litestream v0.5.14 go: downloading golang.org/x/net v0.62.0 go: downloading modernc.org/sqlite v1.55.0 go: downloading golang.org/x/sys v0.49.0 go: downloading golang.org/x/crypto v0.58.0 go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0 go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2 go: downloading github.com/pierrec/lz4/v4 v4.1.22 go: downloading github.com/pion/randutil v0.1.0 go: downloading github.com/pion/transport/v4 v4.0.2 go: downloading github.com/pion/dtls/v3 v3.1.4 go: downloading github.com/klauspost/compress v1.20.2 go: downloading github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.14 go: downloading github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.23 go: downloading github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.31 go: downloading github.com/wlynxg/anet v0.0.5 go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18 go: downloading github.com/prometheus/client_golang v1.17.0 go: downloading github.com/lmittmann/tint v1.1.3 go: downloading github.com/cespare/xxhash/v2 v2.3.0 go: downloading github.com/prometheus/common v0.45.0 go: downloading github.com/prometheus/client_model v0.5.0 go: downloading github.com/prometheus/procfs v0.12.0 go: downloading google.golang.org/protobuf v1.36.10 go: downloading github.com/beorn7/perks v1.0.1 go: downloading golang.org/x/text v0.43.0 go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e go: downloading modernc.org/sqlite v1.55.0 go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0 go: downloading github.com/klauspost/compress v1.20.2 go: downloading github.com/pierrec/lz4/v4 v4.1.22 go: downloading modernc.org/libc v1.74.1 go: downloading modernc.org/libc v1.74.1 go: downloading modernc.org/memory v1.11.0 go: downloading github.com/google/uuid v1.6.0 go: downloading modernc.org/mathutil v1.7.1 go: downloading modernc.org/mathutil v1.7.1 amadan: job cancelled — a newer push superseded it
Intent
<task-notification> <task-id>a1fffac0df555cda2</task-id> <tool-use-id>toolu_018XeWykfhSmsajM74nrdo3m</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/260ddc60-0dfc-4cf8-8857-7688d6275097/tasks/a1fffac0df555cda2.output</output-file> <status>completed</status> <summary>Agent "Implement Task 4: dpaInForce" 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 (fix round 1) Commit: 634c0c5b "console: dpaPending only reports versions newer than the one in force". The stale-lock message appeared again, but `git log -1` shows the commit. Change: `dpaPending` now calls `dpaInForce` first and skips documents with ID <= the one in force. `dpaInForce` uses a `found` flag in place of the nested ID check. Tests: `go test ./internal/console -run TestDPAInForce -count=1` passes, and gofmt and vet are clean. I added your two cases: - v2 undelivered and v3 qualifies: in force 3, pending nil. - v2 qualifies and v3 needs notice: in force 2, pending 3. Concerns: none. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/.superpowers/sdd/2026-11-25-dpa-acceptance/task-4-report.md</result> <usage><subagent_tokens>49400</subagent_tokens><tool_uses>2</tool_uses><duration_ms>72545</duration_ms></usage> </task-notification>
<task-notification> <task-id>a5c9cdc80909cebac</task-id> <tool-use-id>toolu_01SRDmfuxLvx2aECKJDPZ8ra</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/260ddc60-0dfc-4cf8-8857-7688d6275097/tasks/a5c9cdc80909cebac.output</output-file> <status>completed</status> <summary>Agent "Re-review Task 4 fix round 1" 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>### Findings 1. ADDRESSED: `dpaPending` now computes `dpaInForce(...).ID` first and skips every dpa document with `ID <= inForce` (dpainforce.go, new line in `dpaPending` and the changed `continue` condition). The two required cases are in `dpainforce_test.go` at the "newer qualifying version hides the older pending one" and "v2 qualifies and v3 is pending" entries. The first gives in force 3 and pending 0 (nil). The second gives in force 2 and pending 3. The report gives `go test ./internal/console -run TestDPAInForce -count=1` with `ok ... 0.031s`, plus gofmt and vet clean. The `dpaPending` logic is correct only if `dpaInForce` is correct, and see New Issues for a case where it isn't. 2. ADDRESSED, but with a regression. The nested check is replaced by a `found` flag (dpainforce.go), which reads more clearly. The new code behaves differently from the old in one case. ### New Issues in the Fix Diff - **Important, regression in `dpaInForce` (dpainforce.go, `if d.ID == accepted.DocumentID` block).** The old guard `best.ID == accepted.DocumentID` stopped the accepted document from overwriting a newer qualifying document that had already been selected. The new guard `!found` does not. The input is order-independent by contract ("docs may be in any order"). If a later qualifying document comes before the accepted one, the accepted document overwrites it. - Example: accepted 1, docs `[v2 qualifies, v1]`. The loop sets `best` to v2. It then reaches v1, `found` is false, and `best` becomes v1. The function returns 1 where the old code returned 2. - `dpaPending` calls `dpaInForce`, so it inherits the wrong answer. With docs `[v2 qualifies, v1]`, `dpaPending` would return nil. If v2 qualifies and v3 is pending, `dpaPending` would then report v2 as pending. - No table case covers this. The existing out-of-order case orders the docs 3,1,2, so the accepted document comes before the qualifying one, and the old and new code agree there. - The missing-accepted fallback is unchanged. `best` starts as a zero document carrying the accepted ID, `found` stays false, and a later qualifying document still wins because `d.ID > best.ID`. - A correct fix is to apply the accepted document only when it is newer than the current `best`. For example, `if !found && best.ID == accepted.DocumentID` would restore the old behaviour. A table case with a qualifying document listed before the accepted one should be added. ### Out-of-Scope Observations - If the docs contain duplicate IDs for the accepted document, the old code took the last one and the new code takes the first. This is unlikely to occur. ### Verdict **Fix round:** Open findings remain</result> <usage><subagent_tokens>40689</subagent_tokens><tool_uses>1</tool_uses><duration_ms>18952</duration_ms></usage> </task-notification>
Attributed to this commit: 22.7 g CO₂e (2,914,552 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/dpainforce.go b/internal/console/dpainforce.go| index dfab4cee6..84eca5778 100644 |
| --- a/internal/console/dpainforce.go |
| +++ b/internal/console/dpainforce.go |
| @@ -34,18 +34,13 @@ func dpaQualifies(d LegalDocument, accountID int64, notified noticeLookup, now t |
| // it returns a zero document carrying the accepted ID. |
| func dpaInForce(accepted DPAAcceptance, docs []LegalDocument, notified noticeLookup, now time.Time) LegalDocument { |
| best := LegalDocument{ID: accepted.DocumentID} |
| - found := false |
| for _, d := range docs { |
| - if d.Kind != "dpa" || d.ID < accepted.DocumentID { |
| + if d.Kind != "dpa" || d.ID < accepted.DocumentID || d.ID < best.ID { |
| continue |
| } |
| - if d.ID == accepted.DocumentID { |
| - if !found { |
| - best, found = d, true |
| - } |
| - continue |
| - } |
| - if d.ID > best.ID && dpaQualifies(d, accepted.AccountID, notified, now) { |
| + // The accepted document competes by ID like any other, but needs no |
| + // qualification. |
| + if d.ID == accepted.DocumentID || dpaQualifies(d, accepted.AccountID, notified, now) { |
| best = d |
| } |
| } |
diff --git a/internal/console/dpainforce_test.go b/internal/console/dpainforce_test.go| index efbb0db34..3096d817b 100644 |
| --- a/internal/console/dpainforce_test.go |
| +++ b/internal/console/dpainforce_test.go |
| @@ -57,6 +57,11 @@ func TestDPAInForce(t *testing.T) { |
| {"v2 qualifies and v3 is pending", 1, |
| []LegalDocument{doc(1, pp(past), true), doc(2, pp(past), false), doc(3, pp(past), true)}, |
| nil, 2, 3}, |
| + {"qualifying later version listed before the accepted one", 1, |
| + []LegalDocument{doc(2, pp(past), false), doc(1, pp(past), true)}, nil, 2, 0}, |
| + {"pending and qualifying listed before the accepted one", 1, |
| + []LegalDocument{doc(3, pp(past), true), doc(2, pp(past), false), doc(1, pp(past), true)}, |
| + nil, 2, 3}, |
| {"accepted v2 during v2's notice period", 2, |
| []LegalDocument{doc(1, pp(past), true), doc(2, pp(past), true)}, nil, 2, 0}, |
| {"earlier documents are ignored", 2, |