Skip to content

Commit bd6ae2e

Browse files
committed
fix: improve app metadata registration and add flow debugging
1 parent b103c38 commit bd6ae2e

5 files changed

Lines changed: 35 additions & 11 deletions

File tree

packages/cli/src/commands/serve.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,22 @@ export default class Serve extends Command {
255255
}
256256

257257
// 3. Auto-register AppPlugin if config contains app definitions
258-
// Skip if config is a host/aggregator config that already contains
259-
// instantiated plugins — wrapping it would cause duplicate registration
260-
// and startup failures (e.g. plugin.app.dev-workspace).
261-
if (!isHostConfig(config) && (config.objects || config.manifest || config.apps)) {
258+
// (objects / manifest / apps / flows / apis). Even host/aggregator
259+
// configs (those whose `plugins` array contains instantiated plugins)
260+
// need this wrap when they ALSO carry top-level metadata — otherwise
261+
// top-level `flows`, `objects`, etc. never reach the ObjectQL registry
262+
// and downstream services like AutomationServicePlugin start with 0 flows.
263+
//
264+
// To avoid double-registration when the host already wraps itself with
265+
// an AppPlugin (e.g. apps/objectos's dev-workspace stack), we skip if
266+
// any plugin in `plugins[]` is already an AppPlugin instance.
267+
const hasAppPluginAlready = plugins.some(
268+
(p: any) => p && (p.type === 'app' || p.constructor?.name === 'AppPlugin' || (p.name && typeof p.name === 'string' && p.name.startsWith('plugin.app.')))
269+
);
270+
const configHasMetadata = !!(
271+
config.objects || config.manifest || config.apps || config.flows || config.apis
272+
);
273+
if (!hasAppPluginAlready && configHasMetadata) {
262274
try {
263275
const { AppPlugin } = await import('@objectstack/runtime');
264276
await kernel.use(new AppPlugin(config));

packages/objectql/src/engine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ export class ObjectQL implements IDataEngine {
374374
const id = manifest.id || manifest.name;
375375
const namespace = manifest.namespace as string | undefined;
376376
this.logger.debug('Registering package manifest', { id, namespace });
377+
console.warn(`[ObjectQL:registerApp] id=${id} flows=${Array.isArray(manifest.flows) ? manifest.flows.length : typeof manifest.flows} keys=${Object.keys(manifest).join(',')}`);
377378

378379
// Store manifest for defaultDatasource lookup
379380
if (id) {

packages/runtime/src/app-plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export class AppPlugin implements Plugin {
6565
? { ...this.bundle.manifest, ...this.bundle }
6666
: this.bundle;
6767

68+
console.warn(
69+
`[AppPlugin:init] appId=${appId} keys=${Object.keys(servicePayload).join(',')} flows=${Array.isArray((servicePayload as any).flows) ? (servicePayload as any).flows.length : 'n/a'}`,
70+
);
71+
6872
ctx.getService<{ register(m: any): void }>('manifest').register(servicePayload);
6973
}
7074

packages/runtime/src/standalone-stack.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ export async function createStandaloneStack(config?: StandaloneStackConfig): Pro
8888
artifactBundle = (parsed?.schemaVersion != null && parsed?.metadata !== undefined)
8989
? parsed.metadata
9090
: parsed;
91-
} catch {
92-
// No artifact yet — AppPlugin skipped.
91+
console.warn(
92+
`[StandaloneStack] artifact loaded: path=${artifactPath} keys=${artifactBundle ? Object.keys(artifactBundle).join(',') : '(null)'} flows=${Array.isArray(artifactBundle?.flows) ? artifactBundle.flows.length : 'n/a'}`,
93+
);
94+
} catch (err: any) {
95+
console.warn(`[StandaloneStack] artifact load FAILED: path=${artifactPath} error=${err?.message}`);
9396
}
9497

9598
const plugins: any[] = [

packages/services/service-automation/src/plugin.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ export class AutomationServicePlugin implements Plugin {
6868
}
6969

7070
async start(ctx: PluginContext): Promise<void> {
71-
if (!this.engine) return;
71+
console.warn('[Automation:start] entering start()');
72+
if (!this.engine) {
73+
console.warn('[Automation:start] engine missing, bailing');
74+
return;
75+
}
7276

7377
// Trigger hook to notify engine is ready — other plugins can start registering nodes
7478
await ctx.trigger('automation:ready', this.engine);
@@ -87,14 +91,14 @@ export class AutomationServicePlugin implements Plugin {
8791
registry?: { listItems?: (type: string) => unknown[] };
8892
}>('objectql');
8993
if (!ql) {
90-
ctx.logger.warn('[Automation] objectql service not found at start()');
94+
console.warn('[Automation] objectql service not found at start()');
9195
} else if (!ql.registry) {
92-
ctx.logger.warn('[Automation] objectql.registry is undefined at start()');
96+
console.warn('[Automation] objectql.registry is undefined at start()');
9397
} else if (typeof ql.registry.listItems !== 'function') {
94-
ctx.logger.warn('[Automation] objectql.registry.listItems is not a function');
98+
console.warn('[Automation] objectql.registry.listItems is not a function');
9599
}
96100
const flows = ql?.registry?.listItems?.('flow') ?? [];
97-
ctx.logger.warn(`[Automation] flow pull: registry returned ${flows.length} flow(s)`);
101+
console.warn(`[Automation] flow pull: registry returned ${flows.length} flow(s)`);
98102
let registered = 0;
99103
for (const f of flows) {
100104
const def = f as { name?: string };

0 commit comments

Comments
 (0)