← Back to Pull requests

perf(effect-runtime): reuse a private source digest across processes #7748

Closed
unknown closed this pull request without merging on Nov 01, 2026 02:50 UTC
View on GitHub
unknown unknown commented on Oct 31, 2026 09:44 UTC
Author

Delivery brief

  • Goal/source: make a short LoopX CLI process pay only for the work it uses. The heartbeat chain (heartbeat-prompt, quota should-run, status, refresh-state, todo) starts a fresh Python process for each step, and each step computes the managed TypeScript runtime fingerprint once.

  • Current gap: the fingerprint re-opens all ~380 packaged .ts/.json sources in every process. Fresh-process measurement on macOS shows the cost is dominated by open(), not by hashing or stat (a stat-only pass is ~1 ms). It was 0.15–0.55 s per command, and 100% of the first explore-validation cost on the measured route.

  • Observable result: after a source revision has been hashed once, later processes reuse the digest. A changed, added or removed source, a different release root, interpreter or schema, or an untrusted record still triggers the existing full-byte hash.

  • Owning boundary: loopx/control_plane/effect_runtime.py (_runtime_fingerprint_for_snapshot). This does not change TS authority, the fingerprint value, runtime locators, scheduling, settlement, defaults or output contracts.
  • Change

    On POSIX, after a successful full hash plus the existing freshness recheck, the digest is recorded in the existing private per-user runtime namespace as source-digest-<id>.json, mode 0600, written atomically.

  • Key: schema, sys.executable, Python version, normalized release root and the complete (path, mtime_ns, ctime_ns, size) source snapshot. That snapshot is already computed for the in-process cache.

  • Reuse: only when the directory is a regular private directory (owned by the user, no group/other bits), the file is opened with O_NOFOLLOW, it is a regular 0600-style file owned by the user, and both the key and the sha256 digest validate. Otherwise the code falls back to the unchanged full read.

  • Never recorded:

  • - after a read failure or a source change during hashing;
    - when any source changed within the last 2 s, since a coarse ctime clock could otherwise preserve timestamps across a rewrite;
    - when the namespace does not exist, because the memo never creates it.
  • Name choice: the file avoids runtime-.json, the .ts-effect.lock names and start-.lock. Locator retirement, fixture cleanup and lock observation are therefore unaffected.

  • Non-POSIX hosts: keep full reads in every process.
  • The bilingual TypeScript migration RFC replaces "still reads every admitted byte" with this trade-off and its residual risk. Another file with identical size, mtime and ctime (for example a retargeted symlink), or a filesystem that does not maintain ctime, can hide a change.

    Evidence

    Base 04c5799b8 and head were run alternately in fresh processes against one isolated private namespace, on macOS with a synthetic SQLite fixture and 0.6 s gaps between runs:

    | Measure | Base median | Head median |
    |---|---:|---:|
    | _runtime_fingerprint() in a fresh process (n=12) | 298 ms | 13 ms (first run 380 ms) |
    | heartbeat-prompt --thin total (n=6) | 1.34 s | 0.77 s |
    | quota should-run total (n=6) | 2.40 s | 1.64 s |
    | status total (n=6) | 1.13 s | 0.79 s |

    The fingerprint value is identical on base and head. After the run, canary fixture retirement completed normally, and the namespace contained only the digest record and the existing compile cache.

    Validation at head 249773887:

  • New tests in tests/control_plane/test_runtime_source_read_batching.py, checked against an independent serial reference:

  • - cross-process reuse with zero source reads;
    - edit, add and remove each rotate the fingerprint;
    - a copied release root misses the cache;
    - a foreign-mode file, symlink, shared namespace, corrupt JSON, stale key or invalid digest each recompute;
    - an unsettled source, a read failure or a missing namespace records nothing.
    - The reuse test fails on base.
  • pytest over the fingerprint, readiness, status-scan, all test_effect_runtime_, managed-fixture, telemetry-isolation, performance-diagnosis, local-delegation and goal-portfolio suites: 388 passed, 1 skipped.

  • ruff check on changed Python: passed.

  • scripts/check_rfc_bilingual.py --base origin/main --head HEAD: passed.

  • loopx canary premerge --from-git-diff --git-diff-base origin/main (standard tier):

  • - 6 direct checks and 15 selected checks, 0 failures, 0 manual holds;
    - surfaces: control_plane, docs_project_content, public_boundary, python.

    Not covered

  • Windows and Linux were not measured locally; Windows keeps full reads by design.

  • The open-cost driver is host-specific; on hosts without per-open scanning the gain is smaller.

  • This changes runtime behavior in loopx/*, so it needs maintainer review and merge authorization. It is not self-merged.
  • Diff: 599 lines (+449 / -150) across 7 files Reviewer: JasonBuildAI Review duration: 1025m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 599 lines diff across 7 files
    0.50
    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.383
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #7748"
    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: 50.1% (MEDIUM) · Higher = larger blast radius
    50.1%
    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: 19.8% · Safe to merge
    19.8%