Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/gitbook/src/components/Search/server-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ export async function streamAskQuestion({
}

if (!spacePromises.has(source.space)) {
// Extract the source revision ID if it's a computed revision.
const revisionId = source.revision.startsWith('computed_')
? (source.revision.split('_')[1] ?? '')
: source.revision;

Comment on lines +160 to +164
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's the right fix. computed IDs can change format in the future. It's risky

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah definitelly we should NEVER NEVER do this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it's plain wrong, the second part is not the revision ID

spacePromises.set(
source.space,
throwIfDataError(
context.dataFetcher.getRevision({
spaceId: source.space,
revisionId: source.revision,
revisionId,
})
Comment on lines 168 to 171
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we call the getRevisionById API endpoint using a computed revision ID which looks like this:

computed_kYuvMBuVxyeIcLP8yB1C_306581b1fb17ec1cfde808f99ecb55e092c4e762

Since the source revision ID is embedded inside the computed revision ID, we can extract and use it instead:
https://github.com/GitbookIO/gitbook-x/blob/6811c63ef2ad1381c578c70a54e869ed0af5c797/packages/hive-core/src/computed/revision.ts#L30-L37

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why ? we should work with the actual computed revision; this is what is indexed

Copy link
Member Author

@utkuufuk utkuufuk Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamyPesse We extract the pages from the revision so we can display relevant pages along with the AI answer. However, we can only look up revisions (from Hive, via the getRevisionById API endpoint) by the source ID, not by the computed ID.

The revision returned by the API is still the computed one:
https://github.com/GitbookIO/gitbook-x/blob/621360305b4c1563e7373e0d35dcac8ab9e495a3/services/cloudrun/api/src/operations/spaces/content/utils.ts#L98-L124

)
);
Expand All @@ -175,8 +180,15 @@ export async function streamAskQuestion({
// Get the pages for all spaces referenced by this answer.
const pages = await Promise.all(
spaces.map(async (space) => {
const revision = await spacePromises.get(space);
return { space, pages: revision?.pages };
try {
const revision = await spacePromises.get(space);
return { space, pages: revision?.pages };
} catch (err) {
console.error('Error getting revision', err);
// TODO: should we swallow the error as it's not essential to the answer?
// return { space, pages: null };
throw err;
}
})
).then((results) => {
return results.reduce((map, result) => {
Expand Down