fix(windows): repair coder mode input, path validation, prompt rendering and version info#1177
Merged
Merged
Conversation
added 2 commits
July 12, 2026 19:13
…ork on Windows Coder mode input hang: the stdin reader goroutine could get stuck in a blocking console read after WaitForSingleObject signaled for non-key events, stealing keystrokes from the next prompt until Enter was pressed. The poll now classifies pending console records via PeekConsoleInput and only reports readiness for real text input, and stopStdinReader aborts an in-flight read with CancelSynchronousIo on the reader thread. RestoreCookedMode and resetTTYToSane gained a real Windows implementation via SetConsoleMode instead of being no-ops. Workspace boundary: path checks concatenated a slash separator by hand, which never matches backslashed absolute paths, so every coder write outside exact equality was rejected on Windows. The new stdlib-only pkg/fspath package provides WithinBoundary and Equal with normalized separators and case-insensitive comparison on Windows, now used by the engine, the agent path validators and the read validator. The sweep also fixed real security gaps: the sensitive-file read blocklist was anchored to HOME which is unset on Windows, extra read paths split on colon breaking drive letters, path traversal detection ignored backslash traversal, sensitive-path matching was case-sensitive on a case-insensitive filesystem, and command allowlists did not strip backslashed directories or Windows executable extensions. Tool args: models emit Windows paths with single backslashes, which are invalid JSON escapes, and sometimes double-encode the args envelope as a string. Both used to abort the tool call. RepairJSONInvalidEscapes now repairs dirty string literals with an all-or-nothing per-literal rule so coincidentally valid escapes inside dirty strings are treated as path separators while clean sibling strings keep their escapes, and the flattener and policy normalizer recover string envelopes. Prompt rendering: go-prompt skips the wrap-materializing newline on Windows, assuming legacy immediate wrap, but VT-enabled consoles use deferred wrap, desyncing its cursor model one row per exact column boundary. That made the prompt climb and leave ghost lines with large input and with the completion dropdown. A wrap-aware ConsoleWriter now tracks the cursor column and injects the newline at the boundary, gated on VT being active. The palette overlay erases the committed trigger line before opening, and the coder inter-turn prompt gained the AltGr sanitizer and the same writer.
…ation Version displays snapshotted the raw ldflags globals before the update check ran, and the check enriched those globals as a side effect, so builds installed with go install always showed unknown commit and date. One display path had already drifted out of the required call order, proving the ordering contract fragile. The version package is now side-effect free: FetchLatestReleaseImpl is the single injectable network seam, enrichment is a pure method on VersionInfo that fills commit and date from release metadata only when the build itself could not stamp them, and GetReport composes build info resolution, update check and enrichment in one call used by all display paths. The approximate binary-date fallback is marked with a shared suffix constant so the release publish date can take precedence over it, while ldflags-stamped data always wins. Tests now exercise the real default fetch through a test server instead of mocking a copy of the implementation.
Contributor
Quality GateResult: ✅ all floors passed
Config: .github/quality-gate.yml. Workflow: |
Owner
Author
|
Migration note for the intentional API break flagged by Floor 13:
|
…njection Go error strings are not capitalized, and the quality gate reads a capitalized literal under the cli tree as an untranslated user-facing message. The rewritten message also names the operation instead of just the API call.
d7c091e to
1c23fa2
Compare
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.
Summary
Windows users hit four independent defects that together made coder mode nearly unusable. This PR fixes all of them at root cause, plus the security gaps a full Windows path-handling sweep uncovered.
1. Coder mode froze after the first message
Typing showed nothing until Enter was pressed. Root cause: the centralized stdin reader polls with WaitForSingleObject, which signals for any console event — resize, focus, mouse — not just keystrokes. The goroutine then entered a blocking console read that stopStdinReader could not cancel, and the orphaned read stole keystrokes from the next go-prompt instance (which is what echoes them).
2. Coder write rejected every valid Windows path
Boundary checks concatenated a slash by hand, which never matches backslashed absolute paths — so anything short of exact equality was outside the workspace boundary. The new stdlib-only pkg/fspath package normalizes separators and compares case-insensitively on Windows, and now backs the engine and both agent validators.
The sweep across all tools also fixed real security gaps on Windows:
3. Tool args with Windows paths aborted the call
Models emit single-backslash Windows paths — invalid JSON escapes — and sometimes double-encode the args envelope as a JSON string. Both aborted the tool call with parsing errors. RepairJSONInvalidEscapes repairs dirty string literals with an all-or-nothing per-literal rule: a string containing any invalid escape is treated as unescaped, so coincidentally valid escapes inside it (backslash-b in builder, backslash-t in temp) become path separators, while clean sibling strings keep their legitimate escapes. The flattener and the policy normalizer both recover string envelopes, so the security prompt shows real flags instead of a JSON blob.
4. Prompt climbed and left ghost lines; version info empty on go install
Testing
Impact
No API or dependency changes. go.mod untouched. All changes are Windows-gated or behavior-preserving on unix.