Skip to content

Address SDK review issues: context, type safety, and robustness#4

Merged
dmortondev merged 5 commits intomainfrom
address-review-issues
Mar 6, 2026
Merged

Address SDK review issues: context, type safety, and robustness#4
dmortondev merged 5 commits intomainfrom
address-review-issues

Conversation

@dmortondev
Copy link
Copy Markdown
Collaborator

Summary

  • Add context.Context to all Plugin methods — non-streaming methods now accept context as their first parameter, aligning with Go conventions and enabling cancellation/timeout propagation
  • End-to-end api.JobID type safetyJob.ID changed from string to api.JobID, and cache/conformance/plugintest APIs updated to match, eliminating friction from back-and-forth conversions
  • Improve robustness of SDK internals — replace goto-poll loops with idiomatic for+select, add panic recovery in cache goroutine, fix file handle leak in logger, close race window in RunningJobContext, handle previously-discarded JSON unmarshal errors
  • Fix documentation errors — correct Go version (1.25 → 1.24), fix incorrect WithMemory() reference, update .gitignore
  • Update CHANGELOG.md with all unreleased changes

Breaking Changes

All changes are documented in CHANGELOG.md under [Unreleased]:

  • context.Context added as first param to SubmitJob, GetJob, GetJobs, ControlJob, GetJobNetwork, ClusterInfo, Bootstrap, GetClusters
  • Job.ID type changed from string to api.JobID
  • Cache public methods now accept api.JobID instead of string
  • Conformance and plugintest helpers updated to use api.JobID

Test plan

  • just ci passes (lint, fmt, test, build, build-examples)
  • just test-race passes with no data races
  • Conformance suite passes with updated type signatures
  • Examples build and run correctly with new API

Non-breaking internal changes only; no public API modifications.

- Replace goto poll with idiomatic for+select loops (5 locations)
- Add panic recovery to cache background goroutine
- Use non-blocking channel sends to prevent deadlocks under load
- Fix file handle leak in logger when debug log creation fails
- Close race window in RunningJobContext with post-subscribe recheck
- Handle JSON unmarshal error in requestFromJSON instead of discarding
- Add nil guards to stream ResponseWriter methods
- Convert Prune to range-over-func syntax and remove stale TODOs
Breaking changes to improve API consistency:

- Add context.Context as the first parameter to all non-streaming Plugin
  methods (SubmitJob, GetJob, GetJobs, ControlJob, GetJobNetwork,
  ClusterInfo), plus Bootstrap and GetClusters on extension interfaces.
  Streaming methods already accepted context.

- Change cache package public methods (Lookup, Update, WriteJob,
  RunningJobContext, StreamJobStatus) to accept api.JobID instead of
  string, providing type safety at API boundaries. Internal store keeps
  string; conversions happen at the cache layer.

- Document Error.Is() sentinel-style matching, ResponseWriter error
  return semantics, and WriteJob/WriteJobs coupling rationale.

Update all implementations, conformance suite, examples, and docs.
Job.ID was left as `string` when api.JobID was introduced at the
Plugin interface and cache boundaries (6e2b237). This created a
friction point: plugin authors received api.JobID from interface
methods but had to convert back and forth with Job.ID as string.

Since api.JobID is a named string type, JSON serialization, literal
assignments, and format verbs all work unchanged. The only new
conversions are api.JobID(...) at ID generation sites and string(...)
at the internal cache→store boundary.

Simplifications:
- Remove 6 api.JobID(job.ID) casts in cache, conformance, examples
- Remove 2 api.JobID(id) casts where id was already typed

New conversions:
- api.JobID(fmt.Sprintf(...)) at 2 ID generation sites
- string(job.ID) at 2 cache→store boundary calls

Public API changes in conformance/ and plugintest/:
- SubmitJob returns api.JobID (was string)
- GetJob, ControlJob, WaitForStatus, WaitForTerminalStatus,
  CollectOutputStream accept api.JobID for id param
- FindJobByID, AssertJobID, NewJobWithID, WithID accept api.JobID
- README.md: correct Go version requirement from 1.25 to 1.24
- CONTRIBUTING.md: fix nonexistent WithMemory() to WithLimit()
- .gitignore: add built binaries in root and cmd/smoketest
@dmortondev dmortondev merged commit 520f684 into main Mar 6, 2026
11 checks passed
@dmortondev dmortondev deleted the address-review-issues branch March 6, 2026 01:20
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