Skip to content

Comments

Adjust logs#1003

Merged
elie222 merged 5 commits intomainfrom
chore/logs
Nov 24, 2025
Merged

Adjust logs#1003
elie222 merged 5 commits intomainfrom
chore/logs

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Nov 24, 2025

Adjust logging by passing scoped Logger through apps/web/utils/label.server.ts::labelMessageAndSync and related label helpers, and broaden 404 detection in apps/web/utils/gmail/draft.ts::getDraft with isNotFoundError and info logging

Propagate a provided Logger into label operations and rule handlers, remove internal logger creation, and update Gmail draft retrieval to use isNotFoundError for 404-shaped errors with an info log when returning null. Error formatting utilities are refactored to use getSimpleErrorMessage and Object.keys-based serialization. Version bumps to v2.20.20.

📍Where to Start

Start with the updated logger signature in labelMessageAndSync in apps/web/utils/label.server.ts, then follow its call sites in apps/web/utils/ai/actions.ts, apps/web/utils/reply-tracker/label-helpers.ts, and the Gmail draft changes in apps/web/utils/gmail/draft.ts.


Macroscope summarized 8bbdd2c.

Summary by CodeRabbit

  • Bug Fixes

    • Safer error detection/serialization for draft retrieval and error handling.
  • Chores

    • Widespread logging improvements: logger is now propagated into labeling and thread-status flows and tests.
    • Internal error helpers and guards added for more robust error messages.
    • Version bumped to v2.20.20.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Nov 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
inbox-zero Ready Ready Preview Nov 24, 2025 1:32pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 24, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Threads a Logger through AI action handlers, label management, and reply-tracker utilities; replaces internal scoped logger creation with injected logger, adds safer error-inspection helpers, updates Gmail 404 detection, and bumps version to v2.20.20.

Changes

Cohort / File(s) Summary
AI action & rule flows
apps/web/utils/ai/actions.ts, apps/web/utils/ai/choose-rule/run-rules.ts, apps/web/utils/assistant/process-assistant-email.ts
Passes an existing logger into LABEL action handling, executeMatchedRule paths, and assistant email labeling calls so downstream label operations receive logging context.
Label management & reply-tracker
apps/web/utils/label.server.ts, apps/web/utils/reply-tracker/label-helpers.ts, apps/web/utils/reply-tracker/outbound.ts, apps/web/utils/reply-tracker/label-helpers.test.ts
Replaces local scoped-logger construction with an injected logger: Logger parameter; signatures updated and logger propagated through labelMessageAndSync, removeConflictingThreadStatusLabels, and applyThreadStatusLabel. Tests updated to pass a scoped test logger.
Logger utilities & Gmail draft handling
apps/web/utils/logger.ts, apps/web/utils/gmail/draft.ts
Introduces safer error-inspection helpers (getSimpleErrorMessage, isRecord, etc.) and replaces ad-hoc 404 checks with isNotFoundError(error) plus info-level logging when drafts are not found.
Maintenance
version.txt
Bump version from v2.20.19 to v2.20.20.

Sequence Diagram(s)

sequenceDiagram
  actor Caller
  participant AI as AI action / rule runner
  participant LabelSrv as label.server::labelMessageAndSync
  Note right of AI `#D5E8D4`: Logger now threaded\nas parameter
  Caller->>AI: trigger LABEL / matched rule (includes logger)
  AI->>LabelSrv: labelMessageAndSync(..., logger)
  LabelSrv-->>AI: result / errors (uses injected logger)
  AI-->>Caller: continues flow
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify all updated function signatures match callers (especially labelMessageAndSync, removeConflictingThreadStatusLabels, applyThreadStatusLabel).
  • Review logger.ts helpers (isRecord, getSimpleErrorMessage, isNotFoundError) for edge cases and correct handling of nested error shapes.
  • Check tests updated in label-helpers.test.ts correctly instantiate and pass the test logger.

Possibly related PRs

Poem

🐰 I hopped through code with careful paws,
Threading a logger without a pause.
No scopes destroyed, just passed along—
Now every label hums a loggy song.
Hooray for traces, neat and strong! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Adjust logs' is vague and generic, using a non-descriptive term that doesn't convey meaningful information about the specific changes made. Consider a more specific title that describes the main change, such as 'Refactor logging by injecting logger parameter through labeling and reply-tracker helpers' or 'Add logger dependency injection to labeling and error handling utilities'.
✅ 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 chore/logs

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89772f7 and 8bbdd2c.

📒 Files selected for processing (1)
  • apps/web/utils/reply-tracker/label-helpers.test.ts (11 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/utils/reply-tracker/label-helpers.test.ts (1)
apps/web/utils/logger.ts (1)
  • createScopedLogger (17-81)
⏰ 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). (3)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: test
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
apps/web/utils/reply-tracker/label-helpers.test.ts (2)

5-7: LGTM! Logger setup is appropriate for tests.

The test logger is correctly instantiated with a clear scope and reused across all test cases, which is efficient and follows the dependency injection pattern introduced in this PR.


72-349: LGTM! Logger parameter consistently added to all test cases.

All test invocations of applyThreadStatusLabel have been updated to include the logger parameter, maintaining consistency across the test suite while adapting to the new API signature.


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.

err.error?.status ??
err.error?.code;

return statusCode === 404;
Copy link
Contributor

Choose a reason for hiding this comment

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

statusCode can be a string, so strict === 404 may miss not-found cases. Consider normalizing the value to a number before comparing so getDraft returns null consistently.

-  return statusCode === 404;
+  const code = typeof statusCode === "string" ? Number(statusCode) : statusCode;
+  return code === 404;

🚀 Reply to ask Macroscope to explain or update this suggestion.

👍 Helpful? React to give us feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (3)
apps/web/utils/gmail/draft.ts (1)

30-47: Consider the function naming overlap.

The isNotFoundError function is well-implemented and handles multiple Gmail error shapes correctly. However, note that a function with the same name exists in apps/web/utils/prisma-helpers.ts (lines 13-18) for Prisma errors. While they're in different files and handle different error types, consider whether this could cause confusion in the future.

The current implementation is acceptable since:

  • They handle different error domains (Gmail API vs Prisma)
  • They're in separate modules with clear contexts
  • The Gmail-specific checks are appropriate here
apps/web/utils/logger.ts (1)

148-154: Optional: Remove redundant hasOwn check.

The Object.keys(error) on line 149 already returns only own enumerable properties, making the Object.hasOwn(error, key) check on line 150 redundant (though harmless). You could simplify to:

 if (isRecord(error)) {
   for (const key of Object.keys(error)) {
-    if (Object.hasOwn(error, key)) {
-      serialized[key] = error[key];
-    }
+    serialized[key] = error[key];
   }
 }

However, the defensive check doesn't hurt and may prevent issues if the code evolves.

apps/web/utils/label.server.ts (1)

19-19: Dependency injection implemented correctly.

The logger parameter is properly threaded through the function signature and used to create a scoped logger with the appropriate context. The implementation maintains the existing logging behavior while enabling consistent context propagation.

The parameter aliasing pattern (logger: logconst logger = log.with()) is functional but could be clearer. Consider either:

  • Using consistent naming: logger parameter → const scopedLogger = logger.with(...)
  • Or more descriptive names: baseLoggerconst logger = baseLogger.with(...)

However, if this pattern is intentional and consistent across the codebase (per the PR summary), maintaining consistency may be preferable.

Also applies to: 26-26, 28-28

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d979f3c and 89772f7.

📒 Files selected for processing (9)
  • apps/web/utils/ai/actions.ts (1 hunks)
  • apps/web/utils/ai/choose-rule/run-rules.ts (1 hunks)
  • apps/web/utils/assistant/process-assistant-email.ts (1 hunks)
  • apps/web/utils/gmail/draft.ts (1 hunks)
  • apps/web/utils/label.server.ts (2 hunks)
  • apps/web/utils/logger.ts (3 hunks)
  • apps/web/utils/reply-tracker/label-helpers.ts (5 hunks)
  • apps/web/utils/reply-tracker/outbound.ts (1 hunks)
  • version.txt (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
apps/web/utils/gmail/draft.ts (2)
apps/web/utils/prisma-helpers.ts (1)
  • isNotFoundError (14-19)
apps/web/utils/error.ts (1)
  • isGmailError (25-34)
apps/web/utils/reply-tracker/label-helpers.ts (3)
apps/web/utils/reply-tracker/conversation-status-config.ts (1)
  • ConversationStatus (10-14)
apps/web/utils/email/types.ts (2)
  • EmailProvider (45-250)
  • EmailLabel (14-25)
apps/web/utils/logger.ts (1)
  • Logger (5-5)
apps/web/utils/label.server.ts (2)
apps/web/utils/email/types.ts (1)
  • EmailProvider (45-250)
apps/web/utils/logger.ts (1)
  • Logger (5-5)
🪛 GitHub Actions: Run Tests
apps/web/utils/reply-tracker/label-helpers.ts

[error] 141-141: Cannot read properties of undefined (reading 'error') in catch block while applying thread status label. Failed to log error details: 'Failed to apply thread status label'.

⏰ 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: cubic · AI code reviewer
  • GitHub Check: Review for correctness
🔇 Additional comments (13)
version.txt (1)

1-1: LGTM!

Version bump is appropriate for this refactoring PR.

apps/web/utils/ai/actions.ts (1)

126-126: LGTM!

Logger propagation to labelMessageAndSync is correct and consistent with the PR's logging refactor.

apps/web/utils/gmail/draft.ts (1)

22-25: LGTM!

The refactored error handling with isNotFoundError improves clarity and logging.

apps/web/utils/ai/choose-rule/run-rules.ts (1)

331-331: LGTM!

Logger propagation to removeConflictingThreadStatusLabels is correct and improves observability of the conversation status tracking flow.

apps/web/utils/assistant/process-assistant-email.ts (1)

273-273: LGTM!

Logger propagation to labelMessageAndSync is correct and maintains consistency with the PR's logging refactor.

apps/web/utils/logger.ts (2)

129-129: LGTM!

Using getSimpleErrorMessage centralizes error message extraction and improves consistency.


182-220: LGTM!

The new error handling helpers are well-designed and provide safer type guards for error message extraction. The logic correctly handles multiple error shapes (string, Error instance, objects with message, nested errors).

apps/web/utils/reply-tracker/outbound.ts (1)

85-85: LGTM!

Logger propagation to applyThreadStatusLabel is correct and enables consistent logging in the outbound reply tracking flow.

apps/web/utils/reply-tracker/label-helpers.ts (4)

2-2: LGTM!

The transition from internal logger creation to dependency injection is correct. The logger parameter is properly typed and will be propagated through all function calls.

Also applies to: 27-27, 35-35


65-79: LGTM!

Logger usage in removeConflictingThreadStatusLabels is correct, with appropriate info and error logging.


94-94: LGTM!

Logger propagation through applyThreadStatusLabel and its internal calls is correct. The logger is properly threaded through labelMessageAndSync and removeConflictingThreadStatusLabels.

Regarding the pipeline failure about "Cannot read properties of undefined (reading 'error')": The code in this file appears correct. The logger parameter is required and properly typed, and targetLabel is always an object (from dbLabels). The failure might indicate an issue with how this function is being called elsewhere, but the implementation here is sound.

Also applies to: 101-101, 139-139, 157-157, 162-162


126-131: Error logging is correct.

Both error logging locations properly use the logger parameter and include relevant context. The targetLabel variable is guaranteed to be an object at these points (sourced from dbLabels), so accessing its properties is safe.

Also applies to: 140-146

apps/web/utils/label.server.ts (1)

2-2: LGTM!

Good use of type-only import for the Logger type, which aids tree-shaking and clarifies that this is used only for type checking.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 9 files

@elie222 elie222 merged commit bf23c21 into main Nov 24, 2025
15 checks passed
@elie222 elie222 deleted the chore/logs branch November 24, 2025 13:42
@coderabbitai coderabbitai bot mentioned this pull request Nov 24, 2025
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