In the 1st launch with the given context and resource link getRecordId() returns null because the context is not yet in the database. That is why lti2_resource_link.context_pk is null.
Following link launch fixes the situation.
Ideally, the context should be set to resource link after the context was saved to the database e.g.
on the line 1155 reset the context
if (!empty($this->context)) {
$this->resourceLink->setContextId($this->context->getRecordId());
}
https://github.com/Izumi-kun/LTI-Tool-Provider-Library-PHP/blob/df420fea8f7b3ec651a0d382ad36696f70346153/src/ToolProvider/ToolProvider.php#L1005
In the 1st launch with the given context and resource link getRecordId() returns null because the context is not yet in the database. That is why lti2_resource_link.context_pk is null.
Following link launch fixes the situation.
Ideally, the context should be set to resource link after the context was saved to the database e.g.
on the line 1155 reset the context if (!empty($this->context)) { $this->resourceLink->setContextId($this->context->getRecordId()); }