Skip to content

Fix/log message received threaded#3

Closed
kurobon-jp wants to merge 4 commits into
mainfrom
fix/logMessageReceivedThreaded
Closed

Fix/log message received threaded#3
kurobon-jp wants to merge 4 commits into
mainfrom
fix/logMessageReceivedThreaded

Conversation

@kurobon-jp

Copy link
Copy Markdown
Owner

No description provided.

@octopus-review

octopus-review Bot commented May 28, 2026

Copy link
Copy Markdown

🐙 Octopus Review — PR #3

Summary

This PR fixes two issues with ErrorIndicator: switching the log subscription from Application.logMessageReceived to Application.logMessageReceivedThreaded (to match how LogReceiver already works), and relocating the IsShowErrorIndicator guard from the subscription site into the handler body. Additionally, the instant-replay package dependency is switched from a local path to the official Git URL.

Score

Category Score Notes
Security 4/5 Thread-safety concerns remain in handler body
Code Quality 4/5 Guard relocation is clean; minor thread-safety gap
Performance 5/5 No regressions introduced
Error Handling 4/5 Threaded handler calls Unity main-thread APIs
Consistency 5/5 Now matches LogReceiver's threading model
Overall 4/5 One real threading concern worth addressing

Risk Assessment

Metric Value
Overall Risk 🟡 Medium
Complexity Low
Test Coverage Impact Needs Attention
Breaking Change No

Positive Highlights

  • Consistency with LogReceiver: Switching to logMessageReceivedThreaded aligns ErrorIndicator with the threading model already used in LogReceiver.cs — good architectural consistency.
  • Guard relocation logic: Moving the IsShowErrorIndicator check into the handler rather than the subscription site means the setting can be changed at runtime without needing to re-subscribe, which is a cleaner design.
  • Dependency hygiene: Replacing the local absolute path for instant-replay with the canonical Git URL removes a developer-machine-specific path that would have broken builds on any other machine.

Important Files Changed

Filename Overview
Assets/Runtime/Scripts/Log/ErrorIndicator.cs Switched to logMessageReceivedThreaded; moved IsShowErrorIndicator guard into handler body
Packages/packages-lock.json Replaced local absolute path for instant-replay with Git URL
.github/workflows/octopus.yaml Added Octopus Review GitHub Actions workflow

Diagram

graph TD
    LogThread["Background Thread"]
    MainThread["Unity Main Thread"]

    LogThread -- "logMessageReceivedThreaded" --> Handler["OnLogMessageReceived()"]
    Handler --> GuardCheck{"IsShowErrorIndicator?"}
    GuardCheck -- "false" --> Return["return (safe)"]
    GuardCheck -- "true" --> TypeCheck{"Error/Exception/Assert?"}
    TypeCheck -- "false or _isBlinking" --> Return2["return (safe)"]
    TypeCheck -- "true" --> SetError["HasError = true"]
    SetError --> StopCoroutines["StopAllCoroutines()"]
    StopCoroutines --> StartCoroutine["StartCoroutine(Blink())"]
    StartCoroutine --> MainThreadRequired["⚠️ Requires Main Thread"]

    classDef changed fill:#fbbf24,stroke:#92400e,color:#000
    classDef warning fill:#f87171,stroke:#991b1b,color:#000
    classDef safe fill:#4ade80,stroke:#166534,color:#000
    classDef unchanged fill:#374151,stroke:#6b7280,color:#e5e7eb

    class Handler,GuardCheck changed
    class StopCoroutines,StartCoroutine,MainThreadRequired warning
    class Return,Return2 safe
    class LogThread,MainThread,TypeCheck,SetError unchanged
Loading

Last reviewed commit: 8c738bd

Checklist

  • No hardcoded secrets or credentials
  • Error handling is comprehensive — threaded callback invokes StopAllCoroutines/StartCoroutine off the main thread
  • Edge cases are covered — _isBlinking and HasError are not thread-safe
  • Naming is clear and consistent with codebase conventions
  • No unnecessary dependencies added
  • Database migrations are reversible (if applicable) — N/A
  • API changes are backward compatible

@octopus-review octopus-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 files reviewed, 2 findings | View scores & details

🔴 Findings that could not be mapped to diff lines:

Severity File Title Description
🔴 Assets/Runtime/Scripts/Log/ErrorIndicator.cs:L42 MonoBehaviour Coroutine methods called from background thread OnLogMessageReceived is now registered with Application.logMessageReceivedThreaded, which can be invoked from any thread…
🟡 Additional findings
Severity File Title Description
🟡 Assets/Runtime/Scripts/Log/ErrorIndicator.cs:L23 IsShowErrorIndicator guard removed from subscription site — always subscribes regardless of setting The original code only subscribed to the log event when IsShowErrorIndicator was true. The new code unconditionally subs…

Reviewed by Octopus Review, an AI-powered PR review tool.

@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

🐙 Octopus Review — PR #3

Summary

このPRは主に3つの変更を含みます。①ErrorIndicator.cs において Application.logMessageReceived をスレッドセーフな logMessageReceivedThreaded へ切り替え、②IsShowErrorIndicator チェックをイベント購読時からコールバック内に移動、③ローカルパスで参照されていた InstantReplay パッケージをGitリポジトリ参照に変更。さらにGitHub Actions による Octopus Review の CI 設定ファイルも追加されています。

Score

Category Score Notes
Security 4/5 スレッドからのUnity API呼び出しに注意が必要
Code Quality 3/5 logMessageReceivedThreaded コールバック内でUnityメインスレッド専用APIを直接呼び出している
Performance 4/5 logMessageReceivedThreaded により不要なメインスレッドブロックを回避
Error Handling 3/5 スレッド境界を越えた StopAllCoroutines / StartCoroutine の呼び出しが未ガード
Consistency 4/5 パッケージ参照のローカルパスを除去し一貫性が向上
Overall 3/5 メインスレッドAPIをワーカースレッドから呼び出す問題あり

Risk Assessment

Metric Value
Overall Risk 🟡 Medium
Complexity Low
Test Coverage Impact Needs Attention
Breaking Change No

Positive Highlights

  1. ローカルパスの除去: packages-lock.json のローカルパス (C:/Users/kurob/...) をGit URLに変更したことで、他の開発者がリポジトリをクローンしてもビルドが通るようになりました。実用上重要な修正です。
  2. スレッドセーフAPIへの移行意図は正しい: LogReceiver.cs と同様に logMessageReceivedThreaded を使う方向性は適切で、ログが別スレッドから来ても取りこぼさない設計を目指している点は評価できます。
  3. CI設定の追加: Octopus Review の自動レビューワークフローを導入し、PRごとにコードレビューが自動実行される体制が整備されています。

Important Files Changed

Filename Overview
Assets/Runtime/Scripts/Log/ErrorIndicator.cs logMessageReceivedlogMessageReceivedThreaded へ切り替え。IsShowErrorIndicator チェックをコールバック内に移動。ただしコールバックがワーカースレッドから呼ばれるため、StopAllCoroutines/StartCoroutine などのUnityメインスレッドAPIへのアクセスが危険な状態。
Packages/packages-lock.json InstantReplay パッケージの参照をローカルファイルパスからGit URLに変更。
.github/workflows/octopus.yaml Octopus Review CI ワークフローを新規追加。

Diagram

sequenceDiagram
    participant Worker as Worker Thread
    participant Handler as OnLogMessageReceived
    participant Unity as Unity Main Thread

    Worker->>Handler: Application.logMessageReceivedThreaded
    activate Handler
    Handler->>Handler: IsShowErrorIndicator check
    Handler->>Handler: type / _isBlinking check
    Handler->>Unity: HasError = true
    Handler->>Unity: StopAllCoroutines() ← 🔴 NOT thread-safe
    Handler->>Unity: StartCoroutine(Blink()) ← 🔴 NOT thread-safe
    deactivate Handler

    note over Unity: Unity API must be called\nfrom main thread only
Loading

Last reviewed commit: e9c5114

Checklist

  • ハードコードされた秘密情報・認証情報がない
  • エラーハンドリングが適切である(スレッド境界でのUnity API呼び出しが未対応)
  • エッジケースが考慮されている(ワーカースレッドからのコルーチン操作)
  • 命名がコードベースの規約と一致している
  • 不要な依存が追加されていない
  • APIの後方互換性が維持されている


Reviewed by Octopus

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🐙 Octopus posted 3 inline findings. See the pinned Octopus summary comment for the full review.

}

Application.logMessageReceivedThreaded += OnLogMessageReceived;
Clear();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Unconditional subscription when ErrorIndicator is disabled by settings

The old code only subscribed to logMessageReceived when IsShowErrorIndicator was true, avoiding any overhead when the feature is disabled. The new code always subscribes to logMessageReceivedThreaded, and only guards inside the callback. While the overhead per call is small, this now means every log message (including from high-frequency systems) invokes the callback and SDSettings lookup even when the indicator is permanently disabled. Consider retaining the subscription guard, or at minimum caching IsShowErrorIndicator at subscribe time.

Suggested change
Clear();
protected override void OnEnable()
{
// Still subscribe unconditionally if you want runtime toggling,
// but cache the setting to avoid per-call SDSettings lookup:
// _isIndicatorEnabled = SDSettings.Instance.IsShowErrorIndicator;
Application.logMessageReceivedThreaded += OnLogMessageReceived;
Clear();
}
AI Fix Prompt
Fix the following Medium (Performance) issue in `Assets/Runtime/Scripts/Log/ErrorIndicator.cs` at line 23:

Problem: The old code only subscribed to `logMessageReceived` when `IsShowErrorIndicator` was true, avoiding any overhead when the feature is disabled. The new code always subscribes to `logMessageReceivedThreaded`, and only guards inside the callback. While the overhead per call is small, this now means every log message (including from high-frequency systems) invokes the callback and SDSettings lookup even when the indicator is permanently disabled. Consider retaining the subscription guard, or at minimum caching `IsShowErrorIndicator` at subscribe time.

Suggested fix:
protected override void OnEnable()
{
    // Still subscribe unconditionally if you want runtime toggling,
    // but cache the setting to avoid per-call SDSettings lookup:
    // _isIndicatorEnabled = SDSettings.Instance.IsShowErrorIndicator;
    Application.logMessageReceivedThreaded += OnLogMessageReceived;
    Clear();
}

Unity特有の問題を優先してください。

明確な問題のみ指摘してください。
推測ベースの指摘は避けてください。 No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Workflow file missing newline at end of file

The YAML file is missing a trailing newline (\ No newline at end of file). While harmless, POSIX-compliant text files should end with a newline, and some YAML linters will warn about this.

Suggested change
推測ベースの指摘は避けてください
Unity特有の問題を優先してください
明確な問題のみ指摘してください。
推測ベースの指摘は避けてください。
AI Fix Prompt
Fix the following Nit (Style) issue in `.github/workflows/octopus.yaml` at line 73:

Problem: The YAML file is missing a trailing newline (`\ No newline at end of file`). While harmless, POSIX-compliant text files should end with a newline, and some YAML linters will warn about this.

Suggested fix:
            Unity特有の問題を優先してください。

            明確な問題のみ指摘してください。
            推測ベースの指摘は避けてください。

@octopus-review octopus-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 files reviewed, 0 findings | View scores & details

Reviewed by Octopus Review, an AI-powered PR review tool.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🐙 Octopus posted 1 inline finding. See the pinned Octopus summary comment for the full review.

@kurobon-jp kurobon-jp closed this May 28, 2026
@kurobon-jp kurobon-jp deleted the fix/logMessageReceivedThreaded branch May 28, 2026 08:13
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