Skip to content

Design: a reporting session for Go agents (ordering, Flush(ctx), breaker) #52

Backlog

Description

@DzmitryHumianiuk

Part of #27 (slice L6). This is a design proposal to agree on before any code. Per the plan in #27, the session is merged only when two consumers use it: gorp report test2json and the Ginkgo agent from #15. An abstraction with one user is likely to be wrong.

Problem

Every Go agent repeats the same reporting logic, and each copy gets some part wrong:

  • Ordering. A child item must start after its parent and finish before it. On the v2 API the server doesn't report a missing parent or a wrong order back to the client: it answers 201, retries the message and then parks it. A mistake therefore shows up only as missing or IN_PROGRESS items, never as an error.
  • Waiting at the end. Logs and finishes are sent in the background. The agent has to wait for them before it finishes the launch, but only for a time it chooses. The Java client uses rp.reporting.timeout (300 s).
  • Outages. With retries (Add WithRetry: retries with backoff for requests that are safe to repeat #50), a dead server adds attempts × timeout to every request, and that time is added to the test run. The Ginkgo agent in Add Ginkgo v2 agent and ginkgo-rp wrapper (pkg/ginkgo) #15 already has its own failure streak, which so far has needed three review rounds to get right: a launch left In Progress after a finalize error, and 4xx counted as outages.

The building blocks for this exist now and are in review:

Slice PR What it gives the session
L0 #36 *gorp.HTTPError with status and server code, used to tell transient errors from permanent ones
L1 #48 opts ...Option on the constructors
L2 #49 Truncate, BoundedID, TruncateAttributes
L3 #47 SaveLogBatch and LogBatcher: count, size and time flush; Flush, Close
L4 #50 WithRetry(RetryPolicy): network errors and 5xx, client UUIDs on starts so a retried start isn't created twice
L5 #51 LoadConfig / ParseConfig

Proposed API (sketch)

type Session struct{ /* client, options, per-launch queue, LogBatcher */ }

func NewSession(c *ReportingClient, opts ...SessionOption) *Session

// StartLaunch is synchronous: on a rerun the server returns the UUID of the original launch.
func (s *Session) StartLaunch(ctx context.Context, rq *openapi.StartLaunchRQ) (*Launch, error)
// AttachLaunch reports into a launch started elsewhere (sharded CI, test2json --launch-uuid, #43).
// The session never finishes an attached launch.
func (s *Session) AttachLaunch(ctx context.Context, uuid string) (*Launch, error)

func (l *Launch) StartItem(parent *Item, rq *openapi.StartTestItemRQ) *Item // returns at once, UUID is known
func (l *Launch) Log(e LogEntry)
func (l *Launch) Finish(ctx context.Context, rq *openapi.FinishExecutionRQ) (*openapi.FinishLaunchRS, error)

func (i *Item) Log(e LogEntry)
func (i *Item) Finish(rq *openapi.FinishTestItemRQ)
func (i *Item) Retry(rq *openapi.StartTestItemRQ) *Item // sets retry=true and retryOf=i.UUID

// Flush waits until everything queued so far is sent, or ctx is done. No goroutine outlives it.
func (s *Session) Flush(ctx context.Context) error

Decisions to make

  1. Ordering model. Proposal: one worker per launch drains a FIFO queue of starts and finishes. Because the item UUID is generated on the client (uuid.NewString()), StartItem returns at once and children can be queued before the parent's start is sent. Logs go through the LogBatcher and never wait for the queue. Open question: whether a log may be sent before its item's start has been acknowledged. On v2 this is accepted, but a log for an item that never gets created is lost silently.
  2. Errors. Hooks in the test framework must not fail because of reporting. Proposal: collect errors with errors.Join and return them from Flush/Finish, plus an optional WithErrorHandler(func(error)). The CLI fails on them, and the Ginkgo agent only logs them.
  3. Breaker. After N consecutive transient failures (network errors and 5xx, never 4xx, following the L0 classification), stop sending for a cool-down and drop or log locally whatever is queued. When the breaker trips, the launch is stopped (StopLaunch) once the server answers again, or at Finish, so it isn't left In Progress. This is the rule that took three rounds to get right in Add Ginkgo v2 agent and ginkgo-rp wrapper (pkg/ginkgo) #15.
  4. Finish without a reachable server. Launch.Finish with a ctx deadline. On timeout it tries StopLaunch once and returns an error that says the launch may be left In Progress.
  5. Log retries. Log UUIDs have no unique key on the server, so a replayed batch can duplicate entries. Proposal: retry a batch only when no response was received, as L4 does now.
  6. Where limits apply. Proposal: the session applies L2 truncation to every request it sends, so agents can't forget it. One switch turns it off.
  7. Scope. No new configuration keys beyond L5. No v1 (synchronous) reporting path.

Consumers and migration

Both migrations go in the same PR as the session, or in PRs stacked on it, so the API is checked against two real users before it is merged.

Not decided here

🤖 Generated with Claude Code

Activity

  1. DzmitryHumianiuk commented on Nov 29, 2026

    @DzmitryHumianiuk
    MemberAuthor

    The implementation is up for review:

    On a local ReportPortal 6.0.0, the Ginkgo agent produces the same launch tree as before the migration, sequential and parallel. The abort path ends STOPPED.

    Where the implementation differs from the sketch above:

    1. Logs go through the ordered queue (decision 1). A log is sent only after its item's start was answered, and it is reported as dropped if the item was never created. A log is never lost without an error.
    2. The breaker is terminal, with no cool-down (decision 3). After 3 transient failures in a row the session drops its queue and stops sending. Finish then returns ErrLaunchNotFinished, and the caller runs Launch.Abort, which is the only probe. If the server answers again, the open items and the launch are finished STOPPED. Resuming after a cool-down would only add partial data to a launch that ends STOPPED, and dropped starts would leave orphans.
    3. Finish doesn't stop the launch itself (decision 4). When its ctx ends, there is no time left to stop the launch. Every Finish error that can leave the launch open matches ErrLaunchNotFinished, and the owner calls Abort with its own budget. Launch.AbortItems does the same without finishing the launch, for the Ginkgo wrapper, which sends its own STOPPED finish.
    4. API.
      • AttachLaunch(uuid) takes no ctx and sends no request, because the Ginkgo agent attaches in init(). The CLI checks the launch with GET first, as in report test2json: add --launch-uuid to report into an existing launch #43.
      • There is no Item.Retry: both consumers already set Retry/RetryOf on the request.
      • Launch.Item(uuid) is added, for a handle to an item started by another process.
      • A session reports one launch.
    5. Retries (decision 5). The session adds none. With WithRetry on the client, starts and finishes are retried with the same client UUID, and log batches are never retried. The Ginkgo agent used to replay failed log batches; that replay is removed, so logs are no longer duplicated.

    As proposed, the session lives in pkg/gorp, truncation is on by default (WithoutTruncation turns it off), and there are no new config keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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