Stop showing the held tool call as running during a pause

This commit is contained in:
Ian Gulliver
2026-10-22 22:14:19 -07:00
parent 293c21ca8c
commit 11e21bcf18
6 changed files with 42 additions and 12 deletions
+2 -2
View File
@@ -205,7 +205,7 @@ func (m *Manager) agyBeforeModel(l *live) hookcmd.Func {
if in.InvocationNum == 0 || l.reviewID != "" {
return map[string]any{}, nil
}
m.holdWhilePaused(ctx, l)
m.holdWhilePaused(ctx, l, "")
mt := m.deliverMidTurn(ctx, l)
if mt.text == "" {
return map[string]any{}, nil
@@ -216,7 +216,7 @@ func (m *Manager) agyBeforeModel(l *live) hookcmd.Func {
func (m *Manager) agyBeforeTool(l *live) hookcmd.Func {
return func(ctx context.Context, input json.RawMessage) (map[string]any, error) {
if !m.heldBeforeTool(ctx, l) || !m.midTurnWaiting(ctx, l) {
if !m.heldBeforeTool(ctx, l, "") || !m.midTurnWaiting(ctx, l) {
return map[string]any{"decision": "allow"}, nil
}
return map[string]any{"decision": "deny", "reason": pausedCallNotice}, nil
+1 -1
View File
@@ -209,7 +209,7 @@ func (m *Manager) steerMidTurn(ctx context.Context, l *live, s *codex.Session) {
func (m *Manager) codexAfterTool(l *live) hookcmd.Func {
return func(ctx context.Context, input json.RawMessage) (map[string]any, error) {
if m.holdWhilePaused(ctx, l) && ctx.Err() == nil {
if m.holdWhilePaused(ctx, l, "") && ctx.Err() == nil {
m.steerMidTurn(context.WithoutCancel(ctx), l, l.sess.(codexProcess).s)
}
return map[string]any{}, nil
+19 -5
View File
@@ -131,7 +131,15 @@ func (m *Manager) isPaused(sessionID string) bool {
return m.paused[sessionID] != nil
}
func (m *Manager) holdWhilePaused(ctx context.Context, l *live) bool {
func hookToolUseID(input json.RawMessage) string {
in := struct {
ToolUseID string `json:"tool_use_id"`
}{}
json.Unmarshal(input, &in)
return in.ToolUseID
}
func (m *Manager) holdWhilePaused(ctx context.Context, l *live, toolUseID string) bool {
held := false
for {
m.mu.Lock()
@@ -141,7 +149,13 @@ func (m *Manager) holdWhilePaused(ctx context.Context, l *live) bool {
return held
}
if !held {
slog.Info("agent held by pause", "session", l.id)
slog.Info("agent held by pause", "session", l.id, "tool_use_id", toolUseID)
if toolUseID != "" {
err := m.emit(context.WithoutCancel(ctx), l, agentActor, "agent.held", map[string]any{"tool_use_id": toolUseID})
if err != nil {
slog.Error("record held tool call", "session", l.id, "err", err)
}
}
}
held = true
select {
@@ -152,13 +166,13 @@ func (m *Manager) holdWhilePaused(ctx context.Context, l *live) bool {
}
}
func (m *Manager) heldBeforeTool(ctx context.Context, l *live) bool {
return m.holdWhilePaused(ctx, l) && ctx.Err() == nil
func (m *Manager) heldBeforeTool(ctx context.Context, l *live, toolUseID string) bool {
return m.holdWhilePaused(ctx, l, toolUseID) && ctx.Err() == nil
}
func (m *Manager) beforeTool(l *live) hookcmd.Func {
return func(ctx context.Context, input json.RawMessage) (map[string]any, error) {
if !m.heldBeforeTool(ctx, l) {
if !m.heldBeforeTool(ctx, l, hookToolUseID(input)) {
return map[string]any{}, nil
}
mt := m.deliverMidTurn(ctx, l)
+1 -1
View File
@@ -291,7 +291,7 @@ func (m *Manager) afterTool(l *live) hookcmd.Func {
if err != nil {
return nil, err
}
m.holdWhilePaused(ctx, l)
m.holdWhilePaused(ctx, l, hookToolUseID(input))
mt := m.deliverMidTurn(ctx, l)
if mt.text == "" {
return map[string]any{}, nil