Skip to content

Keep Lake setup output out of the startup protocol and recover cancelled initialization - #823

Closed
arnovich wants to merge 2 commits into
leanprover:masterfrom
arnovich:task/395_handle_lean_startup_protocol_corruption_during_walkthrough_d_4ffcf3e8f6
Closed

arnovich wants to merge 2 commits into
leanprover:masterfrom
arnovich:task/395_handle_lean_startup_protocol_corruption_during_walkthrough_d_4ffcf3e8f6

Conversation

@arnovich

@arnovich arnovich commented Nov 12, 2026 •

Copy link
Copy Markdown

Summary

Cold lake serve startup can run dependency post_update hooks before the Lean server starts. Their ordinary stdout then reaches the JSON-RPC reader ahead of its first Content-Length header, leaving initialization stuck. Stopping that client previously did nothing because it was not yet running.

Changes

  • Recognise a complete, bounded JSON-RPC 2.0 frame before entering protocol mode, then pass all bytes through to the existing strict reader. Log HTTP-style hook frames, non-JSON-RPC bodies and progress separately; keep scanning later candidates if an earlier hook header claims an incomplete body. Preserve split headers, UTF-8, IO.print without a newline and carriage-return progress.
  • Latch cancellation across preparation and transport creation, await startup settlement before Stop returns, and ignore events from discarded clients. Return immediately after failed initialization.
  • Include the locked language-client dependency's terminateProcess.sh in the extension bundle and VSIX with executable permissions. Without this asset, its delayed process-tree cleanup silently fails on Unix.
  • Add protocol tests and real extension-host fixtures covering noisy cold startup, warm restart, stopping a sleeping dependency hook, and deterministic cancellation before process creation followed by retry.

Testing

  • Reproduced the original cold/warm stdout difference with an isolated local dependency on Lean 4.33.1; existing ETH walkthrough pins and caches were left intact.
  • Unit suite: 41 passed, including 14 framing tests; 8 PowerShell-only tests skipped on macOS.
  • HTTP-style hook headers and first-frame completeness regressions failed before the review fix and pass afterward, including every split boundary. The real startup fixture also prints an HTTP-style header with an incomplete claimed body.
  • TypeScript compilation, changed-file ESLint, Prettier, and the extension development build pass.
  • VS Code extension-host startup suite on macOS with Lean 4.35.0: all 6 tests pass. Stop must finish within 15 seconds while the hook sleeps for 60 seconds; retry runs without reloading VS Code.
  • Packaged a development smoke VSIX with the locked VSCE and verified extension/dist/terminateProcess.sh has mode 0755 and bytes identical to the dependency's helper.
  • Reviewed protocol correctness, cancellation/process ownership, and packaging with independent reviewers; their blocking findings were addressed.

The language-client library still logs initialization/connection errors when a pending startup is deliberately terminated; cancellation settles and a subsequent restart succeeds.

Route dependency hook progress to the Lean log before protocol startup and allow Stop followed by retry while initialization is pending. Include the process-tree termination helper so cancellation does not wait for a dependency hook to finish.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T10:30:21.218007Z f88b65b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f88b65bb98

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
this.pending = Buffer.concat([this.pending, chunk])
const text = this.pending.toString('latin1')
const header = /Content-Length:[ \t]*[0-9]+\r\n/i.exec(text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate a full frame before entering protocol mode

When a dependency hook writes an HTTP-style line such as Content-Length: 123\r\n (for example, curl -i output) before Lean starts, this regex treats that hook output as the first LSP header. The branch then permanently sets protocolStarted and forwards the hook's response/body to StreamMessageReader, so the cold server startup fails before the real Lean header arrives. Since these hooks can emit arbitrary stdout, wait for a complete frame and validate that it is JSON-RPC before switching modes.

Useful? React with 👍 / 👎.

Hook output can contain HTTP-style Content-Length headers. Validate a bounded complete JSON-RPC body before switching readers, and keep searching later candidates when an earlier hook frame is incomplete.
@arnovich arnovich closed this Nov 12, 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.

1 participant