I3eka opened a new pull request, #44561:
URL: https://github.com/apache/superset/pull/44561

   ### SUMMARY
   
   Reuse the accepted AI run when a message submission or stream connection is 
retried. A replay must not create a second inference or overwrite the first 
answer.
   
   This reproduces the [idempotency finding in 
#43237](https://github.com/apache/superset/pull/43237#discussion_r4002625683), 
and the [POST 
replay](https://github.com/apache/superset/pull/43135#discussion_r3817977421), 
[stream 
replay](https://github.com/apache/superset/pull/43135#discussion_r3817977422), 
and [failed broker 
submission](https://github.com/apache/superset/pull/43135#discussion_r3872111381)
 findings in #43135.
   
   - Insert the assistant's run identifier and accepted context with its 
placeholder, rather than in a later commit. Replays return that stored context, 
even when the submitted parameters differ.
   - Resubmit a still-pending run after a failed or ambiguous broker 
acknowledgement. Reuse the conditional database claim from the lifecycle work 
in #43135 so only one delivery executes; duplicate consumers do not clear the 
owner's cancellation state.
   - Read the stored terminal answer on reconnect, including worker-mode 
answers whose event stream has expired. An inline reconnect to an active run 
waits for its stored result, with a deadline and fresh ownership checks, 
instead of running inference again.
   
   **Dependencies and review scope:** depends on the unmerged AI base #42805. 
The shared compatibility base is `e809854983f396f4824d682935d1300f751d7164`, 
including Apache master `9612437a9c` and the separately committed 
migration/translation/formatter reconciliation. The focused change is [these 
nine files above that shared 
base](https://github.com/I3eka/superset/compare/e809854983f396f4824d682935d1300f751d7164...fix-ai-idempotent-runs).
 The main Apache-master diff includes the unmerged prerequisite; this draft 
does not bypass its SIP/review gate.
   
   Not included: hard-killed worker recovery, queued-turn history boundaries, 
page-context framing, profile selection (#44555), model pinning, or 
cancellation-target association. The parent PRs do not inherit this patch yet; 
their still-open findings remain open until the relevant branch includes the 
fix. Inline reconnects recover the stored answer, not live deltas from another 
web process. No automatic retry of a claimed run or extra LLM continuation is 
added.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   Backend-only behavior; no visual redesign.
   
   Before: the same `request_id` can return a different `run_id`; an extra 
stream GET can repeat inference. A created-only enqueue guard also strands a 
placeholder after broker failure.
   
   After: retries preserve the accepted IDs and parameters; an unclaimed 
delivery can be submitted again, while the database permits only one execution. 
Completed stream reads return the stored answer and outcome.
   
   ### TESTING INSTRUCTIONS
   
   - **723 backend checks pass:** the full AI unit suite, the actual Alembic 
single-head test, and seven translation-template drift checks.
   - **66 focused checks pass:** request replay in inline/worker modes, 
first-commit metadata, rejected and accepted-then-error broker submissions, 
terminal replay without an event bus, duplicate consumer cleanup, terminal 
outcomes, an active inline reader, wait timeout, conversation 
deletion/ownership change, legacy placeholders without a recorded run, a failed 
claim, and competing database connections. The existing unique-constraint race 
test also verifies preservation of the winning run metadata.
   - Independent red control: **seven cases fail on the unchanged shared 
base**, including both broker outcomes after checking the pre-retry persisted 
run identifier.
   - All applicable pre-commit hooks pass over the complete PR delta, not only 
the focused fix, including mypy, frontend type checking, Ruff and pylint.
   - API tests use real routes, command/DAO logic, isolated SQLite and the 
offline EchoProvider; route authentication/current-user identity and dispatch 
are stubbed. Broker acceptance ambiguity is simulated, and deliveries run 
through `execute_turn`. The competing-claim check uses separate database 
connections. These are not real Celery/broker, external LLM, 
supported-database-matrix, or deployed-browser proofs.
   
   ```bash
   pytest -q tests/unit_tests/ai 
tests/unit_tests/migrations/test_single_migration_head.py 
tests/unit_tests/scripts/translations/check_pot_drift_test.py
   ```
   
   Manual check with `AI_ASSISTANT` enabled:
   
   1. Post the same question twice with the same `request_id`; confirm both 
responses contain identical message and run UUIDs.
   2. Consume the returned run, then reconnect after completion. Confirm the 
persisted answer is returned without another provider/tool invocation.
   3. In worker mode, interrupt broker submission before or after acceptance, 
then repeat the POST with the original key. All delivered copies must name the 
same run, and only one may execute.
   
   No deployment, service restart, configuration change, live database 
migration or warehouse query was performed. Remote CI is separate from the 
local results.
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: review findings linked above
   - [x] Required feature flags: `AI_ASSISTANT` from #42805
   - [ ] Changes UI
   - [x] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351)): inherited AI schema 
and shared no-op joins; no idempotency-specific migration
     - [x] Migration is atomic, supports rollback & is backwards-compatible: 
the shared join has no schema/data operations and preserves published revisions
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [x] Runtime estimates and downtime expectations provided: the shared 
join only performs revision bookkeeping; no deployment performed
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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