TS2339: Property 'search' does not exist on type 'PgRetriever'
The subagent received the goal, the route name, and the expected user-facing behavior. It did not receive the thing that mattered most.
// Actual repository contract, omitted from the delegation packet
interface SearchProvider {
retrieve(query: string, k: number): Promise<ReadonlyArray<SearchHit>>;
}
type SearchHit = {
id: string;
text: string;
score: number;
metadata: Record<string, string>;
};
In the isolated workspace, the generated adapter was internally tidy:
const results = await retriever.search({ text: query, topK: limit });
return results.items.map((item) => ({
body: item.content,
confidence: item.similarity,
}));
That code was not careless. It was contract-free. The subagent built a small universe where search({ text, topK }) existed, mocked that universe in tests, and passed. The orchestrator then placed the adapter beside the real PgRetriever, which only implements retrieve(query, k). TypeScript caught the first mismatch with TS2339; the runtime error appeared only after someone cast the retriever to any to see how far the branch would get.
The durable repair was to make interface excerpts part of the orchestration protocol, not an optional nicety. A 30-line contract packet cost less context than the failed integration loop that followed, and it converted the task from API invention back into ordinary implementation.