fix(tunnels): extract tunnel domain from base url#755
Conversation
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Sequence DiagramThis PR updates tunnel URL generation to derive the tunnel domain from the SDK client base URL instead of using a fixed domain. This allows the same method to return correct tunnel hosts across different environments. sequenceDiagram
participant User
participant DevboxSDK
participant DevboxAPI
User->>DevboxSDK: Request tunnel URL for port
DevboxSDK->>DevboxAPI: Retrieve devbox tunnel details
DevboxAPI-->>DevboxSDK: Return tunnel key
DevboxSDK->>DevboxSDK: Derive base domain from client base URL and build tunnel host
DevboxSDK-->>User: Return tunnel URL for requested port
Generated by CodeAnt AI |
Nitpicks 🔍
|
src/sdk/devbox.ts
Outdated
| } | ||
| return `https://${port}-${tunnel.tunnel_key}.tunnel.runloop.ai`; | ||
| const apiHost = new URL(this.client.baseURL).hostname; | ||
| const baseDomain = apiHost.split('.').slice(-2).join('.'); |
There was a problem hiding this comment.
Suggestion: Domain extraction is incorrect for non-DNS hosts like IP-based baseURL values (for example http://127.0.0.1:4010): splitting and taking the last two labels turns 127.0.0.1 into 0.1, producing a broken tunnel URL. Derive the tunnel domain by removing only a leading api. prefix when present, and otherwise keep the full hostname. [logic error]
Severity Level: Major ⚠️
- ⚠️ `getTunnelUrl` breaks with IP-based client baseURL.
- ⚠️ Custom/local deployments get unusable tunnel links.| const baseDomain = apiHost.split('.').slice(-2).join('.'); | |
| const baseDomain = apiHost.startsWith('api.') ? apiHost.slice(4) : apiHost; |
Steps of Reproduction ✅
1. Configure a client with non-DNS/IP host support, which is allowed by `Runloop`
constructor in `src/index.ts:331-346` (`baseURL` is accepted directly with no hostname
restriction).
2. Create or obtain a `Devbox` instance, then call `Devbox.getTunnelUrl()` (method at
`src/sdk/devbox.ts:842`) as shown in real usage at `examples/devbox-tunnel.ts:70`.
3. Execution path is `getTunnelUrl()` → `getTunnel()` (`src/sdk/devbox.ts:811`) →
`getInfo()` (`src/sdk/devbox.ts:793`) and then URL construction at
`src/sdk/devbox.ts:847-849`.
4. In `getTunnelUrl()`, current code derives domain using
`apiHost.split('.').slice(-2).join('.')` (`src/sdk/devbox.ts:848`); for `127.0.0.1` this
deterministically becomes `0.1` (same last-two-label behavior demonstrated via shell
extraction).
5. Returned URL becomes `https://<port>-<tunnel_key>.tunnel.0.1`, which is not the
intended tunnel host format, so consumers get a broken/unresolvable tunnel URL when using
IP-based `baseURL`.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** src/sdk/devbox.ts
**Line:** 848:848
**Comment:**
*Logic Error: Domain extraction is incorrect for non-DNS hosts like IP-based `baseURL` values (for example `http://127.0.0.1:4010`): splitting and taking the last two labels turns `127.0.0.1` into `0.1`, producing a broken tunnel URL. Derive the tunnel domain by removing only a leading `api.` prefix when present, and otherwise keep the full hostname.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.|
CodeAnt AI finished reviewing your PR. |
❌ Object Smoke Tests FailedTest Results❌ Some smoke tests failed Failed Tests:
Please fix the failing tests before checking coverage. |
james-rl
left a comment
There was a problem hiding this comment.
I think we should change this so that it's more obvious what the tunnel url is or just skip this entire test in dev.
Right now this is not really a great example.
That said, I'm eager to fix the smoke test, so I'm approving this
1d591bb to
5af7c81
Compare
5af7c81 to
775c494
Compare
User description
Format:
feat[optional scope]: <description>Examples:
feat: add new SDK method·feat(storage): support file uploads·feat!: breaking API changeDescription
Motivation
Changes
Testing
Breaking Changes
Checklist
feat:orfeat(scope):)CodeAnt-AI Description
Use the API base domain when building tunnel links
What Changed
runloop.airunloop.proImpact
✅ Tunnel links work across API environments✅ Fewer broken devbox tunnel URLs✅ Clearer local access in non-default deployments💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.