Skip to content

fix(agents): preserve literal current session resolution#93138

Merged
vincentkoc merged 7 commits into
openclaw:mainfrom
liuhao1024:fix/sessions-resolve-current-alias
Jun 15, 2026
Merged

fix(agents): preserve literal current session resolution#93138
vincentkoc merged 7 commits into
openclaw:mainfrom
liuhao1024:fix/sessions-resolve-current-alias

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

Real behavior proof

  • Behavior addressed: sessions.resolve gateway action logs INVALID_REQUEST error on every sessionKey="current" tool call because the literal string "current" is sent to the gateway as a sessionId lookup, which rejects it. The wrapper falls back correctly, but the gateway error log is spurious on every turn.
  • Environment tested: macOS 26.4.1, Node.js v22, OpenClaw upstream/main @ ac1042b0
  • Steps run after the patch:
    1. Verified resolveCurrentSessionClientAlias now short-circuits for key="current" when requesterInternalKey is present
    2. Ran node scripts/run-vitest.mjs run src/agents/tools/sessions-resolution.test.ts — all 17 tests pass
    3. Ran pnpm build — succeeds
    4. Confirmed no gateway sessions.resolve call is made for sessionKey="current" via test assertion expect(callGatewayMock).not.toHaveBeenCalled()
  • Evidence after fix:
$ node -e "const fs=require('fs'); const s=fs.readFileSync('src/agents/tools/sessions-resolution.ts','utf-8'); const m=s.match(/current.*well-known alias[\\s\\S]{0,120}requesterKey/); console.log(m?'PASS: current alias short-circuit found':'FAIL')"

PASS: current alias short-circuit found
$ grep -n 'current.*well-known\|params.key.trim.*current\|requesterKey' src/agents/tools/sessions-resolution.ts
81:  // "current" is a well-known alias for the caller's own session, promoted by
85:  if (params.key.trim().toLowerCase() === "current") {
86:    return requesterKey;
$ node scripts/run-vitest.mjs run src/agents/tools/sessions-resolution.test.ts
 ✓  agents  src/agents/tools/sessions-resolution.test.ts (17 tests) 39ms
 Test Files  1 passed (1)
      Tests  17 passed (17)
  • Observed result after fix: When sessionKey="current" and requesterInternalKey is set, the alias resolves locally to the requester's session key without any gateway round-trip. No INVALID_REQUEST error is logged. The existing TUI/CLI/WebChat client label aliases continue to work unchanged.
  • What was not tested: Live Telegram/Discord session with an agent calling session_status(sessionKey="current") — the fix is in the resolution layer tested by unit tests, not in a channel-specific path.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 15, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 14, 2026, 11:36 PM ET / 03:36 UTC.

Summary
The PR adds a local current shortcut in the session resolver and rewrites resolver/session_status tests to expect requester-session resolution without a gateway call.

PR surface: Source +7, Tests -65. Total -58 across 3 files.

Reproducibility: yes. Current-main source still sends raw current through sessions.resolve before fallback, and the linked issue includes live gateway logs showing the failed probe.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/agents/tools/sessions-resolution.test.ts, unknown-data-model-change: src/agents/tools/sessions-resolution.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Preserve literal current key/sessionId behavior while avoiding only the noisy semantic-current probe.
  • [P1] Add redacted live gateway or tool-run proof showing sessionKey="current" no longer emits INVALID_REQUEST in a real setup.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR supplies static grep plus unit/build output, but needs redacted live gateway/tool output showing the INVALID_REQUEST log is gone; after updating the PR body, a fresh ClawSweeper review should run or a maintainer can comment @clawsweeper re-review. 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.

Risk before merge

  • [P1] Merging as-is can silently retarget explicit sessionKey: "current" lookups from a stored literal agent:main:current key or sessionId current to the requester session.
  • [P1] The PR body supplies static grep, unit-test output, and build output, but no redacted live gateway/tool run showing that the INVALID_REQUEST log is gone in a real setup.

Maintainer options:

  1. Preserve Literal Precedence (recommended)
    Keep the existing literal current key/sessionId lookup order and add a narrower semantic-current no-noise path after those lookups miss.
  2. Accept Semantic-Current-Only Behavior
    Maintainers could intentionally retire literal current lookup behavior, but that needs an explicit compatibility decision and updated tests/docs before merge.
  3. Move Binding To Gateway Context
    Pause the wrapper-only shortcut and instead thread requester-current context into the gateway resolver so direct sessions.resolve can handle semantic current.

Next step before merge

  • [P1] Contributor revision and real behavior proof are needed; automation cannot supply the external contributor proof gate for this PR.

Security
Cleared: The diff only changes internal TypeScript session resolution logic and tests; I found no concrete security or supply-chain concern.

Review findings

  • [P1] Preserve literal current lookups — src/agents/tools/sessions-resolution.ts:85-87
Review details

Best possible solution:

Preserve literal current key/sessionId precedence, then skip or bind only the failed semantic-current gateway probe with focused resolver/session_status coverage and redacted live tool or gateway proof.

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

Yes. Current-main source still sends raw current through sessions.resolve before fallback, and the linked issue includes live gateway logs showing the failed probe.

Is this the best way to solve the issue?

No. The PR is too early in the shared resolver path; the safer fix preserves literal current key/sessionId precedence and only removes the failed semantic-current probe.

Full review comments:

  • [P1] Preserve literal current lookups — src/agents/tools/sessions-resolution.ts:85-87
    This helper runs before session_status checks the session store. Returning the requester key for raw "current" here bypasses existing literal agent:main:current keys and sessionId current entries, which current-main tests explicitly preserve. Keep literal key/sessionId lookup precedence and only skip the noisy unresolved semantic-current probe.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.89

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 663fabbe30eb.

Label changes

Label justifications:

  • P2: This is a bounded agent session-resolution bugfix with real operational/session-state impact, but not a crash, outage, data-loss, or security emergency.
  • merge-risk: 🚨 compatibility: The PR changes how existing explicit current session keys or session IDs resolve during upgrade.
  • merge-risk: 🚨 session-state: The changed helper can route session status and related lookups to the requester session instead of the intended stored session.
  • 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 PR supplies static grep plus unit/build output, but needs redacted live gateway/tool output showing the INVALID_REQUEST log is gone; after updating the PR body, a fresh ClawSweeper review should run or a maintainer can comment @clawsweeper re-review. 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

PR surface:

Source +7, Tests -65. Total -58 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 0 +7
Tests 2 14 79 -65
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 21 79 -58

What I checked:

  • Current-main raw-current path: Current main still routes raw current into resolveSessionReference and probes gateway resolution before falling back, so the linked bug is still relevant and not already implemented on main. (src/agents/tools/sessions-resolution.ts:405, 663fabbe30eb)
  • PR shortcut location: The PR adds the raw current shortcut inside the shared current-client alias helper, before later literal key/sessionId resolution paths can run. (src/agents/tools/sessions-resolution.ts:85, b131b2536288)
  • Existing literal-current contract tests: Current-main tests explicitly preserve literal current session key and sessionId resolution before alias fallback; the PR removes or rewrites those expectations. (src/agents/tools/sessions-resolution.test.ts:253, 663fabbe30eb)
  • session_status caller impact: session_status calls resolveCurrentSessionClientAlias before its store lookup, so the PR shortcut can retarget explicit sessionKey: "current" away from stored literal sessions. (src/agents/tools/session-status-tool.ts:597, 663fabbe30eb)
  • Linked issue context: The linked issue remains open and includes live reports of sessions.resolve rejecting raw current, plus the expected compatibility constraint to preserve literal-current behavior.
  • History and owner provenance: GitHub commit history points to prior client-alias, session_status, and gateway resolver work in the same affected surfaces. (src/agents/tools/sessions-resolution.ts:73, dfe58a1b8e1b)

Likely related people:

  • steipete: Recent history for src/agents/tools/sessions-resolution.ts includes the TUI/client-label current-session alias change that this PR extends. (role: introduced adjacent client-alias behavior; confidence: high; commits: dfe58a1b8e1b; files: src/agents/tools/sessions-resolution.ts)
  • nxmxbbd: Recent history for session-status-tool.ts includes route-context/session-status work on the caller affected by the shortcut. (role: recent session_status contributor; confidence: medium; commits: 61e9961abb77; files: src/agents/tools/session-status-tool.ts, src/agents/openclaw-tools.session-status.test.ts)
  • jalehman: Recent gateway session resolver history includes the session accessor seam work adjacent to the direct sessions.resolve behavior discussed in the linked issue. (role: recent gateway resolver contributor; confidence: medium; commits: ef47dd610c87; files: src/gateway/sessions-resolve.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 15, 2026
@vincentkoc vincentkoc self-assigned this Jun 15, 2026
liuhao1024 and others added 7 commits June 15, 2026 12:23
…round-trip

The system prompt tells agents to use sessionKey="current" to refer to
their own session.  Previously, resolveSessionReference sent the literal
string "current" to the gateway sessions.resolve action, which rejected
it with INVALID_REQUEST and logged a noisy error line on every tool call.
The wrapper fell back to requesterInternalKey and succeeded, so the tool
worked — but the gateway error was spurious.

Add "current" to the well-known client alias check in
resolveCurrentSessionClientAlias so it is resolved locally to the
requester's session key, matching how TUI/CLI/WebChat client labels are
handled.  This eliminates the unnecessary gateway round-trip and the
error log line.

Fixes openclaw#78424
…ution"

This reverts commit d9f6c8b5248921c99f43dc222667ffa429b34401.
…ution"

This reverts commit 40bf77d06711833c1beaeedf562b60a765a559d6.
…gateway round-trip"

This reverts commit d92bc9b91e0840ea5823cd44223c139e434c5ec4.
@vincentkoc
vincentkoc force-pushed the fix/sessions-resolve-current-alias branch from b131b25 to 47bed13 Compare June 15, 2026 04:28
@vincentkoc vincentkoc changed the title fix(agents): resolve "current" session alias locally without gateway round-trip (fixes #78424) fix(agents): preserve literal current session resolution Jun 15, 2026
@vincentkoc

Copy link
Copy Markdown
Member

maintainer repair is land-ready.

what changed:

  • preserve literal current key/sessionId precedence without surfacing expected missing-probe RPC errors
  • keep ambiguity, deleted-agent, auth, transport, and server failures as real errors
  • retry only the exact older protocol-v4 rejection of the additive allowMissing field
  • regenerate the Swift protocol model with allowMissing = nil to preserve source compatibility

verification:

  • node scripts/run-vitest.mjs src/gateway/sessions-resolve.test.ts src/gateway/sessions-resolve-store.test.ts src/gateway/server.sessions.preview-resolve.test.ts src/agents/tools/sessions-resolution.test.ts src/agents/tools/embedded-gateway-stub.test.ts packages/gateway-protocol/src/index.test.ts (167 focused tests before rebase)
  • post-rebase focused run: 123 tests passed
  • focused oxlint, oxfmt, import-boundary, protocol generation, and git diff --check passed
  • fresh local autoreview clean (0.94); post-rebase branch autoreview clean (0.93)

proof gap: broad check:changed was unavailable because the repo Crabbox Azure login is expired (AADSTS50132).

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts size: M and removed size: S labels Jun 15, 2026
@vincentkoc
vincentkoc merged commit 7e0128a into openclaw:main Jun 15, 2026
188 of 194 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 15, 2026
)

* fix(agents): resolve "current" session alias locally without gateway round-trip

The system prompt tells agents to use sessionKey="current" to refer to
their own session.  Previously, resolveSessionReference sent the literal
string "current" to the gateway sessions.resolve action, which rejected
it with INVALID_REQUEST and logged a noisy error line on every tool call.
The wrapper fell back to requesterInternalKey and succeeded, so the tool
worked — but the gateway error was spurious.

Add "current" to the well-known client alias check in
resolveCurrentSessionClientAlias so it is resolved locally to the
requester's session key, matching how TUI/CLI/WebChat client labels are
handled.  This eliminates the unnecessary gateway round-trip and the
error log line.

Fixes openclaw#78424

* test: update session_status tests for local current-key resolution

* test: update session_status tests for local current-key resolution

* Revert "test: update session_status tests for local current-key resolution"

This reverts commit d9f6c8b5248921c99f43dc222667ffa429b34401.

* Revert "test: update session_status tests for local current-key resolution"

This reverts commit 40bf77d06711833c1beaeedf562b60a765a559d6.

* Revert "fix(agents): resolve "current" session alias locally without gateway round-trip"

This reverts commit d92bc9b91e0840ea5823cd44223c139e434c5ec4.

* fix(agents): preserve literal current session resolution

---------

Co-authored-by: Vincent Koc <[email protected]>
wangmiao0668000666 pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Jun 17, 2026
)

* fix(agents): resolve "current" session alias locally without gateway round-trip

The system prompt tells agents to use sessionKey="current" to refer to
their own session.  Previously, resolveSessionReference sent the literal
string "current" to the gateway sessions.resolve action, which rejected
it with INVALID_REQUEST and logged a noisy error line on every tool call.
The wrapper fell back to requesterInternalKey and succeeded, so the tool
worked — but the gateway error was spurious.

Add "current" to the well-known client alias check in
resolveCurrentSessionClientAlias so it is resolved locally to the
requester's session key, matching how TUI/CLI/WebChat client labels are
handled.  This eliminates the unnecessary gateway round-trip and the
error log line.

Fixes openclaw#78424

* test: update session_status tests for local current-key resolution

* test: update session_status tests for local current-key resolution

* Revert "test: update session_status tests for local current-key resolution"

This reverts commit d9f6c8b5248921c99f43dc222667ffa429b34401.

* Revert "test: update session_status tests for local current-key resolution"

This reverts commit 40bf77d06711833c1beaeedf562b60a765a559d6.

* Revert "fix(agents): resolve "current" session alias locally without gateway round-trip"

This reverts commit d92bc9b91e0840ea5823cd44223c139e434c5ec4.

* fix(agents): preserve literal current session resolution

---------

Co-authored-by: Vincent Koc <[email protected]>
crh-code pushed a commit to crh-code/openclaw that referenced this pull request Jun 18, 2026
)

* fix(agents): resolve "current" session alias locally without gateway round-trip

The system prompt tells agents to use sessionKey="current" to refer to
their own session.  Previously, resolveSessionReference sent the literal
string "current" to the gateway sessions.resolve action, which rejected
it with INVALID_REQUEST and logged a noisy error line on every tool call.
The wrapper fell back to requesterInternalKey and succeeded, so the tool
worked — but the gateway error was spurious.

Add "current" to the well-known client alias check in
resolveCurrentSessionClientAlias so it is resolved locally to the
requester's session key, matching how TUI/CLI/WebChat client labels are
handled.  This eliminates the unnecessary gateway round-trip and the
error log line.

Fixes openclaw#78424

* test: update session_status tests for local current-key resolution

* test: update session_status tests for local current-key resolution

* Revert "test: update session_status tests for local current-key resolution"

This reverts commit d9f6c8b5248921c99f43dc222667ffa429b34401.

* Revert "test: update session_status tests for local current-key resolution"

This reverts commit 40bf77d06711833c1beaeedf562b60a765a559d6.

* Revert "fix(agents): resolve "current" session alias locally without gateway round-trip"

This reverts commit d92bc9b91e0840ea5823cd44223c139e434c5ec4.

* fix(agents): preserve literal current session resolution

---------

Co-authored-by: Vincent Koc <[email protected]>
badgerbees pushed a commit to badgerbees/openclaw that referenced this pull request Jul 8, 2026
)

* fix(agents): resolve "current" session alias locally without gateway round-trip

The system prompt tells agents to use sessionKey="current" to refer to
their own session.  Previously, resolveSessionReference sent the literal
string "current" to the gateway sessions.resolve action, which rejected
it with INVALID_REQUEST and logged a noisy error line on every tool call.
The wrapper fell back to requesterInternalKey and succeeded, so the tool
worked — but the gateway error was spurious.

Add "current" to the well-known client alias check in
resolveCurrentSessionClientAlias so it is resolved locally to the
requester's session key, matching how TUI/CLI/WebChat client labels are
handled.  This eliminates the unnecessary gateway round-trip and the
error log line.

Fixes openclaw#78424

* test: update session_status tests for local current-key resolution

* test: update session_status tests for local current-key resolution

* Revert "test: update session_status tests for local current-key resolution"

This reverts commit d9f6c8b5248921c99f43dc222667ffa429b34401.

* Revert "test: update session_status tests for local current-key resolution"

This reverts commit 40bf77d06711833c1beaeedf562b60a765a559d6.

* Revert "fix(agents): resolve "current" session alias locally without gateway round-trip"

This reverts commit d92bc9b91e0840ea5823cd44223c139e434c5ec4.

* fix(agents): preserve literal current session resolution

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: M 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.

2 participants