Route Codex approvals to Telegram
Force app-server turns to use the user approval reviewer so command approvals surface in the bot on Codex 0.134. Add focused protocol logs for approval requests and guardian review events to diagnose silent approval stalls.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -26,6 +27,7 @@ type Client struct {
|
||||
pending map[string]chan rpcResult
|
||||
events chan Event
|
||||
connected bool
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
@@ -151,6 +153,12 @@ func New(socketPath, version string) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) SetLogger(logger *log.Logger) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.logger = logger
|
||||
}
|
||||
|
||||
func (c *Client) Events() <-chan Event {
|
||||
return c.events
|
||||
}
|
||||
@@ -240,10 +248,11 @@ func (c *Client) StartThread(ctx context.Context, cwd, model, sandbox string) (T
|
||||
return Thread{}, err
|
||||
}
|
||||
params := map[string]any{
|
||||
"cwd": cwd,
|
||||
"approvalPolicy": "on-request",
|
||||
"sandbox": threadSandbox(sandbox),
|
||||
"serviceName": "codex_telegram_bot",
|
||||
"cwd": cwd,
|
||||
"approvalPolicy": "on-request",
|
||||
"approvalsReviewer": "user",
|
||||
"sandbox": threadSandbox(sandbox),
|
||||
"serviceName": "codex_telegram_bot",
|
||||
}
|
||||
if model != "" {
|
||||
params["model"] = model
|
||||
@@ -327,9 +336,10 @@ func (c *Client) StartTurn(ctx context.Context, threadID, cwd, model, reasoningE
|
||||
return Turn{}, err
|
||||
}
|
||||
params := map[string]any{
|
||||
"threadId": threadID,
|
||||
"input": input,
|
||||
"approvalPolicy": "on-request",
|
||||
"threadId": threadID,
|
||||
"input": input,
|
||||
"approvalPolicy": "on-request",
|
||||
"approvalsReviewer": "user",
|
||||
}
|
||||
if strings.TrimSpace(cwd) != "" {
|
||||
params["cwd"] = cwd
|
||||
@@ -463,6 +473,7 @@ func (c *Client) readLoop(conn *websocket.Conn) {
|
||||
return
|
||||
}
|
||||
if env.Method != "" && hasID {
|
||||
c.logProtocolEvent("server request", env.Method, id.Key(), env.Params)
|
||||
c.events <- Event{
|
||||
ID: &id,
|
||||
Method: env.Method,
|
||||
@@ -476,6 +487,9 @@ func (c *Client) readLoop(conn *websocket.Conn) {
|
||||
continue
|
||||
}
|
||||
if env.Method != "" {
|
||||
if shouldLogNotification(env.Method) {
|
||||
c.logProtocolEvent("notification", env.Method, "", env.Params)
|
||||
}
|
||||
c.events <- Event{
|
||||
Method: env.Method,
|
||||
Params: env.Params,
|
||||
@@ -484,6 +498,29 @@ func (c *Client) readLoop(conn *websocket.Conn) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) logProtocolEvent(kind, method, id string, params json.RawMessage) {
|
||||
c.mu.Lock()
|
||||
logger := c.logger
|
||||
c.mu.Unlock()
|
||||
if logger == nil {
|
||||
return
|
||||
}
|
||||
if id != "" {
|
||||
logger.Printf("codex %s: method=%s id=%s params_bytes=%d", kind, method, id, len(params))
|
||||
return
|
||||
}
|
||||
logger.Printf("codex %s: method=%s params_bytes=%d", kind, method, len(params))
|
||||
}
|
||||
|
||||
func shouldLogNotification(method string) bool {
|
||||
switch method {
|
||||
case "item/guardianApprovalReview/started", "item/guardianApprovalReview/completed", "guardianWarning", "serverRequest/resolved":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) completeCall(id RequestID, result json.RawMessage, rpcErr *RPCError) {
|
||||
c.mu.Lock()
|
||||
ch := c.pending[id.Key()]
|
||||
|
||||
Reference in New Issue
Block a user