The question:
I have a Hilbert space $\mathcal{H}=\mathcal{H}_A\otimes \mathcal{H}_B$, and a codespace $\mathcal{H}_{code}\subset \mathcal{H}$, so that $\mathcal{H}=\mathcal{H}_{code}\oplus\mathcal{H}_\perp$. I know that for all $\psi,\phi\in \mathcal{H}_{code}$, and for all $\mathcal{O}_A=\mathcal{O}_A\otimes \mathcal{I}_B$, we have
$$\langle\phi|[\mathcal{O}_A,\mathcal{O}]|\psi\rangle =0$$
I would like to know what I can conclude about the operator $\mathcal{O}$ from this.
Some thoughts:
Without the projection into the codespace, we could conclude that $\mathcal{O}=\mathcal{O}_B$. With the projection, the most general thing I can think to write down that satisfies the constraint is
$$\mathcal{O}=\mathcal{O}_B + \Pi_\perp \mathcal{O}'\Pi_\perp$$
for any operator $\mathcal{O}'$, where $\Pi_\perp$ projects onto $\mathcal{H}_\perp$. There may be a more general expression, however.
The most related statements I have found occur in the context of operator algebra quantum error correction. For instance (see for instance Preskill and Pastawski, theorem 1) the condition to correct a noise channel $\mathcal{N}(\cdot)=\sum_k N_k(\cdot )N_k^\dagger$ with respect to an algebra $\mathcal{A}$ is that
$$[X,\Pi N_k^\dagger N_l \Pi]=0$$
for all $X\in \mathcal{A}$ and all Kraus operators $N_l,N_k$. This looks like my condition if I took $\mathcal{O}_A$ to be a logical operator. This has lead me to study von Neumann algebras and the theory of operator algebra quantum error correction, but so far this has not been fruitful in answering my original question.