Skip to content

improve(media): reduce metadata fetched during orphan cleanup - #148244

Merged
steipete merged 1 commit into
mainfrom
codex/sqlite-managed-image-orphans-landing-0914
Sep 14, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sqlite-managed-image-orphans-landing-0914

Conversation

@steipete

@steipete steipete commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Managed-image orphan cleanup rereads full metadata when it only needs to identify referenced files.

User Impact

Cleanup fetches less metadata while preserving retained files, durable claims, errors, and retention rules.

Why This Change Was Made

The existing record store provides a narrow projection after the awaited legacy-metadata check. It includes every agent's claimed and unclaimed records and retains all four integer columns so unsafe values still stop deletion.

Evidence

  • Original code fails the intended byte budget (87,803 bytes against a limit below 57,344); nine controls pass. Paired cleanup fixtures preserve results, complete stored rows, and retained file bytes:
Fixture Orphan-read text bytes: before → after Whole-cleanup text bytes: before → after
empty 0 → 0 0 → 0
one-normal 266 → 49 532 → 315
64 rich retained records 1,076,770 → 3,136 2,153,540 → 1,079,906

Query and row counts are unchanged. These Node 24 measurements predate the refresh and use identical candidate bytes; no latency, CPU, allocation, or disk-I/O gain is claimed.

  • Refreshed proof passes 42 cases on Node 24.19.0 (15 owner + 27 cleanup; 102 unrelated sibling cases filtered). The complete 10-case availability regression also passes on Node 26.8.2, including retained bytes, all-agent claims, and four late unsafe-integer controls. Both use the committed counter from merged improve(gateway): reduce publication receipt fetches #148144, without an overlay, satisfying the completed review's requested proof.
  • All 30 selected static slots are covered by successful 23-slot hosted execution and seven local guards. The exact c2 command also passed locally to complete the env-budget comparison skipped by shallow hosted history. This is composite proof; source and dependencies remained unchanged.
  • Independent source review is clean. The earlier compiler-containment failure and temporary-counter proof remain preserved. A later bot input scan stopped at a nonretryable deadline before completing a review; the native wrapper still owns review eligibility.

The required CI gate passed on attempt 2 for the unchanged published commit. Its sole failed worker had stopped during Windows checkout before tests; one fresh-job retry succeeded. Native maintainer gates still apply.

@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review blocked

Automated review did not run, so no review verdict was produced.

Reason: The input-safety check could not safely complete for this revision.

ClawSweeper will not retry this unchanged revision.

Next step: No contributor action is requested. Maintainers should inspect the linked workflow run.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 14, 2026, 8:38 AM ET / 12:38 UTC.

ClawSweeper review

What this changes

The PR reduces metadata returned during managed-image orphan cleanup while preserving file retention and SQLite decoding safeguards.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful, focused optimization absent from the inspected main branch. No introduced correctness or security defect was found, and the maintainer-authored PR is protected from cleanup closure.

Priority: P2
Reviewed head: ef7d64a7c860b83135a093911db2747eec1de4d6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with relevant measured behavior and safety coverage; the declared test-instrumentation dependency remains a landing prerequisite.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body records paired runs of the real cleanup owner against SQLite and filesystem fixtures on Node 24.19.0, showing reduced returned strings with identical cleanup results, persisted rows, and retained bytes; the corrected counter dependency is explicitly disclosed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body records paired runs of the real cleanup owner against SQLite and filesystem fixtures on Node 24.19.0, showing reduced returned strings with identical cleanup results, persisted rows, and retained bytes; the corrected counter dependency is explicitly disclosed.
Evidence reviewed 8 items Introduced change preserves the reference set: The pinned merge-base-to-head patch replaces only the orphan scan's full metadata read. The new query retains all rows without session, agent, or cleanup-claim filtering and preserves the previous ordering.
Freshness and deletion safeguards remain: The reference read still occurs after the awaited legacy-metadata barrier. File age, regular-file checks, retained references, durable record claims, and deletion ordering are unchanged.
Scalar decoding coverage matches the schema: The STRICT table has four integer columns: width, height, size, and cleanup_pending. The projection retains all four, preserving native unsafe-integer failures before orphan deletion; no schema or stored-format change is introduced.
Findings None None.
Security None None.

How this fits together

Gateway maintenance uses stored attachment records to decide which outgoing media files remain referenced. Orphan cleanup reads those references and removes only sufficiently old, unreferenced files after checking for legacy metadata.

flowchart TD
  A[Gateway maintenance] --> B[Managed attachment cleanup]
  B --> C[Legacy metadata check]
  C -->|Clear| D[Fresh SQLite reference projection]
  C -->|Present or unreadable| E[Keep orphan files]
  D --> F[Reference and file age checks]
  F --> G[Remove aged unreferenced files]
Loading

Before merge

  • Resolve merge risk (P1) - The committed resource regression does not fully observe newer Node execution paths until the declared shared-counter dependency is incorporated.
  • Complete next step (P2) - Land improve(gateway): reduce publication receipt fetches #148144 first, refresh this PR with its corrected counter, and verify the cleanup regression on Node 24 and Node 26.6+.
Agent review details

Security

None.

PR surface

Source +16, Tests +133. Total +149 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 21 5 +16
Tests 1 135 2 +133
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 156 7 +149

Review metrics

Metric Value Why it matters
Reported orphan-scan text 1,076,770 → 3,136 bytes with 64 rich retained records The paired production-owner measurement supports the narrow returned-data benefit without claiming faster execution or lower disk I/O.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the narrower query in the existing record-store owner, preserving fresh reads, global references, integer decoding failures, and unchanged retention semantics.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the narrower query in the existing record-store owner, preserving fresh reads, global references, integer decoding failures, and unchanged retention semantics.

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

Not applicable as a functional bug reproduction: this is a metadata-read optimization, supported by source inspection and reported paired cleanup measurements.

Is this the best way to solve the issue?

Yes. A narrower projection at the existing fresh-read boundary removes unnecessary metadata without adding another owner, cache, schema, or configuration path.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded maintenance-performance improvement with no reported urgent user-facing failure.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured body records paired runs of the real cleanup owner against SQLite and filesystem fixtures on Node 24.19.0, showing reduced returned strings with identical cleanup results, persisted rows, and retained bytes; the corrected counter dependency is explicitly disclosed.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body records paired runs of the real cleanup owner against SQLite and filesystem fixtures on Node 24.19.0, showing reduced returned strings with identical cleanup results, persisted rows, and retained bytes; the corrected counter dependency is explicitly disclosed.

Label justifications:

  • P2: This is a bounded maintenance-performance improvement with no reported urgent user-facing failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body records paired runs of the real cleanup owner against SQLite and filesystem fixtures on Node 24.19.0, showing reduced returned strings with identical cleanup results, persisted rows, and retained bytes; the corrected counter dependency is explicitly disclosed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body records paired runs of the real cleanup owner against SQLite and filesystem fixtures on Node 24.19.0, showing reduced returned strings with identical cleanup results, persisted rows, and retained bytes; the corrected counter dependency is explicitly disclosed.

Evidence

What I checked:

  • Introduced change preserves the reference set: The pinned merge-base-to-head patch replaces only the orphan scan's full metadata read. The new query retains all rows without session, agent, or cleanup-claim filtering and preserves the previous ordering. (src/gateway/managed-image-record-store.ts:175, ef7d64a7c860)
  • Freshness and deletion safeguards remain: The reference read still occurs after the awaited legacy-metadata barrier. File age, regular-file checks, retained references, durable record claims, and deletion ordering are unchanged. (src/gateway/managed-image-attachments.ts:449, ef7d64a7c860)
  • Scalar decoding coverage matches the schema: The STRICT table has four integer columns: width, height, size, and cleanup_pending. The projection retains all four, preserving native unsafe-integer failures before orphan deletion; no schema or stored-format change is introduced. (src/state/openclaw-state-schema.sql:776, ef7d64a7c860)
  • Focused regression coverage: The added real-SQLite cleanup cases check retained bytes and persisted rows across agents and claims, reduced returned text, and four unsafe-integer mutations between the first scan and orphan scan. Existing sibling tests cover legacy metadata barriers, filesystem retry, and session-scoped retention. Tests were inspected, not executed. (src/gateway/managed-outgoing-gc-availability.test.ts:139, ef7d64a7c860)
  • Declared counter dependency: The captured PR body explicitly requires improve(gateway): reduce publication receipt fetches #148144 first. The inspected counter wraps get, iterate, and run but not all; the production Kysely executor uses all on Node 26.6+. The related PR supplies that instrumentation correction and remains open in the supplied context. (test/helpers/sqlite-statement-execution-counter.ts:11, 51c9122e1e9c)
  • Recorded production-owner measurements: The complete captured body reports three paired real-cleanup fixtures on Node 24.19.0 with unchanged results, persisted rows, retained bytes, query counts, and returned-row counts. For 64 rich retained records, orphan-scan returned strings decreased from 1,076,770 to 3,136 bytes. Measurements used the corrected dependency counter; no latency, allocation, or disk-I/O improvement is claimed. (ef7d64a7c860)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Yufeng He: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Incorporate the shared-counter dependency and verify the resource regression on both supported Node execution paths.

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.

@steipete
steipete force-pushed the codex/sqlite-managed-image-orphans-landing-0914 branch from ef7d64a to 341d476 Compare September 14, 2026 13:27
@steipete
steipete marked this pull request as ready for review September 14, 2026 13:28
@steipete steipete closed this Sep 14, 2026
@steipete steipete reopened this Sep 14, 2026
@steipete
steipete merged commit a97f0b8 into main Sep 14, 2026
369 of 422 checks passed
@steipete
steipete deleted the codex/sqlite-managed-image-orphans-landing-0914 branch September 14, 2026 15:49
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 14, 2026
* commit '3c08384584f57787a26da9998488233fc15ccf7e': (122 commits)
  fix(agents): keep tool result summaries when middleware details exceed shape limits (#147805)
  test: make full-suite fixtures portable across runtimes (#148247)
  refactor(qa): share unknown confidence results (#148200)
  chore(android): remove unused test dependencies and duplicate Wear settings (#148231)
  test: reuse compiled preflight in startup fixtures (#148330)
  test(wizard): route recovery integration through database forks (#148337)
  refactor(plugins): simplify provider auth patch recursion (#147933)
  fix(cli): drain failed web capability output (#148234)
  refactor(android): remove unused production helpers (#148233)
  fix(plugins): scope feed integrity to hosted ClawHub (#148220)
  test(qa): compare Telegram entities semantically (#148219)
  test(qa): recognize native Slack exec progress rows (#148217)
  test(cron): distinguish repeated delivery incidents (#148151)
  test(qa): preserve restart command ownership (#148218)
  test(qa): isolate bundled skill CLI gateway state (#148150)
  test(qa): align process lifecycle contracts (#148149)
  improve(media): reduce metadata fetched during orphan cleanup (#148244)
  fix(matrix): retain sync state runtime for deferred persistence (#148152)
  test: deduplicate gateway watch exit fixtures (#148237)
  refactor(cli): derive daemon status contract from gatherer (#148108)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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