Skip to content

fix(cli): start fresh TUI Sessions at the default permission mode - #3021

Merged
Astro-Han merged 1 commit into
apache:mainfrom
me2seeks:fix/cli-new-session-permission-reset
Aug 15, 2026
Merged

Astro-Han merged 1 commit into
apache:mainfrom
me2seeks:fix/cli-new-session-permission-reset

Conversation

@me2seeks

Copy link
Copy Markdown
Contributor

Summary

In the TUI, elevating a session to Full access (bypass) and then running /new silently carried the elevation into the fresh session: the status line kept showing Full access, and the next prompt created the new session with permissionMode: 'bypass' — tools ran with direct file/network access in a session the user never elevated.

startNewSession() cleared the session binding and the boundary display mode, but not the base #permissionMode that session.create uses. The fix captures the construction-time default (#defaultPermissionMode, what the TUI passes at cold start — ask) and resets to it in startNewSession(). This matches the desktop model, where a new chat uses the settings-backed default rather than the previously viewed session's mode, and keeps Full access an explicit per-session opt-in: setPermissionMode before the first prompt still raises the fresh session.

Fixes #3020

Verification

  • packages/cli suite: 260/260 pass (includes the new regression test).
  • Mutation check: with the reset line removed, the new test fails with 'bypass' !== 'ask'; restored, it passes.
  • End-to-end driver script (reproduces the exact TUI path: setPermissionMode('bypass') → startNewSession() → preparePrompt()): before — getPermissionMode() after /new returned bypass and the new session.create carried bypass; after — both are ask.
  • biome check clean on both touched files.
  • Not run: full monorepo suite and desktop/e2e suites (change is confined to packages/cli; left to CI).

Security

This changes security-relevant behavior (permission/boundary mode of newly created sessions). Per the review policy and the contributor's request, the fast path does not apply: this PR requires independent review by another human before merge (AI review does not count), in addition to the human contributor of record.

Prepared with AI assistance (Maka agent); the investigation, reproduction, and fix were reviewed by the human contributor. The final commit carries Generated-by: Maka — please keep the trailer when squash-merging.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Elevating a Session to Full access and starting a fresh one with /new
leaked the elevation: the status line kept showing Full access and the
next prompt created the new Session with bypass. startNewSession
cleared the boundary display mode but not the base permission mode
that session.create uses.

Capture the construction-time default and reset to it in
startNewSession, matching the desktop model where a new chat uses the
configured default rather than the previous Session's mode. Full
access stays an explicit per-session opt-in: setPermissionMode before
the first prompt still raises the fresh Session.

Fixes apache#3020

Generated-by: Maka

@Astro-Han Astro-Han 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.

Thanks — this is a small, well-contained fix at the right lifecycle boundary.

I traced the TUI path from /new through startNewSession() and the next preparePrompt() into the actual session.create request. Resetting the driver’s seed permission prevents Full access from leaking across Sessions, while resumed Sessions continue to take their configuration and execution boundary from the Runtime Host. The control lock also prevents /new from racing an in-flight permission change.

The regression test exercises the production driver seam and is mutation-sensitive. The focused CLI suite passes 260/260, and CI is green.

One non-blocking suggestion: because the new field is described as the construction-time default rather than specifically ask, consider using a non-ask value in a small parameterized assertion. That would distinguish the intended implementation from a future hard-coded this.#permissionMode = 'ask'. All current TUI production callers pass ask, so I do not consider this necessary for merge.

Approved.

中文对照

感谢,这是一项边界清楚、落点正确的小修复。

我核对了从 TUI /new、startNewSession() 到下一次 preparePrompt() 和实际 session.create 请求的完整链路。重置 driver 用于创建新 Session 的初始权限,可以阻止 Full access 跨 Session 泄漏;恢复已有 Session 时,配置和 execution boundary 仍然由 Runtime Host 决定。control lock 也避免了 /new 与进行中的权限切换发生竞态。

回归测试命中了生产 driver seam,并且删除重置代码后会失败。CLI 聚焦测试 260/260 通过,CI 全绿。

有一个非阻塞的小建议:新增字段表达的是“构造时传入的默认值”,而不只是固定的 ask。可以考虑用一个非 ask 值补充参数化断言,从而防止未来被简化成硬编码的 this.#permissionMode = 'ask'。当前所有 TUI 生产调用点都明确传入 ask,所以这不影响本次合并。

批准。

Disclosure: This review was prepared with assistance from OpenAI Codex and Claude Opus. I reviewed the evidence, verified the production path and focused tests, and made the final judgment.

@Astro-Han
Astro-Han merged commit 1a71db5 into apache:main Aug 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): TUI /new leaks the previous session's Full access (bypass) into the fresh session

2 participants