Repository: hyperledger/aries-cloudagent-python

Issue:
Prover mixes up thread_id in present-proof/send-proposal flow
I have another one, but this time it shouldn't be about duplicated api calls ;)

version: from rc2
wallet-type: indy or askar
role: prover

- Prover sends proof proposal via /present-proof/send-proposal, auto_present=true
- Verifier receives event:
```json
{
    "@type": "https://didcomm.org/present-proof/1.0/propose-presentation",
    "@id": "3b7403c8-bf0c-4718-a7c8-f95fa27e9ed9",
    "presentation_proposal": {
        "@type": "https://didcomm.org/present-proof/1.0/presentation-preview",
        "attributes": [
            {
                "name": "bic",
                "cred_def_id": "F6dB7dMVHUQSC64qemnBi7:3:CL:571:phil-test-83-multi",
                "value": "qwertz-01"
            },
            {
                "name": "iban",
                "cred_def_id": "F6dB7dMVHUQSC64qemnBi7:3:CL:571:phil-test-83-multi",
                "value": "qwertz-01"
            }
        ],
        "predicates": []
    }
}
```
- Verifier request presentation
- Prover sends presentation
- Verifier receives presentation
```json
 {
    "@type": "https://didcomm.org/present-proof/1.0/presentation",
    "@id": "1a632114-4324-4b1f-83ad-fac9287c954c",
    "presentations~attach": [
        {
            "@id": "libindy-presentation-0",
            "mime-type": "application/json",
            "data": "truncated"
        }
    ]
}
```
- Verifier fails with:

```json
aries_cloudagent.storage.error.StorageNotFoundError: V10PresentationExchange record not found for {'thread_id': '1a632114-4324-4b1f-83ad-fac9287c954c'}, {'role': 'verifier', 'connection_id': 'ebf94709-bb1b-488b-93b3-b540fe0bcb10'}
```

It looks like the prover mixes up the thread id, but only when using send-proposal, if the verifier starts the exchange with present-proof/send-request it works.


Discussion:
I have been able to replicate the issue, working on a fix.

Resolving patch:
diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/presentation_request_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/presentation_request_handler.py
--- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/presentation_request_handler.py
+++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/presentation_request_handler.py
@@ -80,6 +80,10 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
                         "connection_id": connection_id,
                     },
                 )  # holder initiated via proposal
+                presentation_exchange_record.presentation_request = indy_proof_request
+                presentation_exchange_record.presentation_request_dict = (
+                    context.message.serialize()
+                )
         except StorageNotFoundError:  # verifier sent this request free of any proposal
             presentation_exchange_record = V10PresentationExchange(
                 connection_id=connection_id,
@@ -94,7 +98,6 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
                 trace=(context.message._trace is not None),
             )
 
-        presentation_exchange_record.presentation_request = indy_proof_request
         presentation_exchange_record = await presentation_manager.receive_request(
             presentation_exchange_record
         )  # mgr only saves record: on exception, saving state null is hopeless


Test patch: