Skip to content

PR #539 (6/10 rebased): feat: add opt-in LCM task suggestion tools#27

Closed
100yenadmin wants to merge 5 commits into
mainfrom
rebase/539
Closed

PR #539 (6/10 rebased): feat: add opt-in LCM task suggestion tools#27
100yenadmin wants to merge 5 commits into
mainfrom
rebase/539

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented May 3, 2026

Copy link
Copy Markdown
Member

Rebased upstream Martian-Engineering/lossless-claw#539 onto our test fork's main, which already carries the 8 hotfix PRs (Martian-Engineering#572-Martian-Engineering#579) plus PR Martian-Engineering#516.

Resolution strategy: inverse merge

pr-539 was branched from an older main that predates the hotfix stack, so a literal "take pr-539" would delete hotfix code. Started from main and layered pr-539's net-new code on top.

Per-file resolution

File Strategy
src/engine.ts 3-way UNION. Preserved hotfixes (normalizeSummaryOverlapText, messageContentCoveredBySummary, deps.clock.now(), TableColumnInfo cast). Added pr-539's ObservedWorkStore + TaskBridgeSuggestionStore fields, inits, and getters.
src/db/migration.ts Took main; injected pr-539's ensureObservedWorkTables, ensureObservedWorkIndexes, ensureTaskBridgeSuggestionTables, ensureTaskBridgeSuggestionIndexes migration steps after ensureRollupViews. Also fixed SummaryColumnInfo -> TableColumnInfo in addColumnIfMissing (pr-539 already had the right type).
src/plugin/index.ts Took main; added imports + registerTool calls for createLcmWorkDensityTool plus the taskBridgeToolsEnabled-gated createLcmTaskSuggestionsTool / createLcmTaskSuggestionReviewTool.
openclaw.plugin.json Union; appended lcm_task_suggestion_review, lcm_task_suggestions, lcm_work_density to contracts.tools. Added schema + uiHints for taskBridgeToolsEnabled alongside main's rollup token-budget keys.
src/db/config.ts Union; kept rollup token-budget knobs and added taskBridgeToolsEnabled config field with LCM_TASK_BRIDGE_TOOLS_ENABLED env wiring.
src/timezone-windows.ts Took pr-539's startOfWeekDayString export.
README.md, docs/configuration.md Added LCM_TASK_BRIDGE_TOOLS_ENABLED / taskBridgeToolsEnabled documentation.
test/engine.test.ts, test/rollup-store-builder.test.ts, src/tools/lcm-recent-tool.ts, src/rollup-builder.ts, src/store/rollup-store.ts Took main (hotfix-only files).
New pr-539 files Taken cleanly: observed-work-store.ts, task-bridge-suggestion-store.ts, lcm-task-suggestions-tool.ts, lcm-work-density-tool.ts, plus tests, specs, changesets.

Validation

  • 0 conflict markers across the worktree
  • npm run build clean (815.6kb bundle)
  • npm test: 988/988 passing (53/53 suites)

Net diff

19 files changed, 3161 insertions(+), 9 deletions(-)

Summary by CodeRabbit

  • New Features

    • Added work density tool to report observed work summaries across time periods.
    • Added event observation search functionality.
    • Added opt-in task suggestion tools with user review capability (non-destructive, suggestion-only).
    • Added taskBridgeToolsEnabled and observedWorkMaintenanceEnabled configuration options.
  • Documentation

    • Added specifications for observed work density tracking.
    • Added specifications for task bridge suggestion system.
    • Updated configuration documentation with new settings.
  • Tests

    • Added comprehensive test coverage for observed work and task bridge systems.

…suggestion tools

Rebased upstream PR Martian-Engineering#539 (Martian-Engineering#539) onto
main with the 8 hotfix PRs (Martian-Engineering#572-Martian-Engineering#579) + Martian-Engineering#516 already in place.

Inverse-merge resolution per refined policy:
- engine.ts: 3-way UNION; preserved hotfixes (normalizeSummaryOverlapText,
  messageContentCoveredBySummary, clock.now(), TableColumnInfo cast) AND
  added pr-539's ObservedWorkStore + TaskBridgeSuggestionStore fields,
  inits, and getters.
- migration.ts: kept main's Martian-Engineering#569+Martian-Engineering#574 migrations; injected pr-539's new
  ensureObservedWorkTables, ensureObservedWorkIndexes,
  ensureTaskBridgeSuggestionTables, ensureTaskBridgeSuggestionIndexes
  steps after ensureRollupViews. Fixed SummaryColumnInfo->TableColumnInfo
  in addColumnIfMissing helper.
- plugin/index.ts: kept main's tool wiring; added imports +
  registerTool calls for createLcmWorkDensityTool plus gated
  createLcmTaskSuggestionsTool / createLcmTaskSuggestionReviewTool.
- openclaw.plugin.json: union; appended lcm_task_suggestion_review,
  lcm_task_suggestions, lcm_work_density to contracts.tools and added
  schema/uiHints for taskBridgeToolsEnabled while preserving rollup
  token-budget keys.
- db/config.ts: union; both rollup token-budget knobs and
  taskBridgeToolsEnabled config field + env wiring.
- timezone-windows.ts: took pr-539's startOfWeekDayString export.
- README.md / docs/configuration.md: added LCM_TASK_BRIDGE_TOOLS_ENABLED
  and taskBridgeToolsEnabled docs alongside main hotfix doc lines.
- test/engine.test.ts, test/rollup-store-builder.test.ts,
  src/tools/lcm-recent-tool.ts, src/rollup-builder.ts,
  src/store/rollup-store.ts: took main (hotfix code only).
- New pr-539 files (observed-work-store, task-bridge-suggestion-store,
  lcm-task-suggestions-tool, lcm-work-density-tool, plus tests/specs/
  changesets) taken cleanly.

Validation: 0 conflict markers, npm run build clean, 988/988 tests pass.
Copilot AI review requested due to automatic review settings May 3, 2026 23:11
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented May 3, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces observed-work density tracking, event observations, and a task-bridge suggestion ledger for LCM. New database stores persist extracted work items and events from conversation summaries, enable incremental processing with cursor-based replay guards, and expose read-only density queries and suggestion management via opt-in tools.

Changes

Observed Work, Event Observations, and Task Bridge Suggestions

Layer / File(s) Summary
Configuration & Schema
src/db/config.ts, src/db/migration.ts, openclaw.plugin.json, docs/configuration.md, README.md
Config adds observedWorkMaintenanceEnabled and taskBridgeToolsEnabled boolean flags with env overrides. Plugin declares new tools and UI hints. Migrations create lcm_observed_work_items, lcm_observed_work_sources, lcm_observed_work_state, lcm_event_observations, and lcm_task_bridge_suggestions tables with supporting indexes.
Data Stores
src/store/observed-work-store.ts, src/store/event-observation-store.ts, src/store/task-bridge-suggestion-store.ts
Three stores backed by SQLite: ObservedWorkStore manages work-item upserts with conflict-aware merging (preserves terminal status, ensures monotonic counters, clamps confidence), source deduplication, processing-cursor state, and density queries with optional source inclusion. EventObservationStore validates and normalizes timestamps to UTC ISO-8601, deduplicates source IDs, and executes time/kind/query-filtered observation lookups with bounded results. TaskBridgeSuggestionStore validates suggestion inputs, persists ledger entries with review-state transitions (pending → accepted/dismissed), and prevents concurrent races via transactional read-then-write; bulk upsert uses per-row SAVEPOINTs to demote partial failures while preserving batch order.
Extraction Logic
src/observed-work-extractor.ts, src/timezone-windows.ts
ObservedWorkExtractor scans leaf summaries using a (created_at, summary_id, rowid) cursor to avoid same-second duplication. Applies regex-driven classification to extract work candidates (completion/unfinished/decision cues with negation-aware patterns) and event observations, derives stable hashes (conversationId:kind:topicKey) as work-item IDs, computes confidence bands, and upserts work/events with idempotency guards. On failure, marks state pendingRebuild=true to force full rescan. Returns aggregate scan/upsert counts. Utility startOfWeekDayString computes Monday-aligned dates for period queries.
Engine Wiring
src/engine.ts
Engine constructor instantiates EventObservationStore, ObservedWorkStore, ObservedWorkExtractor, and TaskBridgeSuggestionStore, exposing them via public getters. The maintain() flow conditionally runs observedWorkExtractor.processConversation() when config.observedWorkMaintenanceEnabled, logs extraction metrics, and on failure sets pendingRebuild=true and clears the processing cursor.
Tools & Plugin Registration
src/tools/lcm-work-density-tool.ts, src/tools/lcm-event-search-tool.ts, src/tools/lcm-task-suggestions-tool.ts, src/plugin/index.ts
lcm_work_density resolves timezone-aware period bounds (today/week/month/date:YYYY-MM-DD), queries density with optional statuses/kinds/topic/confidence filters, and applies output-budget trimming (iteratively removes per-item sources or whole items until JSON size fits maxOutputTokens). lcm_event_search filters observations by conversation/time/kind/query and returns bounded ranked results. lcm_task_suggestions generates deterministic suggestion IDs, derives candidates from observed-work density, and on record mode bulk-upserts into the suggestion store (preview mode disables writes). lcm_task_suggestion_review updates suggestion review status (accepted/dismissed) while validating ownership. Plugin conditionally registers these tools under their respective feature flags.
Tests & Documentation
test/observed-work-store.test.ts, test/task-bridge-suggestion-store.test.ts, specs/lcm-observed-work-density-option-b.md, specs/lcm-task-bridge-option-c-experimental.md, .changeset/*
Comprehensive test suites verify extractor cursor semantics (no-duplicate same-second handling, rowid drift recovery, fallback-to-rowid when processed-summary ID is missing), evidence redaction, semantic kind preservation, density aggregation, source visibility toggling, review state transitions, and bulk upsert ordering/demotions. End-to-end tool tests exercise parameter validation, period parsing, scope enforcement, and output budget trimming with accounting. Spec documents define thesis, data models, tool contracts, behavioral rules, and implementation scope (inert store + tests; no default-on behavior or task mutation).

Sequence Diagram(s)

Skipped (configuration-heavy changes with independent store operations; no multi-component sequential flows requiring visualization).

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~90 minutes

Rationale: Substantial changes spanning five store implementations with complex SQL (conflict handling, cursor semantics, budget-aware query trimming), regex-driven evidence extraction with replay guards, three tools with parameter validation and normalization, transactional concurrency semantics, and 1900+ lines of heterogeneous tests validating edge cases (rowid drift, same-second summaries, source deduplication, review transitions). Requires careful review of: (1) cursor idempotency & missing-summary-ID fallback logic, (2) conflict-resolution merge semantics (terminal status, monotonic counters, confidence clamping), (3) transactional boundaries in bulk operations, (4) regex classification correctness and negation handling, (5) timestamp canonicalization and timezone-aware period arithmetic, (6) output budget trimming and accounting accuracy.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the primary change: adding opt-in LCM task suggestion tools. It accurately reflects the main feature introduced across the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rebase/539

Review rate limit: 0/5 reviews remaining, refill in 57 minutes and 13 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in “observed work” read model and associated tools for summarizing work density, plus an inert task-suggestion ledger (preview/record + review) that explicitly does not mutate external tasks.

Changes:

  • Introduces SQLite tables + stores for observed work items/sources/state and task-bridge suggestions.
  • Adds lcm_work_density tool and opt-in lcm_task_suggestions / lcm_task_suggestion_review tools (gated by taskBridgeToolsEnabled).
  • Updates plugin wiring, config/env, manifest, docs, and adds comprehensive tests/specs/changesets.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/db/migration.ts Adds observed-work + task-bridge suggestion tables and indexes; small type alias cleanup.
src/store/observed-work-store.ts Implements observed work persistence + density querying with optional source loading and limits.
src/tools/lcm-work-density-tool.ts Exposes observed work density as a tool with period parsing and output-budget trimming.
src/store/task-bridge-suggestion-store.ts Implements inert suggestion ledger (upsert pending, list, review).
src/tools/lcm-task-suggestions-tool.ts Generates/records suggestions from observed work and provides a review tool.
src/timezone-windows.ts Exports startOfWeekDayString for Monday-start week windows on YYYY-MM-DD.
src/plugin/index.ts Registers lcm_work_density and conditionally registers task suggestion tools when enabled.
src/engine.ts Wires new stores into LcmContextEngine and exposes getters.
src/db/config.ts Adds taskBridgeToolsEnabled with LCM_TASK_BRIDGE_TOOLS_ENABLED wiring.
openclaw.plugin.json Adds tool contracts + config schema/uiHints for taskBridgeToolsEnabled.
test/observed-work-store.test.ts Tests migrations, density semantics, period handling, source redaction, and output budget trimming.
test/task-bridge-suggestion-store.test.ts Tests suggestion ledger behavior and tool flows without any external task writes.
docs/configuration.md / README.md Documents the new opt-in config/env var.
specs/lcm-observed-work-density-option-b.md Design/spec doc for observed work density (Option B).
specs/lcm-task-bridge-option-c-experimental.md Design/spec doc for experimental suggestion-ledger bridge (Option C).
.changeset/*.md Release notes for observed work density and suggestion tooling/storage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tools/lcm-task-suggestions-tool.ts
Comment thread src/tools/lcm-task-suggestions-tool.ts
Comment thread src/store/task-bridge-suggestion-store.ts
Comment thread src/tools/lcm-work-density-tool.ts Outdated
Comment thread src/tools/lcm-work-density-tool.ts
Eva added 2 commits May 4, 2026 06:23
…GIN IMMEDIATE bypass); add bulk tests

Wave 2 fix on PR #27 / rebase/539. Wave 1 (1df72b9) introduced a private
runInTransaction helper that called raw BEGIN IMMEDIATE / COMMIT / ROLLBACK
on the shared DatabaseSync handle, with a fallback nested-transaction path
guarded by `(this.db as unknown as { inTransaction?: boolean }).inTransaction`.

Two problems with that:

1. CRITICAL-1 — `node:sqlite`'s DatabaseSync does NOT expose `inTransaction`
   (that's a better-sqlite3 API). The fallback path was unreachable code.
2. CRITICAL-2 — the helper bypassed `withDatabaseTransaction` from
   src/transaction-mutex.ts, the per-database async mutex that serializes
   concurrent transaction entry points sharing the same DB handle. That's
   the exact race the mutex was built to fix (lossless-claw#260): two async
   paths racing BEGIN on a shared connection blow up with "cannot start a
   transaction within a transaction".

Fix: replace `runInTransaction` with `withDatabaseTransaction(db, "BEGIN
IMMEDIATE", ...)`. That's async, so `bulkUpsertSuggestions` and
`upsertSuggestion` become async. The tool callsite (lcm-task-suggestions-tool
record path) was already in an async execute() — now awaits the bulk call.

Per-row failure semantics (MAJOR-1 in audit): pre-Wave-1, a bad row didn't
poison the batch. Post-Wave-1, one FK-deletion race in 50 rows aborted the
whole transaction. Restored with per-row SAVEPOINTs inside the outer
transaction — a row that throws during INSERT (e.g. concurrent FK-delete of
its work item or source evidence) is demoted to a new "skipped" outcome.
The result array stays order-preserving so callers can correlate inputs ↔
results positionally. Input validation errors (bad confidence, blank ID,
non-pending status, missing taskId for targeted kinds, no source IDs) still
throw before the transaction opens — caller gets the same fast-fail.

Empty-input early return preserved (no transaction opened for `[]`).

Tests (MAJOR-2): added bulkUpsertSuggestions describe block with 4 cases —
empty input, mixed insert+refresh, preserved_reviewed determinism with
order preservation, mid-batch skipped row leaving good rows committed.
Existing upsertSuggestion tests migrated to async/await; validation-error
tests use `rejects.toThrow` since async functions convert sync throws to
rejections.

Total: 992 tests pass (988 baseline + 4 new). Build clean.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tools/lcm-task-suggestions-tool.ts
Comment thread src/plugin/index.ts Outdated
Comment thread src/tools/lcm-work-density-tool.ts Outdated
Comment thread src/tools/lcm-task-suggestions-tool.ts
Comment thread src/tools/lcm-task-suggestions-tool.ts Outdated
…ions on top

PR #27 (rebase/539) carried older versions of observed-work-store,
work-density-tool, and migration.ts that pre-dated PR #20/#21/#22/#25/#28
hardening on release/v0.9.4. This commit takes the release/v0.9.4 versions
of those files as the base and layers PR #27's NEW work on top:

- KEPT (PR #27 additions, layered on release):
  - bulkUpsertSuggestions API (uses release's mutex routing + per-row SAVEPOINT)
  - getSuggestionConversationId helper
  - taskBridgeToolsEnabled config flag
  - reviewSuggestion suggestionId trim
  - lcm_task_suggestions + lcm_task_suggestion_review tools (gated)
  - TaskBridgeSuggestionStore engine wiring + getter

- PORT-FORWARDED from release/v0.9.4:
  - src/store/observed-work-store.ts (cursor state, getItem, listItems, etc.)
  - src/store/event-observation-store.ts (NEW from release; wired in engine)
  - src/observed-work-extractor.ts (NEW from release; NEGATED_COMPLETION_RE,
    fingerprintVersion, clearProcessingCursor)
  - src/tools/lcm-work-density-tool.ts (release hardening)
  - src/tools/lcm-event-search-tool.ts (NEW from release)
  - src/db/migration.ts (release index set)
  - src/db/config.ts (observedWorkMaintenanceEnabled flag preserved)
  - src/plugin/index.ts (release gating + PR #27 task-suggestions blocks)
  - src/engine.ts (release ObservedWorkExtractor + EventObservationStore wiring,
    pendingRebuild + clearProcessingCursor on extraction failure)
  - test/observed-work-store.test.ts (release version aligned with new store API)

- MERGED (release base + PR #27 additions):
  - src/store/task-bridge-suggestion-store.ts: MAX_SUGGESTION_SOURCE_IDS=50 cap,
    chunked source-id IN(...) lookup, ORDER BY suggestion_id ASC tiebreaker,
    SQLInputValue typing — all from release; bulkUpsertSuggestions,
    getSuggestionConversationId, "skipped" outcome, savepoint counter — from PR #27.
  - src/db/config.ts: both observedWorkMaintenanceEnabled (from release) and
    taskBridgeToolsEnabled (from PR #27).
  - src/plugin/index.ts: gates work-density + event-search behind
    observedWorkMaintenanceEnabled; gates task-suggestions tools behind
    taskBridgeToolsEnabled.

- ADDED to openclaw.plugin.json:
  - lcm_event_search to contracts.tools (was missing — manifest drift guard caught it)
  - observedWorkMaintenanceEnabled in uiHints + configSchema

Tests: 1006/1006 pass (was 992 before; release hardening added more coverage).
Net new tsc errors: 0 (332 vs 342 baseline = 10 fewer).
100yenadmin pushed a commit that referenced this pull request May 4, 2026
Conflict resolution: took theirs (rebase/539 port-forwarded release + layered PR #27 on top).
New tools: lcm_task_suggestions + lcm_task_suggestion_review (gated behind taskBridgeToolsEnabled flag, default off).
New store API: bulkUpsertSuggestions (per-row SAVEPOINT, skipped outcome), getSuggestionConversationId (cross-conversation review prevention).
Verified all PR #20-#28 hardening preserved.
@100yenadmin

Copy link
Copy Markdown
Member Author

Merged into release/v0.9.4 at 65a0aaa after Wave 1+2+3 adversarial review and comment resolution. Tracked branch: rebase/539. See release/v0.9.4 for the integrated artifact.

@100yenadmin 100yenadmin closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants