qioo777 opened a new pull request, #228:
URL: https://github.com/apache/casbin-gateway/pull/228

   ### Problem
   
   Starting a Codex sign-in and then closing the authorization page without 
completing it leaves Gateway refusing every later attempt with `a sign-in is 
already waiting for the browser`.
   
   The agent has no way to see that page close, so the `codex login` process 
keeps running with its OAuth listener open and the session stays `Running`. 
`StartLogin` scanned every session ever recorded and matched that one, so 
nothing but the ten-minute timeout ever cleared it. The dialog's Cancel button 
only dropped the session in the page — the process, the port and the backend 
state were all left behind.
   
   ### Fix
   
   - One sign-in holds one slot, released on every ending: success, failure, 
cancellation and timeout. `finish` applies once, so the first answer stands and 
later calls are no-ops.
   - Cancelling is a real action. `POST /api/cancel-agent-signin` stops the 
agent and frees the port; closing the sign-in dialog calls it.
   - The agent is stopped as a process tree (`taskkill /F /T` on Windows, 
process group elsewhere). Codex is usually reached through a shim, and killing 
the shim alone would leave the child holding the port.
   - Finished sessions are forgotten once nothing is polling them instead of 
accumulating.
   
   The timeout stays at ten minutes. It is the last resort behind an explicit 
cancel, and shortening it would cut a slow sign-in short.
   
   ### Validation
   
   `agentauth/login_test.go` drives the real child-process lifecycle, using the 
test binary as a stand-in agent that waits for a browser, fails, or signs in. 
It covers the reported case (cancel after an abandoned page, then retry), a 
second sign-in still being refused while one genuinely waits, release after 
failure, success and timeout, cancel being idempotent, and finished sessions 
being forgotten.
   
   - `go build ./...` — passes, and cross-compiles for `linux` and `darwin`
   - `go vet ./...` — passes
   - `go test ./agentauth/...` — 8 tests pass
   - `cd web && npm run lint` — passes
   - `cd web && npm run build` — passes
   
   `object` and `sync` fail on this machine for want of a local MySQL, 
identically on unmodified `master`; unrelated to this change. The race detector 
was unavailable here (no C compiler), so the tests were not run under `-race`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to