permission prompts: route left registered when a request is not held; check CliSession's abandon path

Open
#9,099 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js
Domain
backend, testing

Research direction

Start in packages/server/src/ws-permissions.js and trace handlePermissionRequest, registerPermissionRoute, and cleanup() to identify everything the throw path must release; add a test proving route teardown occurs after a broadcast failure. Then inspect CliSession._onLastPermissionResolved and packages/server/tests/permission-deadline-chain.test.js, especially the production release path and the PTY-gone case. Done when both timer behavior and the teardown comment match the acceptance criteria.

Written by the indexing model from the issue text.

Description

enhancement from-review

Context

Filed from: #9091

Identified during the fix-delta review of PR #9091 (refs #8529). None of these changes what that PR delivers.

Description

Three small follow-ups around what happens to a hook-routed permission prompt that is abandoned or never held.

  1. A request the handler fails to hold leaves its route registered. In packages/server/src/ws-permissions.js, handlePermissionRequest registers the permission route (registerPermissionRoute, or permissionSessionMap.set) before it broadcasts the prompt. If a later step throws, the catch answers 500 and, since #9091, tells the owning session the prompt ended, but it does not call tearDownRoute(requestId) the way cleanup() does. The map entry and the permission-induced subscription then outlive the request. The route leak predates #9091. No resend can resurrect the prompt, because resendPendingPermissions walks pendingPermissions.

  2. Check whether CliSession re-arms its timers while abandoning prompts. BaseSession._expirePendingPermissions emits permission_expired before it clears the id set, and the daemon's release comes back synchronously through notifyPermissionResolved. ClaudeTuiSession now guards against that re-arm (#9091). CliSession._onLastPermissionResolved has the same shape (if (this._isBusy) this._armResultTimeout()). Whether its callers clear the timers afterwards on every path has not been checked.

  3. Say which teardown case exercises the abandon latch. In packages/server/tests/permission-deadline-chain.test.js, of the five "with a prompt pending abandons it" cases only the PTY-gone case fails when the latch is removed; the other four pass because their teardown clears the timers afterwards. A comment should say so, so the set is not read as five proofs of the latch.

Original Review Comment

The new catch tells the session the prompt ended, but it leaves the route that the same path registered (registerPermissionRoute, which writes the permissionSessionMap entry and the permission-induced subscription refcount). That route now outlives a request answered 500, so the session's view and the route map disagree. This leak is older than the delta; the delta made the cleanup partial rather than adding it.

Acceptance Criteria

  • The throw path releases everything cleanup() releases, with a test that fails when the route teardown is removed.
  • CliSession is shown, by a test wired to the production release path, either not to re-arm timers while abandoning prompts or to clear them on every teardown path; fixed if it does not.
  • The teardown tests' comment names the case that depends on the latch.
Dominant language
JavaScript
Stars
7
Forks
1
Avg merge
2h 3m
Merged PRs (30d)
333

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from blamechris/chroxy

All issues in blamechris/chroxy

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.