Skip to content

feat(team-reports): PostgreSQL support - #172855

Merged
steipete merged 6 commits into
mainfrom
pgprep/r17-team-reports-pg
Oct 15, 2026
Merged

steipete merged 6 commits into
mainfrom
pgprep/r17-team-reports-pg

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Team Reports could not use the experimental PostgreSQL backend for its saved reports or participate in database port and backup operations.

User Impact

Team Reports now supports experimental PostgreSQL runtime storage, bidirectional openclaw database port, and matched anchor plus logical database backup/restore. Saved reports, person-day counts, and run history are durable. Collected activity remains session-local TEMP scratch and is excluded from port and backup.

Why This Change Was Made

The existing database worker opens the engine store under admission, uses generated PostgreSQL DDL/port metadata, and delegates its eight JSON projections to the shared engine helper. PostgreSQL writes use the existing transaction/admission envelope. SQLite schema version 1 stays unchanged; the PostgreSQL format is unshipped and needs no migration.

Team Reports is separately installed (bundledDist: false), so offline operations load its selected installed owner's public port API through the existing owner-aware loader. Preflight reads static provider requirements without loading absent optional plugins. Workboard keeps its existing descriptor path without plugin-metadata discovery. Team Reports resolves its selected installation under artifact-preserving state reads, so offline backup cannot mutate shared SQLite sidecars.

Compiled workers and npm packages inline canonical schema SQL through the existing schema inliner. A focused packaging regression loads the built schema export; an isolated build of the actual plugin also passed public-API admission against both SQLite and PostgreSQL.

The approved additive jsonPathValue export uses the existing experimental openclaw/plugin-sdk/database-engine-worker-runtime entrypoint. There is no new SDK subpath and the plugin imports no core internals. SDK export inventories were regenerated/checked, the current declaration baseline was rendered, and the surface budgets account for exactly one additional export/callable. The historical shipped SDK inventory is unchanged.

Evidence

SQLite statement capture

A representative fixture covers 23 operations before/after: results are identical and all 76 existing statements retain identical bytes. No existing statement changed. Cold initialization adds the following four inspections, each twice (84 statements total):

Added statement Reason
PRAGMA schema_version Engine admission reads catalog identity.
PRAGMA user_version Engine admission reads format version.
PRAGMA encoding Engine admission reads encoding.
SELECT type, name, tbl_name, sql FROM main.sqlite_schema WHERE type IN ('table', 'view', 'index', 'trigger') Engine admission records the catalog.

The second inspection follows schema creation invalidating the first snapshot. The warm-reopen test verifies zero repeated schema introspection while admission remains live.

Runtime, port, and backup proof

PostgreSQL 17 conformance runs in process with one fixture per suite, without launching compiled workers. It covers all 23 operation outputs, all eight numeric JSON projections, rollback, independent-session scratch isolation, scratch discard after close/reopen, every canonical table through SQLite → PostgreSQL → SQLite, exact backup/restore fingerprints, and the selected installed plugin owner with bundled artifacts absent. A separate real host-to-worker smoke passed configuration selection, writes, duplicate-finish refusal, and reopen. Existing worker-backed SQLite tests pass unchanged.

The isolated feature review and focused CI-correction review both completed with no actionable P0–P2 findings.

Measured commands use pnpm test <file> --maxWorkers=1; PG cases use the existing PostgreSQL preload. Wall times include wrapper and compiler preparation on the contended local host. CI seconds below are from final head fd9d6dfe592331f4f2eae7d1ad7eb2c8c5d2deda.

Test file Result Local wall seconds Test seconds CI seconds
extensions/team-reports/src/store.conformance.test.ts 1 passed 93.55 0.362 0.118
extensions/team-reports/src/store-read-budget.test.ts 2 passed 181.53 0.396 0.068
extensions/team-reports/src/postgres-store.test.ts 2 passed 129.73 0.718 0.624
src/infra/database-engine/team-reports-port.postgres.test.ts 2 passed 28.05 8.019 2.461
src/infra/database-engine/port-command.postgres.test.ts 6 PG cases passed in CI; corrected local case passed 85.28 6.161 51.278 (6 PG cases)
extensions/team-reports/src/store.test.ts 15 passed 113.36 11.946 4.681
extensions/team-reports/index.test.ts 7 passed 152.27 1.902 0.635
HTTP + scheduler correction replay CI: 55 passed; local import preparation interrupted 1426.66 No result 7.829
src/infra/database-engine/backup.test.ts (correction) Updater + user export passed; Git backup hit local volume-permission guard 634.49 174.346 total; 71.185 updater 58.557 total; 24.845 updater
test/plugin-npm-runtime-build.test.ts (focused packaging regression) 1 passed 34.61 1.481 0.119 new case; 7.257 whole file

The existing backup file reuses its compiled snapshot-worker boundary to prove capture, exact restore, and custody; no in-process helper test proves that path. Its three cases took 58.557 CI seconds. The port-command file exceeds 30 seconds because its existing cases exercise real offline copy/commit, recovery, and custody checks; this change extends those family expectations. The full port-command run passed five cases and exposed one stale family-prefix expectation; its corrected targeted replay passed. Initial CI exposed a duplicate descriptor-export name and HTTP/scheduler read-budget spies on the bypassed worker facade. The descriptor now has a family-specific name, and the spies wrap the real engine operation without weakening their assertions. Registry/provider/import tests also passed (per-file wall times 93.24s, 82.51s, and 78.69s).

341 net handwritten production lines, excluding generated files, docs, and tests. Generated PostgreSQL outputs come from pnpm db:postgres:gen; pnpm db:postgres:check passed. SDK inventories/baseline, formatting, import guards, wrapper inventory/shadowing, Kysely, and dialect/line-cap/assertion-safety checks passed. The full-tree database-worker ratchet passed locally (223 → 223 main-thread calls; 12 → 12 deprecated compatibility calls). The full runtime build completed in 291.3 seconds.

Pre-rebase CI

CI run 38704506995 passed on the final head: 63 jobs succeeded and 22 were skipped. The complete PR rollup has 94 successful checks, 49 skips, and one neutral CodeQL result, with no failing or pending checks.

CI job Result Job seconds
PostgreSQL conformance Passed 1302
Extensions bundle Passed 140
Source contracts Passed 127
Production types Passed 282
Core lint shards Passed 168 / 153
Baseline ratchets Passed 435

The PostgreSQL job's existing 33-case port-command integration suite accounts for 932.622 test seconds; the two new Team Reports PG suites account for 3.085 test seconds combined.

The completed Knip production scan reports six exports in untouched GitHub/channel/UI files; the full-tree scan reports three untouched exports/types. Neither reports a task-file export. The environment-count gate reports 455 versus its 454 budget; this PR adds no environment names in counted production paths. These unrelated findings are recorded rather than masked with budget or ignore changes.

The preceding head passed 92 CI checks. Its PostgreSQL job exposed a new updater-backup regression: descriptor resolution unnecessarily loaded plugin metadata for Workboard after shared-SQLite fingerprints were captured, changing a -shm file. The correction skips discovery for providers that do not need an installed owner and uses artifact-preserving reads for Team Reports. The existing exact updater-backup test is the primary regression; the same updater test now also checks unchanged shared database/sidecar bytes and metadata through the real Team Reports resolver. The in-process port suite is unchanged; the new cold-lookup assertion reuses the updater test’s existing snapshot-worker boundary. The unwrapped negative control failed at the new sidecar assertion (28.070s test time, 654.54s wall, including 266.370s worker preparation). The initial fixed updater replay reached PostgreSQL export and SQLite snapshots, then hit its existing 120s test timeout on this contended host (683.61s wall, 121.186s test time). No timeout was increased. The fixed full-file replay took 634.49s: the updater passed in 71.185s, user export passed in 68.182s, and the unchanged Git-backup case failed in 34.979s at the external-volume ancestor permission check. Its permissions were not changed. The corrective review completed scoped-clean after its launcher’s shared-temp-directory preflight was resolved with a private task directory. Formatting passed; another lint attempt stopped before analysis at the existing 300s SDK declaration timeout, and the queued typecheck was stopped. Final-head CI passed all three backup cases, including the local Git-backup case blocked by the host path gate. It also passed lint and production/test types, covering the local declaration-preparation limitation.

Landing rebase

Rebased onto main after Logbook landed and GitHub reported conflicts. The mechanical resolution preserves both families in the schema generator, runtime schema inliner, conformance targets, provider registry, import-closure coverage, and documentation. The provider-error expectation includes Workboard, Logbook, and Team Reports; the preflight test also preserves main's SecretRef-redaction assertion. This was the single landing fix push, at 17061d89fa0b252a8655e8f63496886ef6f8cd22.

PostgreSQL generation/check passed (19 generator tests); SDK export and plugin inventories were regenerated without tracked changes. Registry/provider tests passed. The import-closure test initially encountered a native compiler crash with pre-rebase dependencies; after installing the rebased lockfile, it passed. The port-command file passed four cases and skipped its two PostgreSQL-dependent cases locally. The one-line expectation correction passed isolated review. Final-head CI is required before merge; the API-baseline render was stopped after CI exposed the missing Logbook provider field.

Landing follow-up

Rebased-head CI run 38718030583 on 17061d89fa0b252a8655e8f63496886ef6f8cd22 found two PR-caused integration defects:

Failure Classification and correction
Build, SDK boundary, and type checks Logbook must supply the newly required provider-level minimumPostgresVersion. Its generated descriptor already specifies 16. Omitting it also makes the real preflight registry compute NaN; declaring 16 restores the expected floor.
Docs and lint format checks The combined generator imports require canonical formatter ordering.

The coordinator-approved two-file integration correction is pushed at 174439b548b85914672e237c3b05f4215fea1f8c. It passed isolated review, and its real registry probe returns 16 for all three families and the combined preflight floor. Required CI passed on this new exact head before landing. The preceding failures are PR-caused integration fallout, not inherited exceptions.

Final landing CI

CI run 38720659699 passed on 174439b548b85914672e237c3b05f4215fea1f8c: 64 jobs succeeded, 22 were skipped, and none failed. Required build, SDK boundaries/API checks, production/test types, docs, lint, ratchets, and openclaw/ci-gate passed. PostgreSQL conformance passed for Workboard, Logbook, and Team Reports, including Team Reports bidirectional port, installed-owner resolution, and backup/restore. The two preceding rebase integration failures are corrected; no inherited-failure exception is used.

@clawsweeper

clawsweeper Bot commented Oct 15, 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 docs Improvements or additions to documentation scripts Repository scripts commands Command implementations plugin: team-reports size: XL labels Oct 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR adds PostgreSQL storage, database porting, and backup/restore support for Team Reports.

Example: Save the daily Team Reports report for 2026-08-20 with PostgreSQL selected.

  • Before: Team Reports stores the report in SQLite regardless of the PostgreSQL setting.
  • After: The report, person-day counts, and run history use PostgreSQL; collected activity remains temporary.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The architecture fits the feature, but a source-proven migration blocker and incomplete existing-state compatibility evidence prevent merge.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Teams selecting PostgreSQL cannot keep Team Reports data in that backend or include it in the corresponding port and backup operations.
Reason: The maintainer-directed feature fills a real storage-family gap through existing owners, with no new user configuration option.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open: it delivers a useful maintainer-directed feature, but adding Team Reports strands previously valid mixed-engine installations without a working port command.

Priority: P2
Reviewed head: 1a7b5d911dd497ec95bfafb104251e14d541eeb9

Before merge

  • Handle existing mixed-engine installations before registering Team Reports (P1) - A valid existing installation can have database.engine=postgres, PostgreSQL Workboard data, and SQLite Team Reports data because Team Reports previously ignored that setting. This registration adds the SQLite reports database to port discovery, while the new runtime selection refuses to open it. The suggested recovery command cannot help: doctor-database-port.ts:108 rejects the reports store as SQLite with PostgreSQL config for either --to direction. Changing the global setting to SQLite instead makes the Workboard anchor fail that same check. Support migration from this mixed state in the existing port owner, including its same-target no-op and recovery handling, before making the family follow global PostgreSQL selection.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P1] Handle existing mixed-engine installations before registering Team Reports — src/infra/database-engine/port-provider.ts:17

Tests

  • Missing end-to-end proof: Supply redacted shipped-CLI upgrade, port, and backup/restore evidence preserving settings and report data, including a PostgreSQL Workboard plus SQLite Team Reports starting state.
Agent review details

How this fits together

The Team Reports plugin sends storage operations to its database worker, which uses shared engine admission and transactions; offline port and backup operations discover the plugin through the database-family registry.

flowchart TD
  A[Team Reports plugin] --> B[Database worker]
  B --> C[Shared engine owner]
  C --> D[SQLite store or anchor]
  C --> E[PostgreSQL reports]
  F[Offline port and backup CLI] --> G[Database family registry]
  G --> C
Loading

Technical review

Best possible solution:

Extend the existing offline port owner to migrate recognized mixed-engine installations while preserving reports, existing PostgreSQL stores, configuration, and recovery guarantees.

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

Source establishes the failure: start with database.engine=postgres, a PostgreSQL Workboard anchor, and existing SQLite Team Reports data; runtime refuses the reports database, while either port direction fails the physical/config engine comparison.

Is this the best way to solve the issue?

Reusing shared engine, admission, and family-provider contracts is appropriate, but adoption must include the mixed-engine migration path rather than assuming every newly registered family already matches the global engine.

Full review comments:

  • [P1] Handle existing mixed-engine installations before registering Team Reports — src/infra/database-engine/port-provider.ts:17
    A valid existing installation can have database.engine=postgres, PostgreSQL Workboard data, and SQLite Team Reports data because Team Reports previously ignored that setting. This registration adds the SQLite reports database to port discovery, while the new runtime selection refuses to open it. The suggested recovery command cannot help: doctor-database-port.ts:108 rejects the reports store as SQLite with PostgreSQL config for either --to direction. Changing the global setting to SQLite instead makes the Workboard anchor fail that same check. Support migration from this mixed state in the existing port owner, including its same-target no-op and recovery handling, before making the family follow global PostgreSQL selection.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4d60655c338b.

Provenance checked

  • Team Reports worker ownership and SQLite schema initialization keeps the original intent (979c0fc: Move synchronous database work and complete transactions into owned workers while retaining admitted work through shutdown.)
  • Engine selection and retained store recovery changes intended behavior with a stated reason (069d40e: Reacquire usable worker handles after failure without replaying uncertain writes; this PR retains that shared owner while adding configured engine selection.)
  • Database port and backup family dispatch keeps the original intent (d6f6f76: Replace Workboard-specific dispatch with a lazy registry explicitly intended to admit additional families, including Team Reports.)
  • Bounded JSON projections keeps the original intent (8f33121: Return chart totals and latest warnings without transferring unused report payloads; the shared dialect helper preserves those projections.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/infra/database-engine/port-command.test.ts --maxWorkers=1
  • node scripts/test-database-conformance.mjs --engine postgres --connection "$TEST_POSTGRES_DSN" -- src/infra/database-engine/port-command.integration.test.ts src/infra/database-engine/team-reports-port.postgres.test.ts --maxWorkers=1
  • Verify the new mixed-engine regression fails on the reviewed head before the repair and passes afterward.
  • Run targeted typecheck, lint, and formatting checks for the repaired files, plus git diff --check.

What I checked:

PR surface

Source +332, Tests +574, Docs +14, Config +4, Generated +286, Other +41. Total +1251 across 40 files. Added test files: 4.

View PR surface stats
Area Files Added Removed Net
Source 22 508 176 +332
Tests 9 577 3 +574
Docs 3 24 10 +14
Config 1 4 0 +4
Generated 1 286 0 +286
Other 4 43 2 +41
Total 40 1442 191 +1251

Review metrics

Metric Value Why it matters
Public SDK expansion 1 additional callable export jsonPathValue shares the existing engine implementation across the plugin's eight JSON projections without adding a subpath.

Labels

Label changes:

  • add P2: This optional experimental storage feature has a concrete migration blocker with a limited affected population.
  • add merge-risk: 🚨 compatibility: Previously valid PostgreSQL Workboard plus SQLite Team Reports installations lose report availability, and the existing recovery command rejects their mixed physical engines; the PR also expands the experimental SDK.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This optional experimental storage feature has a concrete migration blocker with a limited affected population.
  • merge-risk: 🚨 compatibility: Previously valid PostgreSQL Workboard plus SQLite Team Reports installations lose report availability, and the existing recovery command rejects their mixed physical engines; the PR also expands the experimental SDK.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 October 15, 2026, 2:55 AM ET / 06:55 UTC.

@steipete
steipete marked this pull request as ready for review October 15, 2026 06:57
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T10:13:18.371109Z 17061d8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete force-pushed the pgprep/r17-team-reports-pg branch from fd9d6df to 17061d8 Compare October 15, 2026 10:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17061d89fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


export type DatabasePortProvider = {
id: string;
minimumPostgresVersion: number;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Populate the PostgreSQL floor for every provider

Adding this required field without updating logbookPortProvider leaves one registered provider's value undefined; consequently, the preflight calculation Math.max(...databasePortProviders.map(...)) returns NaN, and readPostgresPortCapabilities no longer rejects unsupported PostgreSQL versions for any database port operation. Add Logbook's minimum version when migrating the provider contract.

AGENTS.md reference: AGENTS.md:L48-L53

Useful? React with 👍 / 👎.

Preserve the existing PostgreSQL 16 floor when Team Reports adds the provider-level preflight contract. Keep the merged generator imports formatted.
@steipete
steipete merged commit f6a0035 into main Oct 15, 2026
162 of 163 checks passed
@steipete
steipete deleted the pgprep/r17-team-reports-pg branch October 15, 2026 10:58
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
* feat(team-reports): support PostgreSQL storage

* fix(team-reports): inline schema in compiled runtimes

* fix(team-reports): align descriptor and read-budget probes

* fix(database): preserve SQLite artifacts during port lookup

* test(database): retain Logbook in provider expectation

* fix(database): declare Logbook PostgreSQL preflight minimum

Preserve the existing PostgreSQL 16 floor when Team Reports adds the provider-level preflight contract. Keep the merged generator imports formatted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: team-reports rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL 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