Skip to content

fix(tests): avoid avatar descriptor reuse race - #154747

Merged
steipete merged 1 commit into
mainfrom
codex/avatar-descriptor-close-test
Sep 21, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/avatar-descriptor-close-test

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes intermittent avatar cleanup test failures in agent CI shards after successful avatar inlining. Observed in CI 35589427508 and CI 35589842726.

User Impact

No user-visible behavior change. Production avatar reads and descriptor ownership are unchanged.

Why This Change Was Made

A file descriptor number can be reused immediately after a successful close, so a later fstat cannot prove that the avatar descriptor leaked. Observe the real, call-through closeSync operation and require exactly one close of the pinned descriptor. Extend the same case to a genuine read failure by growing the file past the byte limit after it has been opened.

This is a maintainer-requested flaky-test repair.

Evidence

  • Linux controlled reuse: the real close succeeded, the next real open reused descriptor 27 for a different inode, and the original assertion failed exactly as CI did. The repaired success and failure cases both pass under the same reuse schedule.
  • Removing production's close makes both cleanup cases fail; the other four cases still pass.
  • Twenty clean standalone runs, six tests each. pnpm test src/agents/identity-avatar-file.test.ts --maxWorkers=1 wall time: median 1.833 seconds, range 1.698–2.234 seconds.
  • The unmodified original 230-file agents-core cohort passed (4,088 passed, 12 skipped; 225.90 seconds). That passing replay is not claimed as evidence of a repair.
  • Independent P2 review: no actionable findings.
  • Three clean replays of the original 230-file cohort in the observed CI file order with two workers: 4,089 passed and 12 skipped each; Vitest durations 199.28, 254.17, and 289.87 seconds. All 35 owner/sibling tests passed.
  • All remote changed-file gates passed (355.30 seconds).
  • Exact-head CI 35592812598 passed. Hosted avatar file: six tests passed, 1.21-second Vitest duration / 2.07-second wrapper duration; the cleanup cases took 3 ms and 2 ms.

@clawsweeper

clawsweeper Bot commented Sep 21, 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 agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Sep 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 11:12
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 7:35 AM ET / 11:35 UTC (Revision 2).

ClawSweeper review

What this changes

The PR makes avatar cleanup tests observe the real file-close operation and checks cleanup after both successful inlining and an oversized read failure.

Merge readiness

✅ Ready for maintainer review

Keep open as a useful, focused repair. No actionable defects remain, and the updated evidence resolves the prior review’s validation follow-up. Current main still contains the racy assertion.

Priority: P2
Reviewed head: c23b8ebdbfd6f0257606daf2e1ab4a14fe749ad4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, sound test repair with the prior validation follow-up completed and no remaining actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor runtime gate does not apply to this maintainer-authored test repair; its recorded filesystem reuse experiment, cleanup mutation check, ordered replays, and verified head CI cover the changed test contract.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor runtime gate does not apply to this maintainer-authored test repair; its recorded filesystem reuse experiment, cleanup mutation check, ordered replays, and verified head CI cover the changed test contract.
Evidence reviewed 9 items Introduced change: The pinned merge-base-to-head diff changes only the avatar test. The spy calls through to closeSync, checks exactly one close of the owned descriptor, and restores itself in finally; truncation occurs before installing the spy.
Production ownership contract: The existing reader catches bounded-read failures and closes the pinned descriptor in finally. Its documented exactly-once ownership contract supports the new assertion. Production behavior, workspace checks, and permissions are unchanged.
Still necessary on main and latest release: Fetched main and the supplied latest-release commit both retain the post-close fstat assertion. Neither inspected version contains this test repair.
Findings None None.
Security None None.

How this fits together

OpenClaw reads local agent avatars through a workspace-bounded file descriptor and converts their contents into image data URLs. These tests verify that the avatar reader releases its descriptor on success and failure.

flowchart LR
  A[Workspace avatar file] --> B[Validate and open file]
  B --> C[Bounded avatar read]
  C --> D[Image data URL]
  C --> E[Read failure]
  D --> F[Close owned descriptor]
  E --> F
  F --> G[Test observes real close]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +12. Total +12 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 19 7 +12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 19 7 +12

Review metrics

Metric Value Why it matters
Focused test cost 1.833 s median standalone; 1.21 s hosted Vitest The recorded six-test file remains below the repository’s five-second target.

Technical review

Best possible solution:

Retain the real filesystem cleanup checks for both outcomes without probing a descriptor number after ownership has ended.

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

Yes: current main probes a closed descriptor number that another thread can reuse, and the PR reports a controlled Linux reproduction of that exact failure. This review verified the source mechanism without executing tests.

Is this the best way to solve the issue?

Yes: observing the call-through close operation directly protects the documented ownership contract, while the real oversized-file case adds meaningful failure-path coverage without changing production code.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs a demonstrated intermittent cleanup-test failure with no production behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor runtime gate does not apply to this maintainer-authored test repair; its recorded filesystem reuse experiment, cleanup mutation check, ordered replays, and verified head CI cover the changed test contract.

Evidence

What I checked:

  • Introduced change: The pinned merge-base-to-head diff changes only the avatar test. The spy calls through to closeSync, checks exactly one close of the owned descriptor, and restores itself in finally; truncation occurs before installing the spy. (src/agents/identity-avatar-file.test.ts:48, c23b8ebdbfd6)
  • Production ownership contract: The existing reader catches bounded-read failures and closes the pinned descriptor in finally. Its documented exactly-once ownership contract supports the new assertion. Production behavior, workspace checks, and permissions are unchanged. (src/agents/identity-avatar-file.ts:137, c23b8ebdbfd6)
  • Still necessary on main and latest release: Fetched main and the supplied latest-release commit both retain the post-close fstat assertion. Neither inspected version contains this test repair. (src/agents/identity-avatar-file.test.ts:61, 10c229159ceb)
  • Release source check: The v2026.9.5 source also uses fstat on the already-closed descriptor. (src/agents/identity-avatar-file.test.ts:61, ec9c1a13db89)
  • Prior follow-up addressed: The captured body at sourceRevision 4ee48d0c4a65058f7440123262567e2d7f72c3a9b9b72ccfd8d9c87a8f78dfc6 records three ordered 230-file cohort replays, all 35 sibling tests, hosted timing, and changed-file gates. It also reports controlled descriptor reuse and a mutation check where removing production cleanup fails both cases. These address the previous review’s sole rank-up move. (c23b8ebdbfd6)
  • Exact-head CI verified: GitHub reports run 35592812598 completed successfully for the reviewed head. Tests were not rerun during this read-only review. (c23b8ebdbfd6)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-21T11:18:18.328Z sha c23b8eb :: needs changes before merge. :: none

@steipete
steipete merged commit 18d49c0 into main Sep 21, 2026
182 of 183 checks passed
@steipete
steipete deleted the codex/avatar-descriptor-close-test branch September 21, 2026 11:41
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 21, 2026
Include the verified descriptor-reuse fixture repair from #154747 while
preserving the reviewed session transition cancellation patch unchanged.
vincentkoc added a commit that referenced this pull request Sep 21, 2026
* commit '0883394977d1fb3af657635967f6e447bd7fff9a': (72 commits)
  fix(ui): await scheduled rail layout in focus test
  fix(cron): keep healthy active runs from delaying job lists (#154421)
  fix(plugins): prevent config conflicts during legacy plugin installation (#154539)
  perf(gateway): reduce repeated session-list work (#154551)
  fix(tasks): retain admitted work across list retries (#154338)
  perf(gateway): speed up transcript artifact downloads (#154726)
  chore(ui): refresh control ui locales (#154580)
  fix(release): keep two extended-stable months eligible (#154777)
  fix(tests): avoid avatar descriptor reuse race (#154747)
  perf(plugins): reduce callback scope overhead (#154625)
  fix(ui): include final request time in completed work summaries (#149240)
  fix(ai): avoid retrying conflicting Responses terminal statuses (#149242)
  fix: identify malformed Code Mode JavaScript as input errors (#149222)
  fix(doctor): settle imported JSONL transcript leftovers (#154413)
  fix(cloud): restore node bootstrap with bundled browser runtime (#154654)
  test(ui): await publication state notifications (#154768)
  fix(plugins): keep unchanged plugins running across metadata refreshes (#151281)
  fix: keep chat panel accessibility targets within each pane (#153478)
  fix: forced Gateway restarts cancel healthy subagent work (#154300)
  improve: reduce session delivery reader imports (#154740)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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