Skip to content

fix(apps): probe the clone's .git off the event loop - #24124

Merged
KiroCrewCaptain merged 1 commit into
kirodotdev:mainfrom
IngridMorstrad:fix/registry-checkout-git-probe-off-loop
Oct 26, 2026
Merged

KiroCrewCaptain merged 1 commit into
kirodotdev:mainfrom
IngridMorstrad:fix/registry-checkout-git-probe-off-loop

Conversation

@IngridMorstrad

@IngridMorstrad IngridMorstrad commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Reading a persisted registry clone's origin (_clone_origin_url) no longer blocks the gateway's event loop on its .git probe.

_clone_origin_url in apps/registry_pipeline/checkout.py opens with if not (dest / ".git").is_dir(): return None, a bare stat inside the coroutine, before the sandboxed git remote get-url origin spawn it exists for. The checkout lives in the data home's app-sources directory. On a mount that has stopped answering, that stat blocks in the kernel on the loop thread. check_sync_io_in_async already counts it in the checkout.py row of its baseline.

Why it matters

The gateway runs one event loop. A stalled syscall there freezes every session, channel, cron and MCP call at once, and once the stall outlasts dashboard.loop_stall_exit_after_secs the watchdog restarts the gateway and every in-flight turn is lost (#1572, #3057). The origin read runs on every update of an installed registry app (_clone_origin_matches, and the origin-mismatch path in _git_clone_or_pull).

Not a goal

  • Changing what _clone_origin_url returns: None for a directory that is not a clone, a spawn failure, a timeout or a non-zero exit; the stripped URL otherwise.
  • The other nine baselined fs calls in checkout.py. They decide which fetch, move-aside and rollback branch _git_fetch_ref and _git_clone_or_pull take (see Sibling sweep).
  • install_clone.py's baseline row.

What changed (motivation → approach → change)

Symptom: a slow or wedged data-home mount can stall every session while an installed registry app updates. Root cause: the .git probe at the top of _clone_origin_url ran on the event-loop thread.

The probe now runs through await asyncio.to_thread((dest / ".git").is_dir). That is the lane this module's other clone-metadata reads already use (_read_clone_branch, _resolved_clone_commit). dest is the gateway's own app-sources path, so it goes to the default executor, not the bounded path-probe pool that request-chosen paths use (the same call as #22222 and #23967).

--update-baseline lowers the checkout.py row of .github/sync-io-in-async-fs-baseline.txt from 10 to 9.

Backwards compatibility

Compatible: return values and the git spawn are unchanged. Only the thread the .git stat runs on moves.

Removes nothing: the baseline row drops by one because the call it allowed no longer runs on the loop. No reader, route or key goes away.

Tests

  • test/test_external_registry_origin.py::TestCloneOriginProbeOffLoop::test_missing_git_dir_returns_none_without_spawning: on a plain directory, _clone_origin_url returns None without spawning git, and the .git probe ran on a thread other than the event loop's.
  • ...::test_existing_clone_reads_origin_after_off_loop_probe: on a clone, it returns the origin that git remote get-url origin printed (the spawn runs in dest), and the probe ran off the loop thread.
  • Red before the fix, with only the one-line fix reverted in the working tree:
    FAILED ...::test_missing_git_dir_returns_none_without_spawning - AssertionError: the .git probe ran on the event loop thread
    FAILED ...::test_existing_clone_reads_origin_after_off_loop_probe - AssertionError: the .git probe ran on the event loop thread
    
    Green after the fix: 2 passed. The whole file passes (18 passed). It passes 10/10 on repeat runs. The tests only look at threading.get_ident() and use no timing.

Proof: PROVEN test/test_external_registry_origin.py::TestCloneOriginProbeOffLoop::test_missing_git_dir_returns_none_without_spawning, test/test_external_registry_origin.py::TestCloneOriginProbeOffLoop::test_existing_clone_reads_origin_after_off_loop_probe (head 12ed7b9)

Gates run locally: check_sync_io_in_async.py (130 calls / 55 files), check_black_formatting.py, check_subprocess_encoding.py, comment-history, brand-name, isort, flake8, mypy, docs-lint.sh, test_flake_pattern_ratchet.py and test_sync_io_in_async_gate.py (189 passed). local-gate.py's related backend set: 29,248 passed, 73 failed and 10 errors, across 72 unique node ids. Every one of those ids also fails when run on a clean origin/main worktree on this host, so this diff did not cause them. They come from this host's environment: the sandbox refuses git init in test_ledger_sync_git.py, test_design_tweak_backend.py gets 403s because of the checkout path, and coreutils env here has no --default-signal. semgrep is not installed here, so the SAST lane covers it.

Manual verification

N/A: this is a thread hop with no user-visible output. The unit tests drive the real _clone_origin_url and check which thread the stat runs on, which is the property this change is for.

Related Issues

Closes #24123

Sibling sweep

Swept: the checkout.py sites scripts/check_sync_io_in_async.py's _scan() reports (lines 527, 529, 806, 896, 960, 1263), plus git grep -n '\.git").is_dir()' -- src/kiro_crew/apps/registry_pipeline/
Sibling: src/kiro_crew/apps/registry_pipeline/checkout.py:527 -- not affected -- _git_fetch_ref's .git/exists probe chooses between fetching into an existing checkout and the refuse-or-create branch that the created_here cleanup relies on. Moving it belongs with that lifecycle, in its own PR.
Sibling: src/kiro_crew/apps/registry_pipeline/checkout.py:806 -- not affected -- in _git_clone_or_pull, along with 896, 960 and 1263. These gate the origin-mismatch move-aside, branch re-convergence, pinned-install move-aside and Windows partial-rename rollback, and should move together with that transaction.
Sibling: src/kiro_crew/apps/registry_pipeline/install_clone.py -- not affected -- its own baseline row, handled separately.

Pattern harvest

Not generalizable: scripts/check_sync_io_in_async.py already enforces this class (a blocking fs call inside async def) across the repo. This PR pays down one baselined call of it.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

_clone_origin_url checked whether the registry checkout had a .git
directory with a bare is_dir() at the top of the coroutine, before the
sandboxed git spawn that reads its origin. The checkout lives in the
data home's apps directory, so on a mount that has stopped answering
the stat blocks the gateway's single event loop and stalls every
session until the loop watchdog restarts the gateway.

Run the probe with asyncio.to_thread, the lane the module's other
clone-metadata reads already use. Lower the checkout.py row of the
sync-io baseline with --update-baseline and add tests that the probe
runs off the loop thread both for a directory that is not a clone and
for one whose origin is read.

Closes kirodotdev#24123
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 12ed7b9bc9684b9297b8e86fd4d4115523fd1efb touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 12ed7b9bc9684b9297b8e86fd4d4115523fd1efb via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

This is a disclosed point patch: one of ten baselined loop-thread stats in checkout.py moves off the loop. The other nine are deferred openly, and on their own they are not a blocker.

Notes

  • Item 1 — point patch with counted unfixed siblings: grepping \.is_dir\(\)|\.exists\(\) in checkout.py finds 9 more loop-thread stats, at lines 527, 529, 806 (×2), 896 (×2), 960 (×2) and 1263. Lines 806, 896 and 960 are the same (dest / ".git").is_dir() probe, and they run on the same update path the Goal names. The description defers them because they "should move together with that transaction". But moving a stat to a thread does not change which branch runs, so that reason is weak. Subtraction: none in this PR. The deferral stands, and the baseline row records what is left (9).

What this change ships

Inventory (3 items) — 3 justified

Intent: a stalled data-home mount should not freeze the gateway while an installed registry app updates. This is a FIX.

  1. _clone_origin_url's .git probe now runs on a worker thread instead of the event loop — justified
  2. The checkout.py sync-io baseline row drops from 10 to 9 — justified
  3. Two tests check which thread the probe runs on, for both the missing-clone and the existing-clone case — justified

[FIRST-PRINCIPLES-REVIEWED] 12ed7b9

Description read

[DESCRIPTION-READ] c1ac28614d278ee4f7c6c191e8edc1a4dc817811e368a7b61906b680404af71f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 12ed7b9bc9684b9297b8e86fd4d4115523fd1efb via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: a one-line hop off the event loop, using the lane this module's other clone-metadata reads already use. Return values are unchanged.

Notes

[DESIGN-REVIEWED] 12ed7b9

Description read

[DESCRIPTION-READ] 9bff293ba45eafff20ebe2c384e4573de53960658460626cce8c662fc78c2ee7

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 12ed7b9bc9684b9297b8e86fd4d4115523fd1efb via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 12ed7b9

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 12ed7b9bc9684b9297b8e86fd4d4115523fd1efb via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 12ed7b9

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 26, 2026
@IngridMorstrad

Copy link
Copy Markdown
Contributor Author

Replies to the non-blocking notes on 12ed7b9:

  • First Principles, item 1 (siblings at 806/896/960): agreed, moving a stat to a thread does not change which branch runs, so that was the wrong reason. The real reason is scope. Those probes are in _git_clone_or_pull, next to the move-aside and restore bookkeeping (moved_aside, moved_aside_is_restorable), and next to 527/529, which the created_here cleanup in _git_fetch_ref depends on. Changing them deserves its own review against that transaction's tests, not a ride-along in a one-site fix. The baseline row (9) keeps them visible.
  • Design note (stuck executor threads on a wedged mount): acknowledged. This uses the same default-executor lane as fix(knowledge): read the context search's config off the event loop #22222 and fix(dashboard): list the outbox off the event loop #23967 for a path the gateway owns. No change.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 26, 2026 01:02

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: fix (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: moves the .git stat in the registry clone origin read off the event loop with asyncio.to_thread and lowers its sync-io baseline row by one; tests pin the thread.

@KiroCrewCaptain
KiroCrewCaptain merged commit d23dd97 into kirodotdev:main Oct 26, 2026
108 of 114 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(apps): _clone_origin_url probes the clone's .git on the event loop

2 participants