Repository navigation
fix(tui): run new sessions through lifecycle hooks - #100241
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1836a7ee4a
ℹ️ 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".
| const result = await client.createSession({ | ||
| key: uniqueKey, | ||
| agentId: state.currentAgentId, | ||
| ...(state.currentSessionId ? { parentSessionKey: state.currentSessionKey } : {}), |
There was a problem hiding this comment.
Keep parent linkage when /new follows the first run
When a TUI starts on an empty session, the first sendChat creates the backend session but can leave state.currentSessionId null because the send result only carries run id/status and displayable final events intentionally skip loadHistory(). In that normal path, /new reaches this spread without parentSessionKey, so createGatewaySession skips the command/session lifecycle hooks and plugins never receive the completed parent transcript this change is meant to provide. Use the current key, or refresh/record the session id after the first accepted run, instead of gating parent linkage solely on currentSessionId.
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. Reviewed July 5, 2026, 9:33 AM ET / 13:33 UTC. Summary PR surface: Source +228, Tests +320. Total +548 across 16 files. Reproducibility: yes. Source inspection shows current main and Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Land the shared Gateway-owned create lifecycle after maintainer signoff on the stricter TUI Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows current main and Is this the best way to solve the issue? Yes, with maintainer signoff. Reusing the shared Gateway session-create lifecycle is cleaner than adding a TUI-only synthetic hook, and the current head removed the earlier changelog defect. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against db96218c0562. Label changesLabel justifications:
Evidence reviewedPR surface: Source +228, Tests +320. Total +548 across 16 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (4 earlier review cycles)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3dcf01c4ae
ℹ️ 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".
| break; | ||
| } | ||
| case "new": | ||
| if (hasUnsafeSessionRollover()) { |
There was a problem hiding this comment.
Block duplicate /new while creation is pending
If the user submits /new again before the first client.createSession() resolves, createEditorSubmitHandler fire-and-forgets handleCommand (src/tui/tui-submit.ts:39), so the second invocation reaches this branch with sessionCreationInFlight already true but no active run and starts another backend session from the same parent. That can emit duplicate command:new/lifecycle hooks for the same parent and leave one created session unadopted; treat sessionCreationInFlight as an unsafe rollover before starting another create.
Useful? React with 👍 / 👎.
3dcf01c to
a27b3a1
Compare
|
Maintainer verification complete on exact head Fixups made after the first CI pass:
Proof:
The live paths prove The required changelog entry and issue credit are being aggregated into the final maintainer changelog commit on #91002, avoiding repeated runtime-CI invalidation from unrelated |
da09444 to
06df391
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06df391c88
ℹ️ 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".
|
|
||
| - **Control UI terminal tabs:** vertically center the new-session button in the terminal tab strip. | ||
| - **Control UI composer scrollbar:** show the message-field scrollbar only when the draft actually overflows its autosized height. | ||
| - **TUI new-session hooks:** create `/new` sessions through the shared Gateway lifecycle so command and session hooks receive the completed parent transcript in both Gateway and embedded modes, while preventing rollover during an active turn. (#49918) Thanks @BingqingLyu. |
There was a problem hiding this comment.
Remove the manual changelog entry
This change adds a normal PR fix directly to CHANGELOG.md, but the root AGENTS.md says CHANGELOG.md is release-only and normal PRs/direct fixes should put release-note context in the PR body, squash message, or direct commit instead. Leaving this here bypasses the release-generation flow and can make the already-generated release notes drift or duplicate this entry when the release changelog is regenerated.
Useful? React with 👍 / 👎.
06df391 to
52d3a89
Compare
b6a7974 to
1c52ed1
Compare
5930d61 to
2b556a2
Compare
|
Merged via squash.
|
* fix(tui): run new sessions through lifecycle hooks Co-authored-by: chunqiu <[email protected]> * test(tui): wait for idle before PTY new-session checks * docs(changelog): defer TUI batch entries --------- Co-authored-by: chunqiu <[email protected]>
What Problem This Solves
TUI
/newswitched to an empty local key without running the existing Gateway session-creation lifecycle. Command hooks,before_reset,session_end, andsession_starttherefore missed TUI new-session transitions, so features such as session-memory hooks could not capture the completed parent conversation. Fixes #49918. Builds on the lifecycle-hook direction suggested in BingqingLyu#1006.Why This Change Was Made
sessions.createlifecycle into one shared Gateway-owned service.User Impact
/newnow starts a genuinely persisted fresh TUI session and fires the same hook lifecycle in Gateway and--localmodes. The parent transcript is complete before hooks run. If a turn is active or finishing, the TUI asks the user to abort or wait instead of racing the rollover.Evidence
node scripts/run-vitest.mjs src/gateway/server.sessions.create.test.ts src/gateway/server.sessions.reset-hooks.test.ts src/tui/embedded-backend.test.ts src/tui/tui-command-handlers.test.ts src/tui/tui-session-actions.test.ts src/tui/tui-pty-harness.e2e.test.ts— 70 Gateway, 172 TUI, and 14 PTY tests passed after rebase.OPENCLAW_TUI_PTY_INCLUDE_LOCAL=1 node scripts/run-vitest.mjs src/tui/tui-pty-local.e2e.test.ts— 5 real-backend PTY scenarios passed; both embedded--localand Gateway modes created/adopted canonicalagent:main:tui-*sessions and sent a fresh turn through the mocked Responses endpoint.tbx_01kwrjhsjn8geh91q5w6rnh5j3— strict core TypeScript passed; finalcheck:changedis running on the rebased commit..agents/skills/autoreview/scripts/autoreview --mode local --stream-engine-output— clean, no accepted/actionable findings (overall confidence 0.91).