Skip to content

fix(cron,desktop): pass gateway loop to run_one_job for Matrix cron delivery; discover UGit git binary (#61495, #61494) - #61503

Closed
kyssta-exe wants to merge 2 commits into
NousResearch:mainfrom
kyssta-exe:fix/61495-matrix-cron-delivery-loop-context
Closed

fix(cron,desktop): pass gateway loop to run_one_job for Matrix cron delivery; discover UGit git binary (#61495, #61494)#61503
kyssta-exe wants to merge 2 commits into
NousResearch:mainfrom
kyssta-exe:fix/61495-matrix-cron-delivery-loop-context

Conversation

@kyssta-exe

@kyssta-exe kyssta-exe commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Fix #61495 — Matrix cron delivery timeout context issue

Manual cron runs triggered from a Matrix gateway session (cronjob action='run') failed during delivery with:

Timeout context manager should be used inside a task

The job itself completed (last_status: ok); only the final Matrix delivery failed.

Root Cause

_execute_job_now called run_one_job(job) without adapters or loop, so _deliver_result fell back to the standalone asyncio.run() path. That path created a new event loop, but _send_matrix_via_adapter re-acquired the live Matrix adapter (whose internal aiohttp session was bound to the gateway's original loop) from the new loop, causing the cross-loop RuntimeError.

Changes

  1. _execute_job_now now resolves _gateway_runner_ref() to obtain the gateway runner's adapters and _gateway_loop, then passes them to run_one_job. The delivery then uses the live-adapter path (safe_schedule_threadsafe on the correct gateway loop) instead of creating a new loop.

  2. _send_matrix_via_adapter adds a defense-in-depth RuntimeError catch around the live-adapter branch, falling back gracefully to the ephemeral (E2EE-capable) adapter when the live adapter is unusable from the current event loop.


Fix #61494 — Desktop git binary not found with UGit

Hermes Desktop's check-for-updates and other git operations fail on Windows systems that use UGit instead of standard Git-for-Windows.

Root Cause

UGit installs a portable Git under a versioned app-* subdirectory:
%LOCALAPPDATA%\\UGit\\app-*\\resources\\app\\git\\cmd\\git.exe

The version suffix changes with each UGit update, so the path cannot be hard-coded. The existing findOnPath('git') fallback should catch UGit when its directory is on PATH, but Electron processes launched from Explorer inherit the login-time environment block, which may not include PATH entries added later by UGit's installer.

Changes

resolveGitBinary() now enumerates %LOCALAPPDATA%\\UGit\\ for app-* directories and adds each discovered resources/app/git/cmd/git.exe to the candidate list. The existing fileExists check selects the first valid binary, so stale/removed versions are skipped automatically.

Closes #61495
Closes #61494

kyssta-exe 25470058+kyssta-exe@users.noreply.github.com added 2 commits July 9, 2026 14:36
…ivery uses live-adapter path (NousResearch#61495)

Manual cron runs triggered from a Matrix gateway session (cronjob action='run')
failed during delivery with:

  Timeout context manager should be used inside a task

Root cause: _execute_job_now called run_one_job(job) without adapters or loop,
so _deliver_result fell back to the standalone asyncio.run() path. That path
created a new event loop, but _send_matrix_via_adapter re-acquired the live
Matrix adapter (whose internal aiohttp session was bound to the gateway's
original loop) from the new loop, causing the cross-loop RuntimeError.

Fix:
1. _execute_job_now now resolves the gateway runner's adapters and _gateway_loop
   and passes them to run_one_job, so the delivery uses the live-adapter path
   (safe_schedule_threadsafe on the correct gateway loop).
2. _send_matrix_via_adapter adds a defense-in-depth RuntimeError catch around
   the live-adapter branch, falling back to the ephemeral adapter when the
   live adapter is unusable from the current event loop.
…ry scan (NousResearch#61494)

UGit installs a portable Git under a versioned app-* subdirectory of
%LOCALAPPDATA%\UGit. The standard resolveGitBinary() candidate list
did not include this path, so check-for-updates and other git operations
failed silently on systems that use UGit instead of Git-for-Windows.

Fix: enumerate %LOCALAPPDATA%\UGit\app-*\resources\app\git\cmd\git.exe
dynamically rather than hard-coding a single version, so the discovery
survives UGit updates that change the app-* suffix.
@kyssta-exe kyssta-exe changed the title fix(cron): pass gateway loop to run_one_job so manual Matrix cron delivery uses live-adapter path (#61495) fix(cron,desktop): pass gateway loop to run_one_job for Matrix cron delivery; discover UGit git binary (#61495, #61494) Jul 9, 2026
@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management comp/desktop Electron desktop app (apps/desktop/*) platform/matrix Matrix adapter (E2EE) sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages P3 Low — cosmetic, nice to have labels Jul 9, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Competing fix for #61495 with #61502, via a different mechanism: this PR fixes the caller (_execute_job_now resolves the gateway runner's adapters + loop and passes them to run_one_job, so delivery uses the live-adapter path); #61502 fixes the callee (swaps aiohttp.ClientTimeout for asyncio.wait_for in the Matrix adapter's _standalone_send). Related, not duplicate — maintainer to pick. This PR also bundles a separate Desktop UGit git-discovery fix (#61494).

@tonydwb tonydwb 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.

Code Review Summary

Verdict: Comment

Overview

  • Small change: passes gateway loop to run_one_job for Matrix cron delivery
  • Also discovers UGit git binary

Looks Good

  • Clean, focused fix
  • No security concerns

Reviewed by Hermes Agent

@Suceru

Suceru commented Jul 10, 2026

Copy link
Copy Markdown

bootstrap-installer.log
问题出在 main.py 第 9466 行的 subprocess.run()——它在尝试调用一个不存在的可执行文件。让我看看那段代码到底在调什么:

找到了。第 9466 行就是 subprocess.run(["git", ...])——你的系统 PATH 里没有 git。

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for tracing both failures to their concrete resolution paths. Current main still calls run_one_job(job) without gateway state at tools/cronjob_tools.py:641, while cron/scheduler.py:1539-1712 only uses the loop-safe live-adapter path when adapters and a loop are provided. apps/desktop/electron/main.ts:1921-1936 also still lacks a UGit candidate.

Problems

  • The PR changes three production files but adds no regression tests. tests/tools/test_cronjob_run_immediate.py:20-31 only asserts that run_one_job was called, not that gateway adapters and _gateway_loop were forwarded. The existing desktop Windows resolver tests likewise do not cover UGit discovery.

Suggested changes

  • Add a focused manual-run test asserting that _execute_job_now forwards the runner's adapters and loop to run_one_job.
  • Add a Windows resolver regression assertion for %LOCALAPPDATA%/UGit/app-*/resources/app/git/cmd/git.exe.

This is an automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 11, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Cluster for #61495 (Matrix manual cron delivery cross-loop failure): #61503 (this) fixes the caller (passes the gateway runner's adapters + loop into run_one_job) and also bundles an unrelated UGit git-binary discovery fix for #61494; #61502 fixes the callee (Matrix adapter swaps ClientTimeout for asyncio.wait_for); #62956 fixes the generic cron dispatch (loop-mismatch guard + standalone-sender fallback). All three are competing approaches to the same delivery bug — related, not duplicates. Maintainer picks the canonical fix.

@kyssta-exe

Copy link
Copy Markdown
Contributor Author

Stale — no merge activity for 4-6 days. Can resubmit if still needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have platform/matrix Matrix adapter (E2EE) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [Bug]: Matrix manual cron delivery fails with "Timeout context manager should be used inside a task"

5 participants