Repository navigation
Backlog
Description
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 × timeoutto 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) errorDecisions to make
- 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()),StartItemreturns at once and children can be queued before the parent's start is sent. Logs go through theLogBatcherand 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. - Errors. Hooks in the test framework must not fail because of reporting. Proposal: collect errors with
errors.Joinand return them fromFlush/Finish, plus an optionalWithErrorHandler(func(error)). The CLI fails on them, and the Ginkgo agent only logs them. - 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 atFinish, 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. - Finish without a reachable server.
Launch.Finishwith a ctx deadline. On timeout it triesStopLaunchonce and returns an error that says the launch may be left In Progress. - 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.
- 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.
- Scope. No new configuration keys beyond L5. No v1 (synchronous) reporting path.
Consumers and migration
gorp report test2json: replaces the reporter's ownerrgroupand log batching, and usesAttachLaunchfor--launch-uuid(report test2json: add --launch-uuid to report into an existing launch #43).- The Ginkgo agent (Add Ginkgo v2 agent and ginkgo-rp wrapper (pkg/ginkgo) #15): replaces its own queue, failure streak and finalize logic.
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
- Whether the session lives in
pkg/gorpor a new package (for examplepkg/gorp/session). - The /v6 decision (pkg/openapi: v5.2.2 type names removed on master while module path stays /v5; v6.0.0 tag unusable for Go modules #32). If the session is released after the first v6 tag, it is additive and doesn't depend on that decision.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
No labels
Activity
DzmitryHumianiuk commentedon Nov 29, 2026
The implementation is up for review:
gorp.Sessionand movesgorp report test2jsononto it. It is stacked on pkg/gorp: add SaveLogBatch and LogBatcher, use it in report test2json #47 and needs Return one HTTPError with the server's code and message from both clients #36, Add client options, WARN/TRACE/FATAL log levels and enum parsers #48, Add server limits with UTF-16 truncation and bounded IDs #49 and Add WithRetry: retries with backoff for requests that are safe to repeat #50.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:
Finishthen returnsErrLaunchNotFinished, and the caller runsLaunch.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.Finishdoesn't stop the launch itself (decision 4). When its ctx ends, there is no time left to stop the launch. EveryFinisherror that can leave the launch open matchesErrLaunchNotFinished, and the owner callsAbortwith its own budget.Launch.AbortItemsdoes the same without finishing the launch, for the Ginkgo wrapper, which sends its own STOPPED finish.AttachLaunch(uuid)takes no ctx and sends no request, because the Ginkgo agent attaches ininit(). The CLI checks the launch withGETfirst, as in report test2json: add --launch-uuid to report into an existing launch #43.Item.Retry: both consumers already setRetry/RetryOfon the request.Launch.Item(uuid)is added, for a handle to an item started by another process.WithRetryon 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 (WithoutTruncationturns it off), and there are no new config keys.