mpyw / mpyw/goroutinectx

Refactor: Deduplicate gotask API definitions

Open
#20 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
0
Forks
0
Avg merge
8h 5m
Merged PRs (30d)
12

Description

Problem

The gotask API list is defined in two separate locations with similar but slightly different metadata:

1. internal/apis.go - RegisterGotaskAPIs() (lines 71-89)
  • Purpose: Used by spawnerlabel checker for spawner label validation
  • Called from: analyzer.go:123
  • Data structure: registry.Entry with AlwaysSpawns field
  • APIs registered: DoAll, DoAllSettled, DoRace, DoAllFns, DoAllFnsSettled, DoRaceFns, Task.DoAsync, CancelableTask.DoAsync
2. internal/checkers/gotask.go - GotaskChecker.entries (lines 53-65)
  • Purpose: Used by gotask checker for context propagation validation
  • Called from: analyzer.go:196-200
  • Data structure: gotaskEntry with Variadic and IsDoAsync fields
  • APIs registered: Same list as above

Issues

  1. DRY violation: The same API set is maintained in two places
  2. Maintenance burden: Adding/removing gotask APIs requires changes in both locations
  3. Inconsistency risk: The two lists could drift apart over time

Key Differences

While both define the same API set, they have different metadata requirements:

Aspect RegisterGotaskAPIs GotaskChecker.entries
DoAsync CallbackArgIdx Not specified 0 (explicit)
Metadata fields AlwaysSpawns Variadic, IsDoAsync
Purpose Spawner label detection Context propagation checking

Proposed Solution

Create a unified gotask API registry that both checkers can consume:

  1. Define a single source of truth for gotask APIs (e.g., internal/gotask/apis.go)
  2. Provide adapter functions to convert to checker-specific formats:
    • ToRegistryEntries() → for spawnerlabel checker
    • ToGotaskEntries() → for gotask checker
  3. Update both checkers to use the unified registry

This would maintain flexibility for checker-specific metadata while eliminating duplication.

Alternative

If the metadata requirements are too divergent, document why the duplication is necessary and add validation to ensure both lists stay in sync.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading internal/apis.go and internal/checkers/gotask.go, then inspect their call sites in analyzer.go at lines 123 and 196-200. Compare the two metadata formats and determine whether a shared registry with adapters is suitable. Done means both checkers consume one API definition, or the required duplication is documented and synchronization is validated.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
devtools
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.