Repository navigation
fix(pdf-tool): cache model config resolution per agentDir to avoid 10-12s event-loop stalls (#76644) - #76728
Conversation
|
Codex review: needs changes before merge. Summary Reproducibility: yes. at source level: current main builds the PDF tool during createOpenClawTools and createPdfTool eagerly calls resolvePdfModelConfigForTool, which can reach ensureAuthProfileStore. The live WeCom/Linux arm64 timing was not rerun in this read-only review. Next step before merge Security Review findings
Review detailsBest possible solution: Land the deferred PDF resolution approach after fixing the media-factory regression test so it seeds a real PDF-capable availability signal. Do we have a high-confidence way to reproduce the issue? Yes at source level: current main builds the PDF tool during createOpenClawTools and createPdfTool eagerly calls resolvePdfModelConfigForTool, which can reach ensureAuthProfileStore. The live WeCom/Linux arm64 timing was not rerun in this read-only review. Is this the best way to solve the issue? No, not mergeable as written: deferring automatic PDF model resolution is the narrow maintainable fix, but the new hot-path test must seed a PDF-capable provider or explicit config before it can assert the pdf tool is present. Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 59c523c6b530. |
5caf98b to
1ec5338
Compare
This comment was marked as low quality.
This comment was marked as low quality.
1ec5338 to
cb3d93b
Compare
…-12s event-loop stalls (openclaw#76644) `resolvePdfModelConfigForTool` probes auth profiles from disk on every call. Since `createPdfTool` is invoked on the agent-turn hot path (`createOpenClawTools`), every inbound message pays the full auth- discovery cost even when no PDF is present — causing 10-12 s event-loop stalls and `liveness warning: reasons=event_loop_delay` on Linux/arm64. Add a module-level `Map` cache keyed on `(agentDir, workspaceDir)`. The first call per pair resolves and stores the config; subsequent calls return the cached value. Auth profiles and workspaceDir are stable within a gateway process lifetime, so the cached result is valid for the process duration. Expose `clearPdfToolModelConfigCache()` for test teardown and add a regression test asserting that three consecutive `createPdfTool` calls with the same `agentDir` invoke `resolvePdfModelConfigForTool` exactly once. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
cb3d93b to
6c78cd1
Compare
Defers automatic PDF model/auth resolution until the PDF tool is executed, avoiding agent-turn tool prep stalls while preserving explicit PDF model registration. Fixes openclaw#76644. Thanks @hclsys.
Defers automatic PDF model/auth resolution until the PDF tool is executed, avoiding agent-turn tool prep stalls while preserving explicit PDF model registration. Fixes openclaw#76644. Thanks @hclsys.
Defers automatic PDF model/auth resolution until the PDF tool is executed, avoiding agent-turn tool prep stalls while preserving explicit PDF model registration. Fixes openclaw#76644. Thanks @hclsys.
Defers automatic PDF model/auth resolution until the PDF tool is executed, avoiding agent-turn tool prep stalls while preserving explicit PDF model registration. Fixes openclaw#76644. Thanks @hclsys.
Fixes #76644.
Problem
createPdfToolis called on every agent turn insidecreateOpenClawTools. It callsresolvePdfModelConfigForTool, which probes auth profiles from disk (viahasAuthForProvider→ensureAuthProfileStore) on each invocation — even when no PDF is in the request. On Linux/arm64 with multiple providers configured, this causes 10-12 s synchronous event-loop stalls every message, triggeringliveness warning: reasons=event_loop_delay.Fix
Add a module-level
Mapcache inpdf-tool.tskeyed on(agentDir, workspaceDir). The firstcreatePdfToolcall per pair resolves and caches the model config; subsequent calls return the cached value directly — zero disk I/O.Auth profiles,
agentDir, andworkspaceDirare stable within a gateway process lifetime, so the cached result is valid for the process duration. Config hot-reload does not affect auth profile paths.clearPdfToolModelConfigCache()is exported for test teardown.Test
Added regression test in
pdf-tool.test.ts:Calls
createPdfToolthree times with the sameagentDirand assertsresolvePdfModelConfigForToolis invoked exactly once.All 30 pdf-tool tests pass (
pdf-tool.test.ts,pdf-tool.model-config.test.ts,openclaw-tools.pdf-registration.test.ts).