{"record":{"id":"beea45f7aa94f43c","repo":"apple/pkl","slug":"unknownrequestid","errorCode":"unknownRequestId","errorMessage":"unknownRequestId","messagePattern":"unknownRequestId","errorType":"error_code","errorClass":"ProtocolException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/messaging/MessageTransports.java","lineNumber":163,"sourceCode":"      logger.log(formatter.format(args));\n    }\n\n    protected abstract void doStart() throws ProtocolException, IOException;\n\n    protected abstract void doClose();\n\n    protected abstract void doSend(Message message) throws ProtocolException, IOException;\n\n    protected void accept(Message message) throws ProtocolException {\n      log(\"Received message: {0}\", message);\n      if (message instanceof Message.OneWay msg) {\n        oneWayHandler.handleOneWay(msg);\n      } else if (message instanceof Message.Request msg) {\n        requestHandler.handleRequest(msg);\n      } else if (message instanceof Message.Response msg) {\n        var handler = responseHandlers.remove(msg.requestId());\n        if (handler == null) {\n          throw new ProtocolException(\n              ErrorMessages.create(\n                  \"unknownRequestId\", message.getClass().getSimpleName(), msg.requestId()));\n        }\n        handler.handleResponse(msg);\n      }\n    }\n\n    @Override\n    public final void start(OneWayHandler oneWayHandler, RequestHandler requestHandler)\n        throws ProtocolException, IOException {\n      log(\"Starting transport: {0}\", this);\n      this.oneWayHandler = oneWayHandler;\n      this.requestHandler = requestHandler;\n      doStart();\n    }\n\n    @Override\n    public final void close() {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/messaging/MessageTransports.java#L145-L181","documentation":"When a Response message arrives, accept() looks up its requestId in the responseHandlers map and removes it. If no handler is registered for that requestId, a ProtocolException with code unknownRequestId is thrown, since the library cannot route the response to any pending request.","triggerScenarios":"A Response arrives whose requestId was never registered, was already completed/removed (duplicate response), or whose handler map was cleared (e.g. after transport close/restart).","commonSituations":"Duplicate responses from a misbehaving external reader; requests cancelled/timed out locally and removed from the map just before the response arrives; requestId collisions after reusing or restarting a transport; version-mismatched peers generating wrong ids.","solutions":["Check for duplicate or late responses from the peer and drop responses for unknown ids before calling accept()","Verify the external reader generates unique, monotonic requestIds matching those sent","Avoid cancelling/removing handlers while responses may still be in flight, or handle unknown ids gracefully","Restart the whole transport session cleanly instead of reusing stale handler state"],"exampleFix":"// before\ntransport.accept(response); // throws unknownRequestId\n// after\nif (transport.hasPendingRequest(response.requestId())) {\n  transport.accept(response);\n} else {\n  LOG.warn(\"Ignoring stale response for request \" + response.requestId());\n}","handlingStrategy":"try-catch","validationCode":"if (msg instanceof Message.Response r && !pendingRequests.containsKey(r.requestId())) { LOG.warn(\"dropping stale response \" + r.requestId()); return; }","typeGuard":"boolean isKnownResponse(Message m, Map<Long, ResponseHandler> pending) { return m instanceof Message.Response r && pending.containsKey(r.requestId()); }","tryCatchPattern":"try { transport.accept(msg); } catch (ProtocolException e) { if (\"unknownRequestId\".equals(((ProtocolException) e).getErrorCode())) { LOG.warn(\"stale/duplicate response ignored\"); } else { throw e; } }","preventionTips":["Track pending request ids and validate responses before accept()","Remove handlers only after giving late responses a grace period","Ensure peers generate unique request ids","Restart transports fully rather than reusing handler maps"],"tags":["java","messaging","request-id","protocol"],"backgroundTag":"unknown-request-id","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}