Skip to content

perf(gateway): avoid repeated transcript path resolution - #184082

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-main-thread-sync-fs-sweep-20261026
Oct 26, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-main-thread-sync-fs-sweep-20261026

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolving a legacy absolute transcript path outside the selected agent's directory repeats filesystem canonicalization after the path-resolution owner has already canonicalized the candidate in the same synchronous call.

User Impact

A small reduction in synchronous filesystem work and allocation for sibling-agent and relocated archive paths. Ordinary transcript paths are unchanged; no whole-Gateway speedup is claimed.

Why This Change Was Made

Both callers of the private fallback helper pass the already-resolved realTrimmed. Consume that value directly. The initial per-call external-file canonicalization, fallback-directory canonicalization, containment checks, and reroot existence checks remain. No cache, configuration, or persistent state is added. Changed symlinks are observed on the next invocation.

Production delta: −1 line (src/config/sessions/paths.ts, +2/−3). The added regression (+35 lines) and standalone benchmark (+118 lines) are proof tooling. The broader synchronous-filesystem sweep found no other pure deletion that preserved external-file or authority contracts; the change deliberately stays at one proven site.

Evidence

Work-count regression: resolves a sibling transcript once per call and observes changed symlinks fails on base 4a6e70a2821644a0b0f7fbf5a1b650cbc5969b88 with 2 canonicalizations instead of 1, and passes with the deletion. It also retargets the alias outside the allowed layout and confirms the next invocation falls back safely.

Owner benchmark: node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-transcript-path-measure.ts --iterations 5000 --rounds 5. Forty synthetic agent directories; existing sibling and missing-old-root/relocated paths. AB then BA; five rounds per arm per pair, 50,000 timed calls per revision per workload, plus separate allocation passes with the same work counts. Fixtures and warmup are excluded. CPU/wall time is untraced; allocation uses V8 sampling at 4096 bytes, including collected objects.

Means per 5,000 resolutions:

Workload Base allocation Candidate allocation Change Base CPU Candidate CPU Change
Existing sibling 160.20 MB 135.84 MB −15.21% 1504.18 ms 1518.66 ms +0.96%
Relocated archive 187.97 MB 165.13 MB −12.15% 1364.54 ms 963.57 ms −29.38%

Allocation improved in both orders. CPU was noisy: sibling pair means were 1010.30→1102.56 ms and 1998.07→1934.76 ms; relocated pair means were 864.58→945.74 ms and 1864.50→981.40 ms. Treat sibling CPU as neutral/inconclusive, not a speedup. Wall-time means were 1932.77→1844.36 ms and 2014.85→1215.76 ms respectively. Host one-minute load ranged 26.09–45.41 for base and 26.98–47.86 for candidate. These are owner measurements, not a production-frequency claim.

Validation:

  • node scripts/run-vitest.mjs src/config/sessions/paths.test.ts src/config/sessions.test.ts src/config/sessions/sessions.test.ts --maxWorkers=1: 64 tests passed, 143.90 s wall including first-use worker compilation; individual test execution remained milliseconds.
  • Changed-file oxfmt and repository oxlint passed; git diff --check passed.
  • Independent subagent review (autoreview route unavailable): no P2-or-higher findings. The helper refused the configured provider route; no operator configuration was changed.
  • Exact-head CI passed for 4c13f9773e9c480cae0102322a7568faf8ac6fde; all 77 active PR checks passed, with no failed or pending checks.
  • ClawSweeper review: zero findings on the same head. The disclosed lack of whole-Gateway measurements remains the proof limitation.

No Gateway load campaign was run: this is a synchronous duplicate deletion with no cache or lifecycle changes, using the requested pure-deletion proof path. Whole-Gateway CPU, GC, RSS/heap and latency effects are unmeasured. No production service or state was touched.

Reuse the candidate canonicalized by the synchronous transcript path owner. Retain per-call external-file resolution, fallback-root containment, and moved-archive behavior. Reduce sampled allocation for sibling and relocated archive paths without adding a cache.
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T02:00:52.732025Z 4c13f97 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S labels Oct 26, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses the canonical transcript path already prepared by the resolver instead of canonicalizing it again during agent-directory fallback.

Example: Resolve /state/agents/worker/sessions/sess-1.jsonl while using /state/agents/main/sessions as the selected directory.

  • Before: The candidate is canonicalized twice before returning the worker transcript path.
  • After: The candidate is canonicalized once, and the same transcript path is returned.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The production change is focused and source-supported; supplied evidence reaches the real resolver through an owner harness rather than a shipped Gateway entry point.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its supplied benchmark exercises the changed resolver with real sibling and relocated filesystem fixtures, while the regression checks next-call symlink retargeting.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Legacy sibling-agent and relocated transcript lookups perform avoidable synchronous filesystem work and allocation.
Reason: The maintainer-authored direction removes verified duplicate work with a smaller production implementation and appropriately limited performance claims.

Merge readiness

✅ Ready for maintainer review

This PR is a useful, narrowly scoped optimization with no actionable correctness findings; current main still performs the duplicate resolution.

Priority: P3
Reviewed head: 4c13f9773e9c480cae0102322a7568faf8ac6fde

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied owner benchmark exercises the resolver with real filesystem fixtures; a shipped Gateway flow and whole-Gateway performance effects remain unmeasured.
Agent review details

How this fits together

The shared session-path resolver receives persisted transcript locators and agent-directory context, then returns a canonical artifact path or a derived fallback for Gateway, archive, and Doctor consumers.

flowchart TD
 A[Persisted transcript locator] --> B[Shared session path resolver]
 B --> C[Canonicalize candidate once]
 C --> D[Agent directory containment]
 D --> E[Relocation and structural fallback]
 D --> F[Resolved transcript path]
 E --> F
 F --> G[Gateway and Doctor consumers]
Loading

Technical review

Best possible solution:

Reuse the caller’s canonical candidate within the existing resolver while retaining per-invocation resolution and all fallback checks.

Do we have a high-confidence way to reproduce the issue?

Source inspection establishes the duplicate canonicalization on main, and the supplied regression reports two candidate canonicalizations before the change versus one afterward; no target code was executed during this review.

Is this the best way to solve the issue?

The patch is the smallest complete production fix: it consumes an already-prepared fact at the existing owner without adding caching, state, or another resolution path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d4ae3a731187.

Provenance checked

  • Candidate canonicalization during agent-directory fallback keeps the original intent (6a0fcf6: Resolve symlinks before containment checks while preserving cross-agent compatibility and safe fallback for stale metadata.)
  • Foreign-root transcript rerooting keeps the original intent (0a8e360: Prefer an existing local transcript copy after restoring backups or moving the state directory, while retaining genuine cross-root layouts.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -1, Tests +35, Other +118. Total +152 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 3 -1
Tests 1 35 0 +35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 118 0 +118
Total 3 155 3 +152

Labels

Label changes:

  • add P3: This removes limited synchronous filesystem work for legacy sibling-agent and relocated artifact paths without changing user-facing contracts.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This removes limited synchronous filesystem work for legacy sibling-agent and relocated artifact paths without changing user-facing contracts.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 25, 2026, 10:13 PM ET / October 26, 2026, 02:13 UTC.

@steipete
steipete merged commit 331aa36 into main Oct 26, 2026
158 checks passed
@steipete
steipete deleted the steipete/perf-main-thread-sync-fs-sweep-20261026 branch October 26, 2026 02:27
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…4082)

Reuse the candidate canonicalized by the synchronous transcript path owner. Retain per-call external-file resolution, fallback-root containment, and moved-archive behavior. Reduce sampled allocation for sibling and relocated archive paths without adding a cache.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant