Skip to content

refactor(ai): share replay identity hashing - #137280

Merged
vincentkoc merged 1 commit into
mainfrom
refactor-provider-replay-hash
Sep 4, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
refactor-provider-replay-hash

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Related: #135727

What Problem This Solves

Replay identity construction was duplicated across the OpenAI Responses and Anthropic compaction paths. These fields fence provider replay by provider, API, model, endpoint, session, and authentication identity, so separate builders create avoidable drift risk in a security-sensitive invariant.

Why This Change Was Made

This moves the complete six-field replay-context construction into the shared owner established by #135727. Anthropic now uses that builder directly, while the existing OpenAI builder remains as a thin internal wrapper for its current callers. The shared owner also retains the exact existing trim, blank-to-undefined, and short-hash behavior.

User Impact

No user-visible behavior changes. Replay checkpoints remain fenced to the same provider, API, model, endpoint, session, and authentication identities.

Evidence

  • Production LOC: +33/-46, net -13; test LOC: +97/-20, net +77.
  • 80/80 focused replay tests passed across the Anthropic, OpenAI Responses, and shared provider compaction suites.
  • Behavioral coverage now proves exact identity replay, surrounding-whitespace equivalence, blank-versus-missing optional identity, and fail-closed behavior for session, auth profile, base URL, provider, API, and model mismatches.
  • Changed-file formatting, oxlint, repository ratchets, dependency pins, plugin boundaries, package patches, and conflict-marker checks passed.
  • The local changed-path gate reached core typecheck, where the shared checkout could not resolve existing markdown and phone-number dependencies; no reported error referenced a changed file. Exact-head CI remains the authoritative typecheck.
  • Exact autoreview found no actionable findings and rated the patch correct at 0.98 confidence.
  • Direct inspection of openai/codex at cc4b8bdeb8446144bc6a5e3f6d31b4d5c633c6f4 confirmed compaction uses the active provider, authentication, and session identity while the opaque compaction item does not encode those facts, leaving this replay fence correctly owned by OpenClaw.
  • No public barrel or package export was added. No config, protocol, persistence, dependency, authority, security policy, or prompt-cache behavior changed.

@vincentkoc vincentkoc self-assigned this Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 3, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 9:39 AM ET / 13:39 UTC.

ClawSweeper review

What this changes

The PR centralizes replay-identity hashing used by Anthropic and OpenAI Responses compaction replay, with tests covering equivalent and mismatched identities.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open for maintainer judgment: this member-authored, labeled internal refactor remains useful and source inspection found no correctness or security defect.

Priority: P3
Reviewed head: c57ea481d865a9064ee6bae446d9683370a067c1
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A clean, net-negative production refactor with focused boundary coverage and no actionable defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable: this MEMBER-authored PR is an internal deterministic refactor with no user-visible behavior change; the reviewed owner-boundary tests cover the changed fence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable: this MEMBER-authored PR is an internal deterministic refactor with no user-visible behavior change; the reviewed owner-boundary tests cover the changed fence.
Evidence reviewed 6 items Shared owner preserves prior semantics: The introduced shared builder trims each optional identity and converts blank values to undefined before applying the existing short hash; it retains provider, API, and model verbatim.
Both compaction owners use the canonical builder: Anthropic capture, suppression, and replay resolution call the shared builder; the existing OpenAI Responses wrapper now delegates to it, preserving its current callers and public internal type boundary.
Owner-boundary coverage: The changed Anthropic tests exercise exact identity, whitespace normalization, blank optional identities, and mismatches for session, auth profile, endpoint, provider, API, and model.
Findings None None.
Security None None.

How this fits together

Compaction replay restores a saved provider checkpoint into the next model request. A shared replay context fences that checkpoint to the same provider, API, model, endpoint, session, and authentication identity before history is reused.

flowchart LR
A[Conversation checkpoint] --> B[Replay identity builder]
C[Active model request] --> B
B --> D[Identity comparison]
D -->|match| E[Reuse compaction checkpoint]
D -->|mismatch| F[Send full history]
Loading

Decision needed

Question Recommendation
Should this member-authored internal replay-fence cleanup be accepted once normal exact-head merge gates complete? Accept the shared owner: Merge the refactor because it removes duplicated construction while preserving the established identity fence.

Why: The patch is behavior-neutral and technically sound, but the protected maintainer label requires an explicit maintainer decision rather than automated closure.

Before merge

  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source -13, Tests +77. Total +64 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 33 46 -13
Tests 1 97 20 +77
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 130 66 +64

Review metrics

Metric Value Why it matters
Production versus test LOC production +33/-46 (net -13); tests +97/-20 (net +77) The patch removes duplicated production logic while expanding behavioral coverage of the replay fence.

Technical review

Best possible solution:

Retain one private replay-context builder beside the existing shared comparator so both transports continue to construct the same six-field fence.

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

Not applicable: this PR refactors an internal replay fence rather than reporting a broken user flow; source comparison establishes the claimed equivalence.

Is this the best way to solve the issue?

Yes. The existing shared replay-context module already owns the matching invariant, so placing the identical construction there removes drift without adding a parallel API or behavior path.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is a behavior-neutral internal cleanup rather than a user-facing defect or feature.
  • 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: Not applicable: this MEMBER-authored PR is an internal deterministic refactor with no user-visible behavior change; the reviewed owner-boundary tests cover the changed fence.

Evidence

What I checked:

  • Shared owner preserves prior semantics: The introduced shared builder trims each optional identity and converts blank values to undefined before applying the existing short hash; it retains provider, API, and model verbatim. (packages/ai/src/transports/provider-replay-context.ts:11, c57ea481d865)
  • Both compaction owners use the canonical builder: Anthropic capture, suppression, and replay resolution call the shared builder; the existing OpenAI Responses wrapper now delegates to it, preserving its current callers and public internal type boundary. (packages/ai/src/transports/anthropic-compaction-replay.ts:109, c57ea481d865)
  • Owner-boundary coverage: The changed Anthropic tests exercise exact identity, whitespace normalization, blank optional identities, and mismatches for session, auth profile, endpoint, provider, API, and model. (packages/ai/src/transports/anthropic-compaction-replay.test.ts:106, c57ea481d865)
  • Current-main comparison: Current main already has the shared six-field comparison predicate; this branch adds construction to that same owner rather than creating a parallel replay path. (packages/ai/src/transports/provider-replay-context.ts:10, f670fb5a6803)
  • Shared-module provenance: The preceding merged refactor created the shared replay-context module and its exact comparison invariant; this places construction in the already-established owner. (packages/ai/src/transports/provider-replay-context.ts:34, ef681015e567)
  • Direct Codex contract check: The locally available Codex source selects the active API provider and authentication setup for compaction and sends session headers, while its compaction response item contains only an opaque encrypted payload; the local cache origin cannot establish external repository ownership. (codex-rs/core/src/client.rs:629, 41e22fee981a63b3698df7ed36bad393cda24715)

Likely related people:

  • Vincent Koc: Raw commit ef68101 adds packages/ai/src/transports/provider-replay-context.ts:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ef681015e567; files: packages/ai/src/transports/provider-replay-context.ts)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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-03T12:02:38.325Z sha 590527c :: needs changes before merge. :: none

@vincentkoc
vincentkoc force-pushed the refactor-provider-replay-hash branch from 590527c to c57ea48 Compare September 4, 2026 13:28
@vincentkoc
vincentkoc marked this pull request as ready for review September 4, 2026 13:32
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@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

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision: accept the shared replay-context owner.

The refactor is behavior-neutral, removes duplicated six-field replay identity construction, and keeps production code net-negative. Proceed once the exact-head CI, Testbox, and native merge gates complete.

@vincentkoc
vincentkoc merged commit 20c8702 into main Sep 4, 2026
185 checks passed
@vincentkoc
vincentkoc deleted the refactor-provider-replay-hash branch September 4, 2026 13:55
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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