Gateway: allow webchat session label updates#32574
Gateway: allow webchat session label updates#32574zwright8 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR extracts a focused change from #26712 to allow webchat clients to update the Key changes:
Confidence Score: 4/5
Last reviewed commit: 6f8faa3 |
| function isWebchatLabelOnlyPatch(patch: SessionsPatchParams): boolean { | ||
| const keys = Object.keys(patch).filter((key) => key !== "key"); | ||
| if (keys.length !== 1 || keys[0] !== "label") { | ||
| return false; | ||
| } | ||
| return Object.hasOwn(patch, "label"); | ||
| } |
There was a problem hiding this comment.
Redundant Object.hasOwn check
The final return Object.hasOwn(patch, "label") is always true when reached. At that point, the code has already verified that keys[0] === "label" (line 107), and keys is derived from Object.keys(patch) — so if "label" appears in Object.keys(patch), then Object.hasOwn(patch, "label") is necessarily true. The function could be simplified:
| function isWebchatLabelOnlyPatch(patch: SessionsPatchParams): boolean { | |
| const keys = Object.keys(patch).filter((key) => key !== "key"); | |
| if (keys.length !== 1 || keys[0] !== "label") { | |
| return false; | |
| } | |
| return Object.hasOwn(patch, "label"); | |
| } | |
| function isWebchatLabelOnlyPatch(patch: SessionsPatchParams): boolean { | |
| const keys = Object.keys(patch).filter((key) => key !== "key"); | |
| return keys.length === 1 && keys[0] === "label"; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/server-methods/sessions.ts
Line: 105-111
Comment:
**Redundant `Object.hasOwn` check**
The final `return Object.hasOwn(patch, "label")` is always `true` when reached. At that point, the code has already verified that `keys[0] === "label"` (line 107), and `keys` is derived from `Object.keys(patch)` — so if `"label"` appears in `Object.keys(patch)`, then `Object.hasOwn(patch, "label")` is necessarily `true`. The function could be simplified:
```suggestion
function isWebchatLabelOnlyPatch(patch: SessionsPatchParams): boolean {
const keys = Object.keys(patch).filter((key) => key !== "key");
return keys.length === 1 && keys[0] === "label";
}
```
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
The test is named Prompt To Fix With AIThis is a comment left during a code review.
Path: src/gateway/server.sessions.gateway-server-sessions-a.test.ts
Line: 1211
Comment:
**Misleading test name**
The test is named `"webchat clients cannot patch or delete sessions"`, but this PR explicitly changes the behavior so that webchat clients *can* patch sessions (specifically label-only patches). The test body now asserts that `patchedLabel.ok` is `true`, which directly contradicts the test description. A future developer reading this test name would be confused about the intended contract.
```suggestion
test("webchat clients can patch label but cannot patch other fields or delete sessions", async () => {
```
How can I resolve this? If you propose a fix, please make it concise. |
6f8faa3 to
11e4634
Compare
Summary
Validation
pnpm exec vitest run src/gateway/server.sessions.gateway-server-sessions-a.test.tsContext
This PR is one focused slice extracted from: