Skip to content

fix: keep search current after small PostgreSQL transcript rewrites - #202629

Merged
VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/postgres-integer-aggregates
Nov 20, 2026
Merged

VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/postgres-integer-aggregates

Conversation

@VACInc

@VACInc VACInc commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

High Level TLDR

Small PostgreSQL transcript rewrites now update search in the same transaction. Ingress health counts and cold transcript archive totals are numbers in the returned data.

What Problem This Solves

Rewriting an existing transcript that fits the synchronous byte budget can briefly hide its messages from search while the index catches up. PostgreSQL can also return quoted counts and byte totals where readers expect numbers.

User Impact

Search reflects a small rewrite as soon as it commits. Queue and archive clients can read counts and byte totals as numbers. No migration is required.

Root Cause

PostgreSQL returns SUM(bigint) as numeric. The PostgreSQL driver leaves numeric as text, while OpenClaw's existing bigint decoder returns safe integers as numbers. A real server replay returned "5000" for the raw sum, yielding "5000300" when adding 300 incoming bytes. The invalid total crosses the 4 MiB rebuild cap. The ingress and cold inventory queries similarly returned their sums as text. The cold inventory regression received "203" for a 203-byte embedded archive.

Why This Change Was Made

Cast these integer aggregates to BIGINT in their existing queries. The queries keep their filters, null handling, and rebuild caps. The casts use the numeric result path already used by nearby transcript queries and count fields.

Real behavior proof

The focused transcript rewrite regression was replayed on the PR base 8832901915fb with PostgreSQL 18 and unaccent. With the test alone, Vitest failed with expected true to be false at the in-transaction reconciliation assertion. With the sizing fix applied to that base, one selected test passed. The test also queries search after commit for both the replacement and the old text. Use the conformance command below with just the search test file and add -t "indexes a small replacement".

With PostgreSQL 18.7 on a private Unix socket, the production replacement transaction left needsReconcile: true on the base for a roughly 54 KB transcript. The same production transaction left needsReconcile: false with the patch. A search of the committed replacement found the new message and no longer found the replaced message. On the same private server, the ingress worker returned three quoted counts on the base. After the fix, the foreground Gateway returned {"pendingCount":1,"claimedCount":1,"blockedCount":1} via openclaw health --json.

Evidence

The rewrite replay seeded a fresh session for each sample on the same local server. Across five warmups and 20 measured replacement transactions, median commit time was 8.31 ms on the base and 10.74 ms with the patch. p90 was 10.56 ms and 16.27 ms. With the fix, the measured transaction also publishes the search projection. The measurement excludes deferred reconciliation and does not estimate total rebuild cost.

Autoreview covered the complete patch against base 1fbcec108f4e4 at P0–P2 and reported no actionable findings. Simplification kept the casts inside the three existing queries and reused the existing search and archival fixtures.

Verification

A fresh pnpm build:ci-artifacts on the pushed head also completed successfully. The Control UI build printed advisory size-budget warnings.
Seven PostgreSQL tests and 54 SQLite sibling tests passed. Focused type-aware lint, formatting, and git diff --check passed. Local PostgreSQL project durations were 135 seconds for the search suite, 27 seconds for cold inventory and selection, and 49 seconds for ingress health, including setup. The local runs used the pushed patch and its original base. A three-way merge against current main completed cleanly. Hosted CI passed on this head, including the artifact build, all four PostgreSQL conformance shards, the PostgreSQL 16 smoke job, and the required CI gate. https://github.com/openclaw/openclaw/actions/runs/44785119876

node scripts/test-database-conformance.mjs --engine postgres --connection "$TEST_DSN" -- \
  src/infra/database-engine/session-search-product.postgres.test.ts \
  src/config/sessions/session-cold-storage-selection.postgres.test.ts \
  src/infra/database-engine/ingress-queue-health.postgres.test.ts --maxWorkers=1

What was not tested

Production state, paid model providers, other PostgreSQL server majors, and total background reconciliation latency were outside this proof.

@clawsweeper

clawsweeper Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@VACInc
VACInc marked this pull request as ready for review November 20, 2026 17:37
@VACInc

VACInc commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 20, 2026
@clawsweeper

clawsweeper Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Cast integer aggregates to BIGINT so small transcript rewrites update search immediately and queue health and archive totals return numbers.

Example: Replace a roughly 54 KB PostgreSQL transcript with a message containing “replacement marker”.

  • Before: String-valued byte totals incorrectly exceed the synchronous rebuild budget, leaving search awaiting reconciliation.
  • After: Numeric byte totals keep the replacement within budget, making the new message searchable when the transaction commits.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair supported by real PostgreSQL behavior and distinct regressions; supplied proof was assessed without independently executing it, and hosted CI remains pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied PostgreSQL 18.7 replay exercises the production replacement transaction and committed search results, while the foreground Gateway health CLI demonstrates numeric ingress output; real-database regressions additionally cover archive inventory.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Small PostgreSQL transcript replacements temporarily disappear from search, and health or archive totals can arrive as strings.
Reason: The maintainer-authored repair restores existing numeric and synchronous-indexing contracts without adding configuration, schemas, or another decision owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current PostgreSQL result-type defect with focused changes in the existing query owners; no actionable correctness or security findings were found.

Priority: P2
Reviewed head: a474d4f4422d270fcf31fada313e209eabb20a8b

Before merge

None.

Findings

None.

Agent review details

How this fits together

Session storage and ingress workers query PostgreSQL through the shared SQL bridge; their aggregate results feed transcript rebuild decisions, archive inventory, and Gateway health responses.

flowchart TD
  A[Transcript replacement] --> B[Rebuild sizing query]
  C[Archive and ingress workers] --> D[Inventory and pressure queries]
  B --> E[PostgreSQL BIGINT results]
  D --> E
  E --> F[Existing numeric decoder]
  F --> G[Search projection and health results]
Loading

Technical review

Best possible solution:

Keep the explicit integer casts in the existing queries and land after the required CI gates pass.

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

The aggregate decoding and subsequent byte addition establish the failure path in current source, supported by the author's PostgreSQL red/green replay; this read-only review ran no target code.

Is this the best way to solve the issue?

Casting integer aggregates at their producers is the smallest complete repair and preserves the shared decoder, null handling, filtering, and rebuild budgets.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4332e9aa1613.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned introduction diff contains casts in three existing query owners and regressions for transcript replacement, cold inventory, and ingress pressure. (a474d4f4422d)
  • Root cause confirmed: The SQL bridge converts PostgreSQL int8 results to safe JavaScript numbers but preserves string-valued numeric results; the unchanged sizing loop adds incoming bytes to the aggregate. (src/infra/postgres-sync/protocol.ts:201, a474d4f4422d)
  • Current main still needs the repair: The three production files are unchanged between the introduction base and fetched main, which therefore retains the uncast aggregates. (src/config/sessions/session-transcript-index.ts:105, 4332e9aa1613)
  • Original synchronous rebuild contract: Commit 233ac85 explicitly retained synchronous indexing for transcripts within the existing row and byte budgets; this PR restores that contract for PostgreSQL. (src/config/sessions/session-transcript-index.ts:83, 233ac850f03c)
  • Supplied real PostgreSQL proof: The author reports a PostgreSQL 18.7 production-transaction replay changing needsReconcile from true to false, replacement search results replacing old results, and numeric ingress counts returned through openclaw health --json; the body also records the focused red/green regression. (a474d4f4422d)
  • Related search repair is distinct: fix(postgres): preserve numeric scores in session recall #202304 repairs a text-valued score literal in substring search, rather than the SUM result types changed here. (04d1dd10d05e)

Likely related people:

  • Peter Steinberger: Raw commit 233ac85 adds src/config/sessions/session-transcript-index.ts:80 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 233ac850f03c; files: src/config/sessions/session-transcript-index.ts)

PR surface

Source +15, Tests +86. Total +101 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 28 13 +15
Tests 3 88 2 +86
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 116 15 +101

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +28/-13 lines; tests +88/-2 lines Production growth is limited to explicit casts; the tests cover three distinct consumers of incorrectly decoded integer aggregates.

Labels

Label changes:

  • add P2: Repairs delayed search visibility and incorrectly typed diagnostic totals on PostgreSQL without evidence of lost canonical data or a core outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Repairs delayed search visibility and incorrectly typed diagnostic totals on PostgreSQL without evidence of lost canonical data or a core outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 20, 2026, 12:50 PM ET / 17:50 UTC.

@VACInc
VACInc merged commit 4dcb171 into openclaw:main Nov 20, 2026
240 of 242 checks passed
@VACInc

VACInc commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Merged via squash.

@VACInc
VACInc deleted the fix/postgres-integer-aggregates branch November 20, 2026 22:36
vincentkoc added a commit that referenced this pull request Nov 20, 2026
…202654

* origin/main: (34 commits)
  fix(ui): restore Skills first-visit asset limits (#202694)
  fix: restore Skills discovery recovery checks (#202747)
  fix(database): report disabled memory after a port (#202630)
  test(ui): settle live event imports before cursor assertions (#202752)
  fix: keep installed plugins in the Featured list instead of hiding them
  fix: keep PostgreSQL transcript and health totals numeric (#202629)
  fix(ui): show only SKILL.md in plugin skill previews
  fix: preserve the running installation when an agent updates its Gateway (#201570)
  chore(ui): refresh control ui locales (#202744)
  fix: show saved child results when idle delivery expires (#202732)
  perf(state): adopt producer-owned read commands (#202731)
  fix(cli): restore dashboard Gateway start and install recovery (#202085)
  fix: make plugin catalog artwork easier to recognize
  fix: restore queued compaction writer-fence coverage (#202709)
  fix(ui): remove resting chrome from Customize settings gears
  chore(ui): refresh control ui locales (#202734)
  fix: distinguish a recovered gateway from its failed update checks
  fix(ui): keep known plugin details visible while loading
  fix(cli): connect through gateway.remote.edgeAuth without a Gateway token
  fix: make the Plugins catalog clear when disconnected
  ...
vincentkoc added a commit that referenced this pull request Nov 21, 2026
)

* feat(gateway): add restricted writer transport and steer discovery

* refactor(gateway): retain publication owner across writer expansion

* feat: prepare restricted connections for Session Share steering

OpenClaw-Publication: d030c287-b7c5-8326-aa7e-a2b07b373ac6

* fix(gateway): distinguish disabled publication purposes at handshake

* Publish openclaw/cool-shrimp

OpenClaw-Publication: 096bcc30-6af3-892d-a6b9-456f24a4f5ba

* merge: bring main into the steering transport branch and regenerate the config baseline

* Merge remote-tracking branch 'origin/main' into land/steer-transport-202654

* origin/main: (34 commits)
  fix(ui): restore Skills first-visit asset limits (#202694)
  fix: restore Skills discovery recovery checks (#202747)
  fix(database): report disabled memory after a port (#202630)
  test(ui): settle live event imports before cursor assertions (#202752)
  fix: keep installed plugins in the Featured list instead of hiding them
  fix: keep PostgreSQL transcript and health totals numeric (#202629)
  fix(ui): show only SKILL.md in plugin skill previews
  fix: preserve the running installation when an agent updates its Gateway (#201570)
  chore(ui): refresh control ui locales (#202744)
  fix: show saved child results when idle delivery expires (#202732)
  perf(state): adopt producer-owned read commands (#202731)
  fix(cli): restore dashboard Gateway start and install recovery (#202085)
  fix: make plugin catalog artwork easier to recognize
  fix: restore queued compaction writer-fence coverage (#202709)
  fix(ui): remove resting chrome from Customize settings gears
  chore(ui): refresh control ui locales (#202734)
  fix: distinguish a recovered gateway from its failed update checks
  fix(ui): keep known plugin details visible while loading
  fix(cli): connect through gateway.remote.edgeAuth without a Gateway token
  fix: make the Plugins catalog clear when disconnected
  ...

* merge: bring main into the steering transport branch and regenerate the config baseline

* merge: bring main into the steering transport branch and regenerate the config baseline

* merge: bring main into the steering transport branch and regenerate protocol output

Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…claw#202654)

* feat(gateway): add restricted writer transport and steer discovery

* refactor(gateway): retain publication owner across writer expansion

* feat: prepare restricted connections for Session Share steering

OpenClaw-Publication: d030c287-b7c5-8326-aa7e-a2b07b373ac6

* fix(gateway): distinguish disabled publication purposes at handshake

* Publish openclaw/cool-shrimp

OpenClaw-Publication: 096bcc30-6af3-892d-a6b9-456f24a4f5ba

* merge: bring main into the steering transport branch and regenerate the config baseline

* Merge remote-tracking branch 'origin/main' into land/steer-transport-202654

* origin/main: (34 commits)
  fix(ui): restore Skills first-visit asset limits (openclaw#202694)
  fix: restore Skills discovery recovery checks (openclaw#202747)
  fix(database): report disabled memory after a port (openclaw#202630)
  test(ui): settle live event imports before cursor assertions (openclaw#202752)
  fix: keep installed plugins in the Featured list instead of hiding them
  fix: keep PostgreSQL transcript and health totals numeric (openclaw#202629)
  fix(ui): show only SKILL.md in plugin skill previews
  fix: preserve the running installation when an agent updates its Gateway (openclaw#201570)
  chore(ui): refresh control ui locales (openclaw#202744)
  fix: show saved child results when idle delivery expires (openclaw#202732)
  perf(state): adopt producer-owned read commands (openclaw#202731)
  fix(cli): restore dashboard Gateway start and install recovery (openclaw#202085)
  fix: make plugin catalog artwork easier to recognize
  fix: restore queued compaction writer-fence coverage (openclaw#202709)
  fix(ui): remove resting chrome from Customize settings gears
  chore(ui): refresh control ui locales (openclaw#202734)
  fix: distinguish a recovered gateway from its failed update checks
  fix(ui): keep known plugin details visible while loading
  fix(cli): connect through gateway.remote.edgeAuth without a Gateway token
  fix: make the Plugins catalog clear when disconnected
  ...

* merge: bring main into the steering transport branch and regenerate the config baseline

* merge: bring main into the steering transport branch and regenerate the config baseline

* merge: bring main into the steering transport branch and regenerate protocol output

Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
Co-authored-by: VACInc <[email protected]>
(cherry picked from commit 4dcb171)

Operator-requested 2026.11.10 stable backport (Dallin, 2026-11-24 04:15). Clean apply. Later main mentions: 39bcc3c feat: prepare restricted connections for Session Share steering (#202654);.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
(cherry picked from commit 3d91af2)

Release adaptation: regenerate config docs hashes for this stable tree using config:docs:gen; config:docs:check passed. No config migration or anchor rename.

Companions: no later PR or SHA mentions. Later same-path overlaps are unrelated config baseline regeneration, PostgreSQL operations/docs, or qualification tooling; #202109 is independent upgrade coverage, #202704 is a restore guide, and #202654 is a Session Share feature. Existing anchor selection and numeric aggregate fix #202629 are unchanged.

Co-authored-by: VACInc <[email protected]>

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit abc82993e59c1632ddfcaece8a02ce15c432e990)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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