Skip to content

Commit 53d0792

Browse files
author
peco-engineer-bot[bot]
committed
learn: retrospective learnings
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
1 parent 8877579 commit 53d0792

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Learning journal 2026-11-20
2+
3+
### 2026-11-20: Async lifecycle and FFI — Code that holds the GIL must not block on locks a logging thread may hold
4+
**Context:** PR #477 added a nonblocking fetch fast path that calls try_next_batch with the GIL held. A reviewer found that set_terminal_error logs while holding the terminal_error mutex, and pyo3_log may take the GIL to forward the record or, on a cache miss, to look up the logger. That can deadlock even at WARNING level. The fix made the CloudFetch probes return Pending when a lock is contended, so the fallback waits with the GIL released.
5+
**Rule:** Never log while holding a lock that a GIL-holding caller may wait on, and on paths that run with the GIL held use try-lock and return Pending on contention instead of blocking.
6+
7+
### 2026-11-20: Async lifecycle and FFI — Hold back-references weakly to break Arc ownership cycles
8+
**Context:** In PR #435, the OAuth providers held the HTTP client in an Arc while the client also owned the provider. Every closed session leaked the client, the provider and the provider's tokio runtime handle. The fix stores a Weak reference, upgrades it inside the refresh closure, returns invalid_state if the client is gone, and tests that both Weak handles fail to upgrade after the client is dropped. A by-value compatibility shim was rejected: holding the Arc strongly brings the leak back, and downgrading it turns a compile error into a runtime failure.
9+
**Rule:** When an owned child needs to call back into its owner, store a Weak reference, upgrade it only at the point of use, and add a test that drops the owner and asserts Weak::upgrade returns None for both objects.
10+
11+
### 2026-11-20: Verification and CI — Assert explicit cleanup before Drop's fallback cleanup can hide a missing call
12+
**Context:** In PR #477, the EOF cleanup test closed the result and statement handles before checking for the server DELETE. ExecutedStatement::drop also calls spawn_close_if_open, so the test would still pass if close-on-exhaustion were missing.
13+
**Rule:** When Drop does best-effort cleanup, assert the explicit path's side effect (the request was sent, and how many times) before closing or dropping the handles.

‎.claude/knowledge/lessons.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Lessons
22

3-
<!-- distilled-through: 2026-11-18 -->
3+
<!-- distilled-through: 2026-11-20 -->
44

55
## Public API and bindings
66
- L-0001 (4×, #250 #184 #372): Preserve public Rust compatibility: non-exhaustive structs need external builders, public enums need fallback arms, and breaking 1.x type changes require a major release.
@@ -72,6 +72,9 @@
7272
- L-0061 (1×, #466): Coalesce requests without holding locks across network calls: key attempts, share same-key errors/results, recheck after different-key waits, and detach work from individual waiter cancellation.
7373
- L-0062 (1×, #431): A non-consuming peek buffers errors as well as data for the next read. Test one-shot-error-then-EOF; optional enrichment must not silently turn server success into execution failure.
7474
- L-0063 (1×, #451): Cached terminal ExecuteResponse payloads must be complete and take-once. Clear on error, close, Drop, owner release, timeout and fresh status polls; document how terminal observations retain inline results.
75+
- L-0097 (1×, #478): When sync code triggers lock-guarded async work, take try_lock_owned before spawning and move the guard in so bursts spawn one task; ensure timer/close flushes skipped triggers. Test spawn count via num_alive_tasks on an unstarted current_thread runtime.
76+
- L-0098 (1×, #477): Never log while holding a lock a GIL-holding caller may wait on (pyo3_log can take the GIL). On GIL-held paths, try-lock and return Pending on contention instead of blocking.
77+
- L-0099 (1×, #435): Owned children that call back into their owner must hold a Weak, upgraded only at use (invalid_state if gone). Test that dropping the owner makes Weak::upgrade return None for both objects.
7578

7679
## Arrow results and metadata
7780
- L-0064 (2×, #301 #373): Empty catalog/pattern semantics vary by metadata operation; test short-circuit ordering and avoid turning an empty request into catalog=None (all catalogs). GetFunctions accepts meaningful empty catalogs.
@@ -109,6 +112,7 @@
109112
- L-0092 (2×, #333 #429): Keep required checks always present. Compute path changes from BASE...HEAD with full history and include standalone workspaces plus their root path dependencies.
110113
- L-0093 (1×, #429): repository_dispatch 204 only acknowledges delivery. Sender-owned checks need cancellation/failure completion and stale-check expiry; list check runs with filter: all.
111114
- L-0094 (2×, #411 #412 #473): Regenerate dependency pins on the normal toolchain with a healthy registry. Inspect every lockfile for unrelated downgrades/checksum drift and validate locked builds.
115+
- L-0100 (1×, #477): When Drop does best-effort cleanup, assert the explicit path's side effect (request sent, and how many times) before closing or dropping handles, so Drop cannot mask a missing call.
112116

113117
## Review follow-up [phase=review,followup]
114118
- L-0095 (1×, #257): Before claiming a review finding is already fixed or a symbol exists, reread HEAD and cite its current lines; remembered or partial source reads waste review rounds.

0 commit comments

Comments
 (0)