fix: guard ServerRegions/AgentDeployments slice access in agent log streaming#833
Open
j0nscalet wants to merge 1 commit intolivekit:mainfrom
Open
fix: guard ServerRegions/AgentDeployments slice access in agent log streaming#833j0nscalet wants to merge 1 commit intolivekit:mainfrom
j0nscalet wants to merge 1 commit intolivekit:mainfrom
Conversation
createAgent panics with 'index out of range [0] with length 0' when the CreateAgent response returns an empty ServerRegions and the user accepts the post-deploy 'view logs?' prompt. Fall back to the region already resolved earlier in the function. agentLogs has the same class of bug on AgentDeployments: Agents is length-checked but AgentDeployments is not. Return a clean error instead of panicking when an agent has no deployments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On v2.16.2,
lk agent create .panics immediately after a successful build/deploy if you accept the post-deploy "view logs?" prompt:The agent itself deploys fine — the crash is in the post-deploy log-tailer — so it's cosmetic, but it's a jarring stack trace at the end of an otherwise successful flow.
Diagnosis
Two unguarded slice indexes in
cmd/lk/agent.go:CreateAgentresponse'sServerRegionsslice without a length check. When the server returns an emptyServerRegions, the CLI panics.agent logssubcommand checks that theAgentsslice fromListAgentsis non-empty, but then unconditionally readsAgentDeployments[0]on the first agent. An agent with zero deployments would panic the same way.Fix
cmd/lk/agent.go:646— before:after:
regionis already resolved earlier increateAgentand is the region the build was targeted at — a sensible fallback for log streaming.cmd/lk/agent.go:956— before:after:
Definition of Done
lk agent create .→ accept "view logs?" prompt → no panic, even when theCreateAgentresponse has an emptyServerRegionslk agent logsagainst an agent with zero deployments → returns a clear error instead of panicking