Skip to content

Persist server-mode auth state on session PVC#1

Merged
ianrossi merged 1 commit intomainfrom
issue/7-auth-persistence
Apr 8, 2026
Merged

Persist server-mode auth state on session PVC#1
ianrossi merged 1 commit intomainfrom
issue/7-auth-persistence

Conversation

@ianrossi
Copy link
Copy Markdown

@ianrossi ianrossi commented Apr 8, 2026

This patches server-mode agent deployments so persisted agents store OpenCode auth/config/state on the existing session PVC instead of /tmp.

Changes:

  • when Agent.spec.persistence.sessions is enabled, set HOME, XDG_CONFIG_HOME, XDG_DATA_HOME, and XDG_STATE_HOME under /data/sessions
  • keep the existing /tmp fallback for non-persisted agents
  • add controller tests for both cases
  • add a minimal GHCR workflow to publish the patched controller image

Related deploy issue: https://github.com/aimtheory/quantifai-deploy/issues/7

Copilot AI review requested due to automatic review settings April 8, 2026 21:14
@ianrossi ianrossi merged commit f7ebfff into main Apr 8, 2026
8 checks passed
@ianrossi ianrossi deleted the issue/7-auth-persistence branch April 8, 2026 21:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates server-mode agent deployments so OpenCode auth/config/state can persist on the existing session PVC (when enabled), instead of being written under /tmp, and adds CI plumbing to publish a patched controller image to GHCR.

Changes:

  • When Agent.spec.persistence.sessions is enabled, set HOME and XDG (XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_STATE_HOME) to directories under /data/sessions.
  • Extend controller unit tests to cover both persisted and non-persisted session cases.
  • Add a manual GitHub Actions workflow to build and push a controller image to GHCR.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
internal/controller/server_builder.go Sets persistent HOME/XDG env vars when session PVC persistence is enabled.
internal/controller/server_builder_test.go Adds/extends tests validating env var behavior for persisted vs non-persisted sessions.
.github/workflows/build-ghcr-kubeopencode.yaml Adds a manual workflow to build/push the controller image to GHCR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 255 to +264
envVars = append(envVars, corev1.EnvVar{
Name: OpenCodeDBEnvVar,
Value: ServerSessionDBPath,
})
envVars = append(envVars,
corev1.EnvVar{Name: "HOME", Value: ServerPersistentHomeDir},
corev1.EnvVar{Name: "XDG_CONFIG_HOME", Value: ServerPersistentXDGConfigHome},
corev1.EnvVar{Name: "XDG_DATA_HOME", Value: ServerPersistentXDGDataHome},
corev1.EnvVar{Name: "XDG_STATE_HOME", Value: ServerPersistentXDGStateHome},
)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

When session persistence is enabled, this appends a second HOME env var after the default HOME set earlier. Having duplicate env var names in container.Env is easy to miss (tests map-overwrite it) and can lead to confusing/ordering-dependent behavior. Prefer computing the desired HOME value up front and setting HOME exactly once, then conditionally add the XDG_* env vars.

Copilot uses AI. Check for mistakes.
Comment on lines 1134 to 1140
// Verify OPENCODE_DB env var
var foundEnv bool
envMap := make(map[string]string, len(container.Env))
for _, env := range container.Env {
envMap[env.Name] = env.Value
if env.Name == OpenCodeDBEnvVar {
foundEnv = true
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

The tests build an envMap from container.Env, which will silently drop duplicates (e.g., two HOME entries). Since the production code currently appends HOME twice when session persistence is enabled, these assertions won’t catch it. Consider adding explicit checks that HOME appears exactly once (and likewise for XDG_*), in addition to validating values.

Copilot uses AI. Check for mistakes.
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.

3 participants