Skip to content

Conversation

bagusnl
Copy link
Member

@bagusnl bagusnl commented Aug 30, 2025

Main Goal

  1. Update Sentry package.
  2. Remove "LoadedModules" as its not been that much useful for debugging.
  3. Only push last 100 lines of the log to lower uploaded logs.
  4. Enhance exception handler for loop method

PR Status :

  • Overall Status : Done
  • Commits : Done
  • Synced to base (Collapse:main) : Yes
  • Build status : OK
  • Crashing : No
  • Bug found caused by PR : 0

Templates

Changelog Prefixes
  **[New]**
  **[Imp]**
  **[Fix]**
  **[Loc]**
  **[Doc]**

…abilities

1. Remove "LoadedModules" as its not been that much useful for debugging.
2. Only push last 100 lines of the log to lower uploaded logs.
@bagusnl bagusnl requested review from a team and Copilot August 30, 2025 15:36
@bagusnl bagusnl self-assigned this Aug 30, 2025
@bagusnl bagusnl added Enhancement New feature or request Area: Runtime Issue labeled for runtime, Hi3Helper.Core and other libraries used by Collapse Priority: Medium Size: Small labels Aug 30, 2025
Copilot

This comment was marked as outdated.

1. Let logStream gets handled by GC
2. Increase LastLine method buffer to 8K and not hardcode lineBuffer size
@bagusnl bagusnl requested a review from Copilot August 30, 2025 15:48
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves Sentry integration by updating the Sentry package from version 5.12.0 to 5.14.1, removing the LoadedModules feature that wasn't useful for debugging, limiting log uploads to the last 100 lines to reduce bandwidth, and enhancing the exception handler for loop methods with better concurrency control.

  • Updated Sentry package to version 5.14.1 across the solution
  • Replaced LoadedModules collection with streamlined log handling (last 100 lines only)
  • Enhanced exception loop handler with improved thread safety and cancellation token management

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Hi3Helper.TaskScheduler/packages.lock.json Updated package lock file with new reference assemblies dependency
Hi3Helper.Core/packages.lock.json Updated Sentry package version from 5.12.0 to 5.14.1
Hi3Helper.Core/Hi3Helper.Core.csproj Updated Sentry package reference to version 5.14.1
Hi3Helper.Core/Classes/SentryHelper/SentryLoggerExtension.cs Added new custom diagnostic logger implementation for Sentry
Hi3Helper.Core/Classes/SentryHelper/SentryHelper.cs Major refactoring of Sentry helper with improved exception handling and log management
CollapseLauncher/packages.lock.json Updated transitive Sentry dependency and removed ILCompiler package

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


// trim end and return
var len = sb.Length;
while (sb[len - 1] == ' ')
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Potential index out of bounds exception when sb.Length is 0. The code doesn't check if len is greater than 0 before accessing sb[len - 1].

Suggested change
while (sb[len - 1] == ' ')
while (len > 0 && sb[len - 1] == ' ')

Copilot uses AI. Check for mistakes.


#region Private Tools

private static unsafe string[] GetLastLinesWithBuffer(string filePath, int maxLines)
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Using unsafe code with stack allocation may not provide significant performance benefits for this use case and increases complexity. Consider using a safer approach with managed arrays or spans for better maintainability.

Copilot uses AI. Check for mistakes.

Comment on lines 648 to 651
if (lineLength < lineBufferSize - 1) // Prevent buffer overflow
{
lineBuffer[lineLength++] = (char)b;
}
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Silent truncation of long lines without any indication. Lines longer than the buffer will be silently cut off, which could lead to incomplete log data being sent to Sentry.

Copilot uses AI. Check for mistakes.

Comment on lines 340 to 344
Task.Run(async () =>
{
await oldToken.CancelAsync();
oldToken.Dispose();
}, oldToken.Token);
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Using oldToken.Token as the cancellation token for the task that cancels oldToken creates a circular dependency. The task may be cancelled before it can complete its cleanup work.

Suggested change
Task.Run(async () =>
{
await oldToken.CancelAsync();
oldToken.Dispose();
}, oldToken.Token);
});

Copilot uses AI. Check for mistakes.

+ Switching to write the line to stream on the fly
+ Scan from the end of the stream
+ Remove trailing line feeds if exists at the end of the file
Copy link
Member

@neon-nyan neon-nyan left a comment

Choose a reason for hiding this comment

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

As per internal discussion, some changes have been made. We can continue merging this PR

Copy link

sonarqubecloud bot commented Sep 2, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@neon-nyan neon-nyan merged commit 8546f4a into plugin Sep 2, 2025
4 of 7 checks passed
@Cryotechnic Cryotechnic deleted the feat/exper/sentry-logging branch September 16, 2025 03:34
neon-nyan added a commit that referenced this pull request Sep 16, 2025
![UpdateIsAvailable-Campaign](https://github.com/user-attachments/assets/5c5df62c-8570-4018-b6e7-66d5decf8278)
### Hi there, it's neon-nyan here~

It's been almost 3 weeks since the last preview update. To commemorate
the upcoming Genshin Impact 6.0 (aka: Luna I) update, we have decided to
use a new codename for this release as: "**Luna**"

With this release, we are bringing a long-awaited feature, the Plugin
System. This will catapult the development of Collapse to become not
only an exclusively third-party launcher for HoYoverse/miHoYo titles,
but also others in the future.

Without further ado, let's get into details regarding this update!

# What's New?
## [Plugin System for Other Non-miHoYo Titles
Support](#752), by
@neon-nyan
3 Months, 9000+ of lines changes later, we have finally finished the
first iteration of Plugin System implementation. For now, only basic
functionalities implemented into this plugin system as per the
[v0.1-update1 API
Standard](https://github.com/CollapseLauncher/Hi3Helper.Plugin.Core/tree/98ac5f08e48661f50f34b6d2bb2571fb9bd26730),
including:
- Game Installation
- Game Update/Preload

> Note: Other features like Game Repair, Game Caches and Game Settings
are going to be implemented in the future.

We are planning to make our own in-house plugins which will bring
support to two games are expected to be finished once the Luna release
releases to Stable:
- **Heaven Burns Red**
  Developed and Maintained by: Collapse Project Team (@neon-nyan)
  Status: Completed
- **Wuthering Waves**
  Developed and Maintained by: Collapse Project Team (@Cryotechnic)
  Status: Under Development

This implementation took more time due to a NativeAOT implementation of
the system. We are trying to make the plugin to not only works inside of
our code, but also usable for any code/launchers implementation out
there (if they want to).

We are making the compiled plugin footprint as small as possible by
removing any dependencies with .NET Reflections, stripping out .NET
Runtime and implementing COM-Like interfaces to bridge the communication
with plugins and the launcher, making the plugin compiled as a native
library instead of a .NET standard library. With this, we are achieving
6-7 MB for the plugin library.

The plugin can be managed by using the Plugin Manager menu under the App
Settings. Here's how it works:

[2025-09-14
21-51-48.webm](https://github.com/user-attachments/assets/0e972c82-c6d1-41ac-a2a4-b705b703d234)

> **PS:** Plugin download for Heaven Burns Red will be available soon.
Join our official Discord to get you hands on the early access~ 👀

## Bring Back NativeAOT Build
Due to .NET issues in
[#104583](dotnet/runtime#104583), we are unable
to ship NativeAOT build to preview. Fortunately, the latest .NET 9
Runtime comes with a fix and the UI hang issue has been fixed in most
scenarios.

Publishing a NativeAOT Build brings some benefits, including faster cold
start-up time, slight improvements on overall code performance (which
relies on frequent inline calls) and smaller compiled code.

This demo shows an improvement to the cold start-up time while the
launcher is launched. We took Stable v1.82.31 as a baseline to the
comparison and as a result, old ILCompile build start-up finished in 916
milliseconds while NativeAOT build start-up finished in just 466
milliseconds.


[ComparisonAOTvsNonAOT.webm](https://github.com/user-attachments/assets/5b659198-76c9-4f42-9836-6901e231da31)

This also results in a much smaller build as most of the .NET runtime
code are stripped. Here's the comparison of the build size between two
builds (with debug symbols removed):

<img width="731" height="515" alt="image"
src="https://github.com/user-attachments/assets/5fb87181-7a00-4169-8903-874111024267"
/>

## [Revamp Post-Download Behavior
Settings](#777), by
@gablm
We have added few options on how the launcher will do after game
installation/update. You can also set the Download Speed Limit while
performing game installation or update.

<img width="802" height="454" alt="image"
src="https://github.com/user-attachments/assets/2df669e5-c44a-4d51-b3e7-a98f203f951d"
/>

## Cached API Response for Application-wide Functions, by @neon-nyan
Tired of waiting for the launcher to load up each of the regions? Now,
you can make it faster. With the new HTTP Cache method, you can make
game region loadings much faster (even almost immediate). Previously,
this feature is only available for few functionality, including Game
Repair and Cache Updates. Now, every API calls from the launcher can be
cached so the launcher loads everything much-much faster.

[2025-09-14
22-10-08.webm](https://github.com/user-attachments/assets/012d13cb-5bb9-4bf9-8fcf-d7ef43ddb8fa)

# What's Changed?
- **[Removed]** Taking out CODING from CDN Mirror list
- **[Imp]** Recompile Static Libraries with MSVC for NativeAOT builds,
by @neon-nyan
- **[Imp]** Update .NET components NuGet to 9.0.9, by @bagusnl
@neon-nyan
- **[Imp]** Update WindowsAppSDK to 1.8-stable, by @neon-nyan 
- **[Imp]** [Improve DBHandler reliability and error
handling](#791), by
@bagusnl
- Implements a retry mechanism with exponential backoff for database
operations
  - Adds detailed logging for debugging and troubleshooting
- Uses internal methods for querying and storing data to streamline
error handling
  - Integrates with Sentry for exception reporting
  - Improves stream expiration handling
- **[Imp]** Decouple Hashing Extensions from Collapse Launcher's Main
Code, by @neon-nyan
- **[Imp]** [Improve app-wide logger
extensions](6acea34#commitcomment-164583504),
by @neon-nyan
- Remove memory allocation entirely by writing string directly to Win32
handles
  - Add asynchronous variant for the overloads
- Add ``DefaultInterpolatedStringHandler`` overload for passing
interpolated string.
- **[Imp]** [Improve Sentry
Logging](#795), by
@bagusnl
- Now the telemetry will upload only the last 100 lines from the log
instead of sending everything to Sentry. This will reduce time and
guarantee the log is successfully sent for analysis.
- If multiple errors occurs, the exceptions will be queued and sent
one-by-one. This avoid collisions between other reports being sent at
the same time.
- **[Imp]** Improve I/O Performance on Sophon submodule, by @neon-nyan
  - Use OS-level file caching
  - Limit FileStream handle's access and share parameter
- Automatically increase FileStream's buffer depends on target file size
- Move ``ChunkStream.CopyToAsync`` into Task.Factory and run it
synchronously in the background
- Increase maximum buffer size budget on patch mode from 4 MiB to 32 MiB
- Allocate only a certain amount of buffer based on target data size
(this to avoid buffer overprovision, causing memory and CPU usage
spikes)
- **[Fix/Imp]** Ignore assets that marked as "unused/deleted" on ZZZ
Game Installation/Update and Game Repair, by @neon-nyan
- **[Fix]** ``NotSupportedException`` error while performing Game Repair
on Honkai Impact 3rd and Honkai: Star Rail, by @neon-nyan
- **[Fix]** Legacy Sophon won't recognize already existed files while
installing games from scratch, by @neon-nyan
- **[Locale]** Update Localizations for vn_VN, es_ES/419, ja_JP, id_ID,
zh_CN, by Localizers ❤
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Runtime Issue labeled for runtime, Hi3Helper.Core and other libraries used by Collapse Enhancement New feature or request Priority: Medium Size: Small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants