fix(backend): inherit parent userContext in child sessions#988
Merged
Gkrumbach07 merged 2 commits intomainfrom Mar 23, 2026
Merged
fix(backend): inherit parent userContext in child sessions#988Gkrumbach07 merged 2 commits intomainfrom
Gkrumbach07 merged 2 commits intomainfrom
Conversation
When a runner's service account creates a child session via the backend API, the child session's userContext was derived from the service account identity instead of the original user. This broke credential resolution (e.g., GitHub tokens) because the backend looked up credentials for the service account, which has none. Now, when `parentSessionId` is provided: - Backend fetches the parent session CR and copies its userContext - Child session inherits the parent's userId, displayName, and groups - Credentials (GitHub, Jira, etc.) resolve correctly The runner API client now automatically sets `parentSessionId` to the current session name (from AGENTIC_SESSION_NAME env var) so all child sessions inherit identity without any changes to agent code. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughBackend session creation now supports parent/child inheritance: when a parentSessionID is provided the handler copies the parent's spec.userContext into the new session. The Python client sets parentSessionId from AGENTIC_SESSION_NAME. Manifests adjust operator memory and add HAProxy route annotations. Changes
Sequence DiagramsequenceDiagram
participant Client as Python Client
participant Handler as Backend Handler
participant K8s as Kubernetes API
Client->>Handler: POST /sessions (parentSessionId=X?)
alt parentSessionId provided
Handler->>K8s: GET AgenticSession CR (parentSessionId)
K8s-->>Handler: AgenticSession CR (spec.userContext)
Handler->>Handler: Set newSession.spec.userContext = parent.spec.userContext
else no parentSessionId
Handler->>Handler: Read caller userID, resolve token identity if needed
Handler->>Handler: Build newSession.spec.userContext from identity + req.UserContext
end
Handler-->>Client: 201 Created (new session)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…ancing Operator: - Bump memory request 64Mi→128Mi, limit 256Mi→512Mi to prevent OOM under load (observed 162Mi steady-state with ~70 sessions, was at 63% of the old 256Mi limit with headroom shrinking) Frontend route: - Add roundrobin balance and disable sticky cookies so traffic distributes across all frontend replicas (one pod was at 97% memory while the other was idle due to default cookie affinity) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jeremyeder
pushed a commit
to jeremyeder/platform
that referenced
this pull request
Mar 26, 2026
…ode#988) ## Summary - When a runner service account creates a child session, the child now inherits the **parent session's `userContext`** instead of getting the service account identity - The runner API client automatically sets `parentSessionId` to the current session name - Fixes credential resolution (GitHub, Jira, etc.) for child sessions ## Problem Child sessions created by a runner pod had `userContext.userId` set to the service account identity (e.g., `system-serviceaccount-ns-ambient-session-session-123`). When the backend tried to resolve GitHub credentials for the child, it looked up credentials for the service account — which has none — returning 404. ## Changes **`components/backend/handlers/sessions.go`** - When `parentSessionId` is provided, fetch the parent session CR and copy its `spec.userContext` to the child - Falls back to existing identity resolution if no parent or parent lookup fails **`components/runners/ambient-runner/ambient_runner/tools/backend_api.py`** - `create_session()` now automatically sets `parentSessionId` from `AGENTIC_SESSION_NAME` env var ## Test plan - [ ] Create a session that spawns child sessions — verify child sessions have the parent's userId - [ ] Verify child sessions can resolve GitHub credentials - [ ] Verify sessions created directly (no parent) still work as before - [ ] Verify parent lookup failure (e.g., deleted parent) gracefully falls back 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Ambient Code Bot <bot@ambient-code.local> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
userContextinstead of getting the service account identityparentSessionIdto the current session nameProblem
Child sessions created by a runner pod had
userContext.userIdset to the service account identity (e.g.,system-serviceaccount-ns-ambient-session-session-123). When the backend tried to resolve GitHub credentials for the child, it looked up credentials for the service account — which has none — returning 404.Changes
components/backend/handlers/sessions.goparentSessionIdis provided, fetch the parent session CR and copy itsspec.userContextto the childcomponents/runners/ambient-runner/ambient_runner/tools/backend_api.pycreate_session()now automatically setsparentSessionIdfromAGENTIC_SESSION_NAMEenv varTest plan
🤖 Generated with Claude Code