Skip to content

feat: add /set_topic_name for telegram topic labels#46983

Closed
VjiaoBlack wants to merge 9 commits intoopenclaw:mainfrom
VjiaoBlack:feat/set-topic-name
Closed

feat: add /set_topic_name for telegram topic labels#46983
VjiaoBlack wants to merge 9 commits intoopenclaw:mainfrom
VjiaoBlack:feat/set-topic-name

Conversation

@VjiaoBlack
Copy link
Copy Markdown

@VjiaoBlack VjiaoBlack commented Mar 15, 2026

Summary

  • Add /set_topic_name command for Telegram topics to rename session labels from chat.
  • Sanitize input (strip ·, trim) and cap name length to 64 chars.
  • Avoid duplicate telegram prefix; replace raw errors with generic message + internal logs.
  • Secret word: lobster-biscuit.

Behavior Changes

  • New /set_topic_name <name> command for Telegram topics.
  • Input normalized and capped at 64 chars.
  • Labels no longer double-prefix telegram when base label is empty.
  • User-facing errors are generic; details logged internally.

Tests

  • Not run (code review only).

Manual Testing (omit if N/A)

  • Tested on own OpenClaw + Telegram - in private chat with threads enabled, /set_topic_name works to set and override telegram-thread session labels, and it shows up as the label in chat.

Evidence (omit if N/A)

  • N/A.

Sign-Off

  • Models used: gpt-5.2-codex
  • Submitter effort (self-reported): Medium
  • Agent notes (optional, cite evidence): addressed review feedback on input handling + error messaging.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 15, 2026

Greptile Summary

This PR adds a /set_topic_name command that lets Telegram users rename their topic's session label via chat. The new commands-topic-name.ts handler wires into the existing command-dispatch chain and updates the session label via sessions.patch. Error handling is generic (logging details internally), and the command is correctly gated to authorized senders.

Key observations:

  • Surface check ordering (logic): The !parsed.ok usage-error guard fires before isTelegramSurface, so a non-Telegram user who omits the name argument sees "Usage: /set_topic_name <name>" rather than "only works for Telegram topics" — an incorrect hint for a platform where the command can never succeed. The surface check should move above the usage check.
  • threadId validated but unused (logic): threadId is retrieved and checked for presence (lines 54–59) but is never forwarded to callGateway. This is fine if each Telegram topic maps to a unique sessionKey, but should be explicitly verified — if session keys are not thread-scoped, the patch could silently update the wrong label.
  • The registry declaration (captureRemaining: true) is consistent with the manual regex parsing in the handler; both serve their respective roles (documentation vs. runtime).

Confidence Score: 2/5

  • Not safe to merge yet — there are unresolved logic issues in the core handler that need to be addressed first.
  • Two new logic issues were identified: incorrect check ordering that gives misleading feedback to non-Telegram users, and threadId being validated but never passed to the gateway (creating a risk of silently patching the wrong session if session keys are not thread-scoped). Combined with open items from prior review rounds that are still present in the code, the handler needs further iteration before it is production-ready.
  • src/auto-reply/reply/commands-topic-name.ts requires the most attention — both new issues are in this file.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/commands-topic-name.ts
Line: 45-53

Comment:
**Surface check comes after args validation**

The `!parsed.ok` guard (line 45) runs before `isTelegramSurface` (line 48). This means an authorized user on a non-Telegram surface who types `/set_topic_name` with no name argument will receive `"Usage: /set_topic_name <name>"` instead of `"⚙️ /set_topic_name only works for Telegram topics."` — directing them to fix their usage for a command that can never work on their surface regardless.

The `isTelegramSurface` check should come before the usage-error check:

```typescript
  if (!parsed.ok) {
    return { shouldContinue: false, reply: { text: parsed.error } };
  }
  if (!isTelegramSurface(params)) {
    return {
      shouldContinue: false,
      reply: { text: "⚙️ /set_topic_name only works for Telegram topics." },
    };
  }
```

should be reordered to:

```typescript
  if (!isTelegramSurface(params)) {
    return {
      shouldContinue: false,
      reply: { text: "⚙️ /set_topic_name only works for Telegram topics." },
    };
  }
  if (!parsed.ok) {
    return { shouldContinue: false, reply: { text: parsed.error } };
  }
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/auto-reply/reply/commands-topic-name.ts
Line: 54-78

Comment:
**`threadId` validated but never forwarded to gateway**

`threadId` is extracted and validated on lines 54–59 to ensure the command only runs inside a Telegram topic thread, but it is never included in the `callGateway` payload — only `params.sessionKey` and `label` are sent.

If `sessions.patch` uses `sessionKey` alone and each Telegram topic always maps to a unique session key, this is harmless. However, if multiple topics share the same session key (or if the gateway needs `threadId` to scope which thread's label to update), this silently patches the wrong label without any error.

Please confirm that `sessions.patch` with `sessionKey` alone is sufficient to uniquely identify the correct Telegram topic, or add `threadId` to the gateway payload if the API requires it for disambiguation.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 41137be

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c453720382

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@VjiaoBlack
Copy link
Copy Markdown
Author

oops. nice AI review :)

will make changes in a sec

@openclaw-barnacle openclaw-barnacle bot added app: web-ui App: web-ui gateway Gateway runtime size: M and removed size: S labels Mar 15, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d4112da3e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@VjiaoBlack VjiaoBlack force-pushed the feat/set-topic-name branch from 2d4112d to 41137be Compare March 15, 2026 08:33
@openclaw-barnacle openclaw-barnacle bot added size: S and removed app: web-ui App: web-ui gateway Gateway runtime size: M labels Mar 15, 2026
@VjiaoBlack VjiaoBlack marked this pull request as draft March 15, 2026 09:05
@VjiaoBlack VjiaoBlack marked this pull request as ready for review March 15, 2026 09:06
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41137be04a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25fd11c207

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@openclaw-barnacle openclaw-barnacle bot added docs Improvements or additions to documentation channel: telegram Channel integration: telegram labels Mar 15, 2026
@VjiaoBlack VjiaoBlack force-pushed the feat/set-topic-name branch from 94d6fa6 to 7deb020 Compare March 15, 2026 18:55
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7deb0203cd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector
Copy link
Copy Markdown

💡 Codex Review

https://github.com/openclaw/openclaw/blob/cdaf0c45397649f3f7facece3079709d01b91ea9/docs/.generated/config-baseline.json#L2
P2 Badge Restore canonical config baseline formatting

Reformatting this generated file changed key ordering and array layout from the writer’s canonical output (renderConfigDocBaselineStatefile uses JSON.stringify(..., null, 2)), so pnpm config:docs:check will now report perpetual drift even when the config schema is unchanged. In practice this breaks the config-docs drift validation workflow (.github/workflows/workflow-sanity.yml job config-docs-drift) and forces unnecessary regeneration noise on future changes.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@VjiaoBlack VjiaoBlack force-pushed the feat/set-topic-name branch from 305d96e to a8298ce Compare March 17, 2026 03:58
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a8298ce877

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adb6e44165

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +64 to +65
if (suffix.length >= maxLen) {
return suffix.slice(0, maxLen).trim();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve full topic identity when trimming label base

When long topic names leave only a small maxBaseLen, fitBaseLabel truncates identitySuffix itself (suffix.slice(0, maxLen)), which can drop most or all of id:<chat>/topic:<thread> and collapse different Telegram topics onto the same generated label. In this revision that means two topics with the same long /set_topic_name value can still collide and the second sessions.patch fails with label already in use, even though the handler is trying to disambiguate by thread identity.

Useful? React with 👍 / 👎.

@VjiaoBlack
Copy link
Copy Markdown
Author

@Lukavyi sounds good lol i didn't clean this up fast enough / got sidetracked.

Thanks!

@VjiaoBlack VjiaoBlack closed this Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram docs Improvements or additions to documentation size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant