Skip to content

fix: recover from bad proxy settings, keep proxy traffic within downloadConcurrency, and stop re-fetching mod metadata - #1

Closed
Crow093 wants to merge 5 commits into
lopleec:mainfrom
Crow093:review/v0.3.3-fixes
Closed

Crow093 wants to merge 5 commits into
lopleec:mainfrom
Crow093:review/v0.3.3-fixes

Conversation

@Crow093

@Crow093 Crow093 commented Oct 29, 2026

Copy link
Copy Markdown

Five independent defects, each with a user-visible consequence. All patches were written against the unmodified v0.3.3 tree and verified on a clean checkout.

Why

  1. A bad proxy setting killed the whole extension. activate() ran new URL(proxy) and JSON.parse(credentials) on the minecraftWorkbench.proxy / http.proxy value and the stored secret. A malformed URL, a scheme other than HTTP(S)/SOCKS5, or a corrupt secret threw before any view, command or status item was registered, so the extension disappeared with nothing actionable in the UI.
  2. The User-Agent was frozen at 0.3.1. src/network.ts hard-coded MinecraftWorkbench/0.3.1 in both request paths while the manifest already declared 0.3.3, so Mojang, Modrinth and CDN logs showed a stale client version forever.
  3. Exporting a non-ASCII instance name suggested a filename that was not the name. instance.name.replace(/[^\w.-]/g, '_') in src/ui.ts treats every non-ASCII letter as illegal: 我的世界 became _________.mrpack, and names such as CON / LPT1 produced files Windows rejects.
  4. Check Mod Conflicts bypassed this module's own cache. conflicts() called net.json() directly for every installed mod instead of version(), so the five minute cache every other request in src/content.ts uses was never hit: a second run re-fetched everything, and a large pack paid one sequential round trip per mod.
  5. Proxy traffic ignored downloadConcurrency. Only the direct branch passed connections: concurrency; HTTP(S) (ProxyAgent) and SOCKS (Agent + socks) kept undici's default unbounded client pool, so bulk work opened one tunnel connection per request.

What changed

commit change
fix(lifecycle) New src/proxy.ts with a resolveProxy() pure function that reports invalid input instead of throwing; credentials are merged only when they parse. createNetwork() falls back to a direct connection and warns once, so activation always completes.
fix(network) New src/user-agent.ts reads the version from vscode.extensions.getExtension(...).packageJSON.version; Network takes a userAgent option and both request paths use it.
fix(ui) New suggestedFilename() in src/files.ts rewrites only characters Windows and macOS actually reject, and handles leading/trailing dots, over-long names, empty names and DOS device names. Both defaultUri calls in src/ui.ts use it.
perf(content) conflicts() goes through version() (cached) and issues the lookups together; warnings are assembled per mod so the original local-then-online ordering is preserved exactly.
perf(network) The SOCKS agent gets connections; ProxyAgent is constructed with the object form { uri, connections }, since the string form only accepts a URI.

Stacking

fix(lifecycle) → fix(network) → perf(network) are stacked: the later commits touch code the first one introduces (createNetwork(), this.userAgent). fix(ui) and perf(content) are independent of the others and can be cherry-picked on their own. Happy to split this into separate PRs if that is easier to review — just say how you would like it.

Verification

  • npm test: 44/44 (36 existing, plus test/proxy.test.ts, test/user-agent.test.ts, additions to test/files.test.ts and test/content.test.ts)
  • tsc --noEmit, format:check, legal --check, compile — all clean
  • Clean checkout of the v0.3.3 import, git am of all five patches, npm ci, then tsc and the full suite: green
  • No new dependencies; package.json is untouched

Deliberately not included

  • Memory validation runs at launch instead of in the settings validator: instance-settings.ts:32 only compares min and max when both are set, so minMemory: 8192 with an automatic maximum passes the form and fails when the game starts.
  • accounts.ts retries a failed background token refresh every 60 s indefinitely.

Both are real, but a proper fix needs the recommendation context plumbed into the validator, and changes to the auth state machine respectively. I left them out to keep this reviewable.

Minecraft Workbench Contributor added 5 commits October 29, 2026 16:07
A malformed `minecraftWorkbench.proxy`/`http.proxy` value, a proxy
scheme other than HTTP(S)/SOCKS5, or a corrupt `proxyCredentials`
secret made `activate()` throw: `new URL` or `new ProxyAgent`
failed before any view, command or status item was registered, so the
whole extension disappeared without an error the user could act on.

Credential merging and proxy validation now happen in `src/proxy.ts`,
which reports invalid input instead of throwing, and the network layer
is created with a last-resort fallback to a direct connection. Both
cases surface as a warning so the setting stays discoverable.
Both request paths hard-coded `MinecraftWorkbench/0.3.1` while the
manifest already declares 0.3.3, so Mojang, Modrinth and CDN logs would
keep showing a stale client version forever. The value now comes from
the installed manifest through `vscode.extensions` and is passed into
`Network`, which also prevents the two copies from diverging again.
`instance.name.replace(/[^\\w.-]/g, '_')` treats every non-ASCII letter
as illegal, so exporting an instance called 我的世界 or サーバー用
offered a file named `_________.mrpack`. Only characters that Windows
and macOS actually reject are rewritten now; leading and trailing dots,
over-long names and the DOS device names (CON, LPT1, ...) are handled
too, so the suggestion is a name the platform will accept.
`conflicts()` called `net.json` directly for every installed mod, so
the five minute cache that every other request in this module uses was
bypassed: a second Check conflicts run re-fetched everything, and a
large pack paid one round trip per mod.

The lookups now go through `version()` and are issued together, while
the warnings are assembled per mod, so the local-then-online ordering of
the previous sequential loop stays the same.
Only the direct connection passed `connections: concurrency`, so HTTP and
SOCKS proxies kept undici's default (unbounded) client pool. Bulk work such
as the installed-mod conflict check then opened one connection per request
through the tunnel.

Both proxy branches now carry the limit:

- the SOCKS agent gets `connections` in its options;
- ProxyAgent is constructed with the object form, `{ uri, connections }`,
  because the string form only accepts a URI.

undici 7.29 forwards the value: proxy-agent.js:168 spreads the constructor
options into its inner Agent, agent.js:48 keeps them in kOptions, and the
per-origin factory reaches defaultAgentFactory/Pool, which stops creating
clients at `connections` (pool.js:110). Credentials embedded in the proxy
URI keep working with the object form - ProxyAgent still runs `new URL(uri)`
and derives proxy-authorization from its username/password.
@lopleec

lopleec commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thanks a lot for the contribution!!!! Preserving non-ASCII export filenames and reusing cached Modrinth metadata during conflict checks are useful improvements.

However, I can’t merge this PR as-is. Invalid proxy settings can cause requests to bypass the proxy, some Windows reserved filenames remain invalid, and offline conflict checks no longer stop requesting metadata after a network failure.

The branch is also based on v0.3.3 and conflicts with the current codebase. The hard-coded extension ID and network changes need compatibility adjustments, while some fixes are already present in the current version.

I’ll adapt the useful improvements and address these issues in the next release.

@lopleec lopleec closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants