fix(sessions): stop the opening prompt reporting kubernetes-context as unset - #85
Merged
Merged
Conversation
Preflight seeds <sessionDir>/active-context from the operator's cluster pick and the k8s MCP hydrates from it, but the Investigation's ActiveContext was never copied into sessions.Options, so prompts.Env.Context stayed empty and every opening prompt read "kubernetes-context: <unset>". The agent then believed no context was bound while the MCP was already pointed at the cluster. Plumb Investigation.ActiveContext into Options.Cluster on both the fresh-start and rehydrate paths, and extract the prompt build into startPrompt() so the rendered line is testable without spawning claude. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RWH96oteD5VB4R9togLq5V
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, is exercised by new unit tests, and correctly wires the seeded context through to the prompt renderer without altering runtime behavior beyond the intended prompt output.
Pull request overview
Fixes the investigation opening prompt’s ## Environment block so it reports the kubeconfig context the launcher already seeded (instead of always showing kubernetes-context: <unset>), aligning the agent’s perceived cluster binding with the actual k8s MCP state.
Changes:
- Plumbs
Investigation.ActiveContextintosessions.Options.Clusteron both fresh start and rehydrate paths. - Refactors
Session.Startto delegate opening-prompt rendering to a newstartPrompt()helper that setsprompts.Env.Context. - Adds focused unit tests asserting seeded vs unset rendering for
kubernetes-context.
File summaries
| File | Description |
|---|---|
| internal/sessions/session.go | Uses opts.Cluster to set prompts.Env.Context (driving kubernetes-context rendering) and refactors Start to call startPrompt(). |
| internal/sessions/session_test.go | Adds tests verifying startPrompt() emits the seeded kube context and preserves <unset> when empty. |
| internal/server/rehydrate.go | Passes inv.ActiveContext into sessions.Options.Cluster during session rebuild after restart. |
| internal/server/manager.go | Passes i.ActiveContext into sessions.Options.Cluster when starting a new investigation session. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Description
Every investigation's opening prompt reported
kubernetes-context: <unset>even when preflight had seeded a context from the operator's cluster pick, so the agent believed no context was bound while the k8s MCP was already pointed at the cluster (surfaced in session1940ad81…as a scan for a cluster it already had). The seeded name lived inInvestigation.ActiveContextand<sessionDir>/active-contextbut was never copied intosessions.Options, soprompts.Env.Contextstayed empty. This PR plumbs it through on both the fresh-start and rehydrate paths. The teleport/kubeconfig auth guidance in the system prompt still tells the agent toswitch_contextbefore its first k8s call regardless of what the prompt names; that wording is left as-is.Changes
Investigation.ActiveContextnow flows intosessions.Options.Clusterfrommanager.go(fresh start) andrehydrate.go(resume after launcher restart), which also makes it available tonamespace_derivationasclusterfor the first time.Session.Startdelegates prompt rendering to a newstartPrompt()that setsprompts.Env.Context, so the rendered Environment block is testable without spawningclaude.Testing
Two new tests in
internal/sessions: a seededClusterrenderskubernetes-context: <name>and an empty one still renders<unset>; the first was watched failing on the missing method before the implementation.make lintis clean andmake test-go(race) passes in full. Frontend untouched. To poke at it manually, start an investigation with a cluster selected and check the first## Environmentblock in the transcript.🤖 Generated with Claude Code
https://claude.ai/code/session_01RWH96oteD5VB4R9togLq5V