Skip to content

improve(msteams): reduce repeated reads during poll cleanup - #146575

Merged
steipete merged 2 commits into
mainfrom
codex/sqlite-teams-poll-cleanup-0912
Sep 13, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/sqlite-teams-poll-cleanup-0912

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Related: #146197

What Problem This Solves

Teams poll creation repeatedly fetches every stored vote bucket when cleaning up several expired or excess polls. A concurrent Doctor import can also race with a vote submitted through the direct CLI path.

User Impact

Poll cleanup loads fewer rows while preserving retained polls and votes. Doctor imports share the existing poll mutation lock, so they cannot overwrite a concurrent vote. No new storage migration, configuration change, or operator action is required.

Why This Change Was Made

Reuse one ordered vote-bucket snapshot within each locked prune, loading it only after the first metadata deletion. The legacy poll importer uses that same lock through import, verification, and archival. Existing quotas, retention, transaction boundaries, and partial-failure ordering stay intact.

An opt-in published-upgrade scenario installs the standalone Teams plugin, checks upgrade survival, then verifies installed candidate code before exercising a separate candidate Doctor import.

Evidence

Validation completed:

  • Real file-backed poll, mutation-lock, and Doctor tests: 42 tests across four files. The expanded cleanup regression fails on the original owner (8 full bucket scans versus a budget of 2). The concurrent migration regression fails on the original importer because voting/pruning completes before the paused import resumes.
  • Coverage includes no-prune lazy reads, simultaneous expiry/cap pruning, SQLite delete failures, valid JSON null values, corrupt JSON, concurrent vote preservation, expired metadata/bucket cleanup, exact original archive bytes, restored-source convergence, and existing migration quota/source-retention cases.
  • File-backed before/after benchmark through actual createPoll: original-created stores with synthetic SDK backlog, alternating variants, two warmup pairs and five uninstrumented measured pairs per completed fixture, then a separately instrumented pair. Schema and all persisted user-table state matched, including subsequent reopened-owner vote writes.
Fixture Bucket-namespace SQL reads Fetched rows Payload bytes Median createPoll
999 existing polls, no removals 3 -> 3 3,994 -> 3,994 1,600,466 -> 1,600,466 50.6 -> 53.0 ms
1,000 existing polls, 20 expired 23 -> 4 83,198 -> 7,996 33,341,938 -> 3,204,243 245.7 -> 85.8 ms

Timings are from one WSL Linux host with Node 26.8.2 and include lock acquisition, store open, metadata/vote writes, and pruning. Fixture backup and verification are outside timing. The no-prune case shows no demonstrated timing change. Three bounded benchmark harness invocations reached their 180-second limit; the larger fixture has only three completed measured pairs and no counted sample, so it is excluded from this table. Completed results were preserved between the last two invocations.

All 264 planner, assertion and upgrade-fixture tests pass, as do six Doctor declaration/closure guards. Fresh independent review found no actionable P0-P2 findings. Production, extension-test, script and root-test types pass, along with formatting, lint and selected guards. All 264 harness tests and 15 poll tests pass again on the final source checkout. Initial test-style errors were fixed; the nested-install lint guard was resolved with a separate physical worktree and its own frozen install.

CI exposed a test extraction starting inside the newly guarded consent block. The follow-up extracts the complete recovery region without changing assertions: the original test fails with an unmatched fi, and all 37 mobile, watchOS and Teams scenario tests pass after the repair. Scoped checks and fresh independent review pass.

The opt-in upgrade scenario uses published OpenClaw and Teams 2026.9.4. It checks first-hop preservation, then compares installed JavaScript against the candidate Teams archive before importing a separate legacy specimen through candidate Doctor. The first specimen may be imported before the external plugin refresh; it is not attributed to the new importer. Package Acceptance run 34726845164 tests source 8ed0875; the final follow-up cfd3dc2 changes only the unpublished mobile test. All product, build and upgrade-runner sources are unchanged. This supports reuse of the runtime proof, but does not claim byte-identical rebuilt packages or acceptance on the final commit. Final-head required CI 34727480190 passed. Package Acceptance 34726845164 passed on its first attempt: exactly one Teams cell, 570 seconds, no retries or timeouts. The retained log confirms published-driver migration, byte-for-byte verification of all 35 installed candidate runtime files, a separately seeded Doctor import, subsequent survival assertions, and Gateway start/health/status. The survival assertions verify complete metadata/votes, storage keys, null TTLs and exact archive bytes. The uploaded artifact retains the lane log, plan and summary; raw database/archive files were not uploaded for separate inspection. Restart mode was manual. No live Teams messages or production state are used.

Candidate core tarball SHA-256: 07c513888262fd8d74246736db376874d3acf62b7da7b1220c2cf3bfd5af09e4. Candidate Teams tarball SHA-256: 8aa6c09f33b5746644f803b080d3d2ba8bc583d23f7ed5f8cd95986da759238b. Upgrade evidence artifact.

Native landing completed as 369f63b633d879eddabff4e3da6d3cb8306b6388 and was verified on main. Native completion.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 channel: msteams Channel integration: msteams scripts Repository scripts docker Docker and sandbox tooling size: L maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 00:00
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 8:22 PM ET / September 13, 2026, 00:22 UTC (Revision 2).

ClawSweeper review

What this changes

The Teams plugin reuses vote data during poll cleanup, serializes legacy imports with voting, and adds a published-upgrade validation scenario.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this is useful, maintainer-sponsored work absent from current main and v2026.9.4. Source review found no blocking introduced code defect.

Priority: P2
Reviewed head: cfd3dc20b4d2e879819b74b1d5e0b74a98fc41a3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful owner-level measurements and regression coverage; packaged upgrade validation remains outstanding.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The ordinary external-contributor gate is exempt for this member-authored PR. Recorded file-backed createPoll measurements support cleanup behavior; the repository-required published-driver and packaged Doctor validation remains a separate prerequisite.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor gate is exempt for this member-authored PR. Recorded file-backed createPoll measurements support cleanup behavior; the repository-required published-driver and packaged Doctor validation remains a separate prerequisite.
Evidence reviewed 10 items Current main still needs the change: Current main retains a full vote-bucket read for each removed poll and does not wrap the legacy poll importer in the shared mutation lock.
Released behavior: The v2026.9.4 poll owner also reads vote buckets separately for every pruned poll; this optimization is not present in the supplied latest release.
Snapshot lifetime and failure ordering: The snapshot is local to one locked prune, loads after the first metadata deletion, retains entry order, and removes cached entries only after successful deletion. The existing retention limit, expiry policy, and public store methods remain unchanged.
Findings None None.
Security None None.

How this fits together

The Teams plugin stores poll metadata and votes in OpenClaw’s shared SQLite database. Poll creation, incoming votes, and Doctor’s legacy imports access this state before subsequent poll reads and cleanup.

flowchart TD
  A[Poll creation and incoming votes] --> C[Shared poll mutation lock]
  B[Doctor legacy import] --> C
  C --> D[Poll metadata and vote storage]
  D --> E{Expired or excess polls?}
  E -->|Yes| F[Cleanup using one vote snapshot]
  E -->|No| G[Retained polls and votes]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - Published-driver preservation and execution of the installed candidate Doctor remain unverified until the targeted upgrade scenario completes; owner benchmarks do not establish those installation boundaries.
  • Complete next step (P2) - Record and inspect the successful published-upgrade scenario, including installed candidate Teams bytes, the separate Doctor import, retained votes, and exact archive bytes.
Agent review details

Security

None.

PR surface

Source +18, Tests +446, Other +221. Total +685 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 2 80 62 +18
Tests 5 520 74 +446
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 6 234 13 +221
Total 13 834 149 +685

Review metrics

Metric Value Why it matters
Measured cleanup reads 23 → 4 with 20 expired polls; no-prune reads remain 3 The reported file-backed benchmark demonstrates savings specifically when cleanup removes several polls.
Growth allocation Production +18 lines; upgrade tooling +221; tests +446 Runtime growth is limited to snapshot reuse and locking; most growth supplies regression and upgrade validation.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/msteams/doctor-contract-api.ts, migration/backfill/repair: scripts/e2e/lib/upgrade-survivor/config-recipe.mts, migration/backfill/repair: scripts/e2e/lib/upgrade-survivor/msteams-polls.mjs, serialized state: scripts/e2e/lib/upgrade-survivor/msteams-polls.mjs, unknown-data-model-change: extensions/msteams/doctor-contract-api.ts, unknown-data-model-change: scripts/e2e/lib/upgrade-survivor/assertions.mjs, and 2 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one poll mutation lock and a lazy per-prune snapshot while preserving existing votes, retention, archive bytes, and upgrade behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one poll mutation lock and a lazy per-prune snapshot while preserving existing votes, retention, archive bytes, and upgrade behavior.

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

Yes, from source: pruning multiple polls repeats full bucket reads, and an unlocked importer can overwrite a vote submitted between its lookup and write. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes. Reusing the existing lock and a mutation-local snapshot addresses both mechanisms without adding a competing store, SDK API, schema, or configuration option.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 94a56b2f78fb.

Labels

Label justifications:

  • P2: This is a bounded Teams storage optimization and concurrent-import repair without evidence of an urgent widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 ordinary external-contributor gate is exempt for this member-authored PR. Recorded file-backed createPoll measurements support cleanup behavior; the repository-required published-driver and packaged Doctor validation remains a separate prerequisite.

Evidence

What I checked:

  • Current main still needs the change: Current main retains a full vote-bucket read for each removed poll and does not wrap the legacy poll importer in the shared mutation lock. (extensions/msteams/src/polls.ts:403, 94a56b2f78fb)
  • Released behavior: The v2026.9.4 poll owner also reads vote buckets separately for every pruned poll; this optimization is not present in the supplied latest release. (extensions/msteams/src/polls.ts:403, 3a9d69db306c)
  • Snapshot lifetime and failure ordering: The snapshot is local to one locked prune, loads after the first metadata deletion, retains entry order, and removes cached entries only after successful deletion. The existing retention limit, expiry policy, and public store methods remain unchanged. (extensions/msteams/src/polls.ts:409, cfd3dc20b4d2)
  • Importer coordination: Doctor uses the same state-directory and polls lock as runtime writes through import, survivor verification, and archival. The existing file-lock owner awaits the callback before releasing the lock. (extensions/msteams/doctor-contract-api.ts:403, cfd3dc20b4d2)
  • Regression coverage inspected: Poll tests cover scan budgets, retained state, delete failures, null values, and malformed JSON. Doctor coverage pauses import while voting attempts to proceed and verifies votes, cleanup, archive bytes, and restored-source convergence. Tests were inspected, not executed during this read-only review. (extensions/msteams/doctor-contract-api.test.ts:156, cfd3dc20b4d2)
  • Recorded owner-level measurements: The supplied PR body reports actual file-backed createPoll runs on WSL Linux with Node 26.8.2: the 20-expired-poll fixture reduced namespace reads from 23 to 4 and median time from 245.7 to 85.8 ms, with persisted-state and reopened-write parity. It explicitly excludes incomplete larger-fixture results. Captured context identity: 007d9ce9878f7369d10ccd6d6d49ccf5f1f6ad277841810b149ed48771df7c0d. (8ed08752f255)

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.

  • Record the completed published-upgrade result showing candidate Teams byte verification, the separate Doctor import, retained votes, and unchanged archive bytes.

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-13T00:06:59.787Z sha 8ed0875 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 13, 2026
@steipete
steipete merged commit 369f63b into main Sep 13, 2026
116 checks passed
@steipete
steipete deleted the codex/sqlite-teams-poll-cleanup-0912 branch September 13, 2026 00:33
@steipete

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

channel: msteams Channel integration: msteams docker Docker and sandbox tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L 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