fix(claude-admin): send day-aligned exclusive ending_at for usage/cost streams - #1926
Conversation
…t streams (#1901) The cost_report stream returned HTTP 400 "Invalid date range: ending date must be after starting date" on every daily slice, ingesting 0 rows. The Admin usage/cost API treats ending_at as EXCLUSIVE ("buckets that end before this timestamp") and snaps starting_at to the UTC day start. The CDK computes each slice end as (start + step) - cursor_granularity; with step=P1D, cursor_granularity=PT1S that yielded 00:00:00Z -> 23:59:59Z, which is not before the bucket's midnight end, so zero buckets qualified. Set cursor_granularity=P0D on claude_admin_messages_usage and claude_admin_cost_report so each slice sends ending_at = starting_at + P1D (the next UTC midnight), selecting exactly one daily bucket with no gap and no double-count (verified against CDK 6.60.16 _partition_daterange). claude_admin_code_usage is unchanged (it sends only starting_at). Also correct the manifest version header 7.0.4 -> 6.60.9 to match the CDK line the mock-test harness and every other nocode manifest use; the manifest uses no 7.x-only feature and the deployed SDM 7.23.6 accepts it. This keeps the change isolated to claude-admin (no shared-harness CDK bump, which would regress zoom's substream-parent slicing tests). Adds the L1 mock-server suite (asserts each slice's ending_at is the next midnight, never 23:59:59Z) and registers claude-admin in the connector mock-test CI component. Documents the boundary in ADR-0002 (supersedes ADR-0001) and the connector README. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Dmitry Saukh <38005371+cyberdima@users.noreply.github.com>
|
Warning Review limit reached
Next review available in: 32 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Claude Admin connector now uses ChangesClaude Admin cursor boundary fix
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant DatetimeBasedCursor
participant ClaudeAdminConnector
participant ClaudeAdminAPI
DatetimeBasedCursor->>ClaudeAdminConnector: Compute daily P0D window
ClaudeAdminConnector->>ClaudeAdminAPI: Request usage or cost data through next UTC midnight
ClaudeAdminAPI-->>ClaudeAdminConnector: Return daily bucket results
Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@docs/components/connectors/ai/claude-admin/specs/ADR/0001-cursor-granularity-boundary-fix.md`:
- Around line 11-16: Update the historical statement around “all three streams
include end_time_option” in ADR-0001 to clarify that it applied only to the
older configuration, or revise it to match the supersession note. Ensure the
document no longer contradicts the current behavior that claude_admin_code_usage
does not send ending_at.
In
`@docs/components/connectors/ai/claude-admin/specs/ADR/0002-cost-report-exclusive-ending-boundary.md`:
- Line 3: Update the ADR metadata date at the document header to the actual
acceptance date, July 25, 2026, instead of the future-dated July 26, 2026 value.
In `@src/ingestion/connectors/ai/claude-admin/connector.yaml`:
- Line 1: Align the connector manifest version in connector.yaml with the
verified airbyte_cdk version referenced by the connector’s ADR and tests
package: update the version from 6.60.9 to the supported 6.60.16 range, or
consistently revise the ADR and test dependency to document 6.60.9 instead.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 0f7c493f-22ee-462d-8147-57386b67acf2
📒 Files selected for processing (11)
docs/components/connectors/ai/claude-admin/specs/ADR/0001-cursor-granularity-boundary-fix.mddocs/components/connectors/ai/claude-admin/specs/ADR/0002-cost-report-exclusive-ending-boundary.mdscripts/ci/components.pysrc/ingestion/connectors/ai/claude-admin/README.mdsrc/ingestion/connectors/ai/claude-admin/connector.yamlsrc/ingestion/connectors/ai/claude-admin/tests/config.pysrc/ingestion/connectors/ai/claude-admin/tests/conftest.pysrc/ingestion/connectors/ai/claude-admin/tests/fixtures/cost_result.jsonsrc/ingestion/connectors/ai/claude-admin/tests/fixtures/messages_result.jsonsrc/ingestion/connectors/ai/claude-admin/tests/test_claude_admin_cost_report.pysrc/ingestion/connectors/ai/claude-admin/tests/test_claude_admin_messages_usage.py
- ADR-0001: clarify end_time_option statement is historical (code_usage no longer sends ending_at per ADR-0002) - ADR-0002: fix future-dated acceptance date (2026-07-26 -> 2026-07-25) - connector.yaml: align CDK pin with verified version (6.60.9 -> 6.60.16) - descriptor.yaml: bump version so reconcile republishes the manifest (ADR-0015 gate compares descriptor version, unchanged = noop) Signed-off-by: Dmitry Saukh <38005371+cyberdima@users.noreply.github.com>
|
Populate missing docstrings in config.py and test modules (test_claude_admin_cost_report.py, test_claude_admin_messages_usage.py) to satisfy the 80% coverage threshold. Coverage was 10.53% due to new helper functions and test cases lacking docstrings. Added one-line docstrings to all test helpers (_day_params, _bucket, _next, _register_all) and test functions. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Signed-off-by: Dmitry Saukh <38005371+cyberdima@users.noreply.github.com>
…1901-claude-admin-cost-report-date-range
c4cb69a to
d43e43a
Compare
Summary
Fix
claude-adminconnector'smessages_usageandcost_reportstreams to emit day-alignedending_attimestamps.The Anthropic cost API (
/v1/organizations/cost_report) withbucket_width=1drequires day-aligned (midnight)ending_atvalues. Current implementation usescursor_granularity: PT1Swhich produces non-aligned endings (e.g.,23:59:59Z), causing 400 errors on the cost_report endpoint.Root cause:
DatetimeBasedCursorcomputesending_at = partition_start + step - cursor_granularity. Withstep:P1Dandcursor_granularity:PT1S, the ending lands at 23:59:59Z instead of the next midnight.Fix: Set
cursor_granularity: P0Dfor bothmessages_usageandcost_reportstreams. This ensuresending_at = start + P1D= next midnight, producing day-aligned exclusive boundaries (00:00 → next 00:00) as required by the cost API.Verified behavior: Live sync probe confirms cost_report now returns valid day buckets with proper alignment.
Changes
src/ingestion/connectors/ai/claude-admin/connector.yaml: Updatecursor_granularityformessages_usageandcost_reportstreams toP0DRefs #1901
Summary by CodeRabbit
Bug Fixes
Documentation
Tests