Repository navigation
cli: fail fast instead of hanging on a busy or wrong port - #9
Merged
Merged
Conversation
Squash replaces the pull request with one commit whose subject is the pull request title: the individual commits, their messages and their sign-offs are gone, and the title is written into a history that cannot be rewritten. #7 is the proof -- "Agent/shutdown op (#7)" reached main that way and the commit gate could only complain afterwards, on a protected branch. Only Rebase and merge stays enabled, so the commits a reviewer approved are the commits that land, with their authors intact. The price is that the message has to be right before the merge, which is what the pull request gate and the local hook are for. The settings, the helper script's description, the gates table, the merge step in CONTRIBUTING and the measured pitfalls all said "squash"; they say "rebase" now, including what it costs to forget. Signed-off-by: cadywang <cadywang@users.noreply.github.com>
devctl.py has always given up on the TCP connect after 15 seconds (socket.create_connection); devctl.ps1 called TcpClient.Connect and waited for the OS. Against an address that swallows packets that is a 20-second stall, and against a port somebody else already answers -- a VS Code port forward, say -- the script simply sat there, which is how "the port is busy on the client" turned into "the tool hangs" for whoever ran it. Connect asynchronously, give up after the same 15 seconds, report the socket error unwrapped (a .NET wrapper message reads as a stack trace, not as an error) and exit 1. Both implementations now wait the same. Checked by hand: nothing listening -> refusal reported, exit 1; a blackholed address -> "connect timed out after 15000 ms", exit 1 in 15 s; a mock agent -> info and shutdown still work. Signed-off-by: cadywang <cadywang@users.noreply.github.com>
Both self tests defaulted to a fixed port (17801 and 17870). The agent binds 0.0.0.0 and on Windows a more specific 127.0.0.1 listener wins over it, so the usual way to run the tests locally -- on the machine that also has the IDE open -- could talk to a stranger instead: VS Code forwards the ports it reads from the terminal, and the whole test then hangs inside devctl with nothing to say why. 17801 is exactly the port the bridge documents for its own agent, so the collision was not hypothetical. Ask the OS for a free port when none is given, and refuse to run against an explicit port that already answers. A wrong peer is now a message and exit 2 instead of a hang, and a plain "tests/selftest.ps1" works on a busy developer machine again. The end-to-end test notices the same way, and the ports it reports now include the one it picked. CI keeps explicit ports for the cross checks but runs the first PowerShell and Python pass on the default path, so the auto-pick is exercised on both runners. Signed-off-by: cadywang <cadywang@users.noreply.github.com>
The connect timeout and the self-test port choice change what people see when something is wrong: a wrong endpoint now says so instead of waiting, and the self tests no longer need a port picked by hand. Say it where the options are listed and where the tests are introduced, so the next reader does not take the 15-second exit for a broken bridge or wonder which port the tests used. The changelog records the failure paths that were checked on Windows, not just the passing runs. Signed-off-by: cadywang <cadywang@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
1. 合并方式改为只允许 Rebase and merge(
governance/repository-settings.json,线上设置已同步)Squash 会把整个 PR 压成一个提交:标题变成 PR 标题、每个提交的
Signed-off-by:也不再是原文。#7 就是这么把
main判红的,而受保护的历史改不回来。rebase 让 PR 里的提交原样落到main,代价是提交信息必须一开始就写对(
pr-gate与本地钩子仍会在合并前把关)。2.
cli/devctl.ps1连接加超时devctl.py一直是 15 秒放弃,PowerShell 版却是阻塞等待:端口不通时脚本一直挂着,正是「client 上的端口被占」被感知成「工具卡死」的原因。现在两版一致:15 秒内报错退出 1,
错误信息也去掉了 .NET 包装(直接显示 socket 的错误)。
3. 两套自测不再卡死
selftest.ps1曾默认用 17801,而本机这个端口常已被 VS Code 的端口转发占住(Windows 上更具体的
127.0.0.1监听会盖过 agent 的0.0.0.0),devctl 于是连到陌生人身上、永远等回复。现在两套自测默认向系统要一个空闲端口(
-Port/--port仍可指定),指定的端口已被占用时立刻报错退出(退出码 2)。CI 的第一次 PowerShell / Python 运行改走默认路径。
本 PR 的提交:
docs: document the two fail-fast pathstests: pick a free port for the self testscli: time out the PowerShell connect instead of hangingrepo: land pull requests by rebasing, never by squashing变更类型
影响面清单
cli/devctl.ps1tests/*测试
失败路径(本机实测,重点是「不再卡死」):
bash tests/verify-live.sh <client>:<port>设备与链路信息(涉及传输改动时必填):
base64/awk/od/md5sum)合并前清单
PROTOCOL.md与agent/*、cli/*四个实现已同步更新.tmp-*/、*.log、__pycache__/)<subsystem>: 祈使句摘要、正文 72 列折行,并带Signed-off-by:(git commit -s)<subsystem>: 祈使句摘要>(网页端 squash 会把它写成提交标题)CHANGELOG.md(如面向用户的行为有变化)SECURITY.md(不引入默认对外暴露、无鉴权的行为)关联 Issue
无独立 Issue。起因:#7 合并后
main的 Hygiene 变红(PR 标题被 squash 成提交标题),以及本机跑
tests/selftest.ps1会永久卡住。合并方式与两个卡死点都在本 PR 里修掉。