Skip to content

Feat/reported timestamp#64

Merged
thedevyashsaini merged 6 commits into
mainfrom
feat/reported-timestamp
Jun 2, 2026
Merged

Feat/reported timestamp#64
thedevyashsaini merged 6 commits into
mainfrom
feat/reported-timestamp

Conversation

@thedevyashsaini

Copy link
Copy Markdown
Member

No description provided.

@greptile-apps

greptile-apps Bot commented Jun 2, 2026

Copy link
Copy Markdown

Greptile Summary

This PR introduces an optional reportedTimestamp field (Unix epoch seconds) that callers can provide to control the timestamp recorded for billing events, falling back to Date.now() when omitted. It also correctly hoists the timestamp resolution before the retry loop in consumeEvent so retries carry a stable value.

  • EventPayloadSchema and AITokenUsagePayloadSchema gain reportedTimestamp: z.number().int().nonnegative().optional(), and both TypeScript types are updated to match.
  • consumeEvent resolves the timestamp once before the retry loop; the middleware path now also forwards reportedTimestamp through rawPayload → Zod → normalizedPayload.
  • The basicUsageEventConsumer direct path and the transformAITokenStream path still have gaps where rawPayload is built without reportedTimestamp, causing the caller-supplied value to be silently discarded.

Confidence Score: 3/5

The middleware path is correctly wired and the retry-loop timestamp is now stable, but two of the three call paths still silently discard a caller-supplied reportedTimestamp.

The direct basicUsageEventConsumer path omits reportedTimestamp from rawPayload before Zod validation, so any caller-provided value is always discarded and replaced by Date.now(). The transformAITokenStream path has the same unfixed gap. Together these mean the feature works only on the middleware path, giving callers a false sense that setting the field has effect.

packages/scrawn/src/core/scrawn.ts — the rawPayload construction sites in basicUsageEventConsumer and transformAITokenStream both need reportedTimestamp forwarding.

Important Files Changed

Filename Overview
packages/scrawn/src/core/scrawn.ts Adds reportedTimestamp forwarding across three call paths (direct API, middleware, AI stream), hoists timestamp resolution before the retry loop, but rawPayload in basicUsageEventConsumer still omits the field — causing it to always be undefined after Zod validation.
packages/scrawn/src/core/types/event.ts Adds optional reportedTimestamp field to EventPayloadSchema, AITokenUsagePayloadSchema, and their TypeScript types with int().nonnegative() validation — clean schema addition.
.changeset/spotty-plums-enter.md New changeset entry for the reportedTimestamp feature, classified as a patch release of @scrawn/core.

Comments Outside Diff (1)

  1. packages/scrawn/src/core/scrawn.ts, line 450-454 (link)

    P1 reportedTimestamp is read from validationResult.data but was never included in rawPayload, so Zod never sees it and validationResult.data.reportedTimestamp is always undefined. Any caller who sets reportedTimestamp on their EventPayload will have it silently dropped and consumeEvent will always fall back to Date.now().

Reviews (3): Last reviewed commit: "chore: release" | Re-trigger Greptile

Comment thread packages/scrawn/src/core/types/event.ts
Comment thread packages/scrawn/src/core/types/event.ts
Signed-off-by: Devyash Saini <dysaini2004@gmail.com>
@thedevyashsaini thedevyashsaini merged commit 6808a9d into main Jun 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant