Skip to content

OpenClaw-owned semantic enrichment for chat turns and imports#192

Draft
Jurij89 wants to merge 71 commits intofeat/dkg-memory-integrationfrom
codex/openclaw-semantic-enrichment
Draft

OpenClaw-owned semantic enrichment for chat turns and imports#192
Jurij89 wants to merge 71 commits intofeat/dkg-memory-integrationfrom
codex/openclaw-semantic-enrichment

Conversation

@Jurij89
Copy link
Copy Markdown
Contributor

@Jurij89 Jurij89 commented Apr 15, 2026

Summary

  • Add a durable semantic_enrichment_events outbox in the daemon/node-ui DB layer so chat turns and file imports can enqueue semantic enrichment work without introducing a node-owned LLM worker.
  • Add OpenClaw-owned execution for those events through the adapter runtime: the new semantic enrichment worker leases jobs from the daemon, runs api.runtime.subagent.*, parses structured triples, and appends them back into the same DKG graph with source-grounded provenance.
  • Extend chat persistence, file import, extraction-status, and client/UI response surfaces to report semantic enrichment status, plus ship a temporary authenticated _ontology writer and replace-only ontologyRef handling for day-one ontology seeding.
  • Keep v1 intentionally scoped to source-grounded expansion of chat turns and imported files. This PR does not add WM/project-memory distillation or broader dreaming-style synthesis over all memory.

Related

Files changed

File What
packages/node-ui/src/db.ts Added the semantic enrichment outbox table, lease-safe claim/renew/fail/complete helpers, and retention/health plumbing.
packages/node-ui/test/semantic-enrichment-events.test.ts Added lifecycle coverage for claim, renew, reclaim, retry, dead-letter, and prune behavior.
packages/cli/src/semantic-enrichment.ts Added shared semantic enrichment payload, descriptor, and idempotency helper types for daemon-side orchestration.
packages/cli/src/daemon.ts Enqueued semantic events from persist-turn and import-file, added internal semantic-enrichment endpoints, same-graph append/provenance handling, _ontology seeding helper, and status-surface updates.
packages/cli/src/extraction-status.ts Extended extraction status records with semantic enrichment metadata.
packages/cli/src/api-client.ts Exposed semantic enrichment descriptors in CLI client import/extraction-status responses.
packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Added the adapter-owned claimant loop that leases daemon events, loads ontology/source context, runs the OpenClaw subagent, and appends extracted triples.
packages/adapter-openclaw/src/DkgChannelPlugin.ts Wired the channel plugin to the new worker, reused the ALS-stamped project context, and passed semantic-enrichment wakeups through the existing chat persistence flow.
packages/adapter-openclaw/src/dkg-client.ts Added daemon client methods and payload types for semantic event claim/renew/append/fail plus file-text retrieval.
packages/adapter-openclaw/src/types.ts Added runtime subagent typings needed for capability-gated OpenClaw execution.
packages/adapter-openclaw/test/semantic-enrichment-worker.test.ts Added focused adapter worker coverage for runtime probing and daemon-queue execution.
packages/node-ui/src/ui/api.ts Surfaced semantic enrichment status to the UI import/extraction-status client.

Test plan

  • Run pnpm --filter @origintrail-official/dkg-node-ui exec vitest run test/db.test.ts test/semantic-enrichment-events.test.ts
  • Run pnpm --filter @origintrail-official/dkg-adapter-openclaw test
  • Run pnpm --filter @origintrail-official/dkg exec vitest run test/daemon-openclaw.test.ts test/import-file-integration.test.ts test/extraction-status.test.ts
  • Run pnpm build:runtime
  • Verify the semantic enrichment flow stays asynchronous and source-grounded by checking that chat/file writes still complete before enrichment and that semantic status is returned on the API surfaces

Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
@Jurij89
Copy link
Copy Markdown
Contributor Author

Jurij89 commented Apr 15, 2026

Pushed follow-up hardening on codex/openclaw-semantic-enrichment (commit a04a5964).

This round closes the latest review findings around:

  • semantic append idempotency / replay handling
  • safe RDF-term validation on semantic append input
  • projectContextGraphId validation before enqueue
  • wake-only transport reuse by deriving bridge/gateway targets from wakeUrl
  • assistant-role preference when parsing subagent output
  • opaque ontologyRef normalization + quoted prompt rendering
  • clearer typed-literal prompt guidance
  • authoritative semantic triple counts rehydrated from _meta / per-event provenance instead of caller payloads

Verification rerun after the final fixes:

  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/semantic-enrichment-worker.test.ts
  • pnpm --filter @origintrail-official/dkg exec vitest run test/daemon-openclaw.test.ts
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw test
  • pnpm --filter @origintrail-official/dkg exec vitest run test/semantic-enrichment.test.ts test/import-file-integration.test.ts test/extraction-status.test.ts
  • pnpm build:runtime

I also had two fresh independent review passes on the updated diff and folded their last concrete findings into this push.

Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
@Jurij89
Copy link
Copy Markdown
Contributor Author

Jurij89 commented Apr 15, 2026

Closed the remaining open review threads on current HEAD (fe60ae5b).

What changed in this round:

  • made semantic enqueueing best-effort after the primary write path, so persist-turn / import-file no longer return false 500s when queue creation or wake delivery fails
  • gated file-import semantic enqueueing on a configured OpenClaw local-agent transport to avoid orphaned pending events on standalone installs
  • restored the previous _meta.semanticTripleCount if a file-import semantic append replacement write fails
  • changed malformed/non-JSON subagent output from an implicit zero-triple success into a retryable failure
  • bounded worker shutdown so a stalled in-flight drain no longer hangs stop forever

Verification rerun:

  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/semantic-enrichment-worker.test.ts
  • pnpm --filter @origintrail-official/dkg exec vitest run test/daemon-openclaw.test.ts
  • pnpm --filter @origintrail-official/dkg exec vitest run test/semantic-enrichment.test.ts test/import-file-integration.test.ts test/extraction-status.test.ts
  • pnpm build:runtime

Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
@Jurij89
Copy link
Copy Markdown
Contributor Author

Jurij89 commented Apr 15, 2026

Pushed follow-up \8b49a17e\ on \codex/openclaw-semantic-enrichment\ and closed the latest four review threads.

This round:

  • gates durable semantic queueing on an explicit adapter-advertised \semanticEnrichment\ capability instead of \enabled\ alone
  • validates quoted \_ontology/write\ RDF literals before \store.insert\
  • makes the temporary \_ontology\ deprecation payload point at the live helper while marking the spec route as planned
  • snapshots file-import extraction-status records in \DashboardDB\ and rehydrates them for restart-safe \/api/assertion/:name/extraction-status\ polling

Verification rerun:

  • \pnpm --filter @origintrail-official/dkg exec vitest run test/daemon-openclaw.test.ts\
  • \pnpm --filter @origintrail-official/dkg-node-ui exec vitest run test/semantic-enrichment-events.test.ts\
  • \pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/plugin.test.ts\
  • \pnpm build:runtime\

I also did two independent teammate re-checks on the final diff; one surfaced a stale already-fixed concern and the other came back with no blocking findings.

Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/node-ui/src/db.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/cli/src/daemon.ts Outdated
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Codex review produced 2 comment(s) but all targeted lines outside the diff and were dropped. Check the workflow logs for details.

@Jurij89
Copy link
Copy Markdown
Contributor Author

Jurij89 commented Apr 27, 2026

Follow-up on the latest Codex Review run where GitHub dropped 2 comments because they targeted lines outside the current diff:

  • The no-text / ack-send stale-head concern appears stale against current ChatTurnWriter: onMessageSent(...) consumes the pending inbound before failed/no-text exits, so it does not leave that inbound at the queue head.
  • The W4a/W4b consecutive-user pairing concern was valid in spirit. Fixed in f369cb76 by making W4a computeDelta(...) match consecutive user messages FIFO against assistant messages, aligning it with W4b's pendingUserMessages queue instead of overwriting with the latest user.

Verification:

  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw run build
  • pnpm build:runtime

Comment thread packages/cli/src/daemon/semantic-enrichment.ts
Comment thread packages/cli/src/daemon/local-agents.ts Outdated
Comment thread packages/node-ui/src/db.ts
Comment thread packages/cli/src/daemon/semantic-enrichment.ts Outdated
Comment thread packages/node-ui/src/db.ts Outdated
Comment thread packages/adapter-openclaw/src/SemanticEnrichmentWorker.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgNodePlugin.ts Outdated
Comment thread packages/cli/src/daemon/semantic-enrichment.ts Outdated
Comment thread packages/node-ui/src/db.ts
Comment thread packages/cli/src/daemon/routes/assertion.ts Outdated
Comment thread packages/cli/src/daemon/semantic-enrichment.ts
Comment thread packages/cli/src/daemon/semantic-enrichment.ts
Comment thread packages/cli/src/daemon/semantic-enrichment.ts Outdated
Comment thread packages/adapter-openclaw/src/dkg-client.ts
Comment thread packages/cli/src/daemon/local-agents.ts
Comment thread packages/cli/src/daemon/semantic-enrichment.ts Outdated
Comment thread packages/cli/src/daemon/semantic-enrichment.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts Outdated
Comment thread packages/cli/src/daemon/semantic-enrichment.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgNodePlugin.ts Outdated
Comment thread packages/cli/src/daemon/semantic-enrichment.ts
Comment thread packages/cli/src/daemon/semantic-enrichment.ts
Comment thread packages/cli/src/daemon/semantic-enrichment.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts
Comment thread packages/cli/src/daemon/semantic-enrichment.ts
Comment thread packages/cli/src/daemon/semantic-enrichment.ts
Comment thread packages/cli/src/daemon/semantic-enrichment.ts Outdated
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Codex review completed — no issues found.

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.

1 participant