Input.is_action_just_pressed report true for two frames

Godot Version

Godot 4.3

Question

When awaiting a signal in a coroutine and that signal is emmited by checking an InputEvent, Input.is_action_just_pressed() will return true for the action associated with the event for two consecutive physics frames. Below is the code used to check:

func _input(event):
	print(event)
	if event is InputEventKey:
		if event.is_action_pressed("ui_up"):
			print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
			print("Emitting Signal \n")
			InputDetected.emit()

func coroutine_await_physics():
	print("Coroutine Start:")
	print("Is action pressed? ", Input.is_action_pressed("ui_up"))
	print("Is action just pressed? ", Input.is_action_just_pressed("ui_up"))
	print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
	print("Awaiting.....")
	print("Are we in physics frame? ", Engine.is_in_physics_frame(),"\n")
	await InputDetected
	print("After Signal:")
	print("Is action pressed? ", Input.is_action_pressed("ui_up"))
	print("Is action just pressed? ", Input.is_action_just_pressed("ui_up"))
	print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
	print("Are we in physics frame? ", Engine.is_in_physics_frame(),"\n")
	await get_tree().physics_frame
	print("After await frame:")
	print("Is action pressed? ", Input.is_action_pressed("ui_up"))
	print("Is action just pressed? ", Input.is_action_just_pressed("ui_up"))
	print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
	print("Are we in physics frame? ", Engine.is_in_physics_frame(),"\n")
	await get_tree().physics_frame
	print("After second await frame")
	print("Is action pressed? ", Input.is_action_pressed("ui_up"))
	print("Is action just pressed? ", Input.is_action_just_pressed("ui_up"))
	print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
	print("Are we in physics frame? ", Engine.is_in_physics_frame(),"\n")

the terminal output:

InputEventKey: keycode=4194320 (Up), mods=none, physical=false, location=unspecified, pressed=true, echo=false
Phyiscs Frame 125 Process Frame 165
Emitting Signal 

After Signal:
Is action pressed? true
Is action just pressed? true
Phyiscs Frame 125 Process Frame 165
Are we in physics frame? false

After await frame:
Is action pressed? true
Is action just pressed? true
Phyiscs Frame 126 Process Frame 165
Are we in physics frame? true

After second await frame
Is action pressed? true
Is action just pressed? false
Phyiscs Frame 127 Process Frame 167
Are we in physics frame? true

InputEventKey: keycode=4194320 (Up), mods=none, physical=false, location=unspecified, pressed=false, echo=false

I was going to open an issue but wanted to double check if this is actually an expected behavior?

Possibly expected, from the docs:

While it is possible, to achieve the best performance, one should avoid making input checks during these callbacks. _process() and _physics_process() will trigger at every opportunity (they do not “rest” by default). In contrast, *_input() callbacks will trigger only on frames in which the engine has actually detected the input.

I think that remark is regarding the Input checks happening every frame for no reason where it can be limited to when events occur.

There is a problem with using the Input.is_action_just_pressed() in the *_input() function too. These functions get called at every key press and can trigger multiple times in one frame which will return true multiple times.

Also, the maintainers in github tend to agree that the Input singleton should be used in process/physics_process mainly.