Skip to content

Add optional server lifecycle hooks - #151

Merged
Eduardo Villalpando Mello (edvilme) merged 5 commits into
mainfrom
refactor/s7-lifecycle-hooks
Nov 16, 2026
Merged

Eduardo Villalpando Mello (edvilme) merged 5 commits into
mainfrom
refactor/s7-lifecycle-hooks

Conversation

@edvilme

Copy link
Copy Markdown
Contributor

Summary

  • Add a per-launch hook to patch the inherited server environment before env-file and static overrides.
  • Add synchronous pre-start client configuration with generation-owned disposable cleanup on replacement, failure, and shutdown.
  • Document the opt-in APIs and cover lifecycle and environment behavior with tests.

Validation

  • npm test (TypeScript compilation and 183 tests passed)

Apply optional runtime patches before env-file merging without mutating the extension host or changing existing environment precedence.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 85ef72cc-9e26-4bc4-b1c3-55256d9bef91
Register consumer handlers before client startup and clean partial, failed, retired, and cancelled setup without changing restart scheduling. Keep hook resources separate from pre-stop state listeners.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 85ef72cc-9e26-4bc4-b1c3-55256d9bef91
@bschnurr

Copy link
Copy Markdown
Member

🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR.

@edvilme Eduardo Villalpando Mello (edvilme) added the debt Code Cleanup, Refactorings and Repo health. Not feature related label Nov 16, 2026

Copilot AI 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.

🟡 Changes recommended

Environment overrides can fail to remove inherited variables after the language-client merge, and Windows case-insensitive aliases can cause inherited values to override replacements.

2 open issues
What changed in this PR

Adds opt-in lifecycle hooks to the shared TypeScript runtime so tool extensions can customize launch environments and register client handlers without replacing lifecycle management.

Changes:

  • Adds per-launch environment patches and synchronous pre-start client configuration.
  • Tracks hook disposables across replacement, failure, and shutdown.
  • Documents the APIs and adds lifecycle, environment, and type-check coverage.
File Description
typescript/​tests/​toolExtension.typecheck.ts Checks hook types and rejects async setup callbacks.
typescript/​tests/​toolExtension.test.ts Tests hook execution and generation cleanup.
typescript/​tests/​server.test.ts Tests environment precedence, setup failures, and cancellation.
typescript/​tests/​activation.test.ts Checks cleanup when the interpreter is cleared.
typescript/​tests/​_languageclient_mock.ts Adds notification registration and simulation.
typescript/​src/​toolExtension.ts Accepts and forwards optional hooks.
typescript/​src/​server.ts Implements environment patches and client setup ownership.
typescript/​src/​index.ts Exports the public hook types.
typescript/​src/​activation.ts Integrates setup retirement and shutdown cancellation.
typescript/​README.md Documents hook contracts and cleanup behavior.
README.md Links to the optional launch-hook APIs.

Review effort: Balanced

Comment thread typescript/src/server.ts Resolved
Comment thread typescript/src/server.ts Resolved
Comment thread typescript/src/server.ts Resolved
@bschnurr

Bill Schnurr (bschnurr) commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Reviewed commit: e7e7875e59de819a72c67209cc0d4c21105d4f9b

Result: 🔴 could-not-verify

Verification details

Verification: Automated verification is best effort. The PR author remains responsible for testing.

Summary: [unavailable] Container verification could not start and local execution was not authorized for this PR HEAD: C:\Program Files\RedHat\Podman\podman.EXE --connection pyrx-automation failed: stderr: Error: unable to start container "c5d588b17c674aebef0aff78c260127b95ad3613c6573f6091d7f84dd2649fc9": crun: open `memory.max` for writing: No such file or directory: OCI runtime attempted to invoke a command that was not found

Test runs: none recorded.

@bschnurr Bill Schnurr (bschnurr) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved via Review Center.

@bschnurr Bill Schnurr (bschnurr) added the review-auto:approved Automated review: no blocking findings (approval posted). label Nov 16, 2026
Update and remove matching inherited aliases without creating competing casing, preserve other platforms and environment layering, and verify actual executable child environments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 85ef72cc-9e26-4bc4-b1c3-55256d9bef91
@edvilme

Copy link
Copy Markdown
Contributor Author

Acknowledged the automated-review ownership notice. I have not changed ownership or the review automation. The actionable environment feedback has been investigated and answered on its review threads, with the Windows alias fix pushed as 2a58e1f.

🤖 AI-authored reply via Agency Finish PR.

@edvilme

Copy link
Copy Markdown
Contributor Author

Regarding the container verification report: this is a Podman/container startup failure before any tests ran, not a failing test in this PR. I have not changed or bypassed reviewer infrastructure; its owner can rerun verification once the container issue is repaired.

Independently verified updated head 2a58e1f locally with Node 24.17.0: all 187 TypeScript tests, build, source/test lint and whitespace checks pass (existing lint warnings only), including real executable child-environment checks.

🤖 AI-authored reply via Agency Finish PR.

@edvilme

Copy link
Copy Markdown
Contributor Author

Thanks for the approval. A follow-up to the Windows casing recommendation is now pushed as 2a58e1f; it preserves case-sensitive behavior elsewhere and adds executable child-environment regressions. All 187 tests, build and lint pass (existing warnings only).

🤖 AI-authored reply via Agency Finish PR.

@edvilme

Copy link
Copy Markdown
Contributor Author

Regarding the Copilot review summary: Windows inherited-name matching is fixed in 2a58e1f, with mixed-case replacement/removal and env-file reintroduction tests. The reported general environment remerge does not apply to the pinned 8.1.0 executable transport; I verified its actual transport method launches a child without a deleted inherited sentinel. Details are answered on both inline threads.

All 187 TypeScript tests, build, source/test lint and whitespace checks pass (existing lint warnings only).

🤖 AI-authored reply via Agency Finish PR.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Reconcile removal aliases with later env-file and static values before executable spawn. Preserve the concurrent explicit-undefined representation while validating actual child behavior and case-sensitive matching elsewhere.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 85ef72cc-9e26-4bc4-b1c3-55256d9bef91

Copilot AI 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.

🔵 Needs a closer look

On Windows, a defined hook environment value can defeat a later differently cased override, causing the child process to receive the wrong value.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Case-insensitive env overrides leave defined Windows aliases in conflict

typescript/​src/​server.ts:231

On Windows, this only reconciles undefined aliases, so a defined hook value can defeat a later env-file or static override. For example, a hook returning { TOOL_FLAG: 'hook' } followed by extraEnvVars: { tool_flag: 'static' } leaves both spellings defined, and Node selects the lexicographically first alias, passing 'hook' to the child. Apply later environment layers case-insensitively to all matching aliases while preserving PATH/PYTHONPATH merging, and add a regression for a defined hook value followed by a differently cased override.

2 resolved since last review

Review effort: Balanced

@edvilme

Copy link
Copy Markdown
Contributor Author

Regarding the latest review's defined-value Windows alias concern: this is a real limitation. I checked the pre-S7 base (85155e2): env-file and static assignments already use exact property names, so the same conflict can occur without hooks when the defined value is inherited. The current fix addresses hook replacement/removal and undefined-alias reintroduction; it does not claim to make all later environment layers case-insensitive.

I am deferring the broader request rather than expanding this lifecycle-hook PR into a Windows environment-assembly rewrite through another review round. A separate stacked PR should define case-insensitive precedence across inherited, hook, env-file, built-in and static layers; preserve PATH/PYTHONPATH append semantics; and characterize no-hook behavior with native Windows regressions. That follow-up needs the author's approval before creation. No additional code change is made for this review summary; the tested head remains e7e7875 (187 passing tests, build and lint passing with existing warnings).

🤖 AI-authored reply via Agency Finish PR.

@edvilme
Eduardo Villalpando Mello (edvilme) merged commit 664672c into main Nov 16, 2026
19 checks passed
@edvilme
Eduardo Villalpando Mello (edvilme) deleted the refactor/s7-lifecycle-hooks branch November 16, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debt Code Cleanup, Refactorings and Repo health. Not feature related review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants