Repository navigation
[Bug]: Revit selector reads process ids 2000-2099 as years (flaky AgentClientTests.AYearOrAProcessIdSelectsTheHost) #3817
Description
✈ Pre-Flight checks
- I have checked that my antivirus or endpoint protection software is not blocking pyRevit (not applicable: code-level bug, reproduced in CI)
- I have searched in the issues (open and closed) but couldn't find a similar issue
- I have searched in the pyRevit Forum for similar issues
- I already followed the installation troubleshooting guide thoroughly (not applicable)
- I am using the latest pyRevit Version (current
develop)
🐞 Describe the bug
The pyRevit command-line client lets you choose which Revit session to target with a selector, which can be either a Revit year or a Revit process id. PyRevitAgentClient.Resolve treats every number from 2000 to 2099 as a year, so a Revit session whose process id falls in that range can never be selected by its process id.
This also makes the unit test pyRevitCLI.Tests.AgentClientTests.AYearOrAProcessIdSelectsTheHost flaky. The test selects the fake host by Environment.ProcessId. When the CI runner gives the test process an id between 2000 and 2099, the id is read as a year and the test fails. This happened on CI run 39803629931, where the test process got id 2024. That run belongs to PR #3814, which changes no command-line code; the PR's previous run of the same workflow passed.
The selection logic is in dev/pyRevitLabs/pyRevitCLI/PyRevitAgentClient.cs, in Resolve:
matches = instances
.Where(instance => number >= 2000 && number < 2100
? instance.RevitVersion == selector
: instance.ProcessId == number)
.ToList();⌨ Error/Debug Message
Failed pyRevitCLI.Tests.AgentClientTests.AYearOrAProcessIdSelectsTheHost [3 ms]
Error Message:
pyRevitCLI.AgentClientException : No running Revit matches '2024'.
Stack Trace:
at pyRevitCLI.PyRevitAgentClient.Resolve(String selector) in D:\a\pyRevit\pyRevit\dev\pyRevitLabs\pyRevitCLI\PyRevitAgentClient.cs:line 132♻️ To Reproduce
In the product:
- Start Revit with the pyRevit agent enabled, so that the session has a process id between 2000 and 2099. Process ids are assigned by Windows, so this happens by chance.
- Target that session by its process id with any
pyrevit agentorpyrevit mcpcommand that takes the Revit selector. - The command fails with
No running Revit matches '<pid>', or it targets a session of that Revit year if one is running.
In the tests:
- Run
dotnet test dev/pyRevitLabs/tests/pyRevitCLI.Tests/pyRevitCLI.Tests.csprojuntil the test process gets an id between 2000 and 2099. AYearOrAProcessIdSelectsTheHostfails.
⏲️ Expected behavior
A selector that equals a running session's process id selects that session, whatever its value. Selecting by year keeps working.
The test should be deterministic and not depend on the id Windows assigns to the test process.
🖥️ Hardware and Software Setup (please complete the following information)
Not machine-specific: the logic in PyRevitAgentClient.Resolve on current develop (9586cbc73).
Reproduced on the GitHub Actions Windows runner (pyRevit CI workflow, .NET 10).Additional context
Possible fixes, any of which would do:
- Match process ids first. If the number equals a running session's process id, select it; otherwise treat a number from 2000 to 2099 as a year. Real Revit years and process ids rarely collide, and an exact process id match is unambiguous.
- Separate syntax. Accept an explicit form such as
pid:2024or--pid, and keep the plain number for years. - Test only. The client drops registrations whose process is not alive, so the fake host cannot simply use a made-up process id. The test could register a live helper process whose id is outside 2000–2099. This removes the flakiness but leaves the product bug.
Activity
fix(cli): select Revit sessions by process id before year