Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

waleedlatif1 and others added 9 commits June 30, 2025 18:12
… for easier debugging (#593)

* added more granular error logs for function execution

* added tests

* fixed syntax error reporting
* improvement: added knowledge upload

* improvement: added greptile comments (#579)

* improvement: changed to text to doc (#579)

* improvement: removed comment (#579)

* added input validation, tested persistence of KB selector

* update docs

---------

Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>
Co-authored-by: Waleed Latif <walif6@gmail.com>
…olumn in any routes (#586)

* fix(remove workflow.state usage): no more usage of deprecated state col in routes

* fix lint

* fix chat route to only use deployed state

* fix lint

* better typing

* remove useless logs

* fix lint

* restore workflow handler file

* removed all other usages of deprecated 'state' column from workflows table, updated tests

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>
Co-authored-by: Waleed Latif <walif6@gmail.com>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan>
* feat(billing): added migrations for usage-based billing

* lint

* lint
* feat(logging): add new schemas + types for logging

* fix lint

* update migration

* fix lint

* Remove migration 48 to avoid conflict with staging

* fixed merge conflict

* fix lint

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>
@vercel
Copy link

vercel bot commented Jul 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sim (staging) ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 3:35pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Skipped (Inspect) Jul 2, 2025 3:35pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR introduces usage-based billing, enhanced function debugging, and significant architectural improvements to workflow execution.

  • Added granular workflow execution tracking with new tables (workflow_execution_blocks, logs, snapshots) in migrations 0048-0049 for cost and token usage monitoring
  • Implemented detailed function execution error reporting with line numbers, stack traces, and helpful debugging suggestions in /api/function/execute
  • Added temperature controls (0-2 range) for GPT-4.1 model family in providers/models.ts
  • Refactored workflow state management to use normalized tables, removing deprecated state column across all routes
  • Fixed dependency resolution in executor/index.ts to properly handle blocks with multiple inputs from inactive paths

37 files reviewed, 16 comments
Edit PR Review Bot Settings | Greptile

Comment on lines +451 to 463
state: {
blocks: workflowData.state.blocks || {},
edges: workflowData.state.edges || [],
loops: workflowData.state.loops || {},
parallels: workflowData.state.parallels || {},
isDeployed: workflowData.isDeployed || false,
deployedAt: workflowData.deployedAt
? new Date(workflowData.deployedAt)
: undefined,
},
timestamp: Date.now(),
action: 'Loaded from database',
action: 'Loaded from database (normalized tables)',
subblockValues: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

style: History state now uses normalized data structure consistently. Consider extracting this state shape into a type definition to ensure consistency across the codebase

@@ -0,0 +1,9 @@
ALTER TABLE "user_stats" ADD COLUMN "current_usage_limit" numeric DEFAULT '5' NOT NULL;--> statement-breakpoint
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider specifying numeric precision and scale for monetary/limit values to ensure consistent handling across the platform

Comment on lines +362 to +363
const buffer = Buffer.from(base64Data, 'base64')
const result = await parseBuffer(buffer, extension)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Re-using buffer from line 352 would be more efficient than creating new Buffer instance.

Suggested change
const buffer = Buffer.from(base64Data, 'base64')
const result = await parseBuffer(buffer, extension)
const result = await parseBuffer(buffer, extension)

Comment on lines +5 to +6
ALTER TABLE "user_stats" ADD COLUMN "billing_period_start" timestamp DEFAULT now();--> statement-breakpoint
ALTER TABLE "user_stats" ADD COLUMN "billing_period_end" timestamp;--> statement-breakpoint
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using timestamptz instead of timestamp to handle timezone data properly

@@ -83,6 +97,10 @@ export const functionExecuteTool: ToolConfig<CodeExecutionInput, CodeExecutionOu
},

transformError: (error: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: type 'any' should be avoided - consider creating an interface for the error object with expected properties

Suggested change
transformError: (error: any) => {
transformError: (error: Error & { enhancedError?: boolean; line?: number; column?: number; errorType?: string }) => {

Comment on lines +54 to +59
const utf8Bytes = new TextEncoder().encode(textContent)
const base64Content =
typeof Buffer !== 'undefined'
? Buffer.from(textContent, 'utf8').toString('base64')
: btoa(String.fromCharCode(...utf8Bytes))

Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Double encoding of content - already encoded in TextEncoder step, then again in Buffer/btoa

Comment on lines +109 to +110
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Timestamps should come from the server response rather than being generated client-side

Comment on lines +412 to +479
describe('Router downstream path activation', () => {
beforeEach(() => {
// Create router workflow with downstream connections
mockWorkflow = {
version: '1.0',
blocks: [
{
id: 'router1',
metadata: { id: 'router', name: 'Router' },
position: { x: 0, y: 0 },
config: { tool: 'router', params: {} },
inputs: {},
outputs: {},
enabled: true,
},
{
id: 'api1',
metadata: { id: 'api', name: 'API 1' },
position: { x: 0, y: 0 },
config: { tool: 'api', params: {} },
inputs: {},
outputs: {},
enabled: true,
},
{
id: 'api2',
metadata: { id: 'api', name: 'API 2' },
position: { x: 0, y: 0 },
config: { tool: 'api', params: {} },
inputs: {},
outputs: {},
enabled: true,
},
{
id: 'agent1',
metadata: { id: 'agent', name: 'Agent' },
position: { x: 0, y: 0 },
config: { tool: 'agent', params: {} },
inputs: {},
outputs: {},
enabled: true,
},
],
connections: [
{ source: 'router1', target: 'api1' },
{ source: 'router1', target: 'api2' },
{ source: 'api1', target: 'agent1' },
{ source: 'api2', target: 'agent1' },
],
loops: {},
parallels: {},
}

pathTracker = new PathTracker(mockWorkflow)
mockContext = {
workflowId: 'test-router-workflow',
blockStates: new Map(),
blockLogs: [],
metadata: { duration: 0 },
environmentVariables: {},
decisions: { router: new Map(), condition: new Map() },
loopIterations: new Map(),
loopItems: new Map(),
completedLoops: new Set(),
executedBlocks: new Set(),
activeExecutionPath: new Set(),
workflow: mockWorkflow,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider extracting the workflow setup to a shared helper function since it's reused across multiple test cases

Comment on lines +28 to +31
error: any,
userCodeStartLine: number,
userCode?: string
): EnhancedError {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: error parameter should be typed with a specific error type rather than any to ensure type safety

Comment on lines +67 to +73
// Check if this is a syntax error in wrapper code caused by incomplete user code
const isWrapperSyntaxError =
stackLine > userCodeStartLine &&
error.name === 'SyntaxError' &&
(error.message.includes('Unexpected token') ||
error.message.includes('Unexpected end of input'))

Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider extracting this complex condition into a named function like isIncompleteSyntaxError for better readability

@delve-auditor
Copy link

delve-auditor bot commented Jul 2, 2025

No security or compliance issues detected. Reviewed everything up to 6779ec7.

Security Overview
  • 🔎 Scanned files: 38 changed file(s)
Detected Code Changes

The diff is too large to display a summary of code changes.

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

@waleedlatif1 waleedlatif1 merged commit 3b98253 into main Jul 2, 2025
9 checks passed
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
* feat(function): added more granular error logs for function execution for easier debugging (simstudioai#593)

* added more granular error logs for function execution

* added tests

* fixed syntax error reporting

* feat(models): added temp controls for gpt-4.1 family of models (simstudioai#594)

* improvement(knowledge-upload): create and upload document to KB (simstudioai#579)

* improvement: added knowledge upload

* improvement: added greptile comments (simstudioai#579)

* improvement: changed to text to doc (simstudioai#579)

* improvement: removed comment (simstudioai#579)

* added input validation, tested persistence of KB selector

* update docs

---------

Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>
Co-authored-by: Waleed Latif <walif6@gmail.com>

* fix(remove workflow.state usage): no more usage of deprecated state column in any routes (simstudioai#586)

* fix(remove workflow.state usage): no more usage of deprecated state col in routes

* fix lint

* fix chat route to only use deployed state

* fix lint

* better typing

* remove useless logs

* fix lint

* restore workflow handler file

* removed all other usages of deprecated 'state' column from workflows table, updated tests

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>
Co-authored-by: Waleed Latif <walif6@gmail.com>

* fix(doc-selector-kb): enable doc selector when kb is selected (simstudioai#596)

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan>

* fix(unload): remove beforeunload warning since we communicate via wss (simstudioai#597)

* fix(executor): fix dependency resolution, allow blocks with multiple inputs to execute (simstudioai#598)

* feat(billing): added migrations for usage-based billing (simstudioai#601)

* feat(billing): added migrations for usage-based billing

* lint

* lint

* feat(logging): add new schemas + types for new logging system (simstudioai#599)

* feat(logging): add new schemas + types for logging

* fix lint

* update migration

* fix lint

* Remove migration 48 to avoid conflict with staging

* fixed merge conflict

* fix lint

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>

---------

Co-authored-by: Adam Gough <77861281+aadamgough@users.noreply.github.com>
Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>
Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>
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.

4 participants