Skip to content

Commit e1b71fe

Browse files
committed
refactor: simplify session repository structure and status handling
- Replaced the unified session repository mapping with a simplified format, reducing complexity in the session spec. - Removed unnecessary fields from the session status, focusing on essential information (phase, message, is_error). - Updated frontend components to align with the new repository structure, enhancing clarity and usability. - Eliminated deprecated fields and logic related to input/output repositories, streamlining the session management process. These changes improve the maintainability and performance of the session handling system.
1 parent 9798183 commit e1b71fe

File tree

22 files changed

+1447
-793
lines changed

22 files changed

+1447
-793
lines changed
Lines changed: 376 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,376 @@
1+
# Comprehensive Field Usage Analysis: All Session Operations
2+
3+
## Summary
4+
Complete analysis of field usage across all session-related operations:
5+
- **CreateSession** (POST)
6+
- **UpdateSession** (PUT)
7+
- **PatchSession** (PATCH)
8+
- **CloneSession** (POST /clone)
9+
- **StartSession** (POST /start)
10+
- **StopSession** (POST /stop)
11+
- **Other operations**
12+
13+
---
14+
15+
## 1. CreateSession (POST /api/projects/:projectName/agentic-sessions)
16+
17+
### ✅ USED FIELDS
18+
19+
| Field | Frontend Sends | Backend Uses | Handler Lines |
20+
|-------|---------------|--------------|---------------|
21+
| `prompt` | ✅ page.tsx, dialog.tsx || 358 |
22+
| `llmSettings.model` | ✅ Both || 312-313 |
23+
| `llmSettings.temperature` | ✅ Both || 315-316 |
24+
| `llmSettings.maxTokens` | ✅ Both || 318-319 |
25+
| `timeout` | ✅ Both || 324-325 |
26+
| `interactive` | ✅ page.tsx || 411-412 |
27+
| `autoPushOnComplete` | ✅ page.tsx || 416-417 |
28+
| `repos` | ✅ page.tsx || 424-444 |
29+
| `mainRepoIndex` | ✅ page.tsx || 446-447 |
30+
| `environmentVariables` | ✅ page.tsx || 375-377 |
31+
| `labels` | ✅ page.tsx || 338-343 |
32+
| `parent_session_id` | ❌ Not sent || 380-402 (if provided) |
33+
34+
### ⚠️ PARTIALLY USED
35+
36+
| Field | Frontend | Backend | Notes |
37+
|-------|----------|---------|-------|
38+
| `displayName` | ❌ Not sent | ✅ Line 359 | Read but often empty string |
39+
| `userContext` | ❌ Not sent | ⚠️ Lines 470-475 | **userId ALWAYS overwritten** from auth token. Only `displayName`/`groups` used as fallback if auth doesn't provide them |
40+
| `annotations` | ❌ Not sent | ✅ Lines 345-350 | Handler supports it, but frontend never sends |
41+
42+
### ❌ UNUSED FIELDS
43+
44+
| Field | Type Definition | Handler Usage | Frontend Sends |
45+
|-------|----------------|---------------|----------------|
46+
| `WorkspacePath` | Line 71 |**NEVER referenced** | ✅ page.tsx sends it (line 126) |
47+
| `BotAccount` | Line 78 | ✅ Lines 485-488 | ❌ Never sent |
48+
| `ResourceOverrides` | Line 79 | ✅ Lines 492-508 | ❌ Never sent |
49+
50+
### Frontend Form Fields (Never Sent)
51+
52+
| Field | Location | Status |
53+
|-------|----------|--------|
54+
| `agentPersona` | page.tsx defaultValues (line 91) | ❌ Form field exists, **never added to request** |
55+
| `anthropicApiKey` | dialog.tsx (line 80) | ❌ Form field, **explicitly not sent** (TODO comment line 99) |
56+
| `saveApiKeyForFuture` | dialog.tsx (line 81) | ❌ Form field, **explicitly not sent** (TODO comment line 99) |
57+
58+
---
59+
60+
## 2. UpdateSession (PUT /api/projects/:projectName/agentic-sessions/:sessionName)
61+
62+
### ✅ USED FIELDS
63+
64+
| Field | Backend Handler | Lines |
65+
|-------|----------------|-------|
66+
| `prompt` || 934 |
67+
| `displayName` || 935 |
68+
| `llmSettings.model` || 939-940 |
69+
| `llmSettings.temperature` || 942-943 |
70+
| `llmSettings.maxTokens` || 945-946 |
71+
| `timeout` || 951-952 |
72+
73+
### ❌ UNUSED FIELDS (Handler Ignores)
74+
75+
| Field | Type Definition | Handler Usage |
76+
|-------|----------------|---------------|
77+
| `Interactive` | Line 70 |**Not updated** - UpdateSession only updates prompt, displayName, llmSettings, timeout |
78+
| `WorkspacePath` | Line 71 | ❌ Not used |
79+
| `ParentSessionID` | Line 72 | ❌ Not used |
80+
| `Repos` | Line 74 | ❌ Not used |
81+
| `MainRepoIndex` | Line 75 | ❌ Not used |
82+
| `AutoPushOnComplete` | Line 76 | ❌ Not used |
83+
| `UserContext` | Line 77 | ❌ Not used |
84+
| `BotAccount` | Line 78 | ❌ Not used |
85+
| `ResourceOverrides` | Line 79 | ❌ Not used |
86+
| `EnvironmentVariables` | Line 80 | ❌ Not used |
87+
| `Labels` | Line 81 | ❌ Not used |
88+
| `Annotations` | Line 82 | ❌ Not used |
89+
90+
**Note**: UpdateSession uses `CreateAgenticSessionRequest` type but only processes 4 fields. All other fields are ignored.
91+
92+
### Frontend Usage
93+
- **No frontend calls UpdateSession** - The route exists but no React Query hook or component uses it
94+
- Frontend uses `UpdateSessionDisplayName` instead (dedicated endpoint)
95+
96+
---
97+
98+
## 3. PatchSession (PATCH /api/projects/:projectName/agentic-sessions/:sessionName)
99+
100+
### ✅ USED FIELDS
101+
102+
| Field | Backend Handler | Lines |
103+
|-------|----------------|-------|
104+
| `metadata.annotations` || 873-883 |
105+
106+
### ❌ UNUSED FIELDS
107+
108+
| Field | Handler Behavior |
109+
|-------|------------------|
110+
| `spec.*` |**Not patched** - Only metadata.annotations supported |
111+
| `status.*` |**Not patched** - Only metadata.annotations supported |
112+
| `metadata.labels` |**Not patched** - Only metadata.annotations supported |
113+
| `metadata.name` |**Not patched** - Only metadata.annotations supported |
114+
115+
**Note**: PatchSession only supports patching `metadata.annotations`. All other fields are ignored.
116+
117+
### Frontend Usage
118+
- **No frontend calls PatchSession** - Route exists but unused
119+
120+
---
121+
122+
## 4. CloneSession (POST /api/projects/:projectName/agentic-sessions/:sessionName/clone)
123+
124+
### ✅ USED FIELDS
125+
126+
| Field | Frontend Sends | Backend Handler | Lines |
127+
|-------|---------------|----------------|-------|
128+
| `targetProject` | ✅ clone-session-dialog.tsx (line 78) || 1629, 1682, 1692, 1703 |
129+
| `newSessionName` | ✅ clone-session-dialog.tsx (line 79) || 1653, 1660, 1681 |
130+
131+
### ❌ UNUSED FIELDS
132+
133+
| Field | Type Definition | Handler Usage |
134+
|-------|----------------|---------------|
135+
| `DisplayName` | CloneAgenticSessionRequest line 100 |**Not used** - Uses source session's displayName |
136+
| `Prompt` | CloneAgenticSessionRequest line 101 |**Not used** - Uses source session's spec |
137+
| `TargetSessionName` | CloneAgenticSessionRequest line 99 |**Not used** - Uses `newSessionName` instead |
138+
139+
**Note**: `CloneAgenticSessionRequest` has unused fields. Handler only uses `targetProject` and `newSessionName` from `CloneSessionRequest`.
140+
141+
### Frontend Usage
142+
- Frontend sends: `{ targetProject, newSessionName }`
143+
- Backend type has extra fields that are never used
144+
145+
---
146+
147+
## 5. StartSession (POST /api/projects/:projectName/agentic-sessions/:sessionName/start)
148+
149+
### Request Body
150+
- **No body** - Frontend sends empty POST (sessions.ts line 90)
151+
- Handler doesn't read any request body
152+
153+
### Handler Logic
154+
- Reads current session from CRD
155+
- Updates status to "Pending" to trigger operator
156+
- Handles continuation logic (parent session annotation)
157+
- Regenerates runner token
158+
- Deletes old job if continuation
159+
160+
---
161+
162+
## 6. StopSession (POST /api/projects/:projectName/agentic-sessions/:sessionName/stop)
163+
164+
### Request Body
165+
- **Optional body** - Frontend can send `StopAgenticSessionRequest` (sessions.ts line 74)
166+
- **Handler ignores body** - No code reads request body (lines 1939-2078)
167+
168+
### Handler Logic
169+
- Reads current session from CRD
170+
- Deletes Job and Pods
171+
- Updates status to "Stopped"
172+
- Sets `interactive: true` in spec for restart capability
173+
174+
### Unused Type
175+
- `StopAgenticSessionRequest` type exists but handler never reads it
176+
177+
---
178+
179+
## 7. UpdateSessionDisplayName (PUT /api/projects/:projectName/agentic-sessions/:sessionName/displayname)
180+
181+
### ✅ USED FIELDS
182+
183+
| Field | Backend Handler | Lines |
184+
|-------|----------------|-------|
185+
| `displayName` || 989, 1016 |
186+
187+
### Frontend Usage
188+
- **No frontend calls this** - Route exists but unused
189+
190+
---
191+
192+
## 8. SelectWorkflow (POST /api/projects/:projectName/agentic-sessions/:sessionName/workflow)
193+
194+
### ✅ USED FIELDS
195+
196+
| Field | Backend Handler | Lines |
197+
|-------|----------------|-------|
198+
| `gitUrl` || 1078 |
199+
| `branch` || 1080-1083 |
200+
| `path` || 1085-1086 |
201+
202+
### Frontend Usage
203+
- **No frontend calls this** - Route exists but unused
204+
205+
---
206+
207+
## 9. AddRepo (POST /api/projects/:projectName/agentic-sessions/:sessionName/repos)
208+
209+
### ✅ USED FIELDS
210+
211+
| Field | Backend Handler | Lines |
212+
|-------|----------------|-------|
213+
| `url` || 1172 |
214+
| `branch` || 1173 |
215+
| `output.url` || 1178 |
216+
| `output.branch` || 1179 |
217+
218+
### Frontend Usage
219+
- **No frontend calls this** - Route exists but unused
220+
221+
---
222+
223+
## 10. RemoveRepo (DELETE /api/projects/:projectName/agentic-sessions/:sessionName/repos/:repoName)
224+
225+
### Request Body
226+
- **No body** - Uses URL param `repoName`
227+
228+
### Frontend Usage
229+
- **No frontend calls this** - Route exists but unused
230+
231+
---
232+
233+
## 📊 SUMMARY STATISTICS
234+
235+
### CreateSession
236+
- **Total fields in type**: 13
237+
- **Fields sent by frontend**: 8-9 (varies by form)
238+
- **Fields used by handler**: 10
239+
- **Fields ignored**: 3 (`WorkspacePath`, `UserContext.userId`, `status`)
240+
241+
### UpdateSession
242+
- **Total fields in type**: 13
243+
- **Fields used by handler**: 4 (`prompt`, `displayName`, `llmSettings.*`, `timeout`)
244+
- **Fields ignored**: 9 (all others)
245+
246+
### CloneSession
247+
- **Total fields in type**: 4
248+
- **Fields used by handler**: 2 (`targetProject`, `newSessionName`)
249+
- **Fields ignored**: 2 (`displayName`, `prompt`)
250+
251+
### StopSession
252+
- **Request body**: Optional, but **never read by handler**
253+
254+
---
255+
256+
## 🚨 CRITICAL FINDINGS
257+
258+
### 1. Type Mismatch: UpdateSession
259+
- **Type**: Uses `CreateAgenticSessionRequest` (13 fields)
260+
- **Reality**: Only processes 4 fields (`prompt`, `displayName`, `llmSettings.*`, `timeout`)
261+
- **Impact**: Misleading API contract - clients might send fields that are silently ignored
262+
263+
### 2. Unused Request Types
264+
- `UpdateAgenticSessionRequest` (line 90-95) - **Defined but never used**
265+
- UpdateSession uses `CreateAgenticSessionRequest` instead
266+
- Should use `UpdateAgenticSessionRequest` for clarity
267+
- `StopAgenticSessionRequest` - **Defined but handler never reads body**
268+
269+
### 3. Frontend Form Fields Never Sent
270+
- `agentPersona` - Form field exists, never added to request
271+
- `anthropicApiKey` - Form field exists, explicitly not sent (TODO)
272+
- `saveApiKeyForFuture` - Form field exists, explicitly not sent (TODO)
273+
274+
### 4. Backend Fields Never Used
275+
- `WorkspacePath` - Frontend sends it, backend **never references it**
276+
- `UserContext.userId` - **Always overwritten** from auth token (security)
277+
- `UpdateSession` ignores 9 out of 13 fields in request type
278+
279+
### 5. Unused Endpoints
280+
- `UpdateSession` - No frontend calls it
281+
- `PatchSession` - No frontend calls it
282+
- `UpdateSessionDisplayName` - No frontend calls it
283+
- `SelectWorkflow` - No frontend calls it
284+
- `AddRepo` - No frontend calls it
285+
- `RemoveRepo` - No frontend calls it
286+
287+
---
288+
289+
## 🎯 RECOMMENDATIONS
290+
291+
### High Priority
292+
293+
1. **Fix UpdateSession Type Mismatch**
294+
- Use `UpdateAgenticSessionRequest` instead of `CreateAgenticSessionRequest`
295+
- Or document that UpdateSession only supports 4 fields
296+
297+
2. **Remove or Implement Unused Frontend Fields**
298+
- Remove `agentPersona` from form OR wire it into request
299+
- Remove `anthropicApiKey` fields OR implement backend support
300+
301+
3. **Remove WorkspacePath**
302+
- Frontend sends it but backend never uses it
303+
- Remove from request type or document why it's sent but ignored
304+
305+
### Medium Priority
306+
307+
4. **Document Security Overrides**
308+
- Clearly document that `userContext.userId` is ALWAYS overwritten
309+
- Document that `metadata.name` and `metadata.namespace` are controlled
310+
311+
5. **Clean Up Unused Endpoints**
312+
- Remove or document endpoints that frontend never calls
313+
- Or implement frontend support for them
314+
315+
6. **Fix CloneSession Type**
316+
- Remove unused fields from `CloneAgenticSessionRequest`
317+
- Or use `CloneSessionRequest` consistently
318+
319+
### Low Priority
320+
321+
7. **Consider Separate Types**
322+
- Create-specific fields vs Update-specific fields
323+
- Reduces confusion about what fields are actually used
324+
325+
---
326+
327+
## 📋 FIELD USAGE BY OPERATION
328+
329+
| Operation | Request Type | Fields Used | Fields Ignored | Frontend Calls |
330+
|-----------|-------------|-------------|----------------|----------------|
331+
| **CreateSession** | `CreateAgenticSessionRequest` | 10/13 | 3 | ✅ Yes |
332+
| **UpdateSession** | `CreateAgenticSessionRequest` | 4/13 | 9 | ❌ No |
333+
| **PatchSession** | `map[string]interface{}` | 1 (annotations) | All others | ❌ No |
334+
| **CloneSession** | `CloneSessionRequest` | 2/2 | 0 | ✅ Yes |
335+
| **StartSession** | No body | 0 | N/A | ✅ Yes |
336+
| **StopSession** | Optional body | 0 | Body ignored | ✅ Yes |
337+
| **UpdateDisplayName** | `{displayName}` | 1/1 | 0 | ❌ No |
338+
| **SelectWorkflow** | `WorkflowSelection` | 3/3 | 0 | ❌ No |
339+
| **AddRepo** | `{url, branch, output?}` | 4/4 | 0 | ❌ No |
340+
| **RemoveRepo** | URL param only | 0 | N/A | ❌ No |
341+
342+
---
343+
344+
## 🔍 DETAILED FIELD BREAKDOWN
345+
346+
### CreateAgenticSessionRequest (13 fields)
347+
348+
| Field | CreateSession | UpdateSession | Frontend Sends |
349+
|-------|---------------|---------------|----------------|
350+
| `Prompt` | ✅ Used | ✅ Used | ✅ Yes |
351+
| `DisplayName` | ⚠️ Read (often empty) | ✅ Used | ❌ No |
352+
| `LLMSettings` | ✅ Used | ✅ Used | ✅ Yes |
353+
| `Timeout` | ✅ Used | ✅ Used | ✅ Yes |
354+
| `Interactive` | ✅ Used | ❌ Ignored | ✅ Yes |
355+
| `WorkspacePath` |**Never referenced** | ❌ Ignored | ✅ Yes (page.tsx) |
356+
| `ParentSessionID` | ✅ Used | ❌ Ignored | ❌ No |
357+
| `Repos` | ✅ Used | ❌ Ignored | ✅ Yes |
358+
| `MainRepoIndex` | ✅ Used | ❌ Ignored | ✅ Yes |
359+
| `AutoPushOnComplete` | ✅ Used | ❌ Ignored | ✅ Yes |
360+
| `UserContext` | ⚠️ Partial (userId overwritten) | ❌ Ignored | ❌ No |
361+
| `BotAccount` | ✅ Supported | ❌ Ignored | ❌ No |
362+
| `ResourceOverrides` | ✅ Supported | ❌ Ignored | ❌ No |
363+
| `EnvironmentVariables` | ✅ Used | ❌ Ignored | ✅ Yes |
364+
| `Labels` | ✅ Used | ❌ Ignored | ✅ Yes |
365+
| `Annotations` | ✅ Supported | ❌ Ignored | ❌ No |
366+
367+
---
368+
369+
## 💡 KEY INSIGHTS
370+
371+
1. **UpdateSession is broken** - Uses wrong type, ignores 9/13 fields
372+
2. **WorkspacePath is dead code** - Sent but never used
373+
3. **Many endpoints unused** - 6 endpoints have no frontend calls
374+
4. **Type system doesn't match reality** - Types suggest more fields are used than actually are
375+
5. **Security fields always overridden** - `userContext.userId`, `metadata.name`, `metadata.namespace` cannot be set by clients
376+

0 commit comments

Comments
 (0)