feat(project): Added projects#90
Conversation
Greptile Summary
Confidence Score: 3/5Merge safety is reduced by project-isolation and billing-accounting issues in the new project-scoped paths. The changes cover core auth, storage, billing, and query behavior, and the remaining issues can cause cross-project ingestion collisions, incorrect billing windows, and under-reported AI token charges. src/storage/db/postgres/schema.ts; src/storage/adapter/clickhouse/utils.ts; src/storage/adapter/clickhouse/handlers/priceRequestAiTokenUsage.ts; src/storage/adapter/postgres/handlers/queryEvents.ts; src/storage/adapter/clickhouse/handlers/queryEvents.ts
What T-Rex did
|
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
…race, scoped clearClients
…eAITokenUsageDataSchema
| .references(() => projectsTable.id) | ||
| .notNull(), | ||
| eventId: uuid("event_id").notNull(), | ||
| idempotencyKey: text("idempotency_key").notNull().unique(), |
There was a problem hiding this comment.
idempotencyKey is still globally unique after adding projectId to the usage event tables. When Project A records idempotencyKey="checkout-1", Project B cannot independently use the same idempotency key because Postgres rejects the insert before the project scope is considered. This makes one project's events able to block another project's ingestion. The uniqueness should be scoped to (projectId, idempotencyKey) for both basic usage and AI token usage events.
| const VALUE_EXPR = | ||
| "JSONExtractInt(metrics, 'debit_amount', 'input') + JSONExtractInt(metrics, 'debit_amount', 'input_cache') + JSONExtractInt(metrics, 'debit_amount', 'output')"; |
There was a problem hiding this comment.
The ClickHouse AI price expression stores debit_amount.output_cache, but this billing expression does not sum it. When a project prices output-cache tokens with outputCacheTag, outputCacheExpr, or outputCacheAmount, checkout billing undercharges those events. Include output_cache here so ClickHouse pricing matches the stored metrics and the Postgres pricing path.
| const VALUE_EXPR = | |
| "JSONExtractInt(metrics, 'debit_amount', 'input') + JSONExtractInt(metrics, 'debit_amount', 'input_cache') + JSONExtractInt(metrics, 'debit_amount', 'output')"; | |
| const VALUE_EXPR = | |
| "JSONExtractInt(metrics, 'debit_amount', 'input') + JSONExtractInt(metrics, 'debit_amount', 'input_cache') + JSONExtractInt(metrics, 'debit_amount', 'output_cache') + JSONExtractInt(metrics, 'debit_amount', 'output')"; |
Artifacts
Repro: executable output-cache pricing harness
- Contains supporting evidence from the run (text/javascript; charset=utf-8).
Repro: harness output showing SQL omits output_cache and computes zero
- Keeps the command output available without making the summary code-heavy.
No description provided.