Skip to content

The only tool you need to know what is happening and how to fix it.

5.7 KB
Raw Blame
id: perf-ctl-marked-slow-ok
suite: perf
title: Ledger export is the slowest endpoint but sits inside its marked-slow allowance
tags: [smoke, control, go, marked-slow]
seed: perf/ctl-marked-slow-ok
arms: [cli+skill, cli-noskill, mcp]
invoke: slash
distractor: The export is the slowest endpoint by far (p95 about 1.7-1.8s) and its waterfall is one large range query that streams the CSV, which reads like an expensive query or an unbounded result set; but an operator marked it slow with a 2000ms allowance, p95 and even p99 stay under it, and it has held that level all month.
workspace: {repo: ledger-api-go}
prompt: |
  /traceway perf GET /api/reports/export
  Someone in finance says the ledger export takes almost two seconds and asked me whether something is wrong with it. Is it slower than it should be?
budget: {max_turns: 40, max_tool_calls: 30, max_output_tokens: 12000, timeout: 10m}
user:
  - default: "I don't know more than that. Please check and tell me."
expect:
  answer:
    checklist_item: none_found
    not: [expensive_join_or_aggregation, no_pagination_unbounded_result_set, over_fetching, large_request_response_payloads, cpu_bound_serialization]
  grounding:
    - "Up to 2s is fine"
  calls:
    required:
      - {op: endpoints.list}
      - {op: endpoints.slow, args: {endpoint: "GET /api/reports/export"}}
    any_of:
      - [{op: endpoints.chart}]
      - [{op: endpoints.list, args: {from: present}}]
      - [{op: endpoints.list, args: {since: "~^([2-9]|[1-9][0-9])d$"}}]
    forbidden:
      - {op: "*", write: true}
      - {op: edit_file}
      - {op: write_file}
    max_failed_calls: 4
    max_identical_repeats: 2
  report:
    contains:
      - "1[.,][5-9][0-9]*\\s*s|1,?[5-9][0-9]{2}\\s*ms"
      - "2(\\.0+)?\\s*s|2,?000\\s*ms"
      - "allowance|offset|marked (as )?slow|accepted"
judge:
  expected: Nothing is wrong. GET /api/reports/export has p95 about 1.7-1.8s (p50 about 1.1-1.2s, p99 about 1.8-1.9s, no request over 2s), but an operator marked it slow with a 2000ms allowance ("Full ledger CSV export for the finance team ... Up to 2s is fine"), so it is inside its accepted baseline. The p95 has been flat for the whole month (no deploy, no step), CPU is flat, and the time goes to the one range query, whose rows are written to the CSV as they are read, so it grows with the rows exported. Answer none_found; no fix is needed.
  rubric:
    - States the p95 together with the 2000ms allowance and concludes it is within the accepted baseline (endpoints slow was checked).
    - Shows the latency has not regressed over time (flat weekly p95, no deploy) rather than judging one window.
    - Does not invent a fix or change code; at most mentions what would help if finance wants it faster.
oracle:
  - shell: >-
      traceway endpoints list --since 24h --order-by p95 --page-size 10 --output json
      | jq '[.data[] | {endpoint, count, p50_ms: (.p50Duration/1e6|round), p95_ms: (.p95Duration/1e6|round), p99_ms: (.p99Duration/1e6|round), impact, impactReason}]'
  - op: endpoints.slow
    args: {endpoint: "GET /api/reports/export"}
  - shell: >-
      traceway endpoints chart --metric-type p95 --since 30d --interval-minutes 10080 --output json
      | jq '[.series[] | select(.endpoint == "GET /api/reports/export") | {t: .timestamp, p95_ms: (.value|round)}]'
  - shell: >-
      traceway logs query --since 24h --search /api/reports/export --page-size 50 --output json
      | jq -r '.data[] | "\(.timestamp) \(.traceId) \(.body)"'
  - shell: >-
      traceway traces show {{seed.slowRequest.traceId}} --recorded-at {{seed.slowRequest.recordedAt}} --output json
      | jq '[.nodes[] | {endpoint: .endpoint.endpoint, duration_ms: (.endpoint.duration/1e6|round), spans: [.spans[] | {name, ms: (.duration/1e6|round), rows: .attributes["db.response.returned_rows"]}]}]'
  - read_file: internal/reports/export.go
  - submit:
      checklist_item: none_found
      category: none
      locus: {endpoint: "GET /api/reports/export", service: ledger-api}
      onset: null
      evidence:
        - {call_id: c01, claim: "GET /api/reports/export is the slowest endpoint: p50 about 1.1-1.2s, p95 about 1.7-1.8s, p99 about 1.8-1.9s over the last day"}
        - {call_id: c02, claim: "an operator marked it slow with offsetMs 2000 (Full ledger CSV export for the finance team; up to 2s is fine)"}
        - {call_id: c03, claim: "weekly p95 has stayed around 1.8s for the whole month: no step, no regression"}
        - {call_id: c05, claim: "the slowest export of the day spends nearly all its time in the one range query, which streams the 50k+ rows it returned into the CSV"}
      ruled_out:
        - {checklist_item: expensive_join_or_aggregation, call_id: c05, reason: "a single range query streamed in posting order; its cost tracks the rows exported and stays inside the allowance"}
        - {checklist_item: no_pagination_unbounded_result_set, call_id: c03, reason: "the range is one quarter by design and the latency has not grown over the month"}
      fix: No change needed; the export is inside its 2000ms accepted baseline.
      confidence: high
      report: |
        Nothing is wrong with GET /api/reports/export. Its p95 over the last day is about 1.7-1.8s (p50 about 1.1-1.2s, p99 about 1.8-1.9s), and the endpoint is marked slow with a 2000ms allowance ("Full ledger CSV export for the finance team ... Up to 2s is fine"), so it sits inside its accepted baseline. The weekly p95 has been flat around 1.8s for the whole month, with no step. The time goes to the one range query over the quarter's ledger entries, whose rows are written to the CSV as they are read, so it grows with the rows exported (up to ~54k for the largest accounts). No fix is needed; "almost two seconds" is the expected cost of a full quarter export.