larry-zy commented on PR #1596:
URL: https://github.com/apache/dubbo-admin/pull/1596#issuecomment-6383982204

   Reviewed head: `6ada40334596bc938829b349ac075a7a6bcbb480`. I found two 
implementation issues and an additional failure in the new frontend retry test.
   
   **[P1] Check the Session's active interaction before retrying a failed key**
   
   The existing-key retry branches in [Memory 
`PrepareInteraction`](https://github.com/apache/dubbo-admin/blob/6ada40334596bc938829b349ac075a7a6bcbb480/ai/store/memory/store.go#L761-L800)
 and [GORM 
`PrepareInteraction`](https://github.com/apache/dubbo-admin/blob/6ada40334596bc938829b349ac075a7a6bcbb480/ai/store/gorm/store.go#L813-L848)
 only inspect the interaction associated with the requested key. They create a 
replacement running Turn and overwrite the Session's active-interaction pointer 
without checking whether another interaction currently holds a live lease. The 
`SESSION_BUSY` check is in the later new-key branch and is skipped.
   
   Relevant assignments:
   
   ```go
   // Memory retry branch
   m.activeInteractions[sessionID] = interaction.ID
   
   // GORM retry branch
   tx.Model(&SessionModel{}).Where("id = ?", sessionID).
       Update("active_interaction_id", existing.ID)
   ```
   
   Reproduction, confirmed with both Memory and GORM/SQLite:
   
   1. Prepare key A, then fail A.
   2. Prepare a different key B with a live lease.
   3. Retry A with its original request hash while B is still running.
   4. A is accepted instead of returning `ErrSessionBusy`; writes to both A's 
and B's active Turns succeed.
   
   This breaks the one-running-interaction-per-Session guarantee and permits 
concurrent model/tool work for the same Session. Please check and atomically 
claim the Session's active interaction in the failed/expired-key recovery path 
as well. A retry blocked by B must leave B and the old A record unchanged. Add 
this sequence to the shared backend contracts.
   
   **[P2] Do not replay retained results after Session validation fails**
   
   The fallback in 
[`ai/store/gorm/store.go:906–917`](https://github.com/apache/dubbo-admin/blob/6ada40334596bc938829b349ac075a7a6bcbb480/ai/store/gorm/store.go#L906-L917)
 runs after any transaction error, although its comment describes only a 
concurrent unique-key insertion. It then queries the interaction table and 
returns completed results without rechecking Session authorization or lifecycle:
   
   ```go
   if existing.Status == conversationstore.InteractionStatusCompleted {
       return &conversationstore.PreparedInteraction{InteractionID: 
existing.ID, TurnID: existing.TurnID, Replayed: true, Result: existing.Result}, 
nil
   }
   ```
   
   I reproduced this by completing A, deleting its Session, then calling 
`PrepareInteraction` with A's original key/hash before asynchronous cleanup. 
GORM returns `Replayed=true` and the retained answer, despite the Session being 
deletion-pending. Memory correctly rejects the same sequence. This demonstrates 
a Store-contract violation; the current HTTP handler has additional Session 
checks, so this is not a claim of a reproduced HTTP authorization bypass.
   
   Please restrict this fallback to the duplicate-key race it is intended to 
resolve and revalidate access and active Session state before returning a 
result. Add deletion-pending and expired-session replay regressions. Both 
implementation issues above also reproduce at #1611's reviewed head `04fe99de`.
   
   **Additional validation failure: the new frontend retry test compares a raw 
object with its Vue proxy**
   
   In 
[`AiChatDrawer.vue:203,351–361`](https://github.com/apache/dubbo-admin/blob/6ada40334596bc938829b349ac075a7a6bcbb480/ui-vue3/src/components/ai-chat/AiChatDrawer.vue#L351-L361),
 `lastRequestContext` is a normal `ref`. The initial service call receives the 
raw collected object; the retry receives its reactive proxy. The new assertion 
in 
[`AiChatDrawer.spec.ts:182`](https://github.com/apache/dubbo-admin/blob/6ada40334596bc938829b349ac075a7a6bcbb480/ui-vue3/src/components/ai-chat/__tests__/AiChatDrawer.spec.ts#L177-L184)
 fails:
   
   ```ts
   expect(retryCall[2]).toBe(firstCall[2])
   ```
   
   Using the available local dependencies and a temporary test configuration 
that disables PostCSS processing to isolate an unrelated local Tailwind 
dependency mismatch, the two affected test files report 10 passing tests and 
this one failure. Please align context storage and the regression's contract: 
verify a stable request snapshot/content, or deliberately preserve object 
identity if that is required. A reference-equality assertion alone does not 
verify that mutable context contents remain unchanged.
   
   The original full Go test suite and `go vet ./...` pass at this head; the 
added regression cases expose the backend failures above. Production 
MySQL/PostgreSQL behavior was not exercised.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to