Commit 13eea7a
authored
feat: update task configs in agentex db on turn (#309)
When pre-existing PATCH endpoint is supplied with "task_id" params,
shallow merges changed configs into agentex backend:
Clicking "Save" in "Tune Agent" produces this PATCH
<img width="706" height="232" alt="Screenshot 2026-06-18 at 6 01 03 PM"
src="https://github.com/user-attachments/assets/cf7d9e85-5971-4956-8c31-7ed0ebad2a4c"
/>
Querying agentex backend to see if system prompt is updated:
<img width="2144" height="216" alt="image"
src="https://github.com/user-attachments/assets/2b5c4df1-bc0b-442f-9dd3-6de803542b8b"
/>
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR wires a new `merge_params` field through the full API stack —
schema, route, use case, service, and repository — so callers can
shallow-merge a dict into `tasks.params` without overwriting the entire
column. The repository layer uses PostgreSQL's `||` JSONB operator
inside an `UPDATE … RETURNING` statement for a safe, atomic merge.
- **Repository (`merge_params`)**: Atomic JSONB merge via
`COALESCE(params, '{}') || patch` is correct; `expire_on_commit=False`
makes the post-commit `model_validate` safe without an extra `refresh()`
call.
- **Use case (`update_mutable_fields_on_task`)**: Two prior-thread
issues remain open — when both `task_metadata` and `merge_params` are
supplied, the `task_entity = merged` reassignment discards the in-memory
`task_metadata` mutation before the final `update_task` write; and the
`update_task_by_name` route handler does not forward `merge_params`
(flagged in the outside-diff comment).
- **Minor inconsistency**: the early-return guard uses `is None` while
the execution branch uses truthiness (`if merge_params:`), causing an
empty-dict `{}` to silently bypass the merge.
<details><summary><h3>Confidence Score: 3/5</h3></summary>
Not yet safe to merge — two functional defects flagged in prior review
rounds remain unaddressed in the code.
When both `task_metadata` and `merge_params` are supplied, `task_entity
= merged` overwrites the in-memory metadata update before the final
`update_task` write, so the caller's `task_metadata` change is silently
discarded. Separately, the `update_task_by_name` route handler does not
forward `merge_params`, silently dropping it for callers using the
name-based endpoint. Both defects were flagged in prior review comments
and are still present in the current diff.
`agentex/src/domain/use_cases/tasks_use_case.py` (dual-field update
logic) and `agentex/src/api/routes/tasks.py` (`update_task_by_name`
handler) need the most attention before merge.
</details>
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| agentex/src/domain/repositories/task_repository.py | Adds
`merge_params` method using PostgreSQL JSONB `||` operator for an atomic
shallow-merge update; correctly handles NULL coalescing and uses
RETURNING to avoid a second SELECT. |
| agentex/src/domain/services/task_service.py | Thin delegation method
`merge_task_params` added; no stream event emitted (intentional per
developer). |
| agentex/src/domain/use_cases/tasks_use_case.py | Two unresolved P1s
from prior threads remain: `task_entity = merged` overwrites in-memory
task_metadata; `if merge_params:` inconsistent with `is None` guard. |
| agentex/src/api/routes/tasks.py | `update_task` (by-id) correctly
forwards `merge_params`; `update_task_by_name` still omits it. |
| agentex/src/api/schemas/tasks.py | Adds `merge_params: dict[str, Any]
| None` to `UpdateTaskRequest` with clear docstring. |
| agentex/openapi.yaml | OpenAPI spec updated to document `merge_params`
with correct `anyOf: [object, null]` schema. |
</details>
</details>
<!-- greptile_failed_comments -->
<details open><summary><h3>Comments Outside Diff (1)</h3></summary>
1. `agentex/src/api/routes/tasks.py`, line 216-218
([link](https://github.com/scaleapi/scale-agentex/blob/4369c55ac1f53428561f71011cebd98a7e6b8264/agentex/src/api/routes/tasks.py#L216-L218))
<a href="#"><img alt="P1"
src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9"
align="top"></a> The `update_task_by_name` handler does not forward
`merge_params` to the use case, so any caller that uses the by-name
endpoint and supplies `merge_params` will silently have the field
dropped. The by-id handler (a few lines above) correctly passes it, but
the by-name handler was not updated in this PR.
<details><summary>Prompt To Fix With AI</summary>
`````markdown
This is a comment left during a code review.
Path: agentex/src/api/routes/tasks.py
Line: 216-218
Comment:
The `update_task_by_name` handler does not forward `merge_params` to the
use case, so any caller that uses the by-name endpoint and supplies
`merge_params` will silently have the field dropped. The by-id handler
(a few lines above) correctly passes it, but the by-name handler was not
updated in this PR.
How can I resolve this? If you propose a fix, please make it concise.
`````
</details>
<a
href="https://app.greptile.com/api/ide/cursor?prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0APath%3A%20agentex%2Fsrc%2Fapi%2Froutes%2Ftasks.py%0ALine%3A%20216-218%0A%0AComment%3A%0AThe%20%60update_task_by_name%60%20handler%20does%20not%20forward%20%60merge_params%60%20to%20the%20use%20case%2C%20so%20any%20caller%20that%20uses%20the%20by-name%20endpoint%20and%20supplies%20%60merge_params%60%20will%20silently%20have%20the%20field%20dropped.%20The%20by-id%20handler%20%28a%20few%20lines%20above%29%20correctly%20passes%20it%2C%20but%20the%20by-name%20handler%20was%20not%20updated%20in%20this%20PR.%0A%0A%60%60%60suggestion%0A%20%20%20%20updated_task_entity%20%3D%20await%20task_use_case.update_mutable_fields_on_task%28%0A%20%20%20%20%20%20%20%20name%3Dtask_name%2C%20task_metadata%3Drequest.task_metadata%2C%20merge_params%3Drequest.merge_params%0A%20%20%20%20%29%0A%60%60%60%0A%0AHow%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20please%20make%20it%20concise.&pr=309&platform=github"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixInCursorDark.svg?v=3"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixInCursor.svg?v=3"><img
alt="Fix in Cursor"
src="https://greptile-static-assets.s3.amazonaws.com/badges/FixInCursor.svg?v=3"
height="20"></picture></a> <a
href="https://app.greptile.com/ide/claude-code?prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0APath%3A%20agentex%2Fsrc%2Fapi%2Froutes%2Ftasks.py%0ALine%3A%20216-218%0A%0AComment%3A%0AThe%20%60update_task_by_name%60%20handler%20does%20not%20forward%20%60merge_params%60%20to%20the%20use%20case%2C%20so%20any%20caller%20that%20uses%20the%20by-name%20endpoint%20and%20supplies%20%60merge_params%60%20will%20silently%20have%20the%20field%20dropped.%20The%20by-id%20handler%20%28a%20few%20lines%20above%29%20correctly%20passes%20it%2C%20but%20the%20by-name%20handler%20was%20not%20updated%20in%20this%20PR.%0A%0A%60%60%60suggestion%0A%20%20%20%20updated_task_entity%20%3D%20await%20task_use_case.update_mutable_fields_on_task%28%0A%20%20%20%20%20%20%20%20name%3Dtask_name%2C%20task_metadata%3Drequest.task_metadata%2C%20merge_params%3Drequest.merge_params%0A%20%20%20%20%29%0A%60%60%60%0A%0AHow%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20please%20make%20it%20concise.&repo=scaleapi%2Fscale-agentex&pr=309&platform=github"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixInClaudeDark.svg?v=3"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixInClaude.svg?v=3"><img
alt="Fix in Claude Code"
src="https://greptile-static-assets.s3.amazonaws.com/badges/FixInClaude.svg?v=3"
height="20"></picture></a> <a
href="https://app.greptile.com/api/ide/codex?prompt=IMPORTANT%3A%20Work%20in%20the%20repository%20%22scaleapi%2Fscale-agentex%22%20on%20the%20existing%20branch%20%22mc%2Fgolden-agent-tuneagent%22.%20Checkout%20that%20branch%20%E2%80%94%20do%20NOT%20create%20a%20new%20branch%20or%20open%20a%20new%20PR.%20Push%20your%20changes%20to%20%22mc%2Fgolden-agent-tuneagent%22.%0A%0AThis%20is%20a%20comment%20left%20during%20a%20code%20review.%0APath%3A%20agentex%2Fsrc%2Fapi%2Froutes%2Ftasks.py%0ALine%3A%20216-218%0A%0AComment%3A%0AThe%20%60update_task_by_name%60%20handler%20does%20not%20forward%20%60merge_params%60%20to%20the%20use%20case%2C%20so%20any%20caller%20that%20uses%20the%20by-name%20endpoint%20and%20supplies%20%60merge_params%60%20will%20silently%20have%20the%20field%20dropped.%20The%20by-id%20handler%20%28a%20few%20lines%20above%29%20correctly%20passes%20it%2C%20but%20the%20by-name%20handler%20was%20not%20updated%20in%20this%20PR.%0A%0A%60%60%60suggestion%0A%20%20%20%20updated_task_entity%20%3D%20await%20task_use_case.update_mutable_fields_on_task%28%0A%20%20%20%20%20%20%20%20name%3Dtask_name%2C%20task_metadata%3Drequest.task_metadata%2C%20merge_params%3Drequest.merge_params%0A%20%20%20%20%29%0A%60%60%60%0A%0AHow%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20please%20make%20it%20concise.&repo=scaleapi%2Fscale-agentex&pr=309&platform=github"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixInCodexDark.svg?v=3"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixInCodex.svg?v=3"><img
alt="Fix in Codex"
src="https://greptile-static-assets.s3.amazonaws.com/badges/FixInCodex.svg?v=3"
height="20"></picture></a>
</details>
<!-- /greptile_failed_comments -->
<sub>Reviews (5): Last reviewed commit: ["Merge branch 'main'
into
mc/golden-agent..."](2a5f83b)
| [Re-trigger
Greptile](https://app.greptile.com/api/retrigger?id=37742683)</sub>
<!-- /greptile_comment -->1 parent 8c060f1 commit 13eea7a
6 files changed
Lines changed: 87 additions & 6 deletions
File tree
- agentex
- src
- api
- routes
- schemas
- domain
- repositories
- services
- use_cases
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6696 | 6696 | | |
6697 | 6697 | | |
6698 | 6698 | | |
| 6699 | + | |
| 6700 | + | |
| 6701 | + | |
| 6702 | + | |
| 6703 | + | |
| 6704 | + | |
| 6705 | + | |
6699 | 6706 | | |
6700 | 6707 | | |
6701 | 6708 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
80 | 88 | | |
81 | 89 | | |
82 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
216 | 257 | | |
217 | 258 | | |
218 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
245 | 254 | | |
246 | 255 | | |
247 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
111 | | - | |
112 | | - | |
| 112 | + | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
118 | | - | |
119 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
120 | 134 | | |
121 | 135 | | |
122 | 136 | | |
| |||
0 commit comments