Skip to content

refactor(sessions): centralize history reply validation - #157240

Draft
vincentkoc wants to merge 1 commit into
mainfrom
refactor/session-history-result-kind-20260924
Draft

vincentkoc wants to merge 1 commit into
mainfrom
refactor/session-history-result-kind-20260924

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

October 14 Integration Disposition

Retain this draft for selective test integration, not the historical production refactor or a wholesale replay of its 37-case factory suite. Source comparison was pinned to main 9ed9c2cd1744.

  • The lazy row-facts admission witness remains useful: it checks captured environment, keys, continuation and byte accounting when inputs change before dispatch. Adapt it to the current createSessionHistoryWorkerRequestStub contract.
  • Current readers have materially different contracts: obsolete reply-kind assertions, readRowBackfill and readUsageCache are gone; search requires readIndexStatus. Preserve paginated entry results and their source/facts fields when assessing separate entry-reader cases.
  • 170560 intentionally removed dedicated wrong-command diagnostics and synthetic wrong-command tests while carrying typed request/result correlation through transport. 168991 removed unconditional reader rotation on ordinary read failures. Transport pairing does not provide runtime domain-shape validation.
  • Retirement-order coverage remains unresolved, not fully superseded. The settlement callback and awaited retirement already existed before those changes. The existing owner must map the historical mismatched-reply witness to the current actual slot-retirement contract before adapting or omitting it. This audit does not authorize weakening that protection.

Preserve the private test-only candidate and existing writer. Current-main integration, remote regression/runtime proof, actionable review disposition, exact-head CI and native landing qualification remain pending. No source, branch, draft or landing transition is made here; no application tests were run for this comparison.

Retained Earlier Status

The following records the earlier branch and inspected-main state. Its test counts and proofs do not qualify a newly integrated head.

Status: retain the draft for a test-only residual; the production consolidation is already on main. 157146 (f2e0c54bec175) introduced the shared typed reply assertion, and 159054 (aec71eae8c24) consolidated the reader construction, including historical eviction and entry-read Result replies. Both are verified merged ancestors of inspected main 6010d074f754d142ee1134416bcd9a4d5290a3db. The formerly referenced 156541 also merged, but its landed delta did not supply this readers-file replacement.

The added 291-line factory suite and mismatched-reply retirement case remain distinct from inspected main; complete supersession is not established. Preserve the current reader owner, lazy captured inputs, paginated entry reads and expanded worker lifecycle. The existing owner should select/adapt useful tests to that owner, without reintroducing the historical production helper. No source, draft, or landing transition is made by this status correction; integrated proof and native qualification remain pending.

What Problem This Solves

This branch originally addressed repeated reply-kind validation in 16 session-history callbacks. That production duplication has since been removed on main; the remaining contribution is distinct reader and retirement coverage.

Maintainer-sponsored refactor: @vincentkoc requested this duplication cleanup and authorized landing.

User Impact

No user-visible behavior change. Reply tags, error messages, return values, lazy request preparation, byte accounting, cancellation, and worker retirement remain unchanged. No config, schema, data migration, or operator action is introduced.

Why This Change Was Made

This branch introduced one private typed assertion for the repeated single-kind check; main now has its own canonical assertion and reader builder. The distinct multi-kind, streamed, array, and boolean decoders retain their existing behavior, including the usage-cache request's usage-refresh-lock reply.

Historical branch delta: production -106 lines; tests +333 lines, covering all 16 public factory mappings, invalid reply shapes, projection identity, request forwarding, and awaited retirement before rejection.

Evidence

The retained evidence below describes the published historical branch, not qualification of a reconstructed test-only residual on current main. This status audit was source-only; no new application tests were run.

  • Paired baseline-owner-on-candidate-context proof: the 37-case factory suite passed on both owners. The original layout also passed the 39-case errors suite and 2-case worker-lanes suite on both owners (156 case executions).
  • The first canonical check caught errors-suite line-cap growth. The unchanged retirement regression moved into the existing worker-lanes suite, and the errors suite was restored byte-for-byte. The final 3-case lanes suite then passed on both owners (6 further executions); unchanged suites were not repeated.
  • Final changed-path validation passed all 31 gates, including all 25 core-test type graphs, production type checking, lint, formatting, line-cap checks, and boundary checks. The warning-only temporary-file report used an empty base-to-base range; direct review separately confirmed the added tests introduce no temporary-file helper.
  • Final standalone candidate wall times: factory 13.51 s; worker lanes 15.39 s. Single-run costs, not a performance comparison.
  • Fresh scoped Codex autoreview: no findings. Independent source, test-layout, metric, and sealed-proof reviews passed. Source restoration and lease shutdown passed. A post-shutdown portal-sync warning did not change the native proof result.
  • Hosted CI and exact-head maintainer review remain pending.
Matched one-file duplication and complexity measurements

Same SCB 0.2.0 policy and adapter; only session-transcript-worker-readers.ts was measured, with one parse per version.

Measure Baseline Candidate
Score (lower is better) 79.5527 71.4399
Source lines 313 230
Cloned source lines 185 103
Clone fraction 59.1054% 44.7826%
Weighted cyclomatic-complexity mass 1468.3963 556.2001
Weighted cognitive-complexity mass 1512.7474 592.1201
Maximum cyclomatic / cognitive complexity 82 / 84 34 / 36

Both original high-complexity functions remain above the threshold. Cyclomatic erosion changes from 100% to 98.0973%, partly because the new low-complexity helper contributes denominator mass. Nested callbacks also contribute to their enclosing function, so aggregate complexity totals are not unique branch counts. These are matched one-file maintainability measurements, not a whole-repository score, correctness proof, or runtime claim.

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

clawsweeper Bot commented Sep 24, 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.

@vincentkoc
vincentkoc marked this pull request as ready for review September 24, 2026 11:25
@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 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 1, 2026, 9:15 AM ET / 13:15 UTC (Revision 4).

ClawSweeper review

What this changes

The branch centralizes session-history reply validation and adds tests for reader projections, invalid replies, cancellation forwarding, captured inputs, and worker retirement.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: current main covers the production consolidation, but distinct reader and retirement tests remain. The maintainer-authored draft is not fully superseded, and no introduced correctness defect was found.

Priority: P3
Reviewed head: cc8dac594e6bdff5bb00bf9639ffc0ee6b055141

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The historical patch is focused and behavior-preserving, with useful coverage; qualification of the retained contribution remains pending.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored refactor is exempt from the external-contributor proof gate. Reported factory and mocked-worker runs supplement source equivalence, but do not qualify the prospective integrated test residual; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored refactor is exempt from the external-contributor proof gate. Reported factory and mocked-worker runs supplement source equivalence, but do not qualify the prospective integrated test residual; no stored-data contract changes.
Evidence reviewed 9 items Pinned introduced change: The merge-base-to-head delta replaces 16 equivalent reply checks with a private assertion; request preparation, projections, error descriptions, and specialized decoders retain their original behavior.
Current canonical production owner: Inspected main already has a shared typed assertion and reader builder, alongside captured storage environments, paginated entry reads, and additional reader operations. This establishes production overlap without establishing the outcome of conflict resolution.
Merged consolidation provenance: GitHub confirms #159054 merged at aec71ea; the provided discussion connects it explicitly to reader construction consolidation. Current-main file history includes that commit.
Findings None None.
Security None None.

How this fits together

Session-history readers turn worker replies into conversation data for OpenClaw callers. The enclosing runtime owns database access, cancellation, and worker cleanup when decoding fails.

flowchart TD
  A[History request] --> B[Reader prepares request]
  B --> C[Database worker]
  C --> D[Validate reply kind]
  D --> E[Return conversation data]
  D --> F[Await worker retirement]
  F --> G[Report decoding error]
Loading

Before merge

  • Resolve merge risk (P1) - The conflicting head has not been reconstructed and qualified as a test-only residual against current main's expanded reader and worker lifecycle.
  • Complete next step (P2) - Resolve the branch as a test-only residual on current main, preserve its canonical production reader and expanded lifecycle fixture, and validate the retained reader and retirement cases on that integrated head.
Agent review details

Security

None.

PR surface

Source -106, Tests +333. Total +227 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 28 134 -106
Tests 2 333 0 +333
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 361 134 +227

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep main's canonical reader implementation and retain useful, nonduplicative decoding and retirement coverage at its existing test boundaries.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep main's canonical reader implementation and retain useful, nonduplicative decoding and retirement coverage at its existing test boundaries.

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

Not applicable: this behavior-preserving refactor reports no product bug; source comparison supports equivalent historical reply decoding.

Is this the best way to solve the issue?

Yes for the remaining test contribution: adapting it to main's existing owner is the narrowest path. The historical production consolidation is no longer needed.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6010d074f754.

Labels

Label changes:

  • remove merge-risk: 🚨 other: Current PR review selected no merge-risk labels.

Label justifications:

  • P3: This is an internal refactor with remaining test coverage and no identified user-facing defect.
  • 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 MEMBER-authored refactor is exempt from the external-contributor proof gate. Reported factory and mocked-worker runs supplement source equivalence, but do not qualify the prospective integrated test residual; no stored-data contract changes.

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)
  • vincentkoc: 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.

  • Qualify one test-only integrated head against current-main reader mappings and retirement behavior, retaining the updated lifecycle fixture.

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 (3 earlier review cycles)
  • reviewed 2026-09-24T11:31:32.109Z sha cc8dac5 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-24T11:53:56.638Z sha cc8dac5 :: blocked before merge. :: none
  • reviewed 2026-09-26T13:05:54.601Z sha cc8dac5 :: blocked before merge. :: none

@vincentkoc
vincentkoc marked this pull request as draft September 24, 2026 11:46
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Sep 24, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Oct 1, 2026

This branch has not been deployed

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

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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