Skip to content

Commit 89dfaff

Browse files
IlyaasKclaude
andcommitted
telemetry events: use X-Has-More to decide if another page exists
Per the SDK contract (Events: 'pass X-Next-Offset and repeat while X-Has-More is true'), gate the next-page cursor on X-Has-More rather than inferring it from a non-zero X-Next-Offset, which the server may still emit on the terminal page. Applies to both the JSON next_offset envelope and the table hint. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4012b0e commit 89dfaff

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

cmd/browsers_telemetry.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,15 @@ func (b BrowsersCmd) TelemetryEvents(ctx context.Context, in BrowsersTelemetryEv
295295
items = page.Items
296296
}
297297

298+
// Pagination: the API sets X-Has-More=true while more pages remain;
299+
// X-Next-Offset is the cursor to pass as --offset for the next page. Surface
300+
// it (in JSON and as the table hint) only when there is actually a next page.
301+
nextOffset := ""
302+
if raw != nil && strings.EqualFold(raw.Header.Get("X-Has-More"), "true") {
303+
nextOffset = raw.Header.Get("X-Next-Offset")
304+
}
305+
298306
if in.Output == "json" {
299-
// Surface the X-Next-Offset cursor in JSON mode too, so scripted callers
300-
// can paginate (table mode prints it as a hint below).
301-
nextOffset := ""
302-
if raw != nil {
303-
if n := raw.Header.Get("X-Next-Offset"); n != "" && n != "0" {
304-
nextOffset = n
305-
}
306-
}
307307
events := make([]json.RawMessage, 0, len(items))
308308
for _, it := range items {
309309
r := it.RawJSON()
@@ -340,12 +340,8 @@ func (b BrowsersCmd) TelemetryEvents(ctx context.Context, in BrowsersTelemetryEv
340340
})
341341
}
342342
PrintTableNoPad(rows, true)
343-
// The next-page cursor is the opaque X-Next-Offset header; surface it so
344-
// --offset is actually usable for paging.
345-
if raw != nil {
346-
if next := raw.Header.Get("X-Next-Offset"); next != "" && next != "0" {
347-
pterm.Info.Printf("More events available — re-run with --offset %s\n", next)
348-
}
343+
if nextOffset != "" {
344+
pterm.Info.Printf("More events available — re-run with --offset %s\n", nextOffset)
349345
}
350346
return nil
351347
}

0 commit comments

Comments
 (0)