Skip to content

typespec-java, Read pinned core sources via git archive zip instead of tar - #4983

Merged
Weidong Xu (weidongxu-microsoft) merged 1 commit into
mainfrom
fix-java-core-archive-tar-windows
Jul 21, 2026
Merged

Weidong Xu (weidongxu-microsoft) merged 1 commit into
mainfrom
fix-java-core-archive-tar-windows

Conversation

@weidongxu-microsoft

Copy link
Copy Markdown
Member

Problem

Following #4972, packages/typespec-java/CoreCommit.ps1 reads the pinned core/ commit's sources by git archive into a temp dir and then extracts them with an external tar. On Windows this fails: the tar first on PATH is Git for Windows' GNU tar, which interprets the archive path -f C:\...\core.tar as a remote host (host:path rsh syntax) and aborts:

/usr/bin/tar: Cannot connect to C: resolve failed

Linux CI doesn't hit this (/tmp/... has no drive-letter colon), so it only bites Windows dev builds.

Fix

Get-CoreSourceRoot now archives with git archive --format=zip and extracts with PowerShell's built-in Expand-Archive (System.IO.Compression). This keeps the whole flow inside PowerShell/.NET with no external archiver dependency and no drive-letter parsing quirk. core/ is still never checked out or modified, and the temp dir is still cleaned up by Remove-CoreSourceRoot.

Also refreshes CONTRIBUTING.md, which still described the pre-#4972 in-place core/ checkout / git checkout . patch flow, to match the current git archive read and copy-and-patch-the-generator flow.

Verification

Pinned core-commit.json to a commit newer than the current core checkout to force the archive path, then ran Copy-Sources.ps1:

  • Took the archive branch ("Reading core sources from pinned commit ... without checking it out").
  • git archive --format=zip + Expand-Archive succeeded; generator copied and core.patch applied; exit=0.
  • git -C core status clean (submodule untouched), pin restored, no temp dir leaked.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:java Issues for @azure-tools/typespec-java emitter label Jul 21, 2026
CoreCommit.ps1 extracted the pinned core/ commit with an external 	ar,
which fails on Windows because Git for Windows' GNU tar treats an archive
path containing a drive letter (C:\...\core.tar) as a remote host spec and
aborts with "Cannot connect to C:". Use git archive --format=zip plus the
built-in Expand-Archive instead, keeping the whole flow inside PowerShell/.NET
with no external archiver dependency. core/ is still never checked out.

Also refresh CONTRIBUTING.md, which still described the old in-place core/
checkout and git checkout . patch flow, to match the current archive-based
read and copy-and-patch generator flow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ec1f621b-9580-4bac-9ef4-41b057cca012
@weidongxu-microsoft
Weidong Xu (weidongxu-microsoft) force-pushed the fix-java-core-archive-tar-windows branch from 663b83d to 1221701 Compare July 21, 2026 05:20
@azure-sdk-automation

azure-sdk-automation Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @azure-tools/typespec-java
Show changes

@azure-tools/typespec-java - internal ✏️

Read pinned core/ sources with git archive --format=zip + Expand-Archive instead of tar, which failed on Windows.

@weidongxu-microsoft Weidong Xu (weidongxu-microsoft) changed the title Read pinned core sources via git archive zip instead of tar typespec-java, Read pinned core sources via git archive zip instead of tar Jul 21, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-java@4983

commit: 1221701

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

@weidongxu-microsoft
Weidong Xu (weidongxu-microsoft) marked this pull request as ready for review July 21, 2026 06:16
Merged via the queue into main with commit 2f47061 Jul 21, 2026
28 of 29 checks passed
@weidongxu-microsoft
Weidong Xu (weidongxu-microsoft) deleted the fix-java-core-archive-tar-windows branch July 21, 2026 07:46
Yuchao Yan (msyyc) pushed a commit to msyyc/typespec-azure that referenced this pull request Jul 22, 2026
…5004)

## Problem

A full-repo `pnpm build` intermittently **hangs at the Java emitter
build**. The output stops right after:

```
@azure-tools/typespec-java:build: core-commit.json SHA ... using current checkout.
```

and never reaches `Copy generator sources from core`. Building
`packages/typespec-java` on its own always works. Prior attempts (Azure#4972,
Azure#4983, and non-interactive/fetch hardening) did not resolve it.

## Root cause

turbo runs each task's process in its own **background process group**
under the build's **controlling terminal** (the TUI). When a PowerShell
cmdlet renders **`Write-Progress`** — which `Copy-Item -Recurse` in
`Copy-Sources.ps1` does — pwsh touches that terminal from a background
process group and the OS stops the process with **SIGTTIN/SIGTTOU** (`T`
state). It never resumes, so the build hangs forever.

This explains all the symptoms:
- **Java-only:** it is the only package that shells out to `pwsh`.
- **Intermittent:** `Copy-Item` only renders progress when the copy is
slow enough (under parallel-build load).
- **Invisible when piped / in isolation:** with piped output (no TUI) or
a standalone build, pwsh is not a background process group of a
controlling terminal, so nothing stops it.
- **Unaffected by `-NonInteractive`:** progress renders regardless.

Reproduced directly: a pwsh running `Write-Progress` in a background
process group under a controlling tty immediately enters `T` (stopped);
with `$ProgressPreference = 'SilentlyContinue'` it never stops.

## Fix

- Set `$ProgressPreference = 'SilentlyContinue'` in `Copy-Sources.ps1`,
`Build-Generator.ps1`, and `CoreCommit.ps1` so no cmdlet touches the
controlling terminal. **This is the actual fix.**

Complementary hardening (removes secondary hang/network vectors):
- `CoreCommit.ps1`: only `git fetch` the pinned core commit when it is
genuinely missing locally (`git cat-file -e <sha>^{commit}` first) —
previously it hit the network on *every* emitter build / doc regen.
- `CoreCommit.ps1`: `GIT_TERMINAL_PROMPT=0` and `pwsh -NonInteractive`
(package.json) so a git credential/host prompt can never block the
headless build.
- `CoreCommit.ps1`: extract pinned sources with
`[System.IO.Compression.ZipFile]::ExtractToDirectory` instead of the
pathologically slow `Expand-Archive`.

## Verification

- Reproduced the `T`-state stop with `Write-Progress` under a
controlling tty; confirmed `$ProgressPreference='SilentlyContinue'`
prevents it.
- 8/8 runs of the real `Copy-Sources.ps1` in a background process group
under a controlling tty never stop.
- Full `pnpm build` completes 63/63; `git -C core status` stays clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:java Issues for @azure-tools/typespec-java emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants