Skip to content

feat: run octolens discovery on a schedule with an integration per subproject - #4989

Merged
themarolt merged 10 commits into
mainfrom
feat/issue-748-octolens-discovery-schedule
Oct 16, 2026
Merged

themarolt merged 10 commits into
mainfrom
feat/issue-748-octolens-discovery-schedule

Conversation

@themarolt

Copy link
Copy Markdown
Contributor

Summary

Runs Octolens keyword-to-project mapping discovery on an hourly connectors_worker Temporal schedule instead of as a connector sync unit, and makes it create the integrations Octolens runs under: one per mapped subproject, plus one segment-less integration that owns the single mention-poll sync unit (Octolens's 500 requests/hour budget is shared org-wide). The mention poll already emits under the subproject integrations (#4988). Once this is deployed with CROWD_OCTOLENS_API_TOKEN set, Octolens mentions start arriving as activities.

Changes

  • New octolensDiscovery workflow, runOctolensDiscovery activity and connectors-octolens-discovery schedule (hourly, overlap SKIP, registered in main.ts next to the dispatcher and shadow-diff schedules). Each run:
    • skips with an info log when CROWD_OCTOLENS_API_TOKEN is not set, before any write;
    • finds or creates the segment-less integration and its mentionPoll sync unit with emitEnabled: true (insert-only, so mentions become activities rather than shadow records);
    • runs the existing discovery rules unchanged (an incomplete Octolens snapshot still writes nothing);
    • in one transaction: finds, creates or restores the Octolens integration of each mapped subproject, upserts its mappings, deactivates mappings no longer seen, and soft-deletes subproject integrations left without keywords;
    • revives the mention-poll unit if it was dead-lettered, since only auth failures dead-letter a unit and discovery's own Octolens calls just succeeded with the same token.
  • An auth failure is not retried within a run; other failures get one retry, and the next hourly run covers the rest.
  • mappingDiscovery is removed from the Octolens manifest and becomes a plain function (octolens/mappingDiscovery.ts). Octolens deps keep only the keyword lookup the poll needs.
  • Data access: new reviveDeadLetteredSyncUnits; the per-integration mapping queries that no longer have callers are removed.
  • Tests: the activity (token guard, emitEnabled, call order inside the transaction, revive only after Octolens answered), the revive query (DB), and the moved discovery logic.

Deployment notes:

  • Set CROWD_OCTOLENS_API_TOKEN on connectors_worker; without it the schedule runs and skips.
  • The schedule is only created when missing. A later change to its interval or timeout needs the existing Temporal schedule deleted first.
  • Prod has no Octolens sync units or integrations today; a hand-made mappingDiscovery unit would fail every hour, so check other environments with SELECT id, "integrationId", "syncName", status FROM integration.sync_units WHERE platform = 'octolens' before deploying there.
  • Protected path: the data-access layer.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Performance improvement
  • Chore / dependency update
  • Documentation

Related issue

Refs linuxfoundation/lfx-cdp-insights-ops#748

The mention poll now resolves each keyword's active mapping across every
Octolens subproject integration and emits under that integration and its
segment, instead of under the poll's own integration. A keyword mapped
under more than one integration is treated as unmapped.

Refs linuxfoundation/lfx-cdp-insights-ops#748

Signed-off-by: Uroš Marolt <uros@marolt.me>
…bproject

Keyword-to-project mapping discovery moves out of the connector's sync units
into an hourly connectors_worker Temporal schedule (overlap skip). Each run
ensures the segment-less anchor integration and its single mention-poll sync
unit, created with emitEnabled so mentions become activities, then writes
each mapping under its subproject's Octolens integration, deactivates the
mappings it no longer sees and soft-deletes subproject integrations left
without keywords. An incomplete Octolens snapshot still writes nothing.

Refs linuxfoundation/lfx-cdp-insights-ops#748

Signed-off-by: Uroš Marolt <uros@marolt.me>
Without CROWD_OCTOLENS_API_TOKEN the hourly run would create the anchor
integration and then fail on every run. It now logs and skips before any
write.

Refs linuxfoundation/lfx-cdp-insights-ops#748

Signed-off-by: Uroš Marolt <uros@marolt.me>
A keyword moving between subprojects was briefly active under both, so a
poll in that window treated it as unmapped and queued a needless full
backfill. The upserts, deactivation and soft-delete now commit together.
Also trims comments to the repo's comment rules.

Refs linuxfoundation/lfx-cdp-insights-ops#748

Signed-off-by: Uroš Marolt <uros@marolt.me>
…rks again

Only provider.auth failures dead-letter a sync unit, and nothing brought
the anchor's mention poll back after the token was fixed. Discovery now
revives it right after its own Octolens calls succeed with that token.

Refs linuxfoundation/lfx-cdp-insights-ops#748

Signed-off-by: Uroš Marolt <uros@marolt.me>
Discovery and the mention poll now work across all subproject
integrations, so the per-integration find, list and deactivate queries
have no callers left.

Refs linuxfoundation/lfx-cdp-insights-ops#748

Signed-off-by: Uroš Marolt <uros@marolt.me>
Integration changes are logged only after the reconcile transaction
commits, an auth failure is no longer retried within a run, the revive
clears the stale auth error, and a missing token logs at info level.

Refs linuxfoundation/lfx-cdp-insights-ops#748

Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 07:20
@cursor

cursor Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Writes integrations, keyword mappings, and sync-unit state on a schedule; incorrect concurrency or reconciliation could misroute mentions or soft-delete integrations, though transactions and SKIP overlap mitigate that.

Overview
Octolens keyword-to-project discovery now runs on an hourly Temporal schedule in connectors_worker instead of as a mappingDiscovery connector sync. The Octolens manifest keeps only mentionPoll; discovery logic is a standalone function that takes a reconcileMappings callback.

Each scheduled run no-ops when CROWD_OCTOLENS_API_TOKEN is unset. Otherwise it ensures a segment-less anchor integration and a single mentionPoll sync unit with emitEnabled: true on insert, runs the same Octolens API mapping rules (still skipping all DB writes on incomplete snapshots), then reconciles mappings in one transaction: create/restore one Octolens integration per subproject, upsert keywords, deactivate unseen mappings org-wide, and soft-delete empty subproject integrations. After a successful Octolens call it revives a dead-lettered mentionPoll on the anchor. The schedule uses overlap SKIP so concurrent discovery cannot cross-soft-delete integrations.

Supporting changes: isOctolensCredentialConfigured, reviveDeadLetteredSyncUnits, reconcileOctolensKeywordMappings in the data layer; Octolens deps trimmed to keyword routing only; tests for the activity, reconcile transaction, and revive behavior.

Reviewed by Cursor Bugbot for commit b37bdef. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI 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.

🔵 Needs a closer look

Live ingestion and automatic integration restoration/deletion warrant human validation, particularly of transactional reconciliation.

1 open finding
What changed in this PR

Moves Octolens mapping discovery to an hourly Temporal schedule, enabling mention ingestion through per-subproject integrations and one shared poll.

Changes:

  • Registers discovery scheduling, workflow, and activity.
  • Reconciles mappings transactionally and revives dead-lettered polling.
  • Removes obsolete discovery dependencies and updates tests.
File Description
services/​libs/​data-access-layer/​src/​octolens/​index.ts Removes unused mapping queries.
services/​libs/​data-access-layer/​src/​octolens/​index.test.ts Adapts mapping tests.
services/​libs/​data-access-layer/​src/​connectors/​syncUnits.ts Adds dead-letter revival.
services/​libs/​data-access-layer/​src/​connectors/​syncUnits.test.ts Tests revival scope and watermark preservation.
services/​libs/​connectors/​src/​credentials.ts Adds token configuration check.
services/​libs/​connectors/​src/​connectors/​octolens/​syncs/​mentionPoll.test.ts Removes obsolete dependency mocks.
services/​libs/​connectors/​src/​connectors/​octolens/​mappingDiscovery.ts Separates discovery from connector syncs.
services/​libs/​connectors/​src/​connectors/​octolens/​mappingDiscovery.test.ts Updates discovery tests.
services/​libs/​connectors/​src/​connectors/​octolens/​index.ts Removes discovery from manifest.
services/​libs/​connectors/​src/​connectors/​octolens/​deps.ts Separates project resolution from polling dependencies.
services/​libs/​connectors/​src/​connectors/​octolens/​deps.test.ts Updates dependency tests.
services/​apps/​connectors_worker/​src/​workflows/​octolensDiscovery.ts Defines discovery workflow and retries.
services/​apps/​connectors_worker/​src/​workflows.ts Exports discovery workflow.
services/​apps/​connectors_worker/​src/​schedules/​octolensDiscovery.ts Creates hourly, non-overlapping schedule.
services/​apps/​connectors_worker/​src/​main.ts Registers discovery schedule.
services/​apps/​connectors_worker/​src/​activities/​octolensDiscoveryActivities.ts Provisions polling and reconciles integrations.
services/​apps/​connectors_worker/​src/​activities/​octolensDiscoveryActivities.test.ts Tests discovery orchestration and guards.
services/​apps/​connectors_worker/​src/​activities.ts Exports discovery activity.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The reconcile is now reconcileOctolensKeywordMappings and is tested
against the real test database: keyword moves, integration restore and
soft-delete, and rollback of every write when a mapping fails partway.
The discovery activity only orchestrates and logs.

Refs linuxfoundation/lfx-cdp-insights-ops#748

Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 07:28

Copilot AI 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.

🔵 Needs a closer look

Automated integration lifecycle changes and first-time live mention emission warrant code-owner review and database-test validation.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@themarolt
themarolt merged commit 27b5bdf into main Oct 16, 2026
14 checks passed
@themarolt
themarolt deleted the feat/issue-748-octolens-discovery-schedule branch October 16, 2026 07:39
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