Skip to content

Hotfix/v1.1.4 - #539

Merged
jwfing merged 8 commits into
mainfrom
hotfix/v1.1.4
Oct 30, 2025
Merged

jwfing merged 8 commits into
mainfrom
hotfix/v1.1.4

Conversation

@jwfing

@jwfing jwfing commented Oct 29, 2025 •

Copy link
Copy Markdown
Member

Summary

Hotfix: logs disappear on cloud.

How did you test this change?

Locally test with project dashboard.

Summary by CodeRabbit

  • Bug Fixes

    • Logging now prefers cloud provider when cloud environment or credentials exist.
    • Unified parsing to populate a top-level metadata.level and normalized levels across log sources.
    • Frontend log severity now reads metadata.level with default to "informational".
    • Signed CloudFront URLs now URL-encode S3 key path segments to handle special characters.
  • New Features

    • Real-time database change notifications broadcast to relevant clients.
    • Routes now use explicit redirect targets for unauthenticated access.
  • Chores

    • Updated package version to 1.1.6

@coderabbitai

coderabbitai Bot commented Oct 29, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Logging and log-parsing behaviors updated: log provider now uses CloudWatch if AWS credentials exist or the runtime is detected as cloud; vector config normalizes level into metadata.level; frontend severity reads metadata.level; S3 CloudFront URLs now URL-encode each path segment; package version bumped to 1.1.6. Additional changes: real-time DB schema update broadcasts added and RequireAuth now accepts an explicit redirect target; route groups updated to pass redirects.

Changes

Cohort / File(s) Change Summary
Log provider selection
backend/src/core/logs/logs.ts
Import isCloudEnvironment; set hasAwsCredentials when AWS keys exist OR isCloudEnvironment() is true; choose CloudWatchProvider when true, otherwise initialize LocalFileProvider; update comments.
Vector log parsing / normalization
docker-init/logs/vector.yml
Populate top-level metadata.level (uppercased) across InsForge request/app logs, Deno logs, and PostgreSQL db_logs; flatten request JSON fields when present and tag log_type: "request"; normalize STATEMENT/DETAIL to INFO and default parse failures to LOG.
Frontend severity derivation
frontend/src/features/logs/hooks/useLogs.ts
getSeverity now reads log.body.metadata.level (default informational), lowercases and maps to error/warning/informational instead of parsing eventMessage or body?.error.
S3 / CloudFront URL encoding
backend/src/core/storage/storage.ts
URL-encode each S3 key path segment when constructing CloudFront object URLs for signed URLs (encodedS3Key) to handle special characters in object keys.
Real-time DB update broadcasts
backend/src/api/routes/database.advance.ts
After successful operations in three routes (rawsql unrestricted, rawsql, import), broadcast DATA_UPDATE to role:project_admin room with resource DATABASE_SCHEMA via SocketService.
Routing: explicit redirects
frontend/src/lib/routing/AppRoutes.tsx
Route groups updated to pass explicit redirect targets: /cloud/* -> /cloud/login, /* -> /dashboard/login.
RequireAuth prop change
frontend/src/lib/routing/RequireAuth.tsx
Add redirectTo: string prop to RequireAuthProps; use redirectTo for unauthenticated navigation; remove unused isInsForgeCloudProject import.
Version bump
package.json
Bump version from 1.1.2 to 1.1.6.

Sequence Diagram(s)

sequenceDiagram
  participant Init as Logs.initialize()
  participant Env as isCloudEnvironment()
  participant AWS as AWS Credentials Check
  participant Selector as Provider Selector
  participant CW as CloudWatchProvider
  participant LF as LocalFileProvider

  Note over Init,Env: Logs initialization
  Init->>AWS: check for AWS keys
  Init->>Env: isCloudEnvironment()
  alt AWS keys OR cloud env
    Selector->>CW: initialize CloudWatchProvider
    Note right of CW: runtime uses CloudWatch
  else neither present
    Selector->>LF: initialize LocalFileProvider
    Note right of LF: fallback to file-based logs
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect backend/src/core/logs/logs.ts for correct detection semantics of isCloudEnvironment() across CI/local/cloud.
  • Validate docker-init/logs/vector.yml regexes and normalization rules (request flattening, DB normalization).
  • Confirm backend/src/core/storage/storage.ts URL-encoding doesn't alter expected signed-URL behavior.
  • Review new socket broadcasts in backend/src/api/routes/database.advance.ts for event payload and room targeting.
  • Check RequireAuth prop usage site changes (routes updated) to ensure all call sites pass redirectTo.

Possibly related PRs

Suggested reviewers

  • tonychang04

Poem

🐇 I hopped through logs at break of dawn,
Cloud or keys now tell me where to yawn,
Levels rise to metadata's light,
Paths encoded for URLs bright,
A little rabbit signs it "done" ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The PR title "Hotfix/v1.1.4" is vague and uses non-descriptive terminology that fails to convey meaningful information about the changeset. While the PR objectives indicate this addresses logs disappearing on cloud, the title does not reflect this primary concern. Additionally, there is a version mismatch: the title references v1.1.4, but package.json shows the version was bumped to v1.1.6. The title reads more like a branch name than a descriptive PR summary, and a teammate scanning the history would not understand what was actually fixed without opening the PR to review the details. Revise the title to be more specific and descriptive about what the hotfix addresses, such as "Fix logs disappearing in cloud environment" or "Fix cloud log parsing and severity detection". Additionally, verify and correct the version reference to match the actual version change (v1.1.6). This will help teammates quickly understand the purpose of this PR when scanning the repository history.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hotfix/v1.1.4

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
backend/src/core/logs/logs.ts (2)

22-23: Minor grammar improvement for comment clarity.

Consider refining the comment for better readability:

-    // Use CloudWatch if AWS credentials are available or if it's cloud environment since we provided the permissions in instance profile
+    // Use CloudWatch if AWS credentials are available or if running in a cloud environment with instance profile permissions
     // otherwise use file-based logging

24-25: Consider renaming variable to better reflect its purpose.

The variable name hasAwsCredentials is misleading since it checks both explicit AWS credentials and cloud environment (instance profile). Consider a more descriptive name like shouldUseCloudWatch or hasCloudWatchAccess.

-    const hasAwsCredentials =
+    const shouldUseCloudWatch =
       (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) || isCloudEnvironment();

-    if (hasAwsCredentials) {
+    if (shouldUseCloudWatch) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4fc9434 and dc82d0a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • backend/src/core/logs/logs.ts (2 hunks)
  • docker-init/logs/vector.yml (3 hunks)
  • package.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use TypeScript for all code files
Use ES modules (import/export syntax)
Prefer descriptive, unabbreviated variable and function names
Implement proper error handling with try-catch blocks and logging where appropriate
Use single quotes for strings
Include semicolons at the end of statements
Use arrow functions for callbacks and inline functions
Prefer const over let; avoid var
Use template literals for string interpolation
Maintain 2-space indentation
Format code with the repository Prettier configuration
Variables, parameters, properties, and functions must use camelCase
Constants and enum members must use UPPER_CASE
Include JSDoc comments for complex functions

Files:

  • backend/src/core/logs/logs.ts
backend/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

backend/src/**/*.{ts,tsx}: Use async/await for asynchronous operations in the backend
Use Zod schemas for request/response validation
Return consistent API responses using utility functions
Validate all user inputs
Sanitize data before database operations
Use prepared statements for SQL queries
Implement proper caching strategies (server-side)

Files:

  • backend/src/core/logs/logs.ts
backend/src/{controllers,core}/**/*.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Implement proper database transaction handling

Files:

  • backend/src/core/logs/logs.ts
**/*.{tsx,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

React components and TypeScript types/interfaces must use PascalCase

Files:

  • backend/src/core/logs/logs.ts
**/[a-z][a-z0-9-]*.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Utility files should use kebab-case or camelCase (kebab-case validated here)

Files:

  • backend/src/core/logs/logs.ts
🧬 Code graph analysis (1)
backend/src/core/logs/logs.ts (1)
backend/src/utils/environment.ts (1)
  • isCloudEnvironment (9-11)
🔇 Additional comments (4)
package.json (1)

3-3: Verify version number matches release intent.

The PR title indicates "Hotfix/v1.1.4", but the version is set to 1.1.6. Please confirm this is intentional and not a typo.

docker-init/logs/vector.yml (3)

84-84: Consider normalizing log level to uppercase for consistency.

The InsForge logs set metadata.level directly from req.level without uppercasing, while both Deno logs (line 131) and DB logs (line 146) apply upcase!(). If InsForge can emit mixed-case levels (e.g., "info", "INFO"), this could lead to inconsistent level values across log sources.

Verify whether InsForge always emits uppercase log levels. If not, consider applying upcase!() for consistency:

-          .metadata.level = req.level
+          .metadata.level = upcase!(req.level)

127-131: LGTM! Proper log level normalization for Deno logs.

The regex parsing and uppercase conversion ensure consistent log level formatting across the system.


146-158: LGTM! Proper PostgreSQL log parsing and normalization.

The implementation correctly:

  • Normalizes log levels to uppercase
  • Maps PostgreSQL-specific levels (STATEMENT, DETAIL) to INFO for better clarity
  • Provides a sensible default level when parsing fails

@Fermionic-Lyu Fermionic-Lyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you provide an example of what the log structure currently look like, so I can parse it correctly in the frontend

Comment thread package-lock.json
"": {
"name": "insforge",
"version": "1.1.2",
"version": "1.1.4",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is going on here?

@Fermionic-Lyu

Copy link
Copy Markdown
Member

Oh should I change the frontend as well before publishing v1.1.6?

@jwfing

jwfing commented Oct 29, 2025

Copy link
Copy Markdown
Member Author

@Fermionic-Lyu Now the level of all different sources has been saved on eventMessage.metadata.level, If the value isn't existed, use the default 'INFO'.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a35fd9c and 97fa170.

📒 Files selected for processing (3)
  • backend/src/api/routes/database.advance.ts (4 hunks)
  • frontend/src/lib/routing/AppRoutes.tsx (2 hunks)
  • frontend/src/lib/routing/RequireAuth.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use TypeScript for all code files
Use ES modules (import/export syntax)
Prefer descriptive, unabbreviated variable and function names
Implement proper error handling with try-catch blocks and logging where appropriate
Use single quotes for strings
Include semicolons at the end of statements
Use arrow functions for callbacks and inline functions
Prefer const over let; avoid var
Use template literals for string interpolation
Maintain 2-space indentation
Format code with the repository Prettier configuration
Variables, parameters, properties, and functions must use camelCase
Constants and enum members must use UPPER_CASE
Include JSDoc comments for complex functions

Files:

  • backend/src/api/routes/database.advance.ts
  • frontend/src/lib/routing/AppRoutes.tsx
  • frontend/src/lib/routing/RequireAuth.tsx
backend/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

backend/src/**/*.{ts,tsx}: Use async/await for asynchronous operations in the backend
Use Zod schemas for request/response validation
Return consistent API responses using utility functions
Validate all user inputs
Sanitize data before database operations
Use prepared statements for SQL queries
Implement proper caching strategies (server-side)

Files:

  • backend/src/api/routes/database.advance.ts
backend/src/api/**/*.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

backend/src/api/**/*.ts: Implement authentication and error-handling middleware
Follow RESTful conventions for API endpoints
Implement rate limiting for API endpoints

Files:

  • backend/src/api/routes/database.advance.ts
**/*.{tsx,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

React components and TypeScript types/interfaces must use PascalCase

Files:

  • backend/src/api/routes/database.advance.ts
  • frontend/src/lib/routing/AppRoutes.tsx
  • frontend/src/lib/routing/RequireAuth.tsx
**/[a-z][a-z0-9-]*.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Utility files should use kebab-case or camelCase (kebab-case validated here)

Files:

  • backend/src/api/routes/database.advance.ts
frontend/src/**/*.{tsx,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

frontend/src/**/*.{tsx,ts}: Use functional React components with hooks exclusively
Use Radix UI primitives for accessibility
Optimize React component re-renders

Files:

  • frontend/src/lib/routing/AppRoutes.tsx
  • frontend/src/lib/routing/RequireAuth.tsx
frontend/src/**/*.tsx

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

frontend/src/**/*.tsx: Implement TypeScript interfaces/types for all component props
Follow component composition patterns; keep components focused and single-purpose
Implement proper loading and error states in UI
Use a consistent icon set from lucide-react

Files:

  • frontend/src/lib/routing/AppRoutes.tsx
  • frontend/src/lib/routing/RequireAuth.tsx
frontend/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

frontend/src/**/*.{ts,tsx}: Use TanStack Query for server state management
Use React Hook Form for form handling with Zod validation
Optimize bundle size with proper imports

Files:

  • frontend/src/lib/routing/AppRoutes.tsx
  • frontend/src/lib/routing/RequireAuth.tsx
frontend/src/**/[A-Z]*.tsx

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Component files must use PascalCase filenames (e.g., DataGrid.tsx)

Files:

  • frontend/src/lib/routing/AppRoutes.tsx
  • frontend/src/lib/routing/RequireAuth.tsx
🧠 Learnings (2)
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
PR: InsForge/InsForge#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to backend/src/{controllers,core}/**/*.ts : Implement proper database transaction handling

Applied to files:

  • backend/src/api/routes/database.advance.ts
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
PR: InsForge/InsForge#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to backend/src/api/**/*.ts : Implement authentication and error-handling middleware

Applied to files:

  • frontend/src/lib/routing/AppRoutes.tsx
🧬 Code graph analysis (2)
backend/src/api/routes/database.advance.ts (1)
backend/src/core/socket/socket.ts (1)
  • SocketService (23-385)
frontend/src/lib/routing/AppRoutes.tsx (1)
frontend/src/lib/routing/RequireAuth.tsx (1)
  • RequireAuth (11-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: CI Pre-merge Check
  • GitHub Check: E2E Tests
🔇 Additional comments (3)
backend/src/api/routes/database.advance.ts (1)

15-16: LGTM - Clean socket service integration.

The imports are appropriate for adding real-time update notifications to database operations.

frontend/src/lib/routing/AppRoutes.tsx (1)

27-27: LGTM - Improved routing clarity.

Making the redirect destinations explicit improves code readability and separates routing concerns from authentication logic. The redirect paths correctly match the login routes defined on lines 22-23.

Also applies to: 49-49

frontend/src/lib/routing/RequireAuth.tsx (1)

8-8: LGTM - Clean separation of concerns.

The refactor successfully externalizes redirect logic, making RequireAuth more reusable. The required redirectTo prop ensures callers explicitly specify authentication flow destinations.

Also applies to: 11-11, 23-23

Comment on lines +63 to +66
const socket = SocketService.getInstance();
socket.broadcastToRoom('role:project_admin', ServerEvents.DATA_UPDATE, {
resource: DataUpdateResourceType.DATABASE_SCHEMA,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Missing broadcast in bulk-upsert route.

The socket broadcasts correctly notify project_admin users of database changes in the raw SQL and import routes. However, the bulk-upsert route (lines 216-281) also modifies database content and should emit the same broadcast for consistency.

Add the broadcast after the audit log in the bulk-upsert route:

       // Log audit
       await auditService.log({
         actor: req.user?.email || 'api-key',
         action: 'BULK_UPSERT',
         module: 'DATABASE',
         details: {
           table,
           filename: req.file.originalname,
           fileSize: req.file.size,
           upsertKey: upsertKey || null,
           rowsAffected: response.rowsAffected,
           totalRecords: response.totalRecords,
         },
         ip_address: req.ip,
       });
 
+      const socket = SocketService.getInstance();
+      socket.broadcastToRoom('role:project_admin', ServerEvents.DATA_UPDATE, {
+        resource: DataUpdateResourceType.DATABASE_SCHEMA,
+      });
+
       res.json(response);

Also applies to: 126-129, 333-336

🤖 Prompt for AI Agents
In backend/src/api/routes/database.advance.ts around lines 63-66 and
specifically for the bulk-upsert route at lines 216-281 (also apply same change
at 126-129 and 333-336): the socket broadcast notifying 'role:project_admin' of
DataUpdateResourceType.DATABASE_SCHEMA is missing for the bulk-upsert flow;
after the audit log is written in the bulk-upsert route, call the SocketService
singleton to broadcast ServerEvents.DATA_UPDATE with resource:
DataUpdateResourceType.DATABASE_SCHEMA to the 'role:project_admin' room
(matching the pattern used at lines 63-66) so project admins receive consistent
update notifications.

@jwfing
jwfing merged commit 7e148d2 into main Oct 30, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Nov 12, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Apr 2, 2026
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.

3 participants