Files
ppsspp/Core/Debugger/WebSocket/ClientConfigSubscriber.cpp
Henrik RydgårdandClaude Opus 5 a8933099b7 Make the deferred-request acknowledgement opt-in, and distinct
The acknowledgement added in "Reply to every debugger request" broke two cases
Nemoumbra pointed out, both of which come down to it reusing the request's own
event name.

A ticketless request is the bad one. {"event":"cpu.resume"} with no ticket drew
an immediate {"event":"cpu.resume"} - byte-identical to the broadcast that fires
when the game actually resumes. A client waiting for that broadcast concluded
the game was running while it was still stopped. Before, it correctly got
nothing until the resume really happened.

input.buttons.press is broken even with a ticket: it answers with the request's
own event name *and* ticket once the button has been held for the requested
frames, so the acknowledgement was indistinguishable from the real completion
and a client resolved on the first of the two. The claim in that commit that
the two are easy to tell apart was simply wrong for this handler.

So the acknowledgement is now off by default - the wire behaviour for every
existing client is exactly what it was - and a client that wants it asks, with
client.config.set {"acknowledgeDeferred": true}. It then arrives as its own
event rather than an echo:

  -> {"event":"cpu.resume","ticket":7}
  <- {"event":"deferred","for":"cpu.resume","ticket":7}
  <- {"event":"cpu.resume"}

which is unambiguous in both cases above. That still gets the original goal -
correlating any request to a reply without hardcoding which events answer
immediately, including ones added later - just without imposing it on clients
that never asked.

Also documents the ticket convention this rests on: send one when you care
about the answer, leave it off to say you aren't waiting. wsdbg followed that
convention badly, silently inserting a ticket into a raw JSON line that
deliberately omitted one; it now sends raw lines exactly as written and simply
doesn't wait on those. It opts into acknowledgements at connect, so --sync
keeps working.

pspautotests 314/314, UnitTest 55/55.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-18 09:32:04 +02:00

147 lines
5.4 KiB
C++

// Copyright (c) 2023- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "Core/Debugger/WebSocket/ClientConfigSubscriber.h"
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
#include "Common/StringUtils.h"
DebuggerSubscriber *WebSocketClientConfigInit(DebuggerEventHandlerMap & map) {
map["broadcast.config.get"] = &WebSocketBroadcastConfigGet;
map["broadcast.config.set"] = &WebSocketBroadcastConfigSet;
map["client.config.get"] = &WebSocketClientConfigGet;
map["client.config.set"] = &WebSocketClientConfigSet;
return nullptr;
}
// Request the current client broadcast configuration (broadcast.config.get)
//
// No parameters.
//
// Response (same event name):
// - disallowed: object with optional boolean fields:
// - logger: whether logger events are disallowed
// - game: whether game events are disallowed
// - stepping: whether stepping events are disallowed
// - input: whether input events are disallowed
void WebSocketBroadcastConfigGet(DebuggerRequest & req) {
JsonWriter &json = req.Respond();
const auto& disallowed_config = req.client->disallowed;
json.pushDict("disallowed");
for (const auto &[name, status] : disallowed_config) {
if (status)
json.writeBool(name, true);
}
json.end();
}
// Request the current per-connection client settings (client.config.get)
//
// No parameters.
//
// Response (same event name):
// - acknowledgeDeferred: boolean, whether "deferred" events are being sent.
void WebSocketClientConfigGet(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
json.writeBool("acknowledgeDeferred", req.client->acknowledgeDeferred);
}
// Update the per-connection client settings (client.config.set)
//
// Parameters (all optional):
// - acknowledgeDeferred: boolean, whether to send a "deferred" event when a request is accepted
// but only finishes later (cpu.resume, cpu.stepInto and friends, gpu.stats.feed,
// input.buttons.press.) Defaults to false.
//
// Response (same event name):
// - acknowledgeDeferred: boolean, the setting as it now stands.
//
// Turning this on lets a client tell "accepted, the result comes in a later event" from "dropped
// on the floor", without hardcoding which events those are. It can't be the default, and can't
// simply reuse the request's own event name, because that's what the later event already uses:
// a client waiting for a bare {"event":"cpu.resume"} would believe the game was running while it
// was still stopped, and input.buttons.press answers with the request's own ticket when the press
// completes, so an early reply under that name would be indistinguishable even with a ticket.
void WebSocketClientConfigSet(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
bool acknowledgeDeferred = req.client->acknowledgeDeferred;
if (!req.ParamBool("acknowledgeDeferred", &acknowledgeDeferred, DebuggerParamType::OPTIONAL))
return;
req.client->acknowledgeDeferred = acknowledgeDeferred;
json.writeBool("acknowledgeDeferred", req.client->acknowledgeDeferred);
}
// Update the current client broadcast configuration (broadcast.config.set)
//
// Parameters:
// - disallowed: object with boolean fields (all of them are optional):
// - logger: new logger config state
// - game: new game config state
// - stepping: new stepping config state
// - input: new input config state
//
// Response (same event name):
// - disallowed: object with optional boolean fields:
// - logger: whether logger events are now disallowed
// - game: whether game events are now disallowed
// - stepping: whether stepping events are now disallowed
// - input: whether input events are now disallowed
void WebSocketBroadcastConfigSet(DebuggerRequest & req) {
JsonWriter &json = req.Respond();
auto& disallowed_config = req.client->disallowed;
const JsonNode *jsonDisallowed = req.data.get("disallowed");
if (!jsonDisallowed) {
return req.Fail("Missing 'disallowed' parameter");
}
if (jsonDisallowed->value.getTag() != JSON_OBJECT) {
return req.Fail("Invalid 'disallowed' parameter type");
}
for (const JsonNode *broadcaster : jsonDisallowed->value) {
auto it = disallowed_config.find(broadcaster->key);
if (it == disallowed_config.end()) {
return req.Fail(StringFromFormat("Unsupported 'disallowed' object key '%s'", broadcaster->key));
}
if (broadcaster->value.getTag() == JSON_TRUE) {
it->second = true;
}
else if (broadcaster->value.getTag() == JSON_FALSE) {
it->second = false;
}
else if (broadcaster->value.getTag() != JSON_NULL) {
return req.Fail(StringFromFormat("Unsupported 'disallowed' object type for key '%s'", broadcaster->key));
}
}
json.pushDict("disallowed");
for (const auto &[name, status] : disallowed_config) {
if (status)
json.writeBool(name, true);
}
json.end();
}