Skip to content

fix(auto-reply): pass topicId when cleaning up transcript after session reset#52782

Closed
kevinWangSheng wants to merge 1 commit into
openclaw:mainfrom
kevinWangSheng:fix/agent-runner-missing-topic-id-cleanup
Closed

fix(auto-reply): pass topicId when cleaning up transcript after session reset#52782
kevinWangSheng wants to merge 1 commit into
openclaw:mainfrom
kevinWangSheng:fix/agent-runner-missing-topic-id-cleanup

Conversation

@kevinWangSheng

Copy link
Copy Markdown
Contributor

Summary

  • When a session resets due to role ordering conflict (cleanupTranscripts: true), the cleanup code calls resolveSessionTranscriptPath(prevSessionId, agentId) without the topicId parameter
  • The new-session creation (lines 320-324) correctly passes sessionCtx.MessageThreadId as the third argument
  • For Telegram forum topic sessions, this mismatch means cleanup targets a path without the topic suffix, leaving the actual transcript file behind

Root cause

The resolveSessionTranscriptPath function accepts an optional topicId parameter that appends a topic-specific suffix to the transcript file path. The session-creation code passes sessionCtx.MessageThreadId, but the cleanup code (line 352) omits it, producing a different path than the one actually written to disk.

Fix

Pass sessionCtx.MessageThreadId to the cleanup call at line 352, matching the pattern used at lines 320-324 for creating the new session transcript path.

Test plan

  • Code inspection confirms the cleanup path now matches the creation path
  • The fix is a one-line change adding the third parameter — no behavior change for non-topic sessions (where MessageThreadId is undefined)

🤖 Generated with Claude Code

…on reset

When a session is reset due to role ordering conflict with
cleanupTranscripts enabled, the code deletes the old transcript file.
However, resolveSessionTranscriptPath was called without the
MessageThreadId parameter, producing a path without the topic suffix.

For Telegram forum topic sessions (where MessageThreadId is set), this
means the cleanup targets a non-existent path while the actual
transcript file (with topic suffix) is left behind.

The new-session creation path (line 320-324) correctly passes
sessionCtx.MessageThreadId. Align the cleanup path to match.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@greptile-apps

greptile-apps Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a stale-transcript leak for Telegram forum-topic sessions. When a session is reset after a role-ordering conflict, the cleanup code was calling resolveSessionTranscriptPath(prevSessionId, agentId) without the topicId argument, producing a path like <prevSessionId>.jsonl instead of the <prevSessionId>-topic-<threadId>.jsonl path that was actually written to disk. The fix passes sessionCtx.MessageThreadId as the third argument, exactly mirroring the pattern used at lines 320-324 when the new session file path is resolved.

  • Root cause confirmed: resolveSessionTranscriptPath appends -topic-<topicId> to the filename only when the third argument is provided (see paths.ts lines 241-250). The creation path passes MessageThreadId; the old cleanup path did not.
  • Non-topic sessions unaffected: when MessageThreadId is undefined, the function behaviour is identical to the two-argument form — no regression risk.
  • Candidate deduplication is safe: transcriptCandidates is a Set, so adding both the resolved entry path and the constructed path has no side-effects even if they resolve to the same file.

Confidence Score: 5/5

  • Safe to merge — minimal, well-targeted fix with no behaviour change for non-topic sessions and no new logic introduced.
  • The change is a single-argument addition that corrects a path mismatch. The fix is consistent with the existing creation-side call, the function signature in paths.ts explicitly accepts an optional topicId, and the undefined pass-through for non-forum sessions is handled correctly by the path resolver. No tests need to be added beyond what exists because the code-inspection rationale holds: the only difference is the presence of the topic suffix in the filename.
  • No files require special attention.

Reviews (1): Last reviewed commit: "fix(auto-reply): pass topicId when clean..." | Re-trigger Greptile

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

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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eabeb72cde

ℹ️ 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 +352 to +353
transcriptCandidates.add(
resolveSessionTranscriptPath(prevSessionId, agentId, sessionCtx.MessageThreadId),

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.

P2 Badge Use persisted thread id when cleaning reset transcripts

For restored thread/topic sessions, dispatch-from-config.ts:221-222 can intentionally leave ctx.MessageThreadId empty and recover the thread from the sessionKey, and session.ts:413-425 persists that value on lastThreadId. This cleanup path now only consults sessionCtx.MessageThreadId, so in those flows it still falls back to the non-thread transcript name. If prevEntry.sessionFile is missing or stale (the legacy case this patch is trying to cover), a role-ordering reset will still leave the real *-topic-*.jsonl transcript behind for slash/ACP/restored thread sessions.

Useful? React with 👍 / 👎.

@vincentkoc vincentkoc added the triage: refactor-only Candidate: refactor/cleanup-only PR without maintainer context. label Apr 26, 2026
@clawsweeper

clawsweeper Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open. The PR points at a real topic-scoped transcript cleanup bug, but the branch now edits an obsolete inline cleanup site while current main routes resets through resetReplyRunSession, and the PR still lacks after-fix Telegram/topic runtime proof.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

Do we have a high-confidence way to reproduce the issue?

Yes, source-level. Current main's reset helper still resolves the cleanup fallback without any topic id while session creation can write topic-qualified transcript paths from active metadata or the parsed session key.

Is this the best way to solve the issue?

No. The branch edits the old inline cleanup site; the maintainable fix belongs in resetReplyRunSession and should mirror the session creation topic resolution contract.

Security review:

Security review cleared: The diff only changes a local transcript path argument and does not touch dependencies, workflows, package metadata, permissions, downloaded code, or secrets.

What I checked:

  • stale F-rated PR: PR was opened 2026-03-23T10:30:47Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Peter Steinberger authored the helper extraction that moved reset cleanup from the PR's old inline site into agent-runner-session-reset.ts, and also authored the original role-ordering transcript deletion path. (role: recent reset helper contributor; confidence: high; commits: aad9ecd9ccdb, 6fa437613b5e; files: src/auto-reply/reply/agent-runner-session-reset.ts, src/auto-reply/reply/agent-runner.ts, src/auto-reply/reply/agent-runner-session-reset.test.ts)
  • jalehman: Josh Lehman authored the topic transcript fallback that parses topic ids from session keys when active metadata is absent, which the reset cleanup should mirror. (role: adjacent topic-session contributor; confidence: high; commits: 77a0ee7f9de7, 62b51a6295ee; files: src/auto-reply/reply/session.ts, src/auto-reply/reply/session.test.ts)
  • neeravmakwana: Neerav Makwana authored adjacent silent session-rotation continuity work in the same reset/replay surface. (role: adjacent reset continuity contributor; confidence: medium; commits: 3de5476f5145, 2645ed154b42; files: src/auto-reply/reply/agent-runner-session-reset.ts, src/auto-reply/reply/session-transcript-replay.ts)
  • vincentkoc: Recent history shows repeated Vincent Koc work across the auto-reply and session paths involved in reset routing and followup behavior. (role: recent auto-reply/session area contributor; confidence: medium; commits: 3de42e946a2b, a35dcf608e8e, c0933e2fc850; files: src/auto-reply/reply/agent-runner.ts, src/auto-reply/reply/session.ts, src/config/sessions/paths.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 996d07ee466c.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels May 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 19, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label May 19, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: refactor-only Candidate: refactor/cleanup-only PR without maintainer context.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants