← Back to Pull requests

fix(runtime): recover a live daemon from a damaged locator #6892

Closed
unknown closed this pull request without merging on Oct 22, 2026 06:33 UTC
View on GitHub
unknown unknown commented on Oct 19, 2026 14:32 UTC
Author

Goal And Delivered Outcome

  • Outcome basis / optional anchor: #6871 — a corrupt Effect runtime locator silently cold-starts a second daemon while loopx doctor reports the runtime as stopped.

  • Goal/source and gap: Make locator inspection distinguish "absent" from "present but invalid", keep the diagnostic and recorded-PID liveness in the lifecycle readback, and reuse an already-running daemon before cold start. Before this change, _read_info collapsed JSON/schema/fingerprint/field failures into None; callers treated that as "no runtime", and doctor had no way to show the live recorded PID.

  • Observable before → after, with the validation row that proves it: With only the live locator's schema_version corrupted, before: doctor stopped, diagnostic null, a new daemon started while the old PID stayed alive and serving. After: doctor running, locator_state=invalid, recorded_pid_alive=true, diagnostic runtime_locator_schema_mismatch, and the next RPC reuses the original PID. The real-daemon test in tests/control_plane/test_effect_runtime_locator_recovery.py proves this end to end.

  • Issue/task and intended base: Fixes #6871. Intended base: loopx-project/loopx:main at 764b989dc.
  • Author Declaration

  • Written by: model_agent (OpenAI Codex) at human direction and review.

  • AI disclosure: this change was drafted with AI assistance at my request, under my direction and review.
    The problem and constraints were set by the human requester; this PR is submitted for human review.

    Implemented against

  • Specification and revision: issue #6871, https://github.com/loopx-project/loopx/issues/6871 (current main at 764b989dc).

  • Criteria:
  • | Criterion (spec clause) | Disposition | Symbol / path | Test or command |
    | --- | --- | --- | --- |
    | Distinguish "no locator" from "locator present but unreadable" | implemented | _inspect_info, _RuntimeLocatorRead in loopx/control_plane/effect_runtime.py | tests/control_plane/test_effect_runtime_locator_recovery.py |
    | Keep a diagnostic code | implemented | _RuntimeLocatorDiagnostic; lifecycle diagnostic_code | same test; collect_effect_runtime_readiness |
    | Doctor reports PID liveness alongside locator state | implemented | collect_effect_runtime_readiness, render_doctor_markdown | doctor markdown assertions in the same test |
    | Before cold-starting, reuse a live daemon that still answers on the recorded port/token | implemented | _recover_runtime_info, _runtime_info_for_request | real-daemon schema-corruption test |
    | Do not trust damaged bytes without proof | implemented | authenticated runtime.ping must match PID, fingerprint and locator path | same test |
    | Malformed bytes do not crash doctor | implemented | UnicodeError/JSON/type guards in _inspect_info | malformed JSON and invalid UTF-8 tests |

  • Self-check before submission: Read the issue, reproduced the defect against current main, and confirmed the old behavior before changing code. Deliberately left out unrelated refactors and new dependencies. A locator whose token/endpoint are destroyed cannot be authenticated safely; that path cold-starts and retains the runtime_locator_unreadable diagnostic.
  • Scope And Continuation

  • Completed scope and remaining work: complete within this scope. The issue's corrupt-locator path is fixed; no successor is needed.

  • Slice boundary / successor: N/A. The change stays in the existing Python Effect runtime adapter; the TypeScript server protocol and locator schema are unchanged.

  • Review follow-up (4b340d9e6): a deep probe now refreshes the locator projection after it may have started the runtime, preserves a damaged-locator diagnostic on success, and reports host-permission or generic locator read failures as invalid rather than missing. Focused tests cover both outcomes.

  • Second review follow-up (607a787ce): recovery now propagates a host-permission denial instead of treating it as no runtime and cold-starting, and readiness inspects locator state/PID liveness even when the Node probe is unavailable. Regressions cover both boundaries.

  • Third review follow-up (9dadb773d): out-of-range recorded PIDs are rejected before the OS liveness probe and platform overflow is contained, so damaged locator bytes cannot crash readiness or the installation-only doctor. API and real console-command regressions cover the boundary.

  • Reporter follow-up (1940477fb): added explicit recovery tests for a ping from a different PID, a rejected token, a different fingerprint, and a different published locator path. Each case asserts that the damaged locator is not reused.
  • Validation

  • Tested revision: 1940477fb7913811db0315547d02ceb82647af8a (all listed checks ran on the final tree).

  • Run state: finished

  • Input classes: synthetic
  • | Check kind | Result | Public-safe evidence / limitation |
    | --- | --- | --- |
    | static | passed | uv run --extra test ruff check ... → All checks passed!; git diff --check 764b989dce...HEAD clean. |
    | unit | passed | uv run --extra test pytest -q tests/control_plane/test_effect_runtime_locator_recovery.py tests/control_plane/test_effect_runtime_host_permission.py tests/control_plane/test_turn_journal_runtime_readiness.py → 51 passed in 56.58s. |
    | integration | passed | Effect runtime/readiness suite over 10 files → 220 passed, 7 skipped, 3 warnings in 152.15s; skips are the platform-gated cases already present in the suite. |
    | real_entrypoint | passed | Real Node daemon through effect_runtime.effect_runtime_result; corrupting only schema_version reports running/invalid/PID alive and reuses the same PID; loopx doctor markdown readback includes the diagnostic. |
    | real_backend | passed | Node.js managed runtime over loopback in an isolated temporary runtime directory; no external service or private state. |
    | regression_parity | passed | New recovery tests failed 2 before the fix and pass after; malformed JSON and invalid UTF-8 retain runtime_locator_unreadable instead of looking absent. Follow-up tests prove deep success refreshes absent → valid and preserves damaged → invalid, while host-permission and generic read errors remain visible. |
    | regression_parity | passed | The second review regressions failed 2 before the follow-up (must not cold start; locator_state was missing) and pass after; the tests prove host-permission recovery does not launch a replacement and Node-unavailable readiness still reports a valid live locator. |
    | regression_parity | passed | The oversized-PID API and console-command regressions failed 2 before 9dadb773d (liveness was incorrectly reported as False) and pass after; both retain locator_state=invalid with unknown liveness and structured doctor JSON. |
    | regression_parity | passed | The four reporter-requested identity rejections pass: different PID, rejected token, different fingerprint, and different published locator path all return no recoverable runtime, so a damaged locator cannot route a request to another daemon. |
    | static | passed | Semantic inventory advisory reports only the local _RuntimeLocatorState / _RuntimeLocatorDiagnostic aliases for the branch; decision: remain local to effect_runtime.py, extending the existing loopx_effect_runtime_lifecycle_v0 readback; no registered vocabulary or shared contract change. |
    | static | failed | uv run --extra test python -m mypy --follow-imports=silent loopx/control_plane/effect_runtime.py loopx/doctor.py exits 1 with the same 48 errors and 4 unique diagnostic shapes as base 764b989dc; this branch adds no new normalized mypy diagnostic. |
    | integration | failed | Exact-head premerge standard against the original PR base 764b989dc: all direct checks, module ceiling, 8/8 risk-profile smokes and public boundary passed. Four catalog canaries failed and each was reproduced independently on that base: install-local-smoke (WinError 1314, symlink privilege), codex-cli-packaged-install-smoke (Bash unavailable), loopx-update-smoke (next_action=None), and semantic-vocabulary-drift-smoke (44 twins vs budget 43). |

  • Coverage and gaps: The real-daemon test covers schema corruption with an intact endpoint/token, malformed JSON, invalid UTF-8, and a dead recorded PID; it also verifies restart stops the original daemon. Four focused negative tests pin the recovery identity checks for PID, token, fingerprint and locator path. A locator that loses its token/port cannot be authenticated and intentionally cold-starts. No live Lark/frontend path is involved; this is a CLI/runtime readback change.
  • Frontend / Visual Evidence

  • UI impact: none

  • Before: N/A

  • After: N/A

  • First viewport and preview: N/A

  • States and viewports shown: N/A

  • Source data: none

  • Attention review: The change adds two doctor text rows (locator_state, recorded_pid_alive) to the existing runtime lifecycle block; no new screen, hero or CTA.

  • Craft review: N/A (no visual surface).
  • Type of Change

  • Bug fix

  • New feature

  • Breaking change

  • Refactoring (no functional changes)

  • Documentation update

  • Test update
  • LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)

  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)

  • Capability or extension (providers, adapters, skills)

  • Public docs or presentation surface (README, protocols, dashboard)

  • Build, packaging, installer, or CI

  • Host or runtime integration
  • Technical Direction

  • Direction / acceptance reference, when applicable: Core control-plane hardening; issue #6871. No roadmap/RFC id is needed for this self-contained reproduced defect. locator_state and its diagnostics stay local to the existing Python Effect runtime adapter; the TypeScript protocol and locator schema are unchanged.
  • Shared-authority RFC fixture impact

  • Production-scale fixture schema: N/A

  • Semantic dimensions changed, or reviewed no-impact rationale: local locator diagnostic vocabulary only; no shared-authority fixture change.

  • Provider conformance arms run: N/A

  • Read-only legacy/file/PostgreSQL three-arm rehearsal (required for promotion, runtime-routing, or compatibility-projection changes): N/A
  • Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).

  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.

  • I kept the change scoped to the linked issue/task.

  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.

  • I completed the visual evidence section for UI changes, or marked UI impact none.

  • Every commit includes a DCO Signed-off-by trailer (git commit -s).
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: JasonBuildAI Review duration: 3841m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #6892"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%