@lssm-tech/app.worker-application-monolithapp.worker-application-monolith
Inspect the package guide, declared imports and source relationships.
@lssm-tech/app.worker-application-monolithSource, 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.
See where this package fits.
Follow a declared connection, inspect an import, then open the source guide when you need the detail.
Arrows point from a package to its direct dependency. Each count is derived from the captured manifests.
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-monoliththrough 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 | Purpose |
|---|---|
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 | Meaning |
|---|---|---|
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:
{
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 | Purpose |
|---|---|
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:
proof.correlationId
== each job.correlationId
== each WS event.correlationId
== each replay event.correlationId
== evidenceReceipt.correlationIdValidate 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 | EFFECT |
|---|---|---|
| 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
idempotencyKeyreturns the cached proof withidempotentReplay: true. - Stale jobs are counted and surfaced — they are not silently discarded.
- Pass a fresh
idempotencyKeyto force a new run:GET /graph-snapshot?idempotencyKey=fresh-key-001
WebSocket reconnect client
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.messageEnvironment variables
| Variable | Default | Purpose |
|---|---|---|
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 |
Copy 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
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 buildBuild 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:
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 successEach message carries a correlationId that links to API requests, replay packets, and evidence receipts.
Health Polling
External monitoring can poll worker health via HTTP:
# 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_xyzA 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†.
3 source links need reconciliation
References marked † point outside the resolved source inventory. Their labels are preserved without inventing a replacement destination.
../../../docs/managed-companyos-private-pilot.md../../../docs/runbooks/special-ops-monolith-production.md../../../../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 entriesThese are package-manifest entry points. Named symbols listed above come from the capability catalogue; this is not an exhaustive TypeScript symbol reference.
1 import
No export paths match this search.
Dependencies and related packages.
Runtime dependencies 5
- @lssm-tech/bundle.managed-companyos
- workspace:*
- @lssm-tech/lib.observability
- workspace:*
- @opentelemetry/api
- ^1.9.1
- @opentelemetry/sdk-trace-base
- ^2.10.0
- posthog-node
- ^5.51.7
Development dependencies 4
- @lssm-tech/tool.typescript
- workspace:*
- @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.
rm -rf dist .turbobun build --target bun --outfile dist/index.js src/server.tsbun --watch src/server.tsbun src/server.tsbun run lint:fixnode ../../../scripts/biome.cjs check --write --unsafe --only=nursery/useSortedClasses . && node ../../../scripts/biome.cjs check --write .node ../../../scripts/biome.cjs check .bun testtsgo --noEmitbun test src/builder-worker-smoke.test.ts src/worker.test.ts src/server.test.ts