Skip to content

fix: synchronous sessions_send self-targets time out - #107267

Closed
aktayal wants to merge 3 commits into
openclaw:mainfrom
aktayal:fix/sessions-send-self-target-107172
Closed

aktayal wants to merge 3 commits into
openclaw:mainfrom
aktayal:fix/sessions-send-self-target-107172

Conversation

@aktayal

@aktayal aktayal commented Jul 14, 2026 •

Copy link
Copy Markdown

Related: #107172

What Problem This Solves

Fixes an issue where an agent synchronously sending a message to its own originating session with sessions_send could wait behind the turn that initiated it and eventually time out.

Why This Change Was Made

Reject synchronous self-target sends after session resolution, including direct keys and aliases or labels that resolve to the originating session. Fire-and-forget self-target sends with timeoutSeconds: 0 remain supported.

Scope

This is a focused safeguard for one failure mode reported in #107172: a synchronous sessions_send resolving back to the currently active originating session. It prevents the self-wait/session-lane dependency, but it does not change the separate Codex terminal message delivery path or fully resolve the Feishu finalization and native-hook lifecycle symptoms from that issue.

For that reason, this PR intentionally uses Related: #107172 rather than Closes #107172.

The broader integration work should follow in a separate TDD change covering:

  • terminal message delivery from Codex through parent reply accounting;
  • Feishu finalization without an additional Done. fallback after a visible tool-delivered reply;
  • native-hook relay grace after terminal dynamic-tool turn release; and
  • a regression test proving a late turn-related hook is handled without native hook relay not found.

Keeping that work separate avoids coupling the core session-send guard to Codex harness and Feishu channel lifecycle changes, and keeps this PR small and reviewable.

User Impact

Agents now receive an immediate actionable error instead of entering a predictable synchronous wait when sessions_send resolves back to the current session. Existing asynchronous self-send workflows continue to work.

Evidence

TDD proof

  • Initial red: the new synchronous self-target cases failed before the guard was implemented.
  • Green: direct keys, aliases, and labels resolving to the originating session are rejected for synchronous sends.
  • Compatibility proof: fire-and-forget self-target sends with timeoutSeconds: 0 remain supported.
  • Existing thread-target rejection and timeout conversion behavior remain covered.

Current-head local validation

  • 39/39 helper and A2A tests passed.
  • 3/3 focused synchronous self-target regressions passed (46 unrelated cases skipped by the test filter).
  • 10/10 unit-fast inventory tests passed after integrating current main.
  • TypeScript LOC ratchet passed for all 3 changed production files.
  • Prompt snapshot generation check passed against the current merged tree; no fixture drift remained.
  • Oxfmt passed for every PR-owned TypeScript source and test file.
  • git diff --check passed.
  • The bundled Codex $autoreview completed cleanly on the final branch diff with no accepted/actionable findings (overall confidence 0.96).

Prior broader regression proof

  • 49/49 focused sessions cases passed.
  • 138/138 unique adjacent tests passed across sessions, sessions tool, A2A, resolution, and send-helper suites (276 configured Vitest project executions).
  • Those broader focused tests ran in a disposable Docker Node 24.16 environment with test-time networking disabled.

CI remediation

  • The LOC failure was fixed by extracting target-context and timeout resolution into the existing sessions-send helper boundary, restoring sessions-send-tool.ts to its ratcheted line budget.
  • The branch was merged with current upstream main; the prompt snapshot checker now reports no drift.
  • The stale unit-fast inventory failure was upstream state and passes after the current-main integration.
  • A fresh full secretless fork CI matrix is running on head 1712bed35e1.

AI-assisted: yes. Codex was used for issue investigation, test-first implementation, focused validation, structured autoreview, CI triage, and PR preparation. The change and evidence were reviewed before submission.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jul 14, 2026
@aktayal
aktayal marked this pull request as ready for review July 14, 2026 08:16
@openclaw-barnacle openclaw-barnacle Bot added size: M triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 14, 2026
@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. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 14, 2026
@clawsweeper

clawsweeper Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 14, 2026, 8:51 AM ET / 12:51 UTC.

Summary
Rejects synchronous sessions_send calls that resolve to the originating session while preserving timeoutSeconds: 0 fire-and-forget self-delivery and adding tool guidance and regression coverage.

PR surface: Source +73, Tests +175. Total +248 across 8 files.

Reproducibility: yes. at source level: the linked fresh-session trace shows a nested sessions_send waiting behind its own active session, and current main still lacks a synchronous self-target guard. This review did not independently run the live Feishu/Codex reproduction.

Review metrics: none identified.

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

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #107172
Summary: This PR is a candidate fix for the synchronous self-target/session-lane slice of the canonical issue, but it intentionally does not resolve that issue's separate Codex terminal-delivery, Feishu finalization, or native-hook relay symptoms.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
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:

  • [P1] Add redacted live-session proof covering both immediate synchronous rejection and preserved fire-and-forget self-delivery.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only tests, CI, snapshots, formatting, and autoreview are supplied; add a redacted live Codex/Feishu or equivalent transcript/log showing immediate synchronous rejection and successful timeoutSeconds: 0 delivery. After updating the PR body, a fresh review should trigger automatically; otherwise ask a maintainer to 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

  • [P2] The claimed improvement has not been demonstrated in a real after-fix Codex/Feishu or equivalent session, so tests alone do not establish that the user sees the immediate error or that zero-timeout self-delivery still completes correctly.
  • [P1] The branch is behind current main, so the final merged head needs refreshed exact-head review and validation after updating the branch; stale-base drift alone is not evidence of a patch defect.

Maintainer options:

  1. Decide the mitigation before merge
    Add redacted live proof for both behavior modes, refresh the branch onto current main, and land this bounded core guard while keeping [Bug]: Codex sessions_send can self-target the active Feishu session, causing lane wait and “Done.” empty-reply fallback #107172 open for Codex terminal-result accounting, Feishu finalization, and native-hook relay lifecycle work.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Wait for contributor-supplied real behavior proof, then refresh the behind branch and perform exact-head merge/check gating; no narrow automated code repair is currently identified.

Security
Cleared: The patch changes local session-routing validation, tests, and prompt text without adding dependency, credential, permission, persistence, workflow, or third-party execution surfaces.

Review details

Best possible solution:

Add redacted live proof for both behavior modes, refresh the branch onto current main, and land this bounded core guard while keeping #107172 open for Codex terminal-result accounting, Feishu finalization, and native-hook relay lifecycle work.

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

Yes at source level: the linked fresh-session trace shows a nested sessions_send waiting behind its own active session, and current main still lacks a synchronous self-target guard. This review did not independently run the live Feishu/Codex reproduction.

Is this the best way to solve the issue?

Yes—the post-resolution canonical self-target check is the narrowest maintainable safeguard for this failure mode, and preserving timeoutSeconds: 0 avoids breaking the non-waiting workflow. The broader Codex/Feishu completion problem correctly remains outside this PR.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9de11f098e65.

Label changes

Label justifications:

  • P1: The PR addresses a reproducible agent-session workflow that can block behind itself, wait for the timeout budget, and delay or suppress the originating reply.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only tests, CI, snapshots, formatting, and autoreview are supplied; add a redacted live Codex/Feishu or equivalent transcript/log showing immediate synchronous rejection and successful timeoutSeconds: 0 delivery. After updating the PR body, a fresh review should trigger automatically; otherwise ask a maintainer to 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 +73, Tests +175. Total +248 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 91 18 +73
Tests 5 183 8 +175
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 274 26 +248

What I checked:

  • Current-main behavior: At current main, sessions_send computes sameSessionA2A from the requester and resolved target but proceeds into dispatch and waiting without rejecting a synchronous self-target; only thread targets are rejected at this point. citeturn531695view0turn368449view0. (src/agents/tools/sessions-send-tool.ts:513, 9de11f098e65)
  • Proposed safeguard: The PR resolves canonical requester/target context after visible-session resolution, returns an immediate error for same-session sends with a nonzero timeout, and retains the existing asynchronous path for zero timeout. (src/agents/tools/sessions-send-helpers.ts:48, 1712bed35e12)
  • Regression coverage: The PR adds direct-key, main-alias, and label-based synchronous self-target cases, verifies that no nested agent wait is dispatched, and separately covers preserved fire-and-forget delivery. (src/agents/tools/sessions.test.ts:1116, 1712bed35e12)
  • Codex contract inspection: The OpenAI Codex app-server contract models dynamic tool calls as request/response exchanges within an active turn before the later turn-completed notification, supporting the PR's diagnosis that synchronously queuing work behind the originating OpenClaw session can create a self-wait. citeturn724547view0. (../codex/codex-rs/app-server/README.md)
  • Proof gate: The PR body reports unit, focused, snapshot, formatting, Docker, CI, and autoreview results, but no redacted after-fix live session transcript or logs showing both immediate synchronous rejection and successful zero-timeout self-delivery; the prior review requested that proof on this same head. (1712bed35e12)
  • Area history: Recent history for the central tool shows sustained sessions-send and A2A work by Peter Steinberger and Scott Huang, including timeout normalization, lifecycle cleanup, nested-lane handling, and A2A ownership fixes. citeturn837853view0. (src/agents/tools/sessions-send-tool.ts, 703fef64c)

Likely related people:

  • Peter Steinberger: Recent file history shows repeated work on sessions-send timeout handling, lifecycle cleanup, nested lane behavior, message context, and A2A routing in the central implementation. (role: recent area contributor; confidence: high; commits: 703fef64c, 0a388d83e, ad4f08e2b; files: src/agents/tools/sessions-send-tool.ts, src/agents/tools/sessions-send-helpers.ts)
  • Scott Huang: Recent merged history attributes focused A2A lifecycle and dispatch-ownership fixes in the same sessions-send path to Scott Huang. (role: A2A flow contributor; confidence: medium; commits: 1c3fbbd40, 8a7c21443; files: src/agents/tools/sessions-send-tool.ts, src/agents/tools/sessions-send-tool.a2a.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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-14T12:26:07.965Z sha 1712bed35e129c48f045605ec7099f8fc9688fea :: needs real behavior proof before merge. :: none

@aktayal
aktayal force-pushed the fix/sessions-send-self-target-107172 branch from 1712bed to e9b47cb Compare July 15, 2026 09:43
@aktayal

aktayal commented Jul 15, 2026

Copy link
Copy Markdown
Author

@clawsweeper re-review

I have rebased the PR against main and gathered the required real behavior proof against the live gateway.

Live Runtime Behavior Proof

Using the OpenClaw gateway and the CLI agent (targeting its own agent:main:main session key), here is the live verification that synchronous self-targets are successfully blocked while fire-and-forget is accepted:

Current session key: `agent:main:main`.

1. `timeoutSeconds: 5` — failed because synchronous sending to the current session isn’t permitted. Run ID: `a4e8f21c-aacd-4b89-aa70-807cd8ea8558`.

2. `timeoutSeconds: 0` — accepted as fire-and-forget; delivery is pending in `announce` mode. Run ID: `a9c688b3-3eac-45b1-84bb-4facf57cd3a0`.

Unit Test Verification

The corresponding gating tests in src/agents/tools/sessions.test.ts also pass cleanly without timeouts:

✓ sessions_send gating > rejects a synchronous send to the current session before dispatching an agent run
✓ sessions_send gating > rejects a synchronous main alias that resolves to the current session
✓ sessions_send gating > rejects a synchronous label target that resolves to the current session
✓ sessions_send gating > canonicalizes a main alias target for fire-and-forget same-session delivery
✓ sessions_send gating > passes a baseline into fire-and-forget same-session A2A delivery

Everything behaves exactly as expected. Please review!

@clawsweeper

clawsweeper Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@aktayal

aktayal commented Jul 15, 2026

Copy link
Copy Markdown
Author

Fixed with PR from clawFather #108354

@aktayal aktayal closed this Jul 15, 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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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.

1 participant