Skip to content

API hardening & cleanup (ROAST.md architectural review) #75

Description

@MasterOfBinary

Summary

Tracker for the API/code-quality points raised in an architectural review (the abandoned ROAST.md from PR #58). Each point is annotated with its current status on master (66070eb) so the still-live items are actionable and the already-fixed ones are recorded.

Tone of the original was deliberately harsh ("a grumpy senior staff engineer"); the substance is summarized neutrally below.

Status of each point

# Critique Status
1 Item.Data was interface{} everywhere → no compile-time type safety Fixed — generics migration (#60); master is Batch[T], New[T any].
2a A whole goroutine + buffered channel (doIDGenerator, b.ids, IDBufferSize) just to increment a counter In progress — open PR #64 replaces it with an inline sync/atomic counter and removes the IDBufferSize API.
2b ExecuteBatches locks a mutex per error (batch/helpers.go:119) ⚠️ Still live — collect errors in a local slice per goroutine and append once.
3 IgnoreErrors spawns a goroutine that leaks if the channel never closes; errors.go hand-rolls Unwrap() 🟡 Partialmaster now nil-guards the channel (avoids the nil-channel leak); the "never-closed channel" case is caller-owned. Revisit Unwrap vs %w if desired.
4 fixConfig silently mutates input (MinItems: 01, batch/batch.go:453) ⚠️ Still live — prefer validating and returning an error (or a documented default) over silent rewrite. Tracked jointly with the resource-limits + config-validation issue.
5 batch.Batch stutters; core API could live in root gobatch so callers write gobatch.New() 🟡 Design decision — would be a breaking rename; reasonable for a v0 but needs a deliberate call.
6a New returns *Batch (concrete) rather than an interface, hurting mockability 🟡 Design decisionmaster: func New[T any](config Config) *Batch[T].
6b Library panics instead of erroring: WithBufferConfig after Go() (batch.go:113) and concurrent Go() (batch.go:240) ⚠️ Still live — APIs should be hard to misuse, not booby-trapped: return errors, or make buffer config immutable at construction (functional options).

Actionable items (still live)

  • 2b — Stop locking per-error in ExecuteBatches; accumulate locally, merge once.
  • 4 — Validate config instead of silent mutation (with the resource-limits/validation work).
  • 6b — Replace library panics with returned errors and/or immutable-at-construction config.
  • (optional) 3 — Reconsider IgnoreErrors contract / use fmt.Errorf("%w", …).
  • (optional) 5 / 6a — Decide on package/type naming and concrete-vs-interface return as part of the path to v1.

Source (for recovery — branch is being deleted)

roast-codebase-7386035102356312858 @ PR #58 (ROAST.md). PR is closed but its diff remains viewable.


Related: #73 (resource limits + config validation — point #4 lands there)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions