Skip to content

fix(gateway): derive attachment visibility from current history - #138377

Merged
steipete merged 2 commits into
mainfrom
codex/team-opt-managed-visibility-20260904
Sep 4, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/team-opt-managed-visibility-20260904

Conversation

@steipete

@steipete steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

A managed attachment could remain downloadable after live SQLite history stopped referencing it when an unchanged reset archive had populated the attachment cache. Archive path, size and mtime were incorrectly treated as authority for current visibility.

Why This Change Was Made

Remove the process cache and its obsolete artifact discovery/stat path, including the unused resolver and barrel export. Each request now selects canonical full history. Cleanup keeps its existing per-pass reuse, ownership, claims and deletion behavior. Selected and unrelated malformed visible rows retain the existing full-history failure and record-retention behavior.

Production decreases by 158 lines; tests increase by 159. No schema, configuration, indexing, concurrency or retention-policy change.

User Impact

Existing ticket and bearer downloads respect current session history, including archive-to-live replacement and inactive branches. Full-history materialization remains a separate optimization; this correctness repair does not claim a general latency improvement.

Evidence

  • Canonical SQLite/archive visibility regressions fail before the repair and pass afterward. The focused suite passes 187 tests across eight files; a separate overlapping archive-reader cohort passes 96. All six final regressions, required changed-file checks, and independent P2 review pass.
  • The identical real in-process Gateway HTTP/WS test ran on isolated Linux/Node 24.19. Baseline full/thumbnail requests through ticket/bearer authentication returned 200 after live history excluded the image. The candidate returns 404 for all four and rejects a new artifact request with artifact_not_found, while preserving the original bytes, authorization, expiry, disconnect and cleanup checks. Only the three production files differed between the variants; processes exited and temporary sources were restored.
  • Earlier dead-export/lint failures were corrected and retained. An initial remote command-envelope failure occurred before any bootstrap or test; the subsequent run changed only that envelope and passed.

Execution used public base92daad5 with fs-safe0.7.0. Read-only qualification at a66263c found unchanged patch preimages and no relevant owner/dependency conflict; it is not a runtime test of the newer main or fs-safe0.7.1. No production workload or whole-server smoothness claim.

@clawsweeper

clawsweeper Bot commented Sep 4, 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: L maintainer Maintainer-authored PR labels Sep 4, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 2:46 PM ET / 18:46 UTC.

ClawSweeper review

What this changes

The PR removes the managed-attachment cache and derives download visibility from the current canonical session history, with SQLite/archive regression coverage.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep this PR open: it fixes the stale-visibility bug still present on current main, but it leaves the prior P2 availability concern unresolved by materializing all visible history for every media or artifact request.

Priority: P1
Reviewed head: 097df2ce0285e39ec76f34b9dbb2b0d5614ea675
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The stale-access repair and boundary coverage are strong, but the unresolved full-history request-path regression prevents a higher rating.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the contributor proof gate; its supplied Gateway HTTP/WebSocket A/B evidence nevertheless maps to the changed media owner and covers post-replacement 404 responses for ticket and bearer requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the contributor proof gate; its supplied Gateway HTTP/WebSocket A/B evidence nevertheless maps to the changed media owner and covers post-replacement 404 responses for ticket and bearer requests.
Evidence reviewed 6 items Current main still has the reported stale-cache behavior: Current main selects an archive path, compares only path/mtime/size, and returns previously cached attachment membership; a nonempty active SQLite history can therefore supersede the archive without invalidating that cache.
Canonical history semantics: The transcript reader projects SQLite history first and consults a reset archive only when the active result is empty, establishing why archive metadata cannot authorize a later active-history result.
PR repairs the visibility decision: The introduced code removes the cross-request cache and rebuilds membership from the canonical full-history projection, retaining only the cleanup-pass cache.
Findings 1 actionable finding [P2] Keep attachment membership lookup bounded per request
Security None None.

How this fits together

Gateway media routes consult session history to decide whether a managed outgoing attachment may still be downloaded. HTTP media requests and artifact-download RPCs both depend on that membership decision before returning bytes or a ticketed URL.

flowchart LR
A[HTTP or artifact request] --> B[Managed attachment record]
B --> C[Session history reader]
C --> D[Attachment membership decision]
D --> E[Download URL or not found]
C --> F[Reset archive fallback]
F --> D
Loading

Decision needed

Question Recommendation
Should this access-correctness repair land with the per-request full-history scan, or should it first provide a bounded current-projection membership lookup? Add bounded membership lookup: Implement a current-projection, generation-consistent exact lookup before merging so download availability does not scale with complete session history.

Why: The cache removal repairs an access bug, but the remaining request-path cost is explicit in source and the prior P2 finding; choosing immediate correctness versus the bounded lookup is a merge-risk tradeoff.

Before merge

  • Keep attachment membership lookup bounded per request (P2) - This introduced full-history read is reached independently by HTTP and artifact downloads, so every request materializes all visible messages after the cache removal. The archive-stat cache was unsound, but a generation-consistent exact current-projection lookup is needed to avoid long-session Gateway delays. This is the still-unresolved P2 from the prior review.
  • Resolve merge risk (P1) - Full, thumbnail, and artifact requests now each rebuild an index from all visible session history; long sessions can turn ordinary media access into a Gateway latency and availability problem.
  • Complete next step (P2) - Resolve the per-request full-history membership scan, or explicitly approve its Gateway availability trade-off before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P2] Keep attachment membership lookup bounded per request — src/gateway/managed-image-attachments.ts:1160-1173
Agent review details

Security

None.

PR surface

Source -158, Tests +159. Total +1 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 5 163 -158
Tests 3 340 181 +159
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 345 344 +1

Review metrics

Metric Value Why it matters
Production versus test LOC production -158 (5 added, 163 removed); tests +159 (340 added, 181 removed) The production cleanup is net-negative and the added test code covers the SQLite and Gateway boundaries; the remaining concern is request-path cost, not code growth.

Merge-risk options

Maintainer options:

  1. Bound the request-path lookup (recommended)
    Replace the full-history materialization with an exact membership read from one active projection snapshot before merging.
  2. Accept the current cost explicitly
    Merge the visibility repair while accepting the long-session latency risk and recording a concrete owner and follow-up for the bounded lookup.

Technical review

Best possible solution:

Use a generation-consistent, exact current-history attachment-membership lookup that falls back to reset archives only when active display history is empty, rather than retaining either archive-stat cache authority or a per-request full scan.

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

Yes—source-reproducible: prime reset-archive membership, replace it with nonempty active SQLite history that omits the attachment, then request the same media; current main's stat-keyed cache can still return it.

Is this the best way to solve the issue?

No—the cache removal correctly repairs stale authorization, but a generation-consistent exact current-history membership read is the more maintainable solution than scanning every visible message on every request.

Full review comments:

  • [P2] Keep attachment membership lookup bounded per request — src/gateway/managed-image-attachments.ts:1160-1173
    This introduced full-history read is reached independently by HTTP and artifact downloads, so every request materializes all visible messages after the cache removal. The archive-stat cache was unsound, but a generation-consistent exact current-projection lookup is needed to avoid long-session Gateway delays. This is the still-unresolved P2 from the prior review.
    Confidence: 0.95

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 26f87a37009b.

Labels

Label justifications:

  • P1: Current main can continue serving a managed attachment after its active session history no longer exposes it.
  • merge-risk: 🚨 availability: The introduced per-request full-history materialization can delay Gateway media and artifact responses as session history grows.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the contributor proof gate; its supplied Gateway HTTP/WebSocket A/B evidence nevertheless maps to the changed media owner and covers post-replacement 404 responses for ticket and bearer requests.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • gaoanze888: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: 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.

  • Replace the per-request full-history scan with a bounded, generation-consistent current-projection membership lookup.

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 (2 earlier review cycles)
  • reviewed 2026-09-04T16:03:43.515Z sha 3507f5e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-04T17:40:44.072Z sha 3507f5e :: blocked before merge. :: [P2] Avoid materializing the full transcript for each media request

@steipete
steipete marked this pull request as draft September 4, 2026 17:08
@steipete
steipete marked this pull request as ready for review September 4, 2026 17:08
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

The remaining scan cost is real: removing cross-request archive-stat reuse means repeated requests against reset-archive history reread that history. This PR makes no latency-improvement claim. The full active-SQLite read already exists in the predecessor; the removed filesystem-stat cache cannot establish current SQLite visibility and can retain access after the active history changes. The replacement keeps the canonical reader and cleanup-pass reuse. See the unchanged full-read boundary and cache removal and current membership owner.

The suggested by-ID reader is not a drop-in replacement: it permits archive fallback after any missing ID, whereas attachment membership must respect nonempty active history. A separate count also needs a consistent generation. The current corruption cases preserve rejection and files when selected or unrelated visible history is malformed; narrowing the lookup needs an explicit canonical validation contract, rather than silently changing that behavior. This does not mean every unrelated JSON row must be parsed forever.

We are retaining this bounded access-correctness repair and deferring both exact-lookup rank-up moves to the next measured follow-up: canonical exact attachment membership with consistent projection generation, archive fallback only for empty active display history, and explicit corruption/cleanup safety. That follow-up is owned and prioritized. The retained proof for this repair includes 187 focused cases, 96 overlap cases, six final regressions, and the real isolated Linux HTTP/WebSocket A/B: all four previously accessible URLs return 404 after live dereference, with authorization, claims, restoration and cleanup controls. The mechanical main integration leaves all six feature files byte-identical; fresh three-pass P2 review is clean. Exact-head CI is still pending, and no current-main live execution or performance gain is claimed.

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

The latest review repeats the same availability trade-off. I am accepting the current request cost for this access-correctness repair and taking the bounded, generation-consistent membership optimization as the next measured follow-up. The prior source-bound disposition remains applicable: #138377 (comment).

One cost clarification: the canonical archive reader already caches its validated index by file identity. Warm archive requests repeat message projection and attachment-reference collection; they do not necessarily rescan or parse the archive. Active SQLite history still materializes its visible range. The follow-up must preserve current visibility, empty-history-only archive fallback, consistent snapshots, and corruption/cleanup safety. No performance improvement is claimed for this PR.

Exact-head CI is now green on 097df2ce0285e39ec76f34b9dbb2b0d5614ea675: https://github.com/openclaw/openclaw/actions/runs/33906874325. The unrelated RSS scanner failure was preserved and investigated before one exact-job retry; no scanner source, measurement, assertion or budget was weakened. The retained HTTP/WebSocket stale-access regression and corruption controls remain the correctness proof.

@steipete
steipete merged commit cf64e4b into main Sep 4, 2026
302 of 304 checks passed
@steipete
steipete deleted the codex/team-opt-managed-visibility-20260904 branch September 4, 2026 19:23
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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