Skip to content

fix(sessions): stop the opening prompt reporting kubernetes-context as unset - #85

Merged
sourcehawk merged 1 commit into
mainfrom
worktree-fix-prompt-kube-context
Aug 25, 2026
Merged

sourcehawk merged 1 commit into
mainfrom
worktree-fix-prompt-kube-context

Conversation

@sourcehawk

Copy link
Copy Markdown
Owner

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 session 1940ad81… as a scan for a cluster it already had). The seeded name lived in Investigation.ActiveContext and <sessionDir>/active-context but was never copied into sessions.Options, so prompts.Env.Context stayed 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 to switch_context before its first k8s call regardless of what the prompt names; that wording is left as-is.

Changes

  • Investigation.ActiveContext now flows into sessions.Options.Cluster from manager.go (fresh start) and rehydrate.go (resume after launcher restart), which also makes it available to namespace_derivation as cluster for the first time.
  • Session.Start delegates prompt rendering to a new startPrompt() that sets prompts.Env.Context, so the rendered Environment block is testable without spawning claude.

Testing

Two new tests in internal/sessions: a seeded Cluster renders kubernetes-context: <name> and an empty one still renders <unset>; the first was watched failing on the missing method before the implementation. make lint is clean and make test-go (race) passes in full. Frontend untouched. To poke at it manually, start an investigation with a cluster selected and check the first ## Environment block in the transcript.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RWH96oteD5VB4R9togLq5V

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
Copilot AI lite review requested due to automatic review settings August 25, 2026 23:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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.ActiveContext into sessions.Options.Cluster on both fresh start and rehydrate paths.
  • Refactors Session.Start to delegate opening-prompt rendering to a new startPrompt() helper that sets prompts.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.

@sourcehawk
sourcehawk merged commit 66e72ef into main Aug 25, 2026
6 checks passed
@sourcehawk
sourcehawk deleted the worktree-fix-prompt-kube-context branch August 25, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants