Repository navigation
fix(discord): ensure resetTriggers rotate sessionId and clear history - #56362
yangyitao100 wants to merge 3 commits into
Conversation
Greptile SummaryThis PR fixes two interrelated bugs that caused Discord sessions using custom Root causes addressed:
The Two new integration tests cover bang-prefix triggers on Discord, including the trailing-text stripping edge case. Confidence Score: 5/5Safe to merge — both fixes are narrowly scoped, well-motivated, and covered by new integration tests. Both changes are minimal, clearly correct, and address well-understood root causes. The only notable nuance — that !reset maps to action "new" rather than "reset" — is explicitly called out in the PR description as intentional. The oldSessionFile archival path is unchanged. No regressions introduced. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/auto-reply/reply/get-reply.ts | Removes the /^/(new |
| src/gateway/session-reset-service.ts | Passes undefined instead of old sessionFile to resolveSessionFilePath, ensuring a fresh path is always derived from the new sessionId. Old file is still captured for archive use. |
| src/auto-reply/reply/session.test.ts | Two new integration tests covering bang-prefix triggers (!new, !reset) on Discord sessions and trailing-text stripping. Tests are well-structured and cover the relevant behavior. |
Reviews (1): Last reviewed commit: "fix(discord): ensure resetTriggers rotat..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3619721e59
ℹ️ 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".
| const sessionFile = resolveSessionFilePath( | ||
| nextSessionId, | ||
| currentEntry?.sessionFile ? { sessionFile: currentEntry.sessionFile } : undefined, | ||
| undefined, |
There was a problem hiding this comment.
Preserve custom sessionFile during gateway reset
Passing undefined into resolveSessionFilePath drops any explicit currentEntry.sessionFile, so a reset now relocates sessions to the default <sessionsDir>/<uuid>.jsonl path instead of keeping the configured transcript location. This regresses sessions that intentionally use custom transcript files (including spawned/owned sessions), and subsequent transcript reads/writes will silently switch files after reset.
Useful? React with 👍 / 👎.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| const resetMatch = command.commandBodyNormalized.match(/^\/(new|reset)(?:\s|$)/); | ||
| if (!resetMatch) { | ||
| return; | ||
| } | ||
| const action: ResetCommandAction = resetMatch?.[1] === "reset" ? "reset" : "new"; |
There was a problem hiding this comment.
Derive reset action from non-slash reset triggers
This fallback still parses action with a slash-only pattern, so configured triggers like !reset emit hooks as action: "new". That means command:reset listeners and any before_reset logic that branches on reason === "reset" will be skipped for non-slash reset triggers even though the reset was matched and executed.
Useful? React with 👍 / 👎.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
This fixes a Discord-specific bug where /reset commands weren't rotating the sessionId and clearing history because resetTriggers were evaluated against the old session context. Now resetTriggers correctly create a new session after rotation. S-sized Discord fix. LGTM. |
Custom reset triggers (e.g. !new, !reset) matched correctly in initSessionState but two downstream paths kept context accumulating: 1. maybeEmitMissingResetHooks in get-reply.ts early-returned when the command body did not match the /new or /reset regex, so internal hook listeners (and ACP cleanup) were never notified for bang-prefix triggers. Removed the early return so hooks fire for ANY matched resetTrigger. 2. performGatewaySessionReset in session-reset-service.ts passed the old entry's sessionFile to resolveSessionFilePath, which reused the stale path instead of deriving a fresh one from the new sessionId. Now passes undefined so the path is always freshly computed. Fixes openclaw#55474 Co-Authored-By: Claude Opus 4.6 <[email protected]>
3619721 to
687cea3
Compare
… sessionFile rotation P2: The reset action regex now matches custom trigger prefixes (e.g. !reset, !new) in addition to slash-prefixed commands, so that command:reset listeners and before_reset hooks fire correctly for all configured resetTriggers. P1: Updated sessionFile rotation comments to clarify design intent and extracted pathOpts for readability. Addresses Codex review feedback on openclaw#56362.
|
Codex Review Feedback Addressed (cf0c2d4) P2 — Non-slash reset trigger action derivation: P1 — Custom sessionFile during reset: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf0c2d4c08
ℹ️ 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".
| storePath, | ||
| agentId: sessionAgentId, | ||
| }); | ||
| const sessionFile = resolveSessionFilePath(nextSessionId, undefined, pathOpts); |
There was a problem hiding this comment.
Keep explicit sessionFile path when rotating gateway sessions
Calling resolveSessionFilePath(nextSessionId, undefined, pathOpts) always drops any configured currentEntry.sessionFile and forces the reset session onto the default store-relative transcript path. For sessions that intentionally use a custom transcript location (for example spawned/owned sessions with explicit sessionFile), a reset now silently relocates storage, so subsequent transcript reads/writes split across files and existing integrations expecting the configured path break.
Useful? React with 👍 / 👎.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@yfge I've added you as a collaborator on the fork (yangyitao100/openclaw) — you should have a GitHub invite pending. Once accepted, feel free to push your patch directly to the |
|
Status Update - Ready for Final Review This PR has been thoroughly tested and addresses all review feedback: ✅ Both root causes fixed:
✅ Codex feedback addressed (cf0c2d4):
✅ @yfge collaboration enabled:
✅ Integration tests added:
Ready for merge - All Discord custom resetTriggers now correctly rotate sessionId and clear history as expected. |
Apply yfge's suggested fix: detect when the current entry uses a custom transcript directory (outside the default sessions dir) and preserve it during session rotation, only changing the filename to the new sessionId. This prevents spawned/owned sessions with explicit sessionFile paths from silently relocating their transcripts after a reset. Co-authored-by: yfge <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f86f1acd8
ℹ️ 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".
| const hasCustomSessionFileDir = | ||
| explicitSessionFileDir !== undefined && | ||
| path.relative(defaultSessionsDir, explicitSessionFileDir).startsWith(".."); |
There was a problem hiding this comment.
Preserve explicit sessionFile for in-dir custom transcripts
This custom-path check only treats a session file as custom when its directory is outside defaultSessionsDir, so explicit transcript files that are custom by filename but still live in the store directory are misclassified as non-custom. In that case, reset falls back to resolveSessionFilePath(nextSessionId, undefined, ...) and silently rewrites the entry to <uuid>.jsonl, which relocates a deliberately pinned transcript path and can split subsequent reads/writes across files for spawned/owned sessions. Fresh evidence: the seeded custom transcript path scenario in src/gateway/server.sessions.gateway-server-sessions-a.test.ts uses this in-directory custom-file shape.
Useful? React with 👍 / 👎.
|
Hi @sallyom 👋 Friendly ping — CI is all green now after rebasing to latest main. Would love your review when you get a chance. Thanks! |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: the useful Discord reset-trigger fix is now carried by open replacement #77639, and this PR still has transcript-path validation blockers from the gateway reset change. So I’m closing this here and keeping the remaining discussion on the canonical linked item. Review detailsBest possible solution: Review and land #77639 as the canonical replacement, preserving the hook fix while keeping transcript paths validated and covered by regression tests. Do we have a high-confidence way to reproduce the issue? Yes, by source inspection. Current main matches configured Is this the best way to solve the issue? No. The hook-emission direction is narrow and correct, but this branch’s transcript reset change bypasses existing preservation and safety contracts; #77639 is the safer replacement path. Security review: Security review needs attention: The PR introduces a transcript path containment concern by writing under directories derived directly from persisted session metadata.
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 58c4f9e190bc. |
Summary
On Discord, custom
resetTriggerslike!newand!resetare matched by the trigger system, but the session doesn't actually reset — history continues accumulating.Root Cause
Two issues:
get-reply.ts: After a reset trigger fires, the code tried to match/^\/(new|reset)/against the command body. Custom triggers like!newdon't match this regex, soemitResetCommandHookswas never called — leaving internal hook listeners and ACP cleanup unnotified.session-reset-service.ts:resolveSessionFilePathwas called with the old entry'ssessionFile, which caused it to reuse the stale path instead of deriving a clean new one from the new sessionId.Changes
get-reply.ts: CallemitResetCommandHooksfor ALL matched reset triggers, not just/newand/reset. Default to action"new"for non-standard trigger formats.session-reset-service.ts: Passundefinedinstead of old sessionFile toresolveSessionFilePathso a fresh path is always generated.!new,!reset) on Discord sessions.Files Changed
src/auto-reply/reply/get-reply.ts— emit hooks for all reset triggerssrc/gateway/session-reset-service.ts— use fresh session file pathsrc/auto-reply/reply/session.test.ts— tests for bang-prefix triggersFixes #55474