fix: ToolResolver instantiate cache hit and CLI session concurrent write loss#1858
fix: ToolResolver instantiate cache hit and CLI session concurrent write loss#1858cursor[bot] wants to merge 2 commits into
Conversation
β¦ite loss - Apply instantiate=True on ToolResolver cache fast path (fixes class tools returned after has_tool/validate_yaml_tools warmed the cache) - UnifiedSessionStore save now read-merge-writes under file lock - Invalidate CLI session cache when on-disk mtime changes Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
Remove mtime-based cache fast path that missed same-second writes. Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
|
@coderabbitai review |
|
/review |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more β On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
β Action performedReview finished.
|
|
No actionable comments were generated in the recent review. π βΉοΈ Recent review infoβοΈ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: π Files selected for processing (4)
π WalkthroughWalkthroughSession store concurrency is hardened by locked read-merge-write semantics that reconcile disk and memory state before saving, and cache-first load paths are removed. Tool resolver now applies the instantiate flag consistently on cached results. Two regression tests validate both behaviors. ChangesSession Store Concurrent Write Safety
Tool Resolver Cached Instantiation
Estimated code review effortπ― 4 (Complex) | β±οΈ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
π₯ Pre-merge checks | β 5β Passed checks (5 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing Touchesπ Generate docstrings
π§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@copilot Do a thorough review of this PR. Read ALL existing reviewer comments above from Qodo, Coderabbit, and Gemini first β incorporate their findings. Review areas:
|
|
@claude You are the FINAL architecture reviewer. If the branch is under MervinPraison/PraisonAI (not a fork), you are able to make modifications to this branch and push directly. SCOPE: Focus ONLY on Python packages (praisonaiagents, praisonai). Do NOT modify praisonai-rust or praisonai-ts. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding. Phase 1: Review per AGENTS.md
Phase 2: FIX Valid Issues Phase 3: Final Verdict |
|
Claude finished @MervinPraison's task ββ View job Final Architecture Review Complete βTodo List:
Phase 1: Architecture Review βAGENTS.md Compliance: This PR affects the wrapper layer (praisonai) which is the appropriate place for CLI session management and tool resolution per the architecture guidelines. Phase 2: Critical Bug Fixes Validated βBug 1: ToolResolver instantiate cache hit regression
Bug 2: UnifiedSessionStore concurrent write message loss
Phase 3: Technical Analysis βArchitecture Compliance
Performance Impact
Backward Compatibility
Phase 4: Reviewer Consensus β
Final Verdict: APPROVED βThis PR delivers minimal, targeted fixes for two critical correctness bugs without introducing scope creep, performance regressions, or architectural violations. The changes:
Recommendation: This PR is ready to merge. The fixes are surgical, well-tested, and architecturally sound. |
Summary
Critical bug scan found two correctness issues in recent wrapper/CLI changes and fixed them with minimal, targeted patches.
Bug 1:
ToolResolver.resolve(instantiate=True)cache fast-path regression (#1797)Impact: YAML/bot workflows that call
has_tool()orvalidate_yaml_tools()beforeresolve(..., instantiate=True)could receive an uninstantiated class instead of a callable instance, causingTypeErroror broken tool execution at kickoff.Root cause: The unlocked cache fast path returned cached values without applying
instantiate=True, whilst the lock-protected double-check path did apply it.Fix: Apply instantiation on the fast path when
instantiate=Trueand the cached value is a class.Bug 2:
UnifiedSessionStoreconcurrent write message loss (#1837 follow-up)Impact: TUI +
--interactive(or any two writers sharing~/.praison/sessions/) could lose chat messages when saves happened within the same second.Root cause:
save()overwrote the file without read-merge-write under lock, andload()used a stale in-process cache / second-granularity mtime checks.Fix:
save()reloads from disk under exclusive lock and merges messages before writingload()always reads from disk (shared lock) so cross-process writes are visibleValidation
test_resolve_instantiate_after_has_tool_cache_hittest_concurrent_writes_preserve_messagestest_save_and_load_sessionSummary by CodeRabbit
Bug Fixes
Tests