Skip to content

Thread context.Context through api.Client and the Requester interface #25

Description

@kshahbw

BLUF

internal/api.Client methods take no context.Context, so an in-flight HTTP request cannot be cancelled or deadlined by the caller. cmdutil.Poll gained an optional PollConfig.Context in the 10DLC foundation work, which makes --wait loops cancellable between attempts — but the request itself still runs to completion.

Why it was deferred

api.Requester has ~110 call sites across cmd/. Changing its method signatures in the 10DLC foundation PR would have made that PR unreviewable, which is exactly what the PR stack exists to prevent. The additive PollConfig.Context covers what PR 4's --wait operations actually need today.

Current state

cmdutil.Poll accepts an optional Context (nil means context.Background()), and the loop selects on ctx.Done() between attempts:

timer := time.NewTimer(cfg.Interval)
select {
case <-ctx.Done():
    timer.Stop()
    return nil, ctx.Err()
case <-timer.C:
}

So Ctrl-C during a --wait is honored at the next interval boundary, but a request already in flight is not interrupted.

Scope

  • Add context-aware methods to Client, or thread context.Context through the existing ones.
  • Migrate the ~110 call sites.
  • Extend or replace the Requester interface.
  • Update the mock implementations in internal/testutil/golden.go and internal/cmdutil/client_seam.go in step.

Worth deciding up front

Whether to change Requester's existing signatures (one large mechanical diff, no lingering dual API) or add parallel …Ctx methods (incremental, but leaves two ways to do the same thing until migration finishes). The first is probably better given this is pre-1.0 and the call sites are mechanical — but it wants a decision before someone starts.

Related

Found while implementing docs/specs/2026-08-12-tendlc-direct-registration-center-design.md. Eight async 10DLC operations in a later PR will use --wait, so this matters more once those land.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions