-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(logging): add preprocessing util shared by all execution paths #2081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryThis PR introduces a centralized Major improvements:
Key behavioral changes:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client
participant API as API Route (Chat/Webhook/Workflow)
participant Preprocess as preprocessExecution()
participant DB as Database
participant Billing as Billing Service
participant RateLimit as Rate Limiter
participant Logging as LoggingSession
participant Executor as Workflow Executor
Client->>API: POST request (trigger workflow)
API->>Logging: new LoggingSession()
API->>Preprocess: preprocessExecution({workflowId, userId, triggerType, ...})
Note over Preprocess: Step 1: Validate Workflow
Preprocess->>DB: SELECT workflow WHERE id = workflowId
alt Workflow not found
DB-->>Preprocess: No records
Preprocess->>Logging: safeStart() + safeCompleteWithError()
Preprocess-->>API: {success: false, error: {message, statusCode: 404}}
API-->>Client: 404 Workflow not found
end
DB-->>Preprocess: workflow record
Note over Preprocess: Step 2: Check Deployment
alt checkDeployment && !isDeployed
Preprocess->>Logging: safeStart() + safeCompleteWithError()
Preprocess-->>API: {success: false, error: {message, statusCode: 403}}
API-->>Client: 403 Workflow not deployed
end
Note over Preprocess: Step 3: Resolve Billing Actor
Preprocess->>Billing: getWorkspaceBilledAccountUserId(workspaceId)
Billing-->>Preprocess: actorUserId
alt actorUserId is null
alt isResumeContext
Note over Preprocess: Fallback to workflow owner for resume
Preprocess->>Preprocess: Use workflowRecord.userId
else
Preprocess->>Logging: safeStart() + safeCompleteWithError()
Preprocess-->>API: {success: false, error: {statusCode: 500}}
API-->>Client: 500 Unable to resolve billing
end
end
Note over Preprocess: Step 4: Get Subscription
Preprocess->>Billing: getHighestPrioritySubscription(actorUserId)
Billing-->>Preprocess: userSubscription
Note over Preprocess: Step 5: Check Rate Limits
alt checkRateLimit
Preprocess->>RateLimit: checkRateLimitWithSubscription()
RateLimit-->>Preprocess: {allowed, remaining, resetAt}
alt !allowed
Preprocess->>Logging: safeStart() + safeCompleteWithError()
Preprocess-->>API: {success: false, error: {statusCode: 429}}
API-->>Client: 429 Rate limit exceeded
end
end
Note over Preprocess: Step 6: Check Usage Limits
alt !skipUsageLimits
Preprocess->>Billing: checkServerSideUsageLimits(actorUserId)
Billing-->>Preprocess: {isExceeded, currentUsage, limit}
alt isExceeded
Preprocess->>Logging: safeStart() + safeCompleteWithError()
Preprocess-->>API: {success: false, error: {statusCode: 402}}
API-->>Client: 402 Usage limit exceeded
end
end
Note over Preprocess: All checks passed
Preprocess-->>API: {success: true, actorUserId, workflowRecord, userSubscription}
API->>Executor: executeWorkflow(workflow, actorUserId, input)
Executor->>Logging: safeStart()
Executor->>Executor: Execute workflow blocks
Executor->>Logging: safeComplete() / safeCompleteWithError()
Executor-->>API: ExecutionResult
API-->>Client: Response (200/streaming)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
17 files reviewed, no comments
Summary
Type of Change
Testing
Tested manually
Checklist