Document ExecutionContext locking strategy and thread-safety guarantees

未关闭 适合新手
#196 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
冷清
技术栈
python
领域
documentation

调研方向

阅读 docs/HANDLER_AUTHORING.md 和 packages/darnit/src/darnit/core/models.py::ExecutionContext;issue 也允许创建 docs/execution-context.md。说明锁定和并发行为、失败语义、何时使用或避免缓存,以及使用新 context 的测试模式。指南涵盖全部五点并与实现一致,即为完成。

由索引模型根据 Issue 内容生成。

描述

documentation module-core

Context

#189 added ExecutionContext with a thoughtful double-checked locking design, but the strategy isn't documented beyond code comments. Handler authors using get_or_run_tool() need to understand:

  • What guarantees does the context provide? (same key → same result within an audit run)
  • What happens under concurrent access? (different keys parallel, same key serialized)
  • What can go wrong? (e.g., if run_func raises, is the lock released properly?)
  • When should handlers NOT use this? (e.g., tool output is non-deterministic or time-sensitive)

What to document

Extend docs/HANDLER_AUTHORING.md (or create a dedicated docs/execution-context.md) with:

  1. Locking strategy explanation — the double-checked locking pattern and why it's used (main lock fast-path + per-tool locks)
  2. Concurrency guarantees — what's serialized (same tool_key), what's parallel (different keys)
  3. Failure semantics — if run_func raises, is the lock released? (Yes, via with — but worth calling out.) Does the exception propagate? (Yes.) Is the key cached on failure? (No — only successful results are cached.)
  4. When to use vs not — cache expensive tool outputs (Scorecard, API queries); DON'T cache time-sensitive state (current time, fresh random numbers, etc.)
  5. Testing patterns — how to test handlers that use ExecutionContext (fixture that provides a fresh context per test)

References

  • Infrastructure: packages/darnit/src/darnit/core/models.py::ExecutionContext
  • Existing usage guide: docs/HANDLER_AUTHORING.md (brief "Shared Execution Context" section added in #189)
  • Related: #193 (audit cache documentation — similar pattern)
主要语言
Python
星标
22
派生
27
平均合并
4 天 20 小时
30 天内合并 PR
75

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

darnitdevorg/darnit 的其他 Issue

查看 darnitdevorg/darnit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。