Skip to content

feat(warehouse-sources): add openrouter session costs table - #126976

Open
Gilbert09 wants to merge 2 commits into
masterfrom
posthog/openrouter-session-costs
Open

Gilbert09 wants to merge 2 commits into
masterfrom
posthog/openrouter-session-costs

Conversation

@Gilbert09

@Gilbert09 Gilbert09 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Problem

  • OpenRouter users cannot sync the public session-cost dataset that OpenRouter announced in its changelog.

Changes

  • A new session_costs table holds the weekly median USD cost per session, per harness, model and turn-count range.
  • Each row also carries the response meta fields.
  • The table is a full refresh with offset paging. A full page at the maximum offset of 5000 fails the sync, so no truncated table ships.
  • Mechanical: column descriptions, caption copy, and a ticked appendix line.
  • Skipped: none. The endpoint is in the API reference.

How did you test this code?

Test rationale: a new transport test catches dropped meta columns, and a sync that succeeds without reading every row past the offset cap. test_offset_limit_stops_on_short_page covers neither.

  • Not checked: a live sync, because no OpenRouter key is available here.

Release status

  • No feature flag controls this change

Docs update

  • None.

🤖 Agent context

Autonomy: Fully autonomous

Agent: Claude Code, Claude Opus 5.5 (claude-opus-5-5)

Skills: /implementing-warehouse-sources, /writing-pr-descriptions

More context for AI agents
  • Session: PostHog Desktop task, checked against the vendor's OpenAPI and SDK docs.
  • Decisions: composite key app_slug, model_permaslug, turn_range. No server time filter, so no incremental sync.
  • Duplicate check: open PRs searched for openrouter and session-cost, plus the maintainer's open PRs. None matched.

Created with PostHog Desktop from a PostHog Desktop task

🤖 Generated with Claude Code

Sync OpenRouter's public /datasets/session-cost dataset: weekly median cost per session by harness, model and turn-count range, with the snapshot meta copied onto each row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: b63918f5-00b6-4cb4-975f-faddb3d77e98
@trunk-io

trunk-io Bot commented Nov 1, 2026

Copy link
Copy Markdown

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@Gilbert09 Gilbert09 added the stamphog Request AI approval (no full review) label Nov 1, 2026 — with Talyn App
@Gilbert09
Gilbert09 requested a review from a team November 1, 2026 12:21
@parameterai

parameterai Bot commented Nov 1, 2026

Copy link
Copy Markdown

 Scanning this PR for security issues

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🤖 CI report

⚠️ Trunk lane — backend Python lane (py:product:warehouse_sources)

This PR is assigned to the backend Python lane (py:product:warehouse_sources). It runs backend Python tests and may merge in parallel with PRs in other lanes.

✅ Duplication (Python) — clean

New Python code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

✅ Duplication (TypeScript) — clean

New TypeScript code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

🚨 Comment density — 8% of added code lines are comments (5 of 60)

This section warns when comments are more than 3% of the code lines a PR adds, and alerts above 6%. Before agent-assisted PRs, the typical share was about 2%. Only full-line comments count. Docstrings, generated files, snapshots, migrations, and workflow files are left out.

Comments that restate the code, record how the change came about, or narrate the next line add noise for the next reader. Keep the comments that explain a reason the code cannot show, and remove the rest. See .agents/skills/writing-code-comments/SKILL.md for the house rules.

Files with the most added comment lines:

File Comment lines Added lines
products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/settings.py 3 15
products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/openrouter.py 1 8
products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/tests/test_openrouter.py 1 18

This check does not block merging. It updates on every push and clears when the share drops.

@bill-ph bill-ph left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the PR description, diff, existing discussion, endpoint configuration, metadata flattening, pagination/resume behavior, source integration, and added test against OpenRouter's API reference. Checked for correctness, security, data safety, performance, missing coverage, overengineering, and scope creep. Tests were not run as requested.

P1

  • Pagination-cap exhaustion is treated as a successful full refresh. If the dataset contains more than 5,500 cells, the sync stops after the page at offset 5,000 and publishes an incomplete table. The documented maximum offset limits requests, not the total dataset size. Fail safely at the cap (as the batches paginator does), or partition requests using the supported filters to retrieve the remaining cells. The new test currently requires successful termination at this boundary without establishing that the dataset is exhausted.

No P0 or P2 issues found.

Inline comments

  • products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/openrouter.py:215 — P1: This break reports successful exhaustion when the page at offset 5000 is full. If the snapshot has more than 5500 cells, every subsequent cell is omitted and the full refresh publishes an incomplete table; the API's offset ceiling does not bound the dataset size. Please raise OpenRouterPageCapError at this boundary, like the batches paginator, unless completeness can be established, or use the supported filters to paginate disjoint subsets. Add coverage that prevents an exhausted pagination cap from silently succeeding.

— Robo Bill v2 (gpt-6.1-sol, high reasoning)

@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team November 1, 2026 12:22

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostHog Review · Standard · reviewed 58e6c2d: 1 Should fix.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

@stamphog stamphog Bot removed the stamphog Request AI approval (no full review) label Nov 1, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not approved — this change needs a human reviewer.

Re-add the stamphog label to request another review once you have addressed this.

Owning-team authorship, strong familiarity, and a current-head approval provide assurance, but @PostHog's substantive pagination concern remains unfixed. Address that comment in openrouter.py and request follow-up review from @PostHog/team-warehouse-sources before re-requesting.

  • Author wrote 100% of the modified lines and has 23 merged PRs in these paths (familiarity STRONG).
  • PostHog Review (Standard) reviewed the current head: 1 finding, posted on the PR.
  • bill-ph, posthog[bot] reviewed the current head.
  • @PostHog, products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/openrouter.py: The pagination-cap concern remains unresolved. Lines 212–215 terminate successfully after a full page at offset 5000 without establishing completeness; source.py exposes this dataset as full-refresh only, so additional rows can be silently omitted. Fail the import when completeness cannot be established and update the test that currently expects successful truncation.
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
size ✓ 42L, 4F substantive, 62L/6F incl. docs/generated/snapshots — within ceiling
tier ✓ T1-agent / T1c-medium (62L, 6F, single-area, feat)
stamphog 2.6.1 .stamphog/policy.yml @ 58e6c2d · reviewed head 58e6c2d
@hosthog

hosthog Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

HostHog preview — posthog-desktop-web

Latest build (db2f793): https://af9c51ddfc6a41cbaa2c4e03037cf194.hosthog.dev

Earlier builds of this PR, still serving:

Employee-gated; every push gets a fresh URL whose content never changes. All previews stop serving when the PR closes.

… cap

A full page at the API's maximum offset can't prove the dataset is exhausted, so raise instead of publishing a truncated full refresh, matching the batches paginator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: b63918f5-00b6-4cb4-975f-faddb3d77e98

Copy link
Copy Markdown
Member Author

Robo Bill's P1 on openrouter.py:215 raised the same point as the PostHog Review finding. Fixed in db2f793: hitting the offset cap now fails the sync instead of succeeding.

@Gilbert09 Gilbert09 added the stamphog Request AI approval (no full review) label Nov 1, 2026 — with PostHog

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

The risky ingestion change has assurance through owning-team authorship and STRONG familiarity. The older pagination concern is fixed in the current code and covered by a boundary regression test; no outstanding substantive concerns remain.

  • Author wrote 100% of the modified lines and has 23 merged PRs in these paths (familiarity STRONG).
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
size ✓ 44L, 4F substantive, 65L/6F incl. docs/generated/snapshots — within ceiling
tier ✓ T1-agent / T1c-medium (65L, 6F, single-area, feat)
stamphog 2.6.1 .stamphog/policy.yml @ db2f793 · reviewed head db2f793

This branch has not been deployed

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

Labels

stamphog Request AI approval (no full review)

2 participants