Skip to content

chore: cleanup follow-ups from #908/#911 reviews - #912

Merged
jiashuoz merged 8 commits into
mainfrom
chore/cleanup-908-911-followups
Aug 19, 2026
Merged

chore: cleanup follow-ups from #908/#911 reviews#912
jiashuoz merged 8 commits into
mainfrom
chore/cleanup-908-911-followups

Conversation

@jiashuoz

Copy link
Copy Markdown
Member

Summary

Small mechanical cleanup PR closing out the leftover findings from the two Opus reviews of #908 and #911 (both merged). Cosmetic/hygiene only — no runtime behavior change, except item 6 which changes what's reachable via errors.Is/errors.As on one error chain (no call site or test currently depends on that, confirmed below).

Re-verified every item against current main (467295318) before touching anything, since the findings were written against abb1faff5 and earlier and line numbers were stale.

Items

1. ForgetSendingIdentityManaged dead code — kept, not removed.
Confirmed zero non-test callers repo-wide (both ErrIdentityNotOwned call sites were removed by #908). I evaluated full removal (method, Store interface entry, storeAdapter shim, both fakes) first, per the task's stated preference.

Its retain/delete DB-test coverage is not actually at risk either way: TestFinalizeSendingIdentityTombstoneRetainsLedgerForLiveOwnedDomain and TestFinalizeSendingIdentityTombstoneRemovesLedgerForGenuinelyDeletedDomain in internal/identity/sender_identity_lock_test.go already pin the identical retain/delete invariant for FinalizeSendingIdentityTombstone (added in a later batch). So "folding tests" turned out to be a non-issue.

What made removal genuinely more invasive than it looked: internal/senderidentity/worker.go's two former call sites carry rationale comments that cite this method's guard by name while explaining why they must never call it, and internal/senderidentity/worker_test.go has three purpose-built regression tests (TestReconcileWorker_NotOwnedRetainsLedgerForLiveDomain, TestSyncWorker_NotOwnedRetainsLedgerForLiveDomain, TestReapWorker_GenuineDeleteStillFinalizesTombstone) that poison a fake implementation of this exact method and assert zero calls to it — built specifically to catch a reintroduced call. Removing the method would mean rewriting all of that to argue from compile-time absence instead, which is a bigger, riskier change than a hygiene pass warrants, with real risk of silently weakening deliberately-designed defense-in-depth tests.

Chose the fallback: kept the method, rewrote its doc comment (internal/identity/store.go) to state plainly it has no callers, why it's kept anyway, and that any future caller must not be an ownership-failure branch. Added a matching one-line pointer on the Store interface entry in worker.go.

2. Stale "Forget" comments in worker.go — fixed 3 (plus one analogous instance not explicitly called out but the same category): the removed-call-site example in reconcileProviderIdentity's closing comment, "out before Forget" → "out before FinalizeSendingIdentityTombstone", and "same rule as the two branches above ... Forget/MarkApplied" (that comparison no longer holds — the two ownership branches have no follow-on store call anymore — so it's dropped and the actual calls named).

3. Doc drift in docs/design/sender-identity-mailfrom.md:

  • accountIDFromCallerIdentityalready fixed, zero occurrences anywhere in the repo. No change needed.
  • "BATCH A fix" → reworded to "the adoption work above."
  • "An earlier draft of this amendment claimed..." narration → rewritten to state the current position directly (same substance).
  • Step 5 was actively wrong ("audit and tag it explicitly") now that adoption tags matching identities automatically — reconciled steps 1–3 (marked optional, with a lead-in explaining why) and rewrote step 5 to point at the ALERT log instead of prescribing a manual tag.
  • Added the ARN-partition derivation to the Verification section (it had test coverage the doc never mentioned).

4. Two (really three) ses_test.go stubs passing for the wrong reasonTestSESProvider_ProvisionRefusesForeignConfiguration's two subtests and TestSESProvider_StatusRefusesMismatchedSelector built DkimAttributes without Status: DkimStatusSuccess, so canAdoptIdentity's DKIM-SUCCESS gate could pass the test even with the named guard deleted. Added the missing Status. Verified by mutation: temporarily disabled the foreign-config guard → TestSESProvider_ProvisionRefusesForeignConfiguration failed as expected (both subtests); temporarily disabled the selector-match guard → TestSESProvider_StatusRefusesMismatchedSelector failed as expected. Both restored; full suite green.

5. TestReapWorker_GenuineDeleteStillFinalizesTombstone comment overstated what it proves — fixed comment only, no assertion changes, per the task's instruction.

6. Inconsistent error-wrapping in ses.goadoptIdentity's account-id-unavailable wrap used %w: ...: %v (making the underlying error unreachable via errors.Is/errors.As) while classifyAdoptionError deliberately double-wraps a few lines below. Switched to %w: ...: %w for consistency. Confirmed no test or call site depends on the original being unreachable: TestSESProvider_AdoptionDegradesWhenAccountIDUnavailable and TestSESProvider_AccountIDResolutionCachesOnlySuccess only assert errors.Is(err, ErrIdentityNotOwned), never against the wrapped resolver error.

7. go mod tidy — one-line diff as predicted: github.com/aws/smithy-go moved from indirect to direct (it's imported directly by ses.go for smithy.APIError). go.sum unchanged.

8. gofmtinternal/senderidentity/fakestore_test.go had two doc comments (immediately preceding a func decl) writing SQL's empty-string literal as two adjacent straight quotes (''); Go's doc-comment reformatter collapses that specific adjacent pair into a single stray Unicode right-double-quote character. Switched to "", which the reformatter leaves alone. Confirmed the several other gofmt-dirty files in the repo (internal/agent/..., internal/limits/..., internal/oauth/..., internal/outbound/compose.go, internal/webhook/ssrf_test.go, internal/webhookpub/outbox_integration_test.go) are pre-existing on main, not touched here.

Verification

go build ./...                                                            # clean
go vet ./internal/senderidentity/... ./internal/identity/...              # clean
gofmt -l ./internal/senderidentity ./internal/identity                    # clean
go test ./internal/senderidentity/... -count=1                            # ok
go test ./internal/identity/ -run 'SendingIdentity|Tombstone|Forget|Managed' -count=1   # ok

Per instructions, did not run the full ./internal/identity/... suite (known-unreliable, DB-shared, baseline-required).

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

Jace and others added 8 commits August 19, 2026 11:29
github.com/aws/smithy-go is imported directly by internal/senderidentity/ses.go
(for smithy.APIError) but was still listed // indirect in go.mod. go mod tidy
moves it to the direct require block; no other changes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two doc comments (immediately preceding a func declaration) wrote SQL's
empty-string literal as two adjacent straight single quotes ('') Go's
doc-comment reformatter collapses that specific adjacent pair into a single
Unicode right-double-quote character, which is what gofmt -l was flagging.
Switch to double quotes (""), which the reformatter leaves alone, so the
comment still reads as the intended SQL literal instead of a mangled
character. Confirmed unrelated to main: the same gofmt run on main shows
several pre-existing non-clean files elsewhere in the repo that this PR does
not touch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… error

adoptIdentity's account-id-unavailable wrap used %w for ErrIdentityNotOwned
but %v for the underlying resolveIdentity error, making that error
unreachable via errors.Is/As — unlike classifyAdoptionError's deliberate
double-%w a few lines below, which exists specifically so both the sentinel
and the original error stay reachable. Match that idiom here too.

Confirmed no test or call site depends on the original error being
unreachable at this call site: TestSESProvider_AdoptionDegradesWhenAccountIDUnavailable
and TestSESProvider_AccountIDResolutionCachesOnlySuccess only assert
errors.Is(err, ErrIdentityNotOwned), never against the wrapped resolver
error, and both still pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
TestSESProvider_ProvisionRefusesForeignConfiguration (both subtests) and
TestSESProvider_StatusRefusesMismatchedSelector built their DkimAttributes
without Status: DkimStatusSuccess, so canAdoptIdentity's DKIM-SUCCESS gate
(checked before the selector match, and — for these three stubs — before
the foreign-configuration/selector guard the test names claim to cover) was
what actually refused adoption in each case; the guard the test name
advertises was never exercised. TestCanAdoptIdentity's truth table already
covers each guard directly, so this was an overclaim, not a coverage hole.

Add Status: sestypes.DkimStatusSuccess to all three stubs so each now fails
for the reason its name states. Verified by mutation: temporarily disabling
the foreign-configuration guard failed
TestSESProvider_ProvisionRefusesForeignConfiguration (both subtests), and
temporarily disabling the selector-match guard failed
TestSESProvider_StatusRefusesMismatchedSelector; both guards restored
afterwards and the full internal/senderidentity suite is green.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…zesTombstone's doc comment

The comment claimed the ForgetCalls/FinalizeTombstoneCalls assertion
disambiguates two live call sites (deletion vs. ownership-failure) inside
syncProviderIdentityWithInspection. ForgetSendingIdentityManaged has zero
production callers (both were removed by #908), so there is only one live
deletion path here — the ForgetCalls check is defense-in-depth, not evidence
of picking between two branches that both actually run. The
FinalizeTombstoneCalls assertion and the independent prov.List() evidence
still carry their original value; only the comment's framing changes, not
the test's assertions.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ents

Three (plus one analogous) comments illustrated 'fire before the error
check' rationale with call sites that no longer exist or no longer apply,
left over from #908 removing both ErrIdentityNotOwned handlers' calls to
ForgetSendingIdentityManaged:

- reconcileProviderIdentity's closing comment cited '(e.g. the ledger Forget
  after a not-owned failure)' as the example of a later store call that
  could fail — that call site is gone, and no later store call remains in
  this function's ownership-failure branch to serve as a replacement
  example, so the stale example is dropped and the general rule kept.
- The no-key branch's 'out before Forget' now precedes
  FinalizeSendingIdentityTombstone, not Forget.
- syncProviderIdentityWithInspection's provision-branch comment claimed
  'same rule as the two branches above' (the two ErrIdentityNotOwned
  branches) — those branches no longer have any store call following their
  out-assignment, so there's nothing left to draw the comparison to; the
  comparison is dropped and 'Forget/MarkApplied' corrected to the calls that
  actually follow (FinalizeSendingIdentityTombstone or
  MarkSendingIdentityApplied).
- The function's closing comment had the same stale '(e.g. the ledger
  Forget)' example; corrected the same way.

No behavior change - comments only.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…as intentionally-retained dead code

After #908 removed both ErrIdentityNotOwned call sites in
internal/senderidentity/worker.go, ForgetSendingIdentityManaged has zero
non-test callers repo-wide. Its doc comment still claimed "Only the
ErrIdentityNotOwned handlers in internal/senderidentity/worker.go call
this" - a relationship that no longer holds.

Evaluated removing the method, its Store interface entry, the storeAdapter
shim, and the two fakes (folding its retain/delete DB test coverage into
FinalizeSendingIdentityTombstone's equivalents, which already exist:
TestFinalizeSendingIdentityTombstoneRetainsLedgerForLiveOwnedDomain and
TestFinalizeSendingIdentityTombstoneRemovesLedgerForGenuinelyDeletedDomain
in internal/identity/sender_identity_lock_test.go already pin the same
retain/delete invariant for Finalize, so the DB-test coverage question is
moot either way). Chose to keep it instead: removal would also require
rewriting several rationale comments in internal/senderidentity/worker.go's
two former call sites (which cite this method's guard by name while
explaining why they must never call it) and restructuring three
purpose-built regression tests in internal/senderidentity/worker_test.go
(TestReconcileWorker_NotOwnedRetainsLedgerForLiveDomain,
TestSyncWorker_NotOwnedRetainsLedgerForLiveDomain,
TestReapWorker_GenuineDeleteStillFinalizesTombstone) that poison a fake
implementation of this exact method and assert zero calls to it, existing
specifically to catch a reintroduced call. That's a larger, riskier change
than this method's own dead-code status warrants in a hygiene-only PR, and
risks silently weakening tests that were deliberately designed as
defense-in-depth against reintroducing the original incident.

Rewrote the doc comment on *Store.ForgetSendingIdentityManaged instead to
state plainly: it has no current callers, why it's kept anyway, and that
any future caller must not be an ownership-failure branch. Added a matching
one-line pointer on the Store interface entry in worker.go. No behavior
change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- accountIDFromCallerIdentity was already renamed to
  identityFromCallerIdentity repo-wide (no occurrences of the old name
  remain) - nothing to fix there, confirmed by grep.
- "deliberately out of scope for the BATCH A fix" used an internal
  review-batch label meaningless in a permanent doc; reworded to
  "deliberately out of scope for the adoption work above."
- The step-4 IAM-hardening paragraph narrated its own revision history ("An
  earlier draft of this amendment claimed... that framing is now only half
  true... the way the original doc implied... the way the original phrasing
  suggested"); rewritten to state the current position directly, same
  substance.
- Reconciled the numbered "Upgrading an existing installation" list with the
  amendment above it, which described automatic per-domain adoption but
  never fed back into the steps themselves:
  - Added a lead-in before step 1 noting steps 1-3 (the original manual
    export/review/tag pass) are no longer required for anything
    canAdoptIdentity adopts automatically, and are now only useful for
    pre-emptive tagging or exclusion before the IAM lockdown in step 4.
  - Step 5 previously said an untagged legacy identity at that point "fails
    closed... audit and tag it explicitly" - actively wrong now that
    automatic adoption already tags matching identities inline. Rewrote it
    to explain that a remaining untagged identity is now either genuinely
    foreign or simply hasn't had a poll cycle yet, and to point at the
    ALERT log line that distinguishes which.
- Added the ARN-partition derivation (arnPartition / identityFromCallerIdentity's
  partition handling) to the Verification section, next to the account-id
  resolution paragraph it belongs beside; it had unit coverage
  (TestIdentityFromCallerIdentity,
  TestSESProvider_AdoptIdentityUsesResolvedPartitionInARN) that the doc
  never mentioned.

No code changes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jiashuoz
jiashuoz merged commit 725a4a5 into main Aug 19, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant