Skip to content

Gateway: allow webchat session label updates#32574

Open
zwright8 wants to merge 1 commit intoopenclaw:mainfrom
zwright8:codex/pr26712-gateway-webchat-session-label-update
Open

Gateway: allow webchat session label updates#32574
zwright8 wants to merge 1 commit intoopenclaw:mainfrom
zwright8:codex/pr26712-gateway-webchat-session-label-update

Conversation

@zwright8
Copy link
Copy Markdown

@zwright8 zwright8 commented Mar 3, 2026

Summary

Validation

  • pnpm exec vitest run src/gateway/server.sessions.gateway-server-sessions-a.test.ts

Context

This PR is one focused slice extracted from:

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR extracts a focused change from #26712 to allow webchat clients to update the label field of a session via sessions.patch. The implementation adds a helper isWebchatLabelOnlyPatch and gates the webchat mutation guard so that a label-only patch bypasses the rejection, while all other patch fields and sessions.delete remain restricted for webchat clients.

Key changes:

  • isWebchatLabelOnlyPatch: correctly identifies patches that contain only key + label (using Object.keys filtering). The logic is sound, though the final Object.hasOwn(patch, "label") guard is redundant since the preceding check already guarantees the key exists.
  • sessions.patch handler: the short-circuit logic properly preserves the existing CONTROL_UI bypass and correctly rejects non-label patches from webchat clients.
  • Tests: the updated test verifies the new allow/reject split, but the test name ("webchat clients cannot patch or delete sessions") now contradicts the behavior it asserts — it should be updated to reflect that label-only patches are permitted.

Confidence Score: 4/5

  • Safe to merge — the logic is correct and well-tested, with only minor style/clarity issues.
  • The core logic of isWebchatLabelOnlyPatch is correct, the handler gating is properly structured, and the test covers label-allow, non-label-reject, and delete-reject paths. Two minor issues prevent a perfect score: the redundant Object.hasOwn call in the helper and the now-inaccurate test description.
  • No files require special attention beyond the minor polish items noted in comments.

Last reviewed commit: 6f8faa3

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +105 to +111
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");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

Suggested change
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.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 3, 2026

Additional Comments (1)

src/gateway/server.sessions.gateway-server-sessions-a.test.ts
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.

  test("webchat clients can patch label but cannot patch other fields or delete sessions", async () => {
Prompt To Fix With AI
This 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.

@zwright8 zwright8 force-pushed the codex/pr26712-gateway-webchat-session-label-update branch from 6f8faa3 to 11e4634 Compare March 3, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant