Clamp agent-facing remaining_pending
This commit is contained in:
@@ -32,6 +32,8 @@ const (
|
||||
// Note: it does NOT reset application-level wall-clock timers
|
||||
// (e.g. the Copilot 60 s limit), which are unaffected by SSE bytes.
|
||||
keepaliveInterval = 5 * time.Second
|
||||
|
||||
minAgentVisibleRemainingPending = 5
|
||||
)
|
||||
|
||||
// Handler wraps the MCP server and holds references to the stores it needs.
|
||||
@@ -237,7 +239,7 @@ func (h *Handler) deliverInstruction(ctx context.Context, item *models.Instructi
|
||||
"consumed_at": item.ConsumedAt,
|
||||
},
|
||||
"response": nil,
|
||||
"remaining_pending": counts.PendingCount,
|
||||
"remaining_pending": agentVisibleRemainingPending(counts.PendingCount),
|
||||
"waited_seconds": waited,
|
||||
}
|
||||
return mcp.NewToolResultText(jsonMarshalStr(result)), nil
|
||||
@@ -255,12 +257,19 @@ func emptyResult(waited int) *mcp.CallToolResult {
|
||||
"result_type": resultType,
|
||||
"instruction": nil,
|
||||
"response": resp,
|
||||
"remaining_pending": 0,
|
||||
"remaining_pending": agentVisibleRemainingPending(0),
|
||||
"waited_seconds": waited,
|
||||
}
|
||||
return mcp.NewToolResultText(jsonMarshalStr(result))
|
||||
}
|
||||
|
||||
func agentVisibleRemainingPending(actualPending int) int {
|
||||
if actualPending < minAgentVisibleRemainingPending {
|
||||
return minAgentVisibleRemainingPending
|
||||
}
|
||||
return actualPending
|
||||
}
|
||||
|
||||
func jsonMarshalStr(v any) string {
|
||||
b, _ := json.Marshal(v)
|
||||
return string(b)
|
||||
|
||||
Reference in New Issue
Block a user