Skip to content

fix(sessions): preserve current session aliases - #111101

Closed
bemsas wants to merge 2 commits into
openclaw:mainfrom
bemsas:fix/cron-telegram-current-history-v2
Closed

bemsas wants to merge 2 commits into
openclaw:mainfrom
bemsas:fix/cron-telegram-current-history-v2

Conversation

@bemsas

@bemsas bemsas commented Jul 19, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Session tools can resolve a supported display alias such as main to the same logical session as the requester, but the visibility guard only recognizes the exact requester key or literal current. Under self or tree visibility, that mismatch incorrectly rejects the current session after resolution.

Summary

  • preserve normalized main/current aliases in the session-tool requester context
  • treat those aliases as the same requester session under self and tree visibility
  • pass the alias set through sessions_list, sessions_history, and sessions_send

This keeps current-session access working when a caller and the session resolver use different supported aliases for the same main session, without broadening visibility to unrelated same-agent sessions.

Evidence

  • node scripts/run-vitest.mjs run src/agents/tools/sessions-access.test.ts --config test/vitest/vitest.agents-tools.config.ts — 1 file passed, 30 tests passed
  • pnpm format:check -- src/agents/tools/sessions-access.test.ts src/agents/tools/sessions-access.ts src/agents/tools/sessions-history-tool.ts src/agents/tools/sessions-list-tool.ts src/agents/tools/sessions-send-tool.ts src/plugin-sdk/session-visibility.ts — passed
  • pnpm tsgo:core — passed
  • git diff --check origin/main...HEAD — clean

Behavior addressed: current-session main aliases were rejected by self/tree visibility after canonical session resolution.

Real environment tested: local OpenClaw source checkout on macOS with Node 24 and the repository Vitest/tsgo wrappers.

Exact steps or command run after this patch: node scripts/run-vitest.mjs run src/agents/tools/sessions-access.test.ts --config test/vitest/vitest.agents-tools.config.ts

Evidence after fix: the focused suite passes 30/30 tests, including alias access under both self and tree visibility while an unrelated direct session remains forbidden.

Observed result after fix: configured aliases of the requester are accepted as the current session; unrelated same-agent sessions retain the existing visibility error.

What was not tested: a deployed cron-to-channel round trip; deployment and live channel credentials were intentionally unchanged.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 19, 2026
@bemsas
bemsas force-pushed the fix/cron-telegram-current-history-v2 branch from d391119 to 5a6c3d2 Compare July 19, 2026 01:19

@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: d391119a09

ℹ️ 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".

@@ -596,6 +596,7 @@ export function createSessionsSendTool(opts?: {
const visibilityGuard = await createSessionVisibilityGuard({
action: "send",
requesterSessionKey: effectiveRequesterKey,
currentSessionKeys,

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 Reject self-send aliases before dispatch

When the caller is the main session, e.g. agentSessionKey is agent:main:main, and the model calls sessions_send with sessionKey: "main" and the default nonzero timeout, this newly lets the alias pass visibility, but the self-send guard just above only checks requesterSessionKey === resolvedKey. The tool can then start a run on the calling session alias instead of returning the intended sessions_send cannot target the calling session error, so it waits behind its own active lane until timeout; the self-send/same-session checks need to use the same alias set before dispatch.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 19, 2026
@clawsweeper

clawsweeper Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 3, 2026, 3:33 AM ET / 07:33 UTC.

ClawSweeper review

What this changes

The branch passes requester session aliases through the list, history, and send visibility checks so supported aliases such as main can access the requester’s current session under self or tree policy.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 11 items remain

Keep this PR open as a useful fix candidate, but the same two functional blockers from the prior review remain: it widens a public plugin SDK visibility contract with caller-supplied alias authority, and it lets an aliased synchronous self-send pass visibility then enter the calling session’s active lane. The PR body provides focused mocked/unit validation only, not after-fix operator-visible behavior proof.

Priority: P2
Reviewed head: 77eac87a0def30eea850ab5a7f6fb3f71065446d

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The branch has a valid bug target but retains two known correctness/security-boundary blockers and lacks real behavior proof.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The body reports focused unit tests and static checks but provides no redacted after-fix session-tool transcript, terminal output, log, or recording showing alias acceptance and self-target rejection in a real runtime. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The body reports focused unit tests and static checks but provides no redacted after-fix session-tool transcript, terminal output, log, or recording showing alias acceptance and self-target rejection in a real runtime. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Public SDK contract expansion: The PR adds currentSessionKeys to exported visibility-checker parameter objects and uses it as an ownership-equivalence condition. session-visibility is a published plugin SDK export and the branch refreshes its API baseline, so this is not a private tool-only implementation detail.
Aliased self-send remains unguarded: After the PR allows the alias through visibility, the synchronous self-send guard still compares only requesterSessionKey === resolvedKey; an alias resolving to the same session can therefore proceed instead of returning the existing self-target error.
Current main still lacks this behavior: Current main builds only one effective requester key and its shared visibility checker recognizes only that exact key or literal current; it does not carry equivalent aliases.
Findings 2 actionable findings [P1] Keep alias authority out of the public SDK contract
[P2] Reject aliased self-targets before dispatch
Security Needs attention Caller-controlled requester equivalence widens visibility: A plugin can pass additional same-agent keys in currentSessionKeys, causing restrictive self or tree policy to treat those sessions as the requester without an owner-derived proof.

How this fits together

OpenClaw session tools resolve a user-facing session key, check it against session visibility policy, then list sessions, read history, or dispatch a message. This PR changes the requester context supplied to the shared plugin SDK visibility checker.

flowchart LR
  Requester[Requester session] --> Context[Session tool context]
  Target[Target session key] --> Resolve[Session resolution]
  Context --> Visibility[Visibility policy]
  Resolve --> Visibility
  Visibility --> List[List sessions]
  Visibility --> History[Read history]
  Visibility --> Send[Dispatch message]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The body reports focused unit tests and static checks but provides no redacted after-fix session-tool transcript, terminal output, log, or recording showing alias acceptance and self-target rejection in a real runtime. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Keep alias authority out of the public SDK contract (P1) - session-visibility is a published plugin SDK module, and this caller-supplied set makes any same-agent target requester-equivalent under self or tree. Normalize the trusted aliases at the core session-tool boundary instead of extending the SDK guard with an authority-bearing parameter.
  • Reject aliased self-targets before dispatch (P2) - Passing currentSessionKeys here allows an alias of the current session through visibility, but the earlier synchronous self-send check still compares only the raw requester and resolved keys. Use the same trusted alias equivalence there so an aliased target returns the existing self-send error instead of waiting on its own active lane.
  • Resolve security concern: Caller-controlled requester equivalence widens visibility - A plugin can pass additional same-agent keys in currentSessionKeys, causing restrictive self or tree policy to treat those sessions as the requester without an owner-derived proof.
  • Resolve merge risk (P1) - The new public currentSessionKeys input lets any plugin caller assert additional same-agent sessions as the requester under self or tree, weakening the existing owner-boundary contract.
  • Resolve merge risk (P2) - An aliased current-session sessions_send with a nonzero timeout can bypass the self-send rejection and wait on its own active lane until timeout.
  • Resolve merge risk (P1) - The branch changes a published plugin SDK API baseline without a documented external-plugin contract or compatibility rationale.
  • Complete next step (P2) - Both blockers have narrow mechanical repairs: retain trusted alias normalization in the core tool owner, reuse it for the pre-dispatch self-target guard, and add focused regressions before obtaining runtime proof.
  • Improve patch quality - Move alias equivalence back behind the core session-tool boundary and remove the public SDK parameter.
  • Improve patch quality - Add a regression covering a synchronous aliased self-send that must return the existing self-target error without dispatch.
  • Improve patch quality - Attach redacted after-fix runtime evidence showing an allowed alias read plus a rejected aliased self-send; updating the PR body should trigger re-review automatically.

Findings

  • [P1] Keep alias authority out of the public SDK contract — src/plugin-sdk/session-visibility.ts:277
  • [P2] Reject aliased self-targets before dispatch — src/agents/tools/sessions-send-tool.ts:599
  • [medium] Caller-controlled requester equivalence widens visibility — src/plugin-sdk/session-visibility.ts:331
Agent review details

Security

Needs attention: The patch introduces a caller-controlled visibility-equivalence input on a public plugin SDK authorization surface.

PR surface

Source +17, Tests +26, Generated 0. Total +43 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 21 4 +17
Tests 1 26 0 +26
Docs 0 0 0 0
Config 0 0 0 0
Generated 1 1 1 0
Other 0 0 0 0
Total 7 48 5 +43

Review metrics

Metric Value Why it matters
Production versus test delta production +22/-4 (net +18), tests +26/-0 Most production growth changes the shared visibility API and call chain; that public-boundary growth needs an owner-boundary justification before merge.
Plugin SDK contract surfaces 1 changed public module baseline plugin-sdk/session-visibility is exported and its generated API baseline changes, so external plugin compatibility requires explicit review.

Stored data model

Persistent data-model change detected: serialized state: src/agents/tools/sessions-access.test.ts, serialized state: src/agents/tools/sessions-access.ts, serialized state: src/plugin-sdk/session-visibility.ts, unknown-data-model-change: src/plugin-sdk/session-visibility.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair the private alias boundary (recommended)
    Keep alias provenance in the core session-tool resolver, remove the new public SDK parameter, and add regression coverage for the supported aliases and unrelated-session denial.
  2. Accept a new SDK contract
    Explicitly approve currentSessionKeys as a plugin SDK capability, document who may supply it, and add tests proving it cannot broaden same-agent visibility beyond canonical aliases.
  3. Pause this approach
    Close or replace the branch if the alias fix cannot be expressed without exposing caller-controlled visibility authority through the public SDK.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Move alias equivalence out of the public plugin SDK parameter objects; reject synchronous aliased self-target sends before dispatch; add focused regression tests and attach redacted after-fix runtime proof.

Technical review

Best possible solution:

Keep alias equivalence owned by the core session-resolution/tool boundary, preserve the SDK checker’s authoritative requester/owner inputs, and use the same resolved equivalence when rejecting synchronous self-target sends before dispatch.

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

Yes, source-reproducible: provide a requester alias such as main, resolve it to the same current session, and call synchronous sessions_send; the changed visibility check accepts it while the unchanged equality guard does not reject it before dispatch.

Is this the best way to solve the issue?

No. The intended alias behavior is valid, but placing caller-provided alias authority in the public SDK checker is broader than necessary and leaves the related self-target invariant split across two comparisons.

Full review comments:

  • [P1] Keep alias authority out of the public SDK contract — src/plugin-sdk/session-visibility.ts:277
    session-visibility is a published plugin SDK module, and this caller-supplied set makes any same-agent target requester-equivalent under self or tree. Normalize the trusted aliases at the core session-tool boundary instead of extending the SDK guard with an authority-bearing parameter.
    Confidence: 0.96
  • [P2] Reject aliased self-targets before dispatch — src/agents/tools/sessions-send-tool.ts:599
    Passing currentSessionKeys here allows an alias of the current session through visibility, but the earlier synchronous self-send check still compares only the raw requester and resolved keys. Use the same trusted alias equivalence there so an aliased target returns the existing self-send error instead of waiting on its own active lane.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 820cd7c152f7.

Labels

Label justifications:

  • P2: The PR addresses a bounded but user-visible session-tool access regression and currently retains a self-send stall path.
  • merge-risk: 🚨 compatibility: The branch changes the published plugin-sdk/session-visibility API and its generated baseline.
  • merge-risk: 🚨 availability: An alias that resolves to the calling session can bypass the synchronous self-send guard and wait behind that session’s active lane.
  • merge-risk: 🚨 security-boundary: Caller-supplied alias sets can mark additional same-agent sessions as requester-equivalent under restrictive visibility policies.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body reports focused unit tests and static checks but provides no redacted after-fix session-tool transcript, terminal output, log, or recording showing alias acceptance and self-target rejection in a real runtime. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [medium] Caller-controlled requester equivalence widens visibility — src/plugin-sdk/session-visibility.ts:331
    A plugin can pass additional same-agent keys in currentSessionKeys, causing restrictive self or tree policy to treat those sessions as the requester without an owner-derived proof.
    Confidence: 0.96

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/tools/sessions-access.test.ts.
  • [P1] Run the focused sessions_send regression test through the repository Vitest wrapper and confirm no dispatch occurs for an aliased synchronous self-target.
  • [P1] pnpm plugin-sdk:surface:check if any public SDK file or baseline remains changed.
  • [P1] Provide redacted after-fix terminal or runtime transcript showing alias acceptance and aliased self-send rejection.

What I checked:

  • Public SDK contract expansion: The PR adds currentSessionKeys to exported visibility-checker parameter objects and uses it as an ownership-equivalence condition. session-visibility is a published plugin SDK export and the branch refreshes its API baseline, so this is not a private tool-only implementation detail. (src/plugin-sdk/session-visibility.ts:277, 77eac87a0def)
  • Aliased self-send remains unguarded: After the PR allows the alias through visibility, the synchronous self-send guard still compares only requesterSessionKey === resolvedKey; an alias resolving to the same session can therefore proceed instead of returning the existing self-target error. (src/agents/tools/sessions-send-tool.ts:579, 77eac87a0def)
  • Current main still lacks this behavior: Current main builds only one effective requester key and its shared visibility checker recognizes only that exact key or literal current; it does not carry equivalent aliases. (src/agents/tools/sessions-access.ts:42, 820cd7c152f7)
  • Current/release provenance: The PR head is not contained in the latest release v2026.7.1, and current main is newer than that release; no merged current-main implementation was found in the inspected owner path. (2d2ddc43d0dc)
  • Current ownership signal: The currently checked visibility and resolution lines blame to the latest direct maintainer touch in this shallow checkout; deeper historical traversal was incomplete because missing promisor objects could not be fetched. (src/plugin-sdk/session-visibility.ts:369, bc212450bc9f)

Likely related people:

  • Peter Steinberger: Current-main blame and the locally available file history attribute the inspected session visibility and resolution area to this recent direct touch; deeper provenance is limited by unavailable promisor objects. (role: recent area contributor; confidence: low; commits: bc212450bc9f, c95a8e3df1e6; files: src/plugin-sdk/session-visibility.ts, src/agents/tools/sessions-resolution.ts, src/agents/tools/sessions-send-tool.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-07-19T01:21:49.058Z sha 5a6c3d2e3eb3662f35bdb052acf308f0d9debad9 :: needs real behavior proof before merge. :: [P2] Reject aliased self-targets before dispatch
  • reviewed 2026-07-19T12:14:56.786Z sha 6be0d1d :: needs real behavior proof before merge. :: [P2] Protect aliased self-targets before dispatch
  • reviewed 2026-07-19T15:15:03.861Z sha 77eac87 :: needs real behavior proof before merge. :: [P2] Reject aliased self-targets before dispatch
  • reviewed 2026-07-29T22:23:06.503Z sha 77eac87 :: needs real behavior proof before merge. :: [P2] Reject aliased self-targets before dispatch
  • reviewed 2026-08-01T09:34:33.719Z sha 77eac87 :: needs real behavior proof before merge. :: [P1] Keep alias state out of the public SDK contract | [P2] Reject aliased self-targets before dispatch

@bemsas
bemsas force-pushed the fix/cron-telegram-current-history-v2 branch from 5a6c3d2 to 6be0d1d Compare July 19, 2026 12:10
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Jul 19, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 30, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Aug 28, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

@openclaw-barnacle openclaw-barnacle Bot closed this Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant