Discord: resolve /think autocomplete from session model#49176
Conversation
Greptile SummaryThis PR fixes a bug where Discord native Key changes:
Notable concern: the Confidence Score: 4/5
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a10d30e33
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
6a10d30 to
3bf90ac
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3bf90acd01
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const storePath = resolveStorePath(params.cfg.session?.store, { | ||
| agentId: route.agentId, | ||
| }); | ||
| const sessionStore = loadSessionStore(storePath); |
There was a problem hiding this comment.
Avoid cloning full session store on every autocomplete keystroke
This new autocomplete context path calls loadSessionStore for each /think autocomplete event, and even cache hits in loadSessionStore return structuredClone(cached.store) of the entire session map (src/config/sessions/store-cache.ts), so typing in Discord can repeatedly clone a large store on the event loop. In deployments with large sessions.json files or many concurrent users, this can add enough synchronous CPU latency to miss or delay autocomplete responses; this path should avoid whole-store reads (for example by memoizing per interaction window or adding a targeted session-entry lookup).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Thanks for the review. Agreed on the performance concern category, with one important distinction:
- This PR removes the new regression in
/thinkautocomplete: we no longer forceloadSessionStore(..., { skipCache: true })on each event. The autocomplete path now usesloadSessionStore(storePath)(extensions/discord/src/monitor/native-command.ts:517), so it goes through the shared session-store cache path (src/config/sessions/store.ts:200-210). - You’re correct that cache hits still return
structuredClone(cached.store)(src/config/sessions/store-cache.ts:60), so there is still synchronous per-call work proportional to store size.
So the acute “forced disk read/parse per keystroke” issue is fixed here; the broader “whole-store clone on cached reads” cost remains a valid follow-up optimization for session-store access generally (including autocomplete). We can track that separately with a targeted API improvement (for example a keyed session-entry read/memoized accessor) rather than block this regression fix.
3bf90ac to
6df099c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6df099c54a
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1079c1f8a
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8651a8bd5
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
b8651a8 to
2ff1434
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d31aace422
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a17162e239
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5306e0fb3f
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d845cc12a
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| typeof arg.choices === "function" && resolveChoiceContext | ||
| ? await resolveChoiceContext(interaction) | ||
| : null; |
There was a problem hiding this comment.
Enforce auth before loading autocomplete session context
The autocomplete handler now calls resolveChoiceContext for function-based choices before any command authorization runs, so /think suggestions are computed from the effective session model even for users who would be denied later by commands.allowFrom, guild/channel restrictions, or DM policy checks in dispatchDiscordCommandInteraction. In restricted servers this leaks bound-session capability metadata (for example whether xhigh appears) to unauthorized users; the context lookup should be gated by the same auth checks or return no sensitive choices when unauthorized.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping this PR scoped to the original bug fix.
This PR changes /think autocomplete to use the effective-route session model so choices match the command target model. I’m not taking on the broader metadata-hardening change in this PR; that would require sharing the full command auth decision with autocomplete and expands the patch materially.
If we want to harden autocomplete visibility, I’d prefer to do that as a follow-up.
4d845cc to
504e14f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 504e14f952
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const context = | ||
| typeof arg.choices === "function" && resolveChoiceContext | ||
| ? await resolveChoiceContext(interaction) |
There was a problem hiding this comment.
Apply command auth before resolving autocomplete context
The autocomplete handler now calls resolveChoiceContext (which reads the effective route/session model) before any authorization checks run, so users who are later denied in dispatchDiscordCommandInteraction can still probe /think and infer bound-session capability metadata (for example whether xhigh appears). This is a behavior regression from static choices because the sensitive part is now session-derived; gate the context lookup behind the same DM/group/guild allowlist checks used for execution.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same call here: keeping this PR scoped to fixing the session-context mismatch for /think autocomplete.
The auth-gating concern is real but broader than this bug fix, and the minimal correct version still adds noticeable complexity. I’d rather defer that hardening to a follow-up than bundle it into this PR.
| const storePath = resolveStorePath(params.cfg.session?.store, { | ||
| agentId: route.agentId, | ||
| }); | ||
| const sessionStore = loadSessionStore(storePath); |
There was a problem hiding this comment.
Avoid full session-store loads per autocomplete keystroke
resolveDiscordNativeChoiceContext loads the session store on every autocomplete request, and loadSessionStore returns a cloned full map even on cache hits (readSessionStoreCache does structuredClone). In large sessions.json deployments, repeated /think keystrokes can cause synchronous clone/parse work on the event loop and delay or miss Discord autocomplete responses; this path needs a targeted lookup or short-lived memoization instead of whole-store loads per event.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agree this is a broader performance concern category, but I’m keeping this PR limited to correcting the model-context source for /think autocomplete.
This branch already removed the earlier uncached read path; what remains is the general session-store read/cloning behavior, which is not specific to this bug. I’d rather track any targeted lookup/memoization work separately.
2b43cea to
a0d6631
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0d66316a3
ℹ️ 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".
| threadBindings: ThreadBindingManager; | ||
| }) { | ||
| const resolved = await resolveDiscordModelPickerRouteState(params); | ||
| return resolved.route; |
There was a problem hiding this comment.
Return effective route for model-picker context
resolveDiscordModelPickerRoute now returns resolved.route, which is the unbound base route from resolveDiscordNativeInteractionRouteState. In bound-thread or configured-binding setups, this drops the session/agent override that the picker UI depends on, so /model picker views can load providers/current model from the wrong session while command execution still targets the effective bound session. This creates inconsistent picker state (including false mismatch warnings) and can surface the wrong model set for the interaction context.
Useful? React with 👍 / 👎.
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
…nto add-json-schema-to-cli * 'add-json-schema-to-cli' of github.com:kvokka/openclaw: (58 commits) test: make vitest config tests platform-aware fix: refresh available tools when the session model changes (openclaw#54184) fix: prefer freshest transcript session owners test: disable Vitest fs cache on Windows fix: prefer deterministic transcript session keys fix: prefer deterministic session usage targets fix: prefer deterministic session id resume targets feat: add /tools runtime availability view (openclaw#54088) fix: enforce sandbox visibility for session_status ids fix: drop spawned visibility list caps fix: verify exact spawned session visibility fix: enforce spawned session visibility in key resolve fix: resolve exact session ids without fuzzy limits Discord: resolve /think autocomplete from session model (openclaw#49176) chore(agents): normalize pi embedded runner imports feat(gateway): make openai compatibility agent-first test(parallel): force unit-fast batch planning test(browser): stabilize default browser detection mocks fix: prefer current parents in session rows fix: prefer current subagent owners in session rows ...
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
* Discord: use session model for /think autocomplete * Discord: use cached session store in think autocomplete * Discord: align think autocomplete with effective bound route * Discord: fix think autocomplete route-resolution test mocks * Discord: stabilize think autocomplete CI coverage * Discord: gate think autocomplete context behind auth * Discord: share slash auth for think autocomplete * Discord: localize think autocomplete auth gate * Discord: drop think autocomplete auth gating * Discord: align native autocomplete auth and route readiness * Discord: use effective route for model picker --------- Co-authored-by: Tak Hoffman <[email protected]>
Summary
Describe the problem and fix in 2–5 bullets:
/thinkautocomplete used config-default model context, not the effective Discord route's session model.openai-codex/gpt-5.4) could missxhighin slash choices.resolveCommandArgChoices./thinkcommand semantics, backend thinking capability logic, or non-Discord channels.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
/thinkautocomplete now reflects the active effective-route session model override rather than only config defaults.Security Impact (required)
No)No)No)No)No)Yes, explain risk + mitigation:Repro + Verification
Environment
openai-codex/gpt-5.4session overrideagents.defaults.model.primary=anthropic/claude-sonnet-4.5Steps
xhigh.openai-codex/gpt-5.4./thinkautocomplete.Expected
xhighappears in autocomplete choices for the effective-route session.Actual
xhigh.xhigh.Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
/thinkautocomplete.Review Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes)No)No)Failure Recovery (if this breaks)
extensions/discord/src/monitor/native-command.ts,extensions/discord/src/monitor/native-command-ui.ts/thinkautocomplete errors or missing choices.Risks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.