Skip to content

Fix LiteRT worker request leaks and fail closed on interrupted cleanup - #527

Merged
leehack merged 4 commits into
mainfrom
fix/litert-reload-lifecycle-521
Sep 18, 2026
Merged

leehack merged 4 commits into
mainfrom
fix/litert-reload-lifecycle-521

Conversation

@leehack

@leehack leehack commented Sep 18, 2026

Copy link
Copy Markdown
Owner

Summary

When a LiteRT-LM worker stopped during an outstanding request, the caller's response port and future could remain alive after CLI run_end. Track and fail pending requests on worker termination, close their ports, observe unexpected worker exits/errors, and share concurrent disposal results. Preserve unverified-cleanup failures through free retries, cancellation races, and automatic backend routing instead of reporting success or replacing the failed runtime.

Partially addresses #521. Native initialization latency remains a separate limitation: one preserved macOS Qwen run exceeded the unchanged 60-second limit, while subsequent runs completed in 48–52 seconds. No native runtime, pin, cache policy, or timeout threshold changes. Requested GPU placement is unverified.

Validation on 97223924ee9a02d61f19965c294c0665b847c066 / base 9946295a77728f2c73e9f8454225f06eddbad122:

  • VM: 2,158 passed / 77 skipped; Chrome: 945 passed; analysis, pinned formatting, docs build and links passed.
  • Affected focused suite: 241 passed. Independent review: 139 passing test cases, zero known change-caused P1/P2 findings; review findings fixed and re-reviewed. Independent Chrome launch was sandbox-blocked; primary Chrome passed.
  • Mutation checks rejected removed pending-request tracking and worker-exit observation.
  • Qwen3.5 0.8B INT8 / LiteRT 0.17.0-5 / macOS arm64: final-head initial/reload/missing-model recovery hello 49.680/49.654/50.060s; cleanup and natural exit passed. Forced initialization timeout reported cleanup error and pending failure, then exited naturally within its outer deadline. Prior 60s failure retained as a failure.
  • Runtime archive SHA256 56760ac7d4678b9cada5041b7a2ee327183d41861a64152dead8338a2392f8cd; model SHA256 684d4d34adf7176eb47f6026ff65c33d42584737254e5524a8d1ad62edc21b98, revision c23b16e43ada6ead533b12593fe500bbe268014f.

High-risk surfaces: backendRuntime, regressionPolicy. Required independent exact-head review completed locally. PR-bound evaluator evidence is populated for PR #527 and the exact head/base below. The evaluator reports unverifiedPrerequisites: local evidence is internally consistent, but authenticated auditor/App/environment/ruleset prerequisites are unavailable. All 16 hosted checks passed on this exact head; live review threads total zero. No external authenticated readiness claim is made here. Other devices/platforms were not real-model tested for this change. Blocking native FFI calls still require an outer process deadline in CLI validation.

Production-readiness scope

  • User-facing scope: Pending LiteRT requests fail when their worker stops; unverified native cleanup cannot report success or be bypassed through the same router.
  • Supported platforms/paths: Native LiteRT worker and automatic backend routing; macOS arm64 real-model evidence, platform-neutral VM regression coverage.
  • Unsupported or unavailable paths: Blocking native FFI termination is not guaranteed; CLI callers need an outer process deadline. Failed cleanup throws typed errors and requires process restart.
  • Out of scope / follow-ups: Native reload latency remains in Qwen3.5 LiteRT GPU reload times out on macOS and leaves CLI alive #521; no cache/runtime/pin changes or GPU-placement qualification.

Completeness checklist

  • Scope explicitly reduced to demonstrated Dart lifecycle cleanup.
  • Unverified cleanup fails loudly with actionable typed errors.
  • Lifecycle docs, test matrix, and changelogs updated.
  • Positive reload/recovery and negative worker/cleanup regression coverage added.
  • New production errors do not include secret-bearing paths or native exception details.
  • Remaining native latency investigation stays tracked in Qwen3.5 LiteRT GPU reload times out on macOS and leaves CLI alive #521.

Test Plan

  • dart run tool/prepare_workspace.dart
  • dart format --output=none --set-exit-if-changed .
  • dart analyze
  • dart test -p vm -j 1 --exclude-tags local-only --coverage=.dart_tool/issue521/coverage-refresh-9946295
  • dart test -p chrome --exclude-tags local-only
  • Docs build/link validation; targeted backend/router tests; real-model lifecycle scenario.

Matrix Evidence

Matrix row Scope Platform / model / backend Result Evidence
static-format-analyze Static gates Flutter 3.47.1 PASS Prepared workspace, format/analyze/boundaries
root-vm Unit/integration macOS VM PASS 2158 passed, 77 skipped
root-chrome Browser compatibility Chrome PASS 945 passed
coverage-lib Library line coverage VM PASS 80.52% (13585/16871); unchanged 70% threshold
litert-lm-lifecycle Reload/recovery and timeout cleanup Qwen3.5 INT8 / LiteRT 0.17.0-5 / macOS arm64 / GPU requested PASS on final head 3 hello cycles plus forced-timeout child; prior 60s failure retained
high-risk-exact-head-independent-qa Blocking review Exact head/base below PASS locally Fresh independent reviewer, 139 tests; 0 P1/P2

High-risk regression review

  • Classification: high-risk; backendRuntime, regressionPolicy.
  • Implementation task: 01a0b507-c270-7141-b98c-840c72ecca55.
  • Independent blocking QA task: fresh subagent /root/audit_521.
  • Exact head / current base: 97223924ee9a02d61f19965c294c0665b847c066 / 9946295a77728f2c73e9f8454225f06eddbad122.
  • Production-branch deletion/bypass proof: Tests failed when pending-request tracking or worker-exit observation was removed; retry/routing/cancellation regressions directly invoke production paths.
  • Affected-family evidence: Qwen3.5 0.8B INT8 and published LiteRT 0.17.0-5 as identified above; final bounded recovery and timeout cleanup passed.
  • Unavailable evidence: Other native platforms/devices; verified GPU placement; authenticated external readiness prerequisites.
  • Known change-caused P1 regressions: 0.
  • Unresolved review threads: 0 at PR creation; recheck live before mark-ready/merge.

Review Notes

Independent exact-head review accepted with zero P1/P2 findings. This remains a narrow cleanup fix; #521 is not closed by it. All hosted CI checks passed on the real PR head. This PR remains draft; no mark-ready or merge authorization.

@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Chat app preview removed for leehack/llamadart-chat-pr-527.

@leehack
leehack marked this pull request as ready for review September 18, 2026 16:50
@leehack
leehack merged commit 6c01a69 into main Sep 18, 2026
16 checks passed
@leehack
leehack deleted the fix/litert-reload-lifecycle-521 branch September 18, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant