fix(compaction): restore session invariants across compaction and reset#69270
fix(compaction): restore session invariants across compaction and reset#69270de1tydev wants to merge 16 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR propagates The fix is correct for the targeted channel-scoped session keys ( Confidence Score: 5/5Safe to merge; the edge case with All findings are P2. The core fix is correct and well-tested. The src/gateway/session-reset-service.ts — the Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/gateway/session-reset-service.ts
Line: 53-63
Comment:
**`inferMessageProviderFromSessionKey` misses non-channel `rest` prefixes**
Session keys built with `dmScope === "per-peer"` use the format `agent:{agentId}:direct:{peerId}`, so `rest.split(":")[0]` yields `"direct"` — a chat-type segment, not a channel name. Since `"direct"` is not in the sentinel list, `normalizeMessageChannel("direct")` is returned as `messageProvider`, giving downstream plugins an incorrect, non-channel value. Similarly, dashboard-scoped keys (`agent:ops:dashboard:…`) would surface `"dashboard"`. For those key shapes the function should return `undefined` to stay consistent with the "unknown provider" fallback the PR is trying to eliminate.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(hooks): preserve messageProvider in ..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f5b0e0e52
ℹ️ 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".
|
Addressed the follow-up issues in a6e53dfd81.
Local verification:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a6e53dfd81
ℹ️ 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".
|
Expanded this into a coordinated compaction/reset invariant fix, per the review suggestion. Included in this update:
I also updated the issue/PR title and description to reflect the broader scope. Local verification:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2171c3b21f
ℹ️ 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: ce4db4ebec
ℹ️ 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: 046100e827
ℹ️ 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: 53dd9aec43
ℹ️ 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".
|
Codex review: needs real behavior proof before merge. Summary Reproducibility: yes. by source inspection. Current main omits messageProvider on reset and subscribe-time compaction hook contexts, and its positive-only token guards skip zero-token compaction results. Real behavior proof Next step before merge Security Review detailsBest possible solution: Land this PR or an equivalent focused fix after real path-level proof and maintainer validation so every reset/compaction hook path uses stable provider context and zero-token compactions clear stale accounting. Do we have a high-confidence way to reproduce the issue? Yes, by source inspection. Current main omits messageProvider on reset and subscribe-time compaction hook contexts, and its positive-only token guards skip zero-token compaction results. Is this the best way to solve the issue? Yes, the shared resolver plus nonnegative token accounting is the narrow maintainable fix shape for this bug cluster. The remaining blocker is proof quality, not a concrete code defect found in this review. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against fb2056750004. |
9619013 to
054a6a8
Compare
|
ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical. Source PR: #69270 |
054a6a8 to
fed80eb
Compare
|
ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical. Source PR: #69270 |
…ovider-context # Conflicts: # CHANGELOG.md
…ovider-context # Conflicts: # CHANGELOG.md
…ovider-context # Conflicts: # CHANGELOG.md # src/agents/pi-embedded-subscribe.handlers.compaction.test.ts # src/auto-reply/reply/commands-reset-hooks.ts # src/gateway/server.sessions.gateway-server-sessions-a.test.ts
Summary
Restore session invariants across compaction and reset instead of patching each symptom in isolation.
This coordinated fix now covers four connected paths:
before_compaction/after_compactionhook contextcompact.queued.ts/new//resethook context inemitResetCommandHookssessions.resethook context inemitGatewayBeforeResetPluginHookIt also fixes compaction bookkeeping so zero-token outcomes reset cached usage instead of leaving the session in a repeated safeguard loop.
What changed
Telegrambecometelegramagent:main:direct:peer_123unresolved instead of emitting fake providerstotalTokens/totalTokensFresh/estimatedCostUsdfrom compaction results even whentokensAfter === 0Why
These reports all describe the same broader failure mode: compaction/reset code paths were not preserving the session invariants downstream systems rely on.
That surfaced as different user-visible bugs:
messageProvidervalues and split one real conversation into multiple logical sessionsIssues
Fixes #69269
Fixes #69286
Also addresses the duplicate token-accounting report in #69287.
Related cluster: #69202.
Tests
pnpm buildpnpm checkpnpm exec vitest run src/auto-reply/reply/commands-core.test.ts src/agents/pi-embedded-subscribe.handlers.compaction.test.ts src/auto-reply/reply/reply-state.test.ts src/gateway/server.sessions.gateway-server-sessions-a.test.tsReal behavior proof
node --import tsx.messageProvider: "feishu", legacy non-channel direct keys leave the provider unset, and explicitTelegramis canonicalized totelegrambefore hook context emission.