Skip to content

Commit b970c5e

Browse files
Claudehotlong
andauthored
fix: Use ctx.getServices() for dynamic service access in protocol
The previous fix attempted to probe for services using a hardcoded list, which missed services not in the list. The correct solution is simpler: ctx.getServices() returns a fresh snapshot of ALL services each time it's called (see kernel.ts:144-145), so we can just pass it as a callback. This ensures the protocol has access to all services registered after ObjectQLPlugin's init() phase, including metadata service (for agents/tools) and AI service, which are registered by later plugins. Root cause: Protocol was capturing ctx.getServices() result during init() instead of calling it at runtime. Now fixed by passing the function itself. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 64a9c3d commit b970c5e

1 file changed

Lines changed: 5 additions & 25 deletions

File tree

packages/objectql/src/plugin.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,36 +72,16 @@ export class ObjectQLPlugin implements Plugin {
7272
});
7373

7474
// Register Protocol Implementation
75-
// IMPORTANT: Use getKernel() to access services dynamically.
76-
// We pass callbacks that invoke kernel methods at request time, ensuring
77-
// we get live access to services registered after this plugin's init().
75+
// IMPORTANT: Pass ctx.getServices as callback to get runtime services.
76+
// ctx.getServices() returns a fresh snapshot of all services each time it's called.
77+
// This ensures we access services registered after this plugin's init() phase.
7878
// MetadataPlugin and AIServicePlugin register after ObjectQLPlugin.
79-
const kernel = ctx.getKernel();
8079
const protocolShim = new ObjectStackProtocolImplementation(
8180
this.ql,
81+
() => ctx.getServices(),
8282
() => {
8383
try {
84-
// Get fresh services map at runtime by probing known service names
85-
const services = new Map<string, any>();
86-
const knownServices = ['data', 'metadata', 'ai', 'feed', 'cache', 'queue', 'manifest'];
87-
for (const name of knownServices) {
88-
try {
89-
const service = kernel.getService(name);
90-
if (service) {
91-
services.set(name, service);
92-
}
93-
} catch {
94-
// Service not available, skip
95-
}
96-
}
97-
return services;
98-
} catch {
99-
return new Map();
100-
}
101-
},
102-
() => {
103-
try {
104-
return kernel.getService('feed') as any;
84+
return ctx.getService('feed') as any;
10585
} catch {
10686
return undefined;
10787
}

0 commit comments

Comments
 (0)