Skip to content

chore: Extract server recovery tracking from controller#1552

Merged
hatayama merged 1 commit into
v3-betafrom
codex/c4-7-recovery-tracking
Jul 6, 2026
Merged

chore: Extract server recovery tracking from controller#1552
hatayama merged 1 commit into
v3-betafrom
codex/c4-7-recovery-tracking

Conversation

@hatayama

@hatayama hatayama commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Preserve server recovery behavior while moving recovery task tracking out of the controller.
  • Keep the public recovery task surface available for existing UI and facade consumers.

User Impact

  • No user-facing behavior is intended to change in this PR.
  • Recovery retry/backoff behavior remains the same, including retry delay order and the give-up error path.

Changes

  • Add an Infrastructure recovery tracking service for startup recovery task tracking and retry/backoff execution.
  • Keep Unity main-thread scheduling, bridge server mutation, readiness binding, and recovery start orchestration in the controller.
  • Preserve the duplicate startup protection clearing shape for the next recovery-unification preflight, as requested by review.
  • Retarget recovery tracking tests to exercise the extracted service directly without adding a new wrapper seam test.

Verification

  • dist/darwin-arm64/uloop compile --project-path "$(git rev-parse --show-toplevel)" -> 0 errors / 0 warnings
  • dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type regex "(DomainReloadRecoveryUseCaseTests|UnityCliLoopServerControllerRecoveryTests|UnityCliLoopServerStartupProtectionTests|UnityCliLoopBridgeServerShutdownTests|JsonRpcHeartbeatTests|UnityCliLoopServerLifecycleRegistryServiceTests|ServerLifecycleContractTests|UnityCliLoopFirstPartyServerLifecycleBindingTests|JsonRpcProcessorCliVersionGateTests|OnionAssemblyDependencyTests)" -> 141/141 passed

Review in cubic

Move recovery task tracking and retry backoff out of the server controller while preserving the public RecoveryTask surface and retry ordering.
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a364a1a1-3b23-416a-ae40-8536650e93ae

📥 Commits

Reviewing files that changed from the base of the PR and between 7114e97 and f0322f4.

⛔ Files ignored due to path filters (1)
  • Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerRecoveryTrackingService.cs.meta is excluded by none and included by none
📒 Files selected for processing (5)
  • Assets/Tests/Editor/UnityCliLoopServerControllerStartupLockTests.cs
  • Assets/Tests/Editor/UnityCliLoopServerStartupProtectionTests.cs
  • Packages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.cs
  • Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerController.cs
  • Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerRecoveryTrackingService.cs

📝 Walkthrough

Walkthrough

Recovery scheduling and retry/backoff logic previously implemented inside UnityCliLoopServerControllerService is extracted into a new UnityCliLoopServerRecoveryTrackingService. The controller now delegates startup and tracked recovery to this injected service. Composition root wiring and test fixtures are updated accordingly.

Changes

Recovery tracking service extraction

Layer / File(s) Summary
New recovery tracking service
Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerRecoveryTrackingService.cs
New sealed service tracks recovery tasks, implements ScheduleStartupRecovery, ScheduleTrackedRecovery/ExecuteTrackedRecoveryAsync with retry/backoff, manual-stop abort handling, session clearing on failure, and cleanup of completed tasks.
Controller delegates to tracking service
Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerController.cs
Constructor now requires UnityCliLoopServerRecoveryTrackingService, drops its own recovery fields/helpers, and delegates RecoveryTask, startup recovery, and tracked recovery scheduling to the injected service.
Composition root wiring
Packages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.cs
Editor startup registration creates a UnityCliLoopServerRecoveryTrackingService and passes it into the controller service constructor.
Test updates
Assets/Tests/Editor/UnityCliLoopServerControllerStartupLockTests.cs, Assets/Tests/Editor/UnityCliLoopServerStartupProtectionTests.cs
Tests create and assert against UnityCliLoopServerRecoveryTrackingService directly, and CreateControllerService helpers are updated to wire the new service into the controller constructor.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Controller as UnityCliLoopServerControllerService
  participant Tracker as UnityCliLoopServerRecoveryTrackingService
  participant Repo as ISessionFlagsRepository

  Controller->>Tracker: ScheduleStartupRecovery(restoreServerState)
  Tracker-->>Controller: RecoveryTask

  Controller->>Tracker: ScheduleTrackedRecovery(recoveryAction)
  loop retry with backoff
    Tracker->>Repo: GetIsServerManuallyStopped()
    alt manually stopped
      Tracker-->>Controller: abandon retries
    else retries exceeded
      Tracker->>Repo: ClearServerSession()
      Tracker-->>Controller: throw InvalidOperationException
    end
  end
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: extracting server recovery tracking from the controller.
Description check ✅ Passed The description matches the changeset and accurately describes the recovery-tracking extraction and preserved behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 codex/c4-7-recovery-tracking

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.

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 6 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerRecoveryTrackingService.cs">

<violation number="1" location="Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerRecoveryTrackingService.cs:168">
P2: Recovery failures can produce an extra unobserved fault from the fire-and-forget cleanup task, which may trigger noisy `UnobservedTaskException` handling and duplicate error surfacing. This happens because `ClearTrackedRecoveryWhenCompleteAsync` rethrows `recoveryTask` faults even though its result is intentionally discarded.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment on lines +168 to +176
await recoveryTask;
}
finally
{
if (ReferenceEquals(_currentRecoveryTask, recoveryTask))
{
_currentRecoveryTask = null;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Recovery failures can produce an extra unobserved fault from the fire-and-forget cleanup task, which may trigger noisy UnobservedTaskException handling and duplicate error surfacing. This happens because ClearTrackedRecoveryWhenCompleteAsync rethrows recoveryTask faults even though its result is intentionally discarded.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerRecoveryTrackingService.cs, line 168:

<comment>Recovery failures can produce an extra unobserved fault from the fire-and-forget cleanup task, which may trigger noisy `UnobservedTaskException` handling and duplicate error surfacing. This happens because `ClearTrackedRecoveryWhenCompleteAsync` rethrows `recoveryTask` faults even though its result is intentionally discarded.</comment>

<file context>
@@ -0,0 +1,179 @@
+
+            try
+            {
+                await recoveryTask;
+            }
+            finally
</file context>
Suggested change
await recoveryTask;
}
finally
{
if (ReferenceEquals(_currentRecoveryTask, recoveryTask))
{
_currentRecoveryTask = null;
}
}
await recoveryTask;
}
catch
{
// Recovery failure is surfaced by the original recoveryTask returned to callers.
}
finally
{
if (ReferenceEquals(_currentRecoveryTask, recoveryTask))
{
_currentRecoveryTask = null;
}
}

@hatayama
hatayama merged commit a6fb801 into v3-beta Jul 6, 2026
10 checks passed
@hatayama
hatayama deleted the codex/c4-7-recovery-tracking branch July 6, 2026 11:40
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