Skip to content

Fix createConsoleSink() ignoring falsy timestamps like 0#705

Merged
dahlia merged 3 commits intomainfrom
fix/issue-311-console-sink-falsy-timestamp
Mar 22, 2026
Merged

Fix createConsoleSink() ignoring falsy timestamps like 0#705
dahlia merged 3 commits intomainfrom
fix/issue-311-console-sink-falsy-timestamp

Conversation

@dahlia
Copy link
Copy Markdown
Owner

@dahlia dahlia commented Mar 22, 2026

createConsoleSink() used a truthiness check on record.timestamp to decide whether to format the record's timestamp or fall back to the current time:

const timestamp = record.timestamp
  ? new Date(record.timestamp).toISOString()
  : new Date().toISOString();

Because 0 is falsy in JavaScript, a valid timestamp of 0 (the Unix epoch, 1970-01-01T00:00:00.000Z) was silently replaced with new Date(), producing the current wall-clock time instead.

The fix replaces the truthiness check with a nullish check (record.timestamp != null), so that 0 and any other falsy-but-valid numeric timestamps are preserved correctly.

A regression test for timestamp: 0 has been added, and the existing "should route by stream resolver" test in index.test.ts has been strengthened to also verify the timestamp value in its output.

Closes #311

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a bug in createConsoleSink() where valid numeric timestamps, such as 0 representing the Unix epoch, were being ignored due to a JavaScript truthiness check. This led to the system substituting the current wall-clock time instead of the provided timestamp. The change ensures that all valid numeric timestamps are correctly processed, enhancing the accuracy of log records. New and updated tests validate this behavior.

Highlights

  • createConsoleSink() Timestamp Fix: Corrected an issue where createConsoleSink() incorrectly handled falsy record.timestamp values, specifically 0 (Unix epoch), by replacing a truthiness check with a nullish check (!= null).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dahlia dahlia self-assigned this Mar 22, 2026
@dahlia dahlia added the bug Something isn't working label Mar 22, 2026
@dahlia dahlia added this to the Optique 1.0 milestone Mar 22, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug where a timestamp of 0 was being ignored by createConsoleSink(). The change from a truthiness check to a nullish check is appropriate. The addition of a regression test and strengthening of an existing test are also great improvements. I've suggested a small refinement to make the code more concise and align with the repository's style guide regarding default values.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bfb79feb-d0fb-462b-bd60-af4dcbf58450

📥 Commits

Reviewing files that changed from the base of the PR and between f1e4357 and d02189e.

📒 Files selected for processing (2)
  • packages/logtape/src/index.test.ts
  • packages/logtape/src/output.ts

Walkthrough

The PR fixes timestamp handling in createConsoleSink() so only null/undefined/NaN cause falling back to the current time; falsy numeric timestamps like 0 are now formatted as the Unix epoch. Tests were added: one asserting timestamp: 0 yields 1970-01-01T00:00:00.000Z, another ensuring timestamp: NaN still produces a valid ISO timestamp; routing tests were updated to expect full timestamp-prefixed lines. CHANGES.md was updated with a changelog bullet and reference links.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main fix: correcting createConsoleSink() to handle falsy timestamps like 0.
Description check ✅ Passed The description is well-related to the changeset, explaining the bug, the fix, and the test additions in clear detail.
Linked Issues check ✅ Passed The PR successfully addresses issue #311 by replacing the truthiness check with a nullish check, adding regression tests, and handling NaN edge cases.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the timestamp handling bug in createConsoleSink() and adding corresponding tests; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-311-console-sink-falsy-timestamp

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.

The truthiness check `record.timestamp ? ...` treated a valid
timestamp of `0` (Unix epoch) as absent because `0` is falsy
in JavaScript. Use a nullish check (`!= null`) instead.

Close #311

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dahlia dahlia force-pushed the fix/issue-311-console-sink-falsy-timestamp branch from 1d29a0f to f638e97 Compare March 22, 2026 13:01
#705 (comment)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dahlia
Copy link
Copy Markdown
Owner Author

dahlia commented Mar 22, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Owner Author

dahlia commented Mar 22, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug where a timestamp of 0 was being ignored by createConsoleSink(). The change from a truthiness check to a nullish coalescing operator is the right approach and aligns with the project's style guide. The addition of a specific regression test for this case and the strengthening of an existing test are excellent practices that improve the robustness of the codebase. The changes are well-implemented and I have no further suggestions.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1e4357bd6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

When record.timestamp is NaN, new Date(NaN).toISOString() throws
a RangeError. Add a Number.isNaN() check to fall back to the
current time instead of crashing.

#705 (comment)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dahlia
Copy link
Copy Markdown
Owner Author

dahlia commented Mar 22, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Owner Author

dahlia commented Mar 22, 2026

/gemini review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d02189e0c1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes an issue where a timestamp of 0 was ignored in createConsoleSink(). The change from a truthiness check to a nullish and isNaN check is robust and also handles the NaN edge case. The added tests effectively cover the fix and the edge case. The suggestion to refactor the new tests to reduce code duplication by extracting a helper function is not necessary, as the duplication is minimal and a local helper is preferred.

@dahlia dahlia merged commit 69c819e into main Mar 22, 2026
6 checks passed
@dahlia dahlia deleted the fix/issue-311-console-sink-falsy-timestamp branch March 22, 2026 13:29
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@c7adf09). Learn more about missing BASE report.
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #705   +/-   ##
=======================================
  Coverage        ?   93.96%           
=======================================
  Files           ?       38           
  Lines           ?    19135           
  Branches        ?     5217           
=======================================
  Hits            ?    17980           
  Misses          ?     1135           
  Partials        ?       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createConsoleSink() ignores falsy timestamps like 0 and substitutes the current time

1 participant