Skip to content

Conversation

@coterp
Copy link

@coterp coterp commented Dec 17, 2025

Summary

This PR improves the reliability of Cypress E2E runs when starting and stopping Chainlit.

Changes

  • Track the spawned Chainlit process and shut it down reliably via process group
  • Use port-based termination (fkill) only as a fallback when no tracked process exists
  • Fix broken entrypoint file existence check (async fs/promises.access was not awaited)
  • Improve signal handling and typing in cypress.config.ts
  • Modernize Node core imports (node: + type imports)

Motivation

Cypress E2E runs were failing consistently due to unreliable Chainlit shutdown and restart behavior in containerized dev environments.

Tests frequently failed with port-in-use errors because previous Chainlit instances were not reliably terminated between runs or between specs. The existing port-based termination (fkill(:port)) proved unreliable in containers and was insufficient as a primary means of terminating Chainlit.

This PR introduces explicit process tracking and shutdown of the spawned Chainlit process, using port-based termination only as a fallback to clean up stray instances from previous runs.

Testing

  • uv run pytest --cov=chainlit
  • pnpm test (Cypress, headless via Xvfb)
  • pnpm test:ui
  • pnpm lint

Summary by cubic

Improves reliability of Cypress E2E runs by cleanly starting and stopping Chainlit to avoid port-in-use errors in containers. Tracks and kills the spawned process group, using port-based termination only as a fallback.

  • Bug Fixes
    • Fix entrypoint check by awaiting fs.promises.access.
    • Add stopChainlit and typed signal handling to kill the process group cleanly; fall back to fkill when no tracked process exists.
    • Streamline Cypress setup and restartChainlit flow; modernize Node imports and types.
    • On Windows, kill the entire Chainlit process tree with taskkill for reliable port release.

Written for commit d8e9a68. Summary will update automatically on new commits.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. dev-tooling Relating to developer/contributor toolings. labels Dec 17, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

@asvishnyakov
Copy link
Member

@coterp Thank you for contribution!

@hayescode @sandangel I would like to review this PR myself, as I tried to implement such functionality earlier and had an issues with that

@coterp
Copy link
Author

coterp commented Dec 17, 2025

@hayescode Sounds good, thanks for your review.
Let me know if you have any questions or want me to adjust anything.

@asvishnyakov asvishnyakov changed the title Fix Cypress Chainlit shutdown and entrypoint checks fix(cypress): Chainlit shutdown and entrypoint checks Dec 23, 2025
Copy link
Member

@asvishnyakov asvishnyakov left a comment

Choose a reason for hiding this comment

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

@coterp Unfortunately I have same issue with it as when I tried implement such feature myself: it doesn't work in Cypress interactive mode, at least on Linux
Try to:

  • Open Cypress in interactive mode (for example, via pnpm test:interactive)
  • Run custom_theme tests (you'll see green screen, then red)
  • Run data_layer tests (you'll see green screen again and tests will fail because login isn't enabled in previous test server, while it is in data_layer test server)

@asvishnyakov
Copy link
Member

But I think we can merge some implements from here, like broken entrypoint file existence check, if you'll remove or fix new server restart code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev-tooling Relating to developer/contributor toolings. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants