Skip to content

fix: keep archived usage path resolution asynchronous - #200461

Merged
RomneyDa merged 1 commit into
mainfrom
fix/transcript-usage-async
Nov 17, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
fix/transcript-usage-async

Conversation

@RomneyDa

Copy link
Copy Markdown
Member

What Problem This Solves

Reading archived transcript usage uses an async API, but resolving the transcript filename still performs synchronous filesystem calls on the Gateway thread. The existing zero-sync-filesystem regression reproduces this on main.

User Impact

Archived usage reads no longer block the Gateway thread during transcript path resolution. Candidate ordering, restored-root and sibling-agent fallback, and existing synchronous callers retain their current behavior. No configuration or migration is required.

Why This Change Was Made

One shared path policy now accepts synchronous or asynchronous filesystem probes, rather than maintaining two containment implementations. Transcript candidate planning is likewise shared. The async usage reader selects the async resolver.

Compatibility review also found that native async realpath handles a symlink followed by a parent segment differently from the existing resolver. Normalize the input before resolving it and retain a regression proving sync/async agreement.

Evidence

  • Original public async usage entry reproduces synchronous realpath calls before the fix (1 failed, 27 skipped). Generated, relative and absolute filenames now retain usage results with zero observed synchronous filesystem calls.
  • A separate symlink/parent-segment regression fails before the normalization correction and passes with it. Existing sibling symlink replacement, restored-root, unsafe-path and fallback cases exercise both resolvers.
  • Final Node focused consumer proof: 83 tests pass across five files (usage, path policy, shutdown draining, history revocation and filesystem helpers).
  • Final Bun proof: 41 tests pass across usage and path policy. Canonical five-file type-aware lint, core typecheck, formatting and diff checks pass.
  • No native Windows execution was available; Windows coverage remains with PR CI. No timeouts or assertions were relaxed. Independent review was explicitly waived by the maintainer; local simplification and compatibility review completed.

Share containment and fallback policy across sync and async path resolvers. Preserve lexical normalization before following symlinks.

Co-authored-by: RomneyDa <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 17, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M labels Nov 17, 2026
@RomneyDa
RomneyDa enabled auto-merge (squash) November 17, 2026 06:52
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR shares transcript path policy between synchronous and asynchronous filesystem probes and switches archived usage reads to the asynchronous resolver.

Example: Read usage from /state/agents/main/sessions/record.jsonl.

  • Before: The asynchronous usage reader performs synchronous filesystem canonicalization before reading the transcript.
  • After: The reader awaits filesystem canonicalization while retaining the usage aggregation.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The repair has clear value and focused integration coverage, but an introduced resolution mismatch blocks correctness and shipped-entry-point proof is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Reading archived usage can stall unrelated Gateway work while transcript paths are resolved synchronously.
Reason: The source establishes the blocking path, and the maintainer-authored direction preserves existing behavior without adding configuration or storage.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep this PR open: it addresses a current synchronous-filesystem path, but the async replacement changes resolution for symlink targets containing parent segments.

Priority: P2
Reviewed head: 583763b6803166a148be5ee251cc5f6e6eb3200d

Before merge

  • Preserve parent normalization inside expanded symlink targets (P2) - Normalizing probe.path only handles parent segments in the input, while the old safeRealpathSync also applies ordinary resolution to symlink targets. For example, let main/sessions/link point to worker/sessions/child and main/sessions/alias.jsonl point to link/../record.jsonl, with record.jsonl in both session directories. The existing resolver selects main/sessions/record.jsonl; native async realpath selects worker/sessions/record.jsonl, which the sibling fallback accepts, so archived usage comes from a different transcript. The pinned fs-safe test at test/realpath.test.ts:32 explicitly establishes this indirect-symlink distinction. Preserve that resolution contract in the asynchronous probe and cover this expanded-target case.
  • Explain or restore the original intent of Ordinary versus native canonicalization - unknown: The pinned fs-safe implementation and tests define distinct ordinary and native symlink-expansion contracts; the PR explains input normalization but misses parent segments inside expanded symlink targets.

Findings

  • [P2] Preserve parent normalization inside expanded symlink targets — src/config/sessions/paths.ts:147-148

Provenance

  • Ordinary versus native canonicalization changes intended behavior without addressing why it exists (unknown: The pinned fs-safe implementation and tests define distinct ordinary and native symlink-expansion contracts; the PR explains input normalization but misses parent segments inside expanded symlink targets.)

Tests

  • Missing end-to-end proof: Provide redacted Gateway-entry-point output or logs exercising archived usage with unchanged totals and no synchronous path probes; redact IPs, keys, phone numbers, and non-public endpoints.
Agent review details

How this fits together

Gateway usage readers turn session identifiers and stored transcript filenames into ordered filesystem candidates, then stream the selected transcript into a usage accumulator.

flowchart TD
A[Archived usage request] --> B[Usage reader]
B --> C[Candidate planner]
C --> D[Shared path policy]
D --> E[Async filesystem probes]
E --> F[Transcript stream]
F --> G[Usage snapshot]
Loading

Technical review

Best possible solution:

Keep the shared path-policy owner, but make its asynchronous canonicalization preserve ordinary symlink-expansion semantics before switching usage reads.

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

Current-main source directly exposes synchronous canonicalization beneath the asynchronous usage reader, and the existing filesystem-observation regression targets that path; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Sharing candidate ordering and containment policy is appropriate, but native asynchronous realpath does not fully preserve the existing ordinary-resolution contract.

Full review comments:

  • [P2] Preserve parent normalization inside expanded symlink targets — src/config/sessions/paths.ts:147-148
    Normalizing probe.path only handles parent segments in the input, while the old safeRealpathSync also applies ordinary resolution to symlink targets. For example, let main/sessions/link point to worker/sessions/child and main/sessions/alias.jsonl point to link/../record.jsonl, with record.jsonl in both session directories. The existing resolver selects main/sessions/record.jsonl; native async realpath selects worker/sessions/record.jsonl, which the sibling fallback accepts, so archived usage comes from a different transcript. The pinned fs-safe test at test/realpath.test.ts:32 explicitly establishes this indirect-symlink distinction. Preserve that resolution contract in the asynchronous probe and cover this expanded-target case.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Asynchronous archived usage keeps the original intent (59d9759: The broader filesystem-stall repair moved existence checks to async I/O; this identifies the recent conversion, not the original introduction of synchronous path resolution.)
  • Containment, sibling paths, and restored roots keeps the original intent (perf(gateway): avoid repeated transcript path resolution #184082: The prior optimization removed repeated canonicalization while explicitly retaining canonicalization, containment, and reroot checks.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/config/sessions/paths.test.ts src/gateway/session-utils.fs.test.ts src/gateway/session-utils.transcript-usage.test.ts --maxWorkers=1
  • Verify the indirect-symlink regression fails on the reviewed head and passes after repair.
  • Run repository changed-file lint, typecheck, and formatting checks without changing baselines.

What I checked:

PR surface

Source +113, Tests +70. Total +183 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 167 54 +113
Tests 2 98 28 +70
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 265 82 +183

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Removing synchronous work from archived usage reads is useful, with limited scope and no demonstrated current outage.
  • add merge-risk: 🚨 compatibility: The replacement can select a different transcript for an existing indirect symlink layout.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Removing synchronous work from archived usage reads is useful, with limited scope and no demonstrated current outage.
  • merge-risk: 🚨 compatibility: The replacement can select a different transcript for an existing indirect symlink layout.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 November 17, 2026, 2:04 AM ET / 07:04 UTC.

@RomneyDa
RomneyDa merged commit 4c79d8f into main Nov 17, 2026
153 checks passed
@RomneyDa
RomneyDa deleted the fix/transcript-usage-async branch November 17, 2026 07:15
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Share containment and fallback policy across sync and async path resolvers. Preserve lexical normalization before following symlinks.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 4c79d8f)
RomneyDa added a commit that referenced this pull request Nov 17, 2026
* fix: preserve archived transcript symlink selection

Restore the ordinary fs-safe path semantics lost in #200461 without moving filesystem work back onto the caller. Reuse the existing realpath worker; cover indirect links and actual usage totals.

Co-authored-by: RomneyDa <[email protected]>

* fix(sessions): isolate asynchronous transcript path dependencies

Keep the shared path policy in the synchronous module and move worker-backed I/O to its async entry point. This removes the CI import cycle and wrapper source dependency without lazy-load synchronous filesystem work. Correct the parameterized test context typing.

Co-authored-by: RomneyDa <[email protected]>

---------

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 17, 2026
* fix: preserve archived transcript symlink selection

Restore the ordinary fs-safe path semantics lost in #200461 without moving filesystem work back onto the caller. Reuse the existing realpath worker; cover indirect links and actual usage totals.

Co-authored-by: RomneyDa <[email protected]>

* fix(sessions): isolate asynchronous transcript path dependencies

Keep the shared path policy in the synchronous module and move worker-backed I/O to its async entry point. This removes the CI import cycle and wrapper source dependency without lazy-load synchronous filesystem work. Correct the parameterized test context typing.

Co-authored-by: RomneyDa <[email protected]>

---------

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 62bb5d3)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
Share containment and fallback policy across sync and async path resolvers. Preserve lexical normalization before following symlinks.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
* fix: preserve archived transcript symlink selection

Restore the ordinary fs-safe path semantics lost in openclaw#200461 without moving filesystem work back onto the caller. Reuse the existing realpath worker; cover indirect links and actual usage totals.

Co-authored-by: RomneyDa <[email protected]>

* fix(sessions): isolate asynchronous transcript path dependencies

Keep the shared path policy in the synchronous module and move worker-backed I/O to its async entry point. This removes the CI import cycle and wrapper source dependency without lazy-load synchronous filesystem work. Correct the parameterized test context typing.

Co-authored-by: RomneyDa <[email protected]>

---------

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant