appsWorkspace onlyv0.2.3

app.worker-application-monolith

Inspect the package guide, declared imports and source relationships.

@lssm-tech/app.worker-application-monolith
Source, release and verification context

Source snapshot bcc79fcc · Declared package version 0.2.3. This page combines the checked-in package guide and manifest; commands and runtime behavior were not executed in this review.

Package source ↗ Manifest ↗
EXPLORE THE PACKAGE

See where this package fits.

Follow a declared connection, inspect an import, then open the source guide when you need the detail.

THIS PACKAGEapp.worker-application-monolithapps

Arrows point from a package to its direct dependency. Each count is derived from the captured manifests.

5 déclarationsSELECT TO INSPECT

Managed CompanyOS Worker Application Monolith

Production status (Vercel-only Managed CompanyOS): this package is not part of the managed CompanyOS production deployment while the cost-capped Vercel topology is active. Production duties are absorbed by packages/apps/api-application-monolith through API snapshots and Vercel Cron, and the web app uses manual refresh/request-time snapshots. Keep this Bun runtime for deterministic proofs, local monitoring, and future VPS mode only; do not wire it as a production readiness dependency for Vercel.

This deferral is part of the canonical private-pilot contract†. Do not activate this worker for the first design-partner pilot.

VPS-suitable Bun worker and WebSocket runtime for Managed CompanyOS background jobs. It publishes deterministic operating-graph snapshots, tracks worker supervision health, and keeps all job projection side-effect-free until production queue, persistence, and provider adapters are approved.

No queue, provider, network, or credential side effects start at module load. The runtime starts only through bun src/server.ts / bun run start.

Special Ops projection contract

The worker-side Special Ops production contract is documented in docs/runbooks/special-ops-monolith-production.md†. Worker projections must consume a repository-compatible tenant/workspace/capability snapshot, preserve correlation IDs across jobs, WebSocket events, replay, and evidence, and surface degraded/stale Special Ops state instead of hiding it behind a green worker response.

Runtime surface

File Objectif
src/server.ts Bun HTTP + WebSocket runtime; all route handlers and WebSocket server
src/index.ts Deterministic job projection: worker runtime, job lifecycle, correlation ID proof, degraded-state evaluation, idempotency store
src/live-client.ts WebSocket client with exponential-backoff reconnect for proof and monitoring

HTTP endpoints

Method Path Query params Response
GET /health tenantId, degraded, lastSyncMs, nowMs, staleAfterMs ManagedCompanyOsWebSocketMessage (200)
GET /graph-snapshot tenantId, idempotencyKey, degraded, lastSyncMs, nowMs, staleAfterMs ManagedCompanyOsWebSocketMessage (200)
GET /worker-supervision tenantId, degraded, nowMs, lastSyncMs, staleAfterMs ManagedWorkerSupervisionHealth (200)
WS /ws tenantId Upgrades to WebSocket; emits ManagedCompanyOsWebSocketMessage on open and each message

Unknown paths return { error: "…" } with status 404.

Worker supervision health

GET /worker-supervision returns a ManagedWorkerSupervisionHealth object:

Field Type Sens
alive boolean true when proof is healthy and not stale
last_heartbeat_at string (ISO 8601) Timestamp of the latest worker run
in_flight_jobs number Count of jobs still in queued or running state
stale_job_count number Count of jobs marked stale
replay_freshness 'fresh' | 'stale' | 'degraded' Replay output health
websocket_connected boolean false when proof is degraded or stale

WebSocket message schema

Every /ws push and /graph-snapshot response is a ManagedCompanyOsWebSocketMessage:

ts
{
  type: 'managed-companyos.graph.snapshot';
  tenantId: string;
  correlationId: string;        // links jobs, replay events, and evidence receipt
  nodeCount: number;
  edgeCount: number;
  replayEventCount: number;
  replayEventIds: readonly string[];
  evidenceReceiptId: string;
  workerJobIds: readonly string[];
  workerStatus: 'queued' | 'running' | 'completed' | 'degraded' | 'stale';
  degraded: boolean;
  stale: boolean;
  idempotentReplay: boolean;    // true when the same idempotencyKey was replayed
  degradedReasons: readonly string[];
}

WebSocket event stream

projectWorkerWebSocketEvents(proof) projects the worker proof into an ordered sequence of typed events. All events carry correlationId and sequence:

Event type Payload extras When emitted
job-started jobId, kind, status: 'queued' Each job enters queued state
job-progress jobId, kind, status: 'running' Each job transitions to running
job-completed jobId, kind, status: 'completed', degraded: false Job succeeds
job-failed jobId, kind, status: 'degraded'|'stale', degraded: true Job fails or goes stale
replay-emitted replayEventId Each replay event in the proof
evidence-issued evidenceReceiptId, verificationHash Evidence receipt issued

Events are ordered by ascending sequence numbers. Degraded proofs emit job-failed instead of job-completed.

Worker job inventory

Job kind Objectif
integration_sync Integration provider sync (side-effect-free until provider approved)
replay_generation Deterministic replay packet generation from workspace state
evidence_generation Evidence receipt derivation from replay events; receipt carries verificationHash
websocket_graph_update Publishes graph snapshot to connected WebSocket clients

Job lifecycle: queued → running → completed (healthy) or degraded / stale (unhealthy).

Correlation ID contract

A single correlationId links the entire proof chain:

code
proof.correlationId
  == each job.correlationId
  == each WS event.correlationId
  == each replay event.correlationId
  == evidenceReceipt.correlationId

Validate with assertManagedWorkerCorrelation(proof) — returns { valid: boolean, reasons: string[] }.

Degraded-state detection

The runtime surfaces degraded and stale conditions instead of hiding them behind healthy status:

Condition Trigger EFFET
Forced degraded ?degraded=true query param All jobs report degraded; supervision alive: false
Stale sync nowMs - lastSyncMs > staleAfterMs All jobs report stale; supervision stale_job_count = 4, replay_freshness: 'stale'
Bundle health degraded Propagated from @lssm-tech/bundle.managed-companyos degradedReasons populated; supervision alive: false

In future VPS mode, a green API response must not hide a degraded realtime runtime. In the active Vercel-only topology, /api/companyos/health/degraded reports API and scheduled snapshot duty health instead of requiring this package.

Stale-job cleanup and idempotency

The deterministic in-memory store (createDeterministicManagedWorkerStore) enforces idempotency:

  • A run with the same idempotencyKey returns the cached proof with idempotentReplay: true.
  • Stale jobs are counted and surfaced — they are not silently discarded.
  • Pass a fresh idempotencyKey to force a new run: GET /graph-snapshot?idempotencyKey=fresh-key-001

WebSocket reconnect client

ts
import { connectManagedCompanyOsLiveClientWithReconnect } from './src/live-client';

const proof = await connectManagedCompanyOsLiveClientWithReconnect({
  url: 'ws://worker.host/ws?tenantId=tenant_id',
  maxAttempts: 3,       // default: 3
  initialBackoffMs: 100, // default: 100ms; doubles each retry (100 → 200 → 400)
  timeoutMs: 1000,      // per-attempt timeout; default: 1000ms
});
// proof.connected, proof.attempts, proof.lastBackoffMs, proof.message

Environment variables

Variable Default Objectif
MANAGED_COMPANYOS_WORKER_HOST 0.0.0.0 Bind address for the HTTP/WebSocket server
MANAGED_COMPANYOS_WORKER_PORT 8787 Bind port
MANAGED_COMPANYOS_DEFAULT_TENANT_ID tenant_managed_companyos_reference Fallback tenant when tenantId query param is absent

Copier deploy/env/worker.env.example to /etc/managed-companyos/worker.env and fill values from the secret manager. Never write raw provider credentials to logs, fixtures, or API responses.

Local commands

bash
bun run --cwd packages/apps/worker-application-monolith dev
bun run --cwd packages/apps/worker-application-monolith test
bun run --cwd packages/apps/worker-application-monolith typecheck
bun run --cwd packages/apps/worker-application-monolith lint:check
bun run --cwd packages/apps/worker-application-monolith build

Build output: dist/index.js (Bun target). Production start: bun dist/index.js.

Integration Points

WebSocket Client Integration

External systems receive real-time graph updates by connecting a WebSocket client to /ws:

typescript
import { connectManagedCompanyOsLiveClientWithReconnect } from '@lssm-tech/app.worker-application-monolith/src/live-client';

const proof = await connectManagedCompanyOsLiveClientWithReconnect({
  url: 'ws://worker.host/ws?tenantId=tenant_123',
  maxAttempts: 3,
  initialBackoffMs: 100, // doubles each retry
  timeoutMs: 1000
});

// proof.message is ManagedCompanyOsWebSocketMessage
// proof.connected indicates success

Each message carries a correlationId that links to API requests, replay packets, and evidence receipts.

Health Polling

External monitoring can poll worker health via HTTP:

bash
# Instant health snapshot (no stale-job cleanup)
curl http://worker.host/health?tenantId=tenant_id

# Worker supervision health (includes job/replay/WebSocket metrics)
curl http://worker.host/worker-supervision?tenantId=tenant_id

# Graph snapshot (deterministic projected state)
curl http://worker.host/graph-snapshot?tenantId=tenant_id&idempotencyKey=key_xyz

A degraded Bun runtime returns { degraded: true, degradedReasons: [...] } for local/future-VPS monitoring. In the active Vercel-only topology, production readiness is proven by API snapshot routes and Vercel Cron evidence rather than this process.

MCP Tool Integration

For AI agents, the planned @lssm-tech/app.managed-companyos-mcp server exposes worker health, job status, replay packet fetching, and evidence verification as MCP tools. Agents can query job state and fetch replay/evidence receipts without holding open a WebSocket connection.

Correlation ID Guarantees

Every worker run produces a correlationId that persists across:

  • Job execution (job.correlationId)
  • WebSocket messages (ManagedCompanyOsWebSocketMessage.correlationId)
  • Replay events (replayEvent.correlationId)
  • Evidence receipts (evidenceReceipt.correlationId)

Validate the full chain with assertManagedWorkerCorrelation(proof) in production health checks.

Build output: dist/index.js (Bun target). Production start: bun dist/index.js.

For the full operator runbook (deploy, start/stop, degraded triage, replay regen, evidence verification), see docs/runbooks/managed-companyos.md†.

Declared capabilities.

This manifest does not declare a capability catalogue. Use the guide, import map and source to assess the package.

Imports and export paths.

1 entries

These are package-manifest entry points. Named symbols listed above come from the capability catalogue; this is not an exhaustive TypeScript symbol reference.

1 import

Dependencies and related packages.

Runtime dependencies 5
@opentelemetry/api
^1.9.1
@opentelemetry/sdk-trace-base
^2.10.0
posthog-node
^5.51.7
Development dependencies 4
@types/bun
catalog:types
@types/node
catalog:types
typescript
catalog:

Package scripts.

Commands declared by this package. Review its setup requirements before running them; no command here was executed by this review.

cleanrm -rf dist .turbo
buildbun build --target bun --outfile dist/index.js src/server.ts
devbun --watch src/server.ts
startbun src/server.ts
lintbun run lint:fix
lint:fixnode ../../../scripts/biome.cjs check --write --unsafe --only=nursery/useSortedClasses . && node ../../../scripts/biome.cjs check --write .
lint:checknode ../../../scripts/biome.cjs check .
testbun test
typechecktsgo --noEmit
companyos:builder:worker-smokebun test src/builder-worker-smoke.test.ts src/worker.test.ts src/server.test.ts
Votre vue

Make room for your context.

Shape the presentation around this moment. You can change it whenever you need.

Votre contexte

The different parts of you

Choose a starting point

Un mélange utile de contexte, de visuels et de guidage discret.

Tune each dimension
Each dimension can change independently. Product permissions and available actions stay unchanged.

Support the way you begin and return

Tune your support

Confort de lecture

Choisir votre langue

La langue de l’interface change uniquement le texte. Les marchés, les prix et les parcours conservent leurs propres paramètres.

Couverture des traductions

Une partie du contenu est affichée en anglais.

Navigation151
Graphe616
Catégories378
Portfolio833
Exemples2 035
Aperçu de la source1 542

D’autres traductions seront ajoutées à mesure que le contenu sera relu.

Cette préférence est enregistrée dans ce navigateur.

Rechercher sur le site

Des points de départ utiles

Aucun résultat. Essayez une expression plus courte, un nom d’opération ou un autre périmètre de recherche.

UN PEU DE PLACE POUR EXPLORER

Trouvez quelque chose à explorer.

Ouvrez un aperçu détaillé sur cette page, essayez une autre perspective ou suivez le détail vers sa propre page.

Fonctionnement des aperçus et des commandes
01

Regarder avant de partir

Survolez un lien ou sélectionnez-le avec Tab pour voir un aperçu. Cliquer sur le lien d’origine ou appuyer sur Entrée ouvre toujours sa destination.

02

Rester dans le contexte

Entrez dans l’aperçu pour explorer ses sections. Depuis un lien sélectionné, utilisez Alt + ↓ pour y entrer au clavier. Échap le ferme.

03

Ouvrir les possibilités

Les lignes dépliables, les choix de perspective et les commandes mises en évidence révèlent davantage. Votre vue adapte le confort de lecture et le contexte exploré.

Un bouton séparé pour voir de plus près

Affichez de petits boutons d’aperçu à côté des liens quand l’espace le permet. Touchez l’œil pour examiner ou le lien pour y aller directement. Ce choix reste dans cet onglet.

Aucun historique de navigation n’est collecté. La réduction des animations suit votre appareil et Votre vue.