Skip to content

Go refactoring 2#2392

Merged
agbishop merged 182 commits into
mainfrom
go-refactoring-2
Jul 18, 2026
Merged

Go refactoring 2#2392
agbishop merged 182 commits into
mainfrom
go-refactoring-2

Conversation

@agbishop

Copy link
Copy Markdown
Collaborator

No description provided.

Witness Patrol and others added 25 commits July 16, 2026 10:59
…mes), drop nolint

Pure reorganization, behavior identical (verbatim AST moves). backend.go (2621) + backend_ops/
agents/agents_batch3 + handler.go (2747) split into 51 op-family files using the new naming
(store.go core, models.go, errors.go, <family>.go for logic, handler_<family>.go for HTTP;
ZERO 'backend' in filenames; max 747). 18 goofy test files (batch1/accuracy*/ops_batch2_audit/
parity_a-b/agents_batch3) -> 37 family test files + test_helpers_test.go (340 tests preserved).
Refactored 5 funlen/cyclop/gocyclo nolints (Reset, ExtractOperation, dispatch*) into helpers.
Zero new nolint. Whole package green (build/test-race/vet/fix/gofmt/lint 0 issues).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… names), drop nolint

Pure reorganization, behavior identical (verbatim AST moves). backend.go (3887) + handler.go
(4083) + proxy.go (1963) split into 62 op-family files (store.go, models.go, errors.go,
<family>.go, handler_<family>.go, proxy_<concern>.go; ZERO 'backend' in filenames; max 856).
backend_destub/handler_stubs absorbed. 12 goofy test files (accuracy_*/apigw_batch2/boost/
destub/parity_*/coverage) -> 22 family test files (265 tests preserved). Removed funlen +
refactored 9 gocognit-flagged action dispatchers into named methods; removed 2 stale dupl.
Zero new nolint. Whole package green (build/test-race/vet/fix/gofmt/lint 0 issues).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; trust-policy/JWT/SAML logic
untouched). backend.go (2156) + backend_accuracy + trustpolicy + tokenvalidation + handler.go
(829) split into op-family files (store.go, errors.go, models.go, <family>.go,
handler_<family>.go; ZERO 'backend' in filenames; max 612). ~13 goofy test files (batch2_audit/
accuracy/refinement1-4/new_operations/new_ops2/parity_*) -> 22 family test files (0 cases
lost). No funlen/gocyclo nolints (none existed); zero new nolint. Whole package green
(build/test-race/vet/fix/gofmt/lint 0 issues).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; ASL interpreter untouched).
backend.go (2683) + handler.go (1452) split into op-family files (store.go, errors.go,
interfaces.go, <family>.go, handler_<family>.go; ZERO 'backend' in filenames; max 762).
13 goofy test files (accuracy_audit/batch1-2_audit/coverage*/new_operations/parity_*/
refinement1/comprehensive) -> family test files (cases preserved). No funlen/gocyclo nolints
(none existed); zero new nolint. Whole package green (build/test-race/vet/fix/gofmt/lint).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; retention-period idempotent fix
preserved). backend.go (2410) + handler.go (2195) + types.go->models.go (592) split into
39 op-family files (store.go, interfaces.go, <family>.go, handler_<family>.go; ZERO 'backend'
in filenames; max 592). 14 goofy test files (parity_*/coverage_ops/batch7/reshard/
accuracy_batch2/refinement1-3/audit2/new_ops) -> 21 family test files (cases preserved).
Fixed one mis-attached doc comment (cosmetic). No funlen/gocyclo nolints (none existed); zero
new nolint. Whole package green (build/test-race/vet/fix/gofmt/lint).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim AST moves; XML/query wire shapes preserved).
backend.go (1467) + missing_ops.go (1085) + handler.go (2872) split into 26 op-family files
(store.go, models.go, errors.go, <family>.go, handler_<family>.go; ZERO 'backend' in
filenames; max 804). 13 goofy test files (coverage_boost/accuracy*/batch2/new_ops/refinement1/
parity_*) -> family test files (344 tests preserved, 184 goofy prefixes stripped). No
funlen/gocyclo nolints (none existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…wed size 0)

DescribeTable's TableSizeBytes/ItemCount read table.totalItemSizeBytes/itemSizes correctly,
but the BatchWriteItem paths (handleBatchPutWithIndex, applyBatchDeletes) never updated those
parallel bookkeeping slices — only doPut/deleteItemAtIndex did. So a table seeded via
BatchWriteItem (the common bulk path) reported TableSizeBytes:0 forever (dashboard 'size 0'
with 40 items), and the itemSizes/Items slices could drift out of length-sync -> latent
index-out-of-range risk (incl. global-table replica cloning). Fix: batch put/delete now keep
itemSizes + totalItemSizeBytes in lockstep via the existing CalculateItemSize helper, mirroring
doPut/deleteItemAtIndex. All under the existing table.mu.Lock; no lock-order change.
+TestDescribeTable_BatchWriteItem_TableSizeBytesMatchesItems (fails pre-fix). Fixes gopherstack-0mtk.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; KMS sealing/crypto untouched).
backend.go (3037) + handler.go (632) split into op-family files (store.go, errors.go,
<family>.go, handler_<family>.go; ZERO 'backend' in filenames; max 774). 17 goofy test files
(accuracy*/audit_sm/batch1_audit/new_ops/parity_*/refinement1-2) -> clean per-op-family test
files + helpers_test.go (1547 assertions preserved). Table-driven consolidations (cron/random
password/resource policy). No funlen/gocyclo nolints (none existed); dupl fixed via generic
decodeAction helper; zero new nolint. Whole package green.

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

Regression coverage for enforceBucketRegion / cross-region 301 PermanentRedirect + global
ListBuckets (previously zero coverage). Investigation of the dashboard S3 'select a region'
bug (gopherstack-pejf) proved the Go transport is correct: ListBuckets is global,
cross-region access returns 301 + X-Amz-Bucket-Region, CreateBucket threads region properly,
and config.DefaultRegion is us-east-1 (not ap-southeast-1). The bug lives in the compiled
SvelteKit frontend's client-side region reactivity (not in this repo's Go source).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (3352) + handler.go
(1950) + models.go (1034) split into op-family files (store.go, errors.go, interfaces.go,
<family>.go, models_<family>.go, handler_<family>.go; ZERO 'backend' in filenames; max 745).
10 goofy test files (parity_a/accuracy_batch2/refinement1/3/new_ops/coverage*/audit1/2/2b)
-> 33 family test files (296 tests preserved); stripped goofy Test prefixes. No funlen/gocyclo
nolints (none existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (1337) + backend_new_ops
(629) + backend_remaining_ops (1456) + handler.go (2152) + handler_remaining_ops (1134) split
into op-family files (store.go, models.go, errors.go, helpers.go, <family>.go,
handler_<family>.go; ZERO 'backend' in filenames; max 529). 8 goofy test files (coverage/
accuracy/audit2/new_ops/refinement1/parity/batch1-2_accuracy) -> family test files (245 tests);
stripped goofy Test prefixes. Refactored CreateCluster to drop 1 nolint:funlen. Zero new
nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; XML/query + rpcv2cbor wire shapes
preserved). backend.go (3406) + backend_accuracy (531) + handler.go (2966) + rpcv2cbor.go
(2275) split into 55 op-family files (store.go, models.go, errors.go, <family>.go,
handler_<family>.go, rpcv2cbor_<family>.go; ZERO 'backend' in filenames; max 919). 10 goofy
test files (accuracy/batch1-2/audit_cw/coverage*/parity) -> 30 family test files (357 tests);
stripped goofy Test prefixes; table-driven consolidations. No funlen/gocyclo nolints (none
existed); zero new nolint. Whole package green.

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

Pure reorganization, behavior identical (verbatim moves) + one required
refactor. backend.go (2952) + handler.go (2231) split into one file per
op-family: store.go, models.go, errors.go, interfaces.go (renamed from
backend_iface.go), docker_registry.go (renamed from registry.go), plus
repositories/layers/images/image_scanning/pull_through_cache/lifecycle_policy/
repository_creation_templates/registry_policy/replication/repository_policy/
signing/account_settings/tags.go and their handler_<family>.go counterparts.
Zero 'backend' in any filename; largest file 587 lines.

Removed the package's only nolint (cyclop on classifyError) by replacing the
~20-branch switch with a small lookup-table loop; error-code mapping is
byte-identical.

20 goofy/giant test files (parity_*, batch1/2, refinement1/2, accuracy,
audit, ops2 sweeps totaling ~12k lines) consolidated into 25 family-aligned
test files, all <=1500 lines. Stripped ~150 goofy Test-func prefixes,
deduplicated ~8 near-identical test helper constructors down to one shared
pair, converted several near-identical standalone tests into table-driven
subtests. All original test scenarios preserved (verified via a full
before/after Test-func-name diff; 5 scenarios dropped during the mechanical
split were caught and restored).

Whole package green: go build, go vet, go test -race, go fix -diff,
golangci-lint (0 issues, no new nolint), gofmt all pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; MSK tag-route MatchPriority fix
preserved: kafkaMatchPriority = PriorityPathVersioned+1). backend.go (2530) + handler.go
(3312) split into 30 op-family files (store.go, models.go, errors.go, <family>.go, routes.go,
handler_<family>.go; ZERO 'backend' in filenames; max 808). 10 goofy test files (parity_a-c/
refinement1-2/accuracy_batch2/coverage*/route_matcher_fixes) -> 24 family test files; stripped
goofy Test prefixes; 4 not-found tests folded table-driven. No funlen/gocyclo nolints (none
existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; MD5OfMessageBody + FIFO SHA256
dedup checksums + their gosec/codeql comments preserved). backend.go (3361) + handler.go
(1704) + query.go (1278) + types.go->models.go (850) split into op-family files (store.go,
errors.go, <family>.go, handler_<family>.go, query_<family>.go; ZERO 'backend' in filenames;
max 850). Goofy test files (accuracy*/coverage/refinement1/parity_*/audit_sqs/issue*) -> family
test files (362 tests preserved). Refactored dispatchQueryAction into a queryActionTable
map-dispatch to drop 1 nolint:cyclop. Zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; server OFFLINE->STARTING->ONLINE
lifecycle + cascade-delete live-verified against the running binary). backend.go (3232) +
handler.go (3477) split into op-family files (store.go, models.go, errors.go, <family>.go,
handler_<family>.go; ZERO 'backend' in filenames; max 645). Goofy test files (parity_a-b/
audit2/refinement1-2/new_ops*/accuracy) -> 27 family test files (~240 tests preserved);
stripped goofy Test prefixes. No funlen/gocyclo nolints (none existed); zero new nolint.
Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (2709) + handler.go
(1781) split into op-family files (store.go, errors.go, ids.go, arn.go, models.go,
<family>.go, handler_<family>.go; ZERO 'backend' in filenames; max 520). 15 goofy test files
(children_index/coverage_ops/audit1-3/batch2_accuracy/extra/new_ops/pagination_gaps/
refinement1) -> 22 family test files (211 tests preserved); stripped goofy Test prefixes;
2 table-driven consolidations. No funlen/gocyclo nolints (none existed); zero new nolint.
Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves, diff-verified byte-for-byte).
backend.go (3085) + handler.go (3195) split into 28 op-family files (store.go, models.go,
errors.go, <family>.go, handler_<family>.go; ZERO 'backend' in filenames; max 747). Goofy
dispatchExtended/NewOps chain renamed to per-family dispatchers (70 cases verified identical).
9 goofy test files (parity/batch1-2/refinement1-2/accuracy_batch2/coverage/failover) -> family
test files (284 tests, 11 true dups removed). No funlen/gocyclo nolints (none existed); zero
new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; Tags []Tag list, base64 File/Content,
job lifecycle advance, Directionality all preserved). backend.go (1556) + backend_accuracy
(563) + handler.go (808) + handler_ops (1146) split into op-family files (store.go, models.go,
errors.go, <family>.go, handler_<family>.go; ZERO 'backend' in filenames; max 343). 8 goofy
test files (backend/accuracy/refinement1-2/parity_a-c/validation) -> family test files (105
tests). Refactored 2 dupl nolints via generic applyListOrURI helper. Zero new nolint. Whole
package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (1390) + handler.go
(666) split into op-family files (store.go, errors.go, validation.go, <family>.go,
handler_<family>.go; ZERO 'backend' in filenames; max 501). 11 goofy test files (lifecycle_
parity/ops_batch2_audit/aws_parity/parity_pass1/audit_batch1-2/refinement1/accuracy/new_
operations) -> family test files (273 tests, 12 dups merged). No funlen/gocyclo nolints (none
existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (1163) + handler.go
(1624) split into op-family files (store.go, models.go, errors.go, validation.go, <family>.go,
handler_<family>.go; ZERO 'backend' in filenames; max 338; batch_load_tasks.go is a legit
op-family). 9 goofy test files (accuracy/accuracy2/batch2_accuracy/refinement1-3/parity_a-b)
-> family test files (213 tests, 9 dups removed). No funlen/gocyclo nolints (none existed);
zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (2250) + handler.go
(1096) split into op-family files (store.go, models.go, errors.go, delivery_streams.go,
records.go, delivery_<dest>.go, flush.go, <family>.go, handler_<family>.go; ZERO 'backend'
in filenames; max 588). 8 goofy test files (audit_firehose/parity_a-b/parity_firehose/
accuracy/accuracy_batch2-3/refinement1) -> family test files; stripped goofy Test prefixes.
No funlen/gocyclo nolints (none existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves; SHA256 tree-hash logic preserved).
backend.go (1439) + handler.go (2110) split into op-family files (store.go, models.go,
errors.go, interfaces.go, <family>.go, handler_<family>.go; ZERO 'backend' in filenames;
max 756). 11 goofy test files (wire_parity/parity_b/ops_audit/refinement1-2/accuracy*/new_
ops/deepen) -> 22 family test files (194 tests, 1 dup removed). No funlen/gocyclo nolints
(none existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (2899) + handler.go
(2726) split into 37 op-family files (store.go, models.go, errors.go, <family>.go,
handler_<family>.go; ZERO 'backend' in filenames; max 485). 9 goofy test files (coverage_ops/
audit/new_ops/refinement1-3/parity_a-b) -> family test files (141 tests, 6 dups removed).
No funlen/gocyclo nolints (none existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim AST moves). backend.go (2219) + handler.go
(1744) + handler_missing_ops (388) split into 38 op-family files (store.go, models.go,
errors.go, <family>.go, handler_<family>.go; ZERO 'backend' in filenames; max 506). 9 goofy
test files (parity/accuracy/refinement1-2/new_ops/deepen/audit_batch1) -> 28 family test files
(236 tests, 3 dups removed). No funlen/gocyclo nolints (none existed); zero new nolint. Whole
package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread services/sqs/checksums.go Dismissed
Comment thread services/sqs/checksums.go Dismissed
Witness Patrol and others added 4 commits July 16, 2026 20:24
Pure reorganization, behavior identical (verbatim moves). backend.go (1712) + handler.go
(1378) split into op-family files (store.go, models.go, errors.go, <family>.go,
handler_<family>.go; ZERO 'backend' in filenames; max 440). 7 goofy test files (coverage_ops/
accuracy_batch2/refinement1-3/parity_b-c) -> 13 family test files (202 tests). No funlen/
gocyclo nolints (none existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (2453) + handler.go
(1305) split into op-family files (store.go, models.go, errors.go, synthetic_blocks.go,
<family>.go, handler_<family>.go; ZERO 'backend' in filenames; max 590). 7 goofy test files
(lifecycle/accuracy/audit1/ops_batch2_audit/refinement1/parity_a-c) -> family test files
(167 tests). No funlen/gocyclo nolints (none existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (1637) + handler.go
(1129) split into op-family files (store.go, models.go, errors.go, brokers.go, users.go,
configurations.go, <family>.go, handler_<family>.go; ZERO 'backend' in filenames; max 717).
9 goofy test files (accuracy/audit2/batch2_accuracy/parity_batch1/refinement1/parity_b/
parity_extension/wire_shape_fixes) -> family test files (all cases preserved, verified).
No funlen/gocyclo nolints (none existed); zero new nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure reorganization, behavior identical (verbatim moves). backend.go (2634) + handler.go
(2793) split into op-family files (store.go, models.go, errors.go, <family>.go,
handler_<family>.go; ZERO 'backend' in filenames; max 435). 8 goofy test files (audit_batch1/
coverage_boost/refinement1/new_operations/new_ops/parity_a/parity_pass5/r53r_coverage) -> 13
family test files (146 tests). Refactored buildOps into per-family opsX() to drop 1
nolint:funlen; added shared generic helpers (paginate/mapSlice/getSimpleConfig). Zero new
nolint. Whole package green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Witness Patrol and others added 3 commits July 18, 2026 07:47
Follow-up to prior cloudformation split. resources_phase2/3/4/6.go (giant, phase<N>-tagged) ->
33 resources_<service>.go files by AWS resource-family (rds, eks, iam, lambda, s3, route53, etc.);
phase dispatchers relocated into resources.go, renamed to descriptive Supplemental/Platform names.
resources_extra_test.go -> resources_supplemental_test.go. 5 giant test files (extensibility 1523,
store_and_handler_supplemental 1421, handler_http 1395, cross_feature 1296, introspection 1117)
split by sub-family (func counts verified). ZERO 'phase'/'extra' in filenames. template.go intrinsic-
eval + GeneratedTemplateNotFound convention byte-identical (untouched). resources.go/template.go/
resources_extended.go remain >1000 as legit content-named exempt files. Zero new nolint. Green.

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

Follow-up nit: the phase-cleanup split created backend_supplemental_test.go (contains 'backend');
renamed to store_direct_test.go (holds direct-backend/store-level tests; store_supplemental_test.go
already held the Backend/Persistence group). No content change. ZERO 'backend' in filenames now.

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

Final sweep cleanup: rename feature-split files that carried a goofy '_ext' suffix (missed by the
backend_-prefix rename pass since they weren't backend_-prefixed). sagemaker: automl_search_ext.go/
handler_automl_search_ext.go/training_plan_ext.go/handler_training_plan_ext.go (+_test) -> base
<family>.go names; cloudwatchlogs: filter_pattern_ext_test.go -> filter_pattern_test.go. Rename
only, content verbatim, no collisions. ZERO '_ext' in filenames repo-wide now. Both packages green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@agbishop
agbishop marked this pull request as ready for review July 18, 2026 13:42
Witness Patrol and others added 24 commits July 18, 2026 08:51
Convert manual mutex unlocks to defer (held-to-end) or locked
closures (early-release/find-then-release/gather-then-process) so a
panic mid-critical-section can no longer leak a held lock and deadlock
the service via PanicRecovery. Lock scope, ordering, and op-name args
are byte-identical; the bucket->obj lock handoff in
commitMultipartObject is preserved. No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Convert manual mutex unlocks to defer (held-to-end) or locked closures
(early-release/gather-then-process) so a panic mid-critical-section can
no longer leak a held lock and deadlock the service via PanicRecovery.
getOrCreateRuntime keeps its rt.mu ownership handoff to
handleContainerStartFailure via a deferred guarded unlock; multi-branch
manual unlocks (CreateFunctionURLConfig) collapse to a single deferred
path. Lock scope, ordering, and op-name args are byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wrap the held-across-work lock regions in defer-based closures so a
panic mid-critical-section cannot leak the lock and deadlock the service:
stepfunctions StartExecution/RedriveExecution (lock held across asl.Parse
+ table writes), storeMapRun; iam Restore (lock held across registry
reset/restore + index rebuild). Also fixes a latent nil-deref in
RedriveExecution's result copy (discarded comma-ok ok). Remaining manual
unlocks in these services were verified panic-free (safemap/map-read/tag
ops only). Lock scope, ordering, op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Convert manual mutex unlocks to defer/closure so a panic mid-critical-
section can no longer leak a held lock and deadlock the service. Notable:
sns CreatePlatformEndpoint (lock held across strings.Split + slice
indexing) and Publish/PublishSMS; sqs move-task and janitor loops use
per-iteration closures to avoid defer-in-loop lock accumulation.
Remaining manual unlocks verified panic-free (store.Table/safemap map
ops, guarded Split index). Lock scope, ordering, op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Convert manual mutex unlocks to defer/closure so a panic mid-critical-
section can no longer leak a held lock and deadlock the service. Fixes
real latent panics now inside defer-protected regions: eventbridge
b.eventLog reslice (deliverScheduledRule, PutEvents) and a nil-pointer
deref of *b.deliveryTargets; ecs RunTask/StopTask/StartTask hold b.mu
across arn.Build + task helpers. Provably-safe regions (tags, time-only)
left as-is. Lock scope, ordering, op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Convert manual mutex unlocks to defer/closure so a panic mid-critical-
section cannot leak a held lock and deadlock the service. cloudwatch
PutMetricData/EvaluateAlarms/SetAlarmState/insight-rule reports; sts
session store/lookup/validate/evict. Where a second lock acquisition
follows (sts storeSession/Reset), a closure is used instead of defer to
avoid widening lock scope. Provably-safe regions (tags, single field
reads) left as-is. Lock scope, ordering, op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Convert manual mutex unlocks to defer/closure so a panic mid-critical-
section cannot leak a held lock and deadlock the service. athena
StartQueryExecution (randomID string index) and janitor delete phases
(Delete does group[len-1] slice index); sesv2 SendEmail /
SendCustomVerificationEmail (b.emails reslice) and ListEmailIdentities.
Remaining manual unlocks verified panic-free (tableData/queryResults are
maps, maps.Copy into fresh maps, Table.Get). Lock scope/order/op-names
byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Convert manual mutex unlocks to defer/closure so a panic mid-critical-
section cannot leak a held lock and deadlock the service. kinesis
sweepRetention (ring-buffer trimBefore indexing), Reset/Purge/DeleteStream
(Tags.Close can panic on Prometheus registration mismatch) — DeleteStream
keeps its b.mu->stream.mu handoff via a conditional defer; textract
Start*/CreateAdapterVersion multi-branch job-start regions. Remaining
manual unlocks verified panic-free. Lock scope/order/op-names identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Convert manual mutex unlocks to defer/closure so a panic mid-critical-
section cannot leak a held lock and deadlock the service. cloudwatchlogs
PutLogEvents (classify/append/filter slice work), sweepRetention,
CreateExportTask, StartQuery; fis StartExperiment/StopExperiment/
sweepCompletedExperiments (Table.Put/Delete drive Index slice ops).
Provably-safe regions (map reads, slice-header copies) left as-is. Lock
scope/order/op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Convert manual mutex unlocks to defer/closure so a panic mid-critical-
section cannot leak a held lock and deadlock the service. firehose
Create/DeleteDeliveryStream (tags.New/Tags.Close reach Prometheus and can
panic), PutRecord/PutRecordBatch; rds Create/Delete/Restore DBInstance
(multi-branch, slices.DeleteFunc), RebootDBCluster, SetDNSRegistrar.
Provably-safe regions (single field reads, guarded event-log reslice,
store.Table map ops) left as-is. Lock scope/order/op-names identical.

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

Wrap lock regions that hold across panic-capable work so a panic cannot
leak the lock and deadlock the service: verifiedpermissions authorization
(Cedar policy parse on user input), amplify advanceDomains (SubDomains
slice loop), dax Snapshot (registry.SnapshotAll -> json.Marshal).
Provably-safe regions (store.Table/map ops) left as-is. batch verified
already safe. Lock scope/order/op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wrap lock regions holding across panic-capable work: glue StopReconciler
(close(channel) can panic), StartTrigger; ses StartWorker; acm Reset
(Tags.Close reaches Prometheus). ec2 verified already panic-safe (Table
map ops, builtin delete). Provably-safe regions left as-is. Lock scope/
order/op-names byte-identical.

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

Wrap lock regions holding across panic-capable work; convert held-to-end
to defer. Fixes a real iot GetRegistrationCode bug: a defer RUnlock()
rebalanced across a write-lock region would fire on the wrong lock type
(fatal on sync.RWMutex) if the body panicked — restructured into two
self-contained regions. secretsmanager sweepExpiredSecrets (Tags.Close
reaches Prometheus). directoryservice verified already safe. Lock scope/
order/op-names byte-identical.

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

Wrap lock regions holding across panic-capable work: apigateway
UpdateUsage/ImportDocumentationParts (multi-branch collapse), acmpca
Reset (Tags.Close reaches Prometheus)/ListCertificateAuthorities,
cloudformation ExecuteChangeSet (handoff) and Wait (notifiers slice
index/reslice). ssm/appconfigdata/backup verified already safe (Table
map ops only). Lock scope/order/op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wrap lock regions holding across panic-capable work: kms sweepExpiredKeys
(heap.Pop does raw slice indexing), sagemaker Shutdown (stored CancelFunc)
and labeling toInProgress (labelingJobsStore -> store.Register panics on
duplicate). support/timestreamquery/appsync/cognitoidp/emr verified
already safe (Table/Index map ops only). Lock scope/order/op-names
byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ns panic-safe

Wrap lock regions holding across panic-capable work: elbv2
applyHealthResults (Targets slice write), elasticache CreateCluster
(pruneRegionLocked -> Tags.Close/miniredis close), redshift StopReconciler
(close(channel)), pipes Start/Wait (doneMu multi-branch), polly
ListLexicons/StartSpeechSynthesisTask. mediaconvert/resourcegroupstaggingapi
verified already safe. Lock scope/order/op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wrap the RLock region holding across registry.SnapshotAll -> json.Marshal
(reflection can panic) in a defer-based closure so a panic cannot leak
the lock. lakeformation/opensearch/rekognition/scheduler/swf/xray verified
already panic-safe (Table/Index map ops, non-lockmetrics mutexes). Lock
scope/order byte-identical.

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

The panic-safety pass wrapped locked regions in inline closures, which
pushed several functions over funlen/gocognit and tripped fatcontext.
Extract each wrapped region into a named *Locked helper method (still
Lock();defer Unlock() inside -> panic-safe), restoring golangci-lint to 0
issues without any //nolint. Also fix post-extraction fieldalignment.
Behavior, lock scope/order/op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extract the panic-safety closures into named *Locked helper methods so
funlen/gocognit/cyclop/fatcontext/gosec pass with 0 issues and no
//nolint. sqs StartWorker+Shutdown both refactored so gosec can trace the
stored cancel field; helpers use unnamed returns (nonamedreturns).
Lock scope/order/op-names and panic-safety (defer Unlock in helpers)
byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… helpers to satisfy linters

Extract the panic-safety closures into named *Locked/collect helper
methods so gocognit/fatcontext/gosec pass with 0 issues and no //nolint.
lambda StartKinesisPoller splits storePollerCancel (direct field store so
gosec traces cancel); ses/secretsmanager StartWorker+Shutdown de-closured
so gosec follows the stored cancel field (Shutdown body is field
read/writes only -> panic-safe with plain lock). Behavior, lock
scope/order/op-names byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add startPprofServer(): when GOPHERSTACK_PPROF_ADDR is set, serve
net/http/pprof on a private mux + dedicated http.Server (ReadHeaderTimeout
set), isolated from the main echo port; fully disabled by default (empty
env). Add GOPHERSTACK_ENDPOINT escape hatch to the integration TestMain so
the suite can run against an already-running server instead of spinning a
container — used by 'make pgo' to drive load for profile capture.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Concurrent aws-sdk-go-v2 load driver against a running server: DynamoDB
table with GSI+LSI under Put/BatchWrite/Query(base,GSI,LSI)/Scan/Update/
Delete/TransactWrite churn, and S3 Put/Get/Delete/List(Objects,Versions)/
multipart across versioned+plain buckets. Flags -endpoint/-duration/
-concurrency (env fallbacks). Errors counted, never fatal. Drives the real
hot paths (index maintenance, marshaling, lockmetrics maps) so the
captured profile reflects representative usage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Two-phase profile generation (scripts/pgo.sh via 'make pgo'): phase 1
drives heavy DynamoDB(GSI+LSI)+S3 load with cmd/pgoload captured alone
(index maintenance, marshaling, map access, S3 compress/hash dominate);
phase 2 runs the integration suite for breadth; the two CPU captures are
merged into default.pgo, which go build auto-consumes. Phases are
sequential because the integration harness resets state between tests and
would otherwise wipe pgoload's data mid-run.

Adds .github/workflows/pgo.yml (weekly + manual, opens a refresh PR),
README PGO section, and .gitignore for intermediate captures. Per-PR
workflow: run 'make pgo', commit default.pgo; builds then use it.

Profile hot paths: map access ~28%, flate ~10%, md5 ~4%, dynamodb
compareStrings ~4% — representative of real DDB/S3 usage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@agbishop
agbishop merged commit 9d7e36e into main Jul 18, 2026
26 checks passed
@agbishop
agbishop deleted the go-refactoring-2 branch July 18, 2026 20:25
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.

2 participants