The Projects list page groups sessions by display name (last segment of git_remote or project_path, e.g. "rudel") via PROJECT_DISPLAY_EXPR in ClickHouse. Each row shows this short name in the table.
However, handleRowClick navigates using the raw row.git_remote || row.project_path — the full URL or absolute filesystem path — not the display name. This causes two problems:
The URL contains a long opaque path that doesn't match what the user sees.
The detail API's buildProjectDisplaySubquery resolves the display name from the full path, which is fragile and may explain the ongoing 500 errors (subquery over-complexity for certain data shapes).
The fix is simple: navigate with row.repository (the display name already returned by getProjectInvestment). The API's buildProjectDisplaySubquery fallback already handles a plain display name correctly — when the input has no /, it returns the input as-is, and the main query becomes WHERE PROJECT_DISPLAY_EXPR = 'rudel', which aggregates all sessions for that project regardless of how they were uploaded.
row.repository is PROJECT_DISPLAY_EXPR (e.g. "rudel"), already in ProjectInvestment returned by getProjectInvestment. This is the only change needed.
Why this works end-to-end:
URL becomes /dashboard/projects/rudel instead of /dashboard/projects/%2FUsers%2Fmarc%2F...
ProjectDetailPage decodes "rudel" and passes it as projectPath to all detail endpoints
buildProjectDisplaySubquery("org", "rudel"): no session has project_path='rudel', so count()=0, fallback runs: position('rudel', '/')=0 → returns 'rudel' directly
Main query: WHERE PROJECT_DISPLAY_EXPR = 'rudel' — correctly aggregates ALL sessions whose display name is "rudel", regardless of git_remote or project_path
Files
apps/web/src/pages/dashboard/ProjectsListPage.tsx — handleRowClick function
Verification
Click a project row in the Projects list — URL should be /dashboard/projects/rudel (short name, not full path)
Project detail page should load and show aggregated data for all sessions named "rudel"
bun run verify passes
If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /Users/rafa/.claude/projects/-Users-rafa-Obsession-rudel/3ed5ef56-9d0b-4e63-8ce5-c2abbc23ae5b.jsonl
Assistant
Done. handleRowClick now prefers row.repository (the display name, e.g. "rudel") over the raw git_remote/project_path. This produces clean URLs like /dashboard/projects/rudel and lets the detail API's fallback path use the simple WHERE PROJECT_DISPLAY_EXPR = 'rudel' query.
User
Can you show me the new query with values please
Assistant
With the new change, navigating to project "rudel" for org "abc-user-id", the subquery becomes:
sql
(
SELECT
if(
count() > 0,
any(if(git_remote != '', arrayElement(splitByChar('/', git_remote), -1), arrayElement(splitByChar('/', project_path), -1))),
if(position('rudel', '/') > 0,
arrayElement(splitByChar('/', 'rudel'), -1),
'rudel' -- ← position('rudel', '/') = 0, so returns 'rudel' directly
)
) as project_display
FROM rudel.session_analytics
WHERE organization_id = 'abc-user-id'
AND (
project_path = 'rudel' -- no rows match (it's a display name, not a path)
OR git_remote = 'rudel' -- no rows match
OR PROJECT_KEY_EXPR = 'rudel' -- no rows match
)
AND (git_remote != '' OR package_name != '' OR project_path != '')
)
-- count() = 0, so result = 'rudel'
So it matches all sessions where the last path segment of git_remote or project_path is "rudel" — regardless of the full path. Previously, with escapedProjectPath = '/Users/marc/Workspace/rudel', ClickHouse had to resolve the display name via a subquery lookup against an exact path match, which could fail for sessions uploaded from different machines.
User
Give me the full query
Assistant
Here's getProjectDetails fully expanded with org = 'abc-user-id', pp = 'rudel', days = 30:
sql
SELECT
any(project_path) as project_path,
COUNT(*) as total_sessions,
SUM(ifNull(input_tokens, 0) + ifNull(output_tokens, 0)) as total_tokens,
SUM(ifNull(input_tokens, 0)) as input_tokens_sum,
SUM(ifNull(output_tokens, 0)) as output_tokens_sum,
COUNT(DISTINCT user_id) as contributors_count,
countIf(success_score < 40) as errors_count,
ifNull(round(avgOrNull(actual_duration_min), 2), 0) as avg_session_duration_min,
ifNull(round(avgOrNull(success_score), 2), 0) as success_rate,
round(SUM(actual_duration_min), 2) as total_duration_min
FROM rudel.session_analytics
WHERE if(git_remote != '',
arrayElement(splitByChar('/', git_remote), -1),
arrayElement(splitByChar('/', project_path), -1)
) = (
SELECT
if(
count() > 0,
any(if(git_remote != '',
arrayElement(splitByChar('/', git_remote), -1),
arrayElement(splitByChar('/', project_path), -1)
)),
if(position('rudel', '/') > 0,
arrayElement(splitByChar('/', 'rudel'), -1),
'rudel'
)
) as project_display
FROM rudel.session_analytics
WHERE organization_id = 'abc-user-id'
AND (
project_path = 'rudel'
OR git_remote = 'rudel'
OR PROJECT_KEY_EXPR = 'rudel'
)
AND (git_remote != '' OR package_name != '' OR project_path != '')
)
AND session_date >= today() - 30
AND organization_id = 'abc-user-id'
AND (git_remote != '' OR package_name != '' OR project_path != '')
The subquery returns 'rudel' (since count() = 0 and position('rudel', '/') = 0), so the WHERE simplifies to:
sql
WHERE if(git_remote != '',
arrayElement(splitByChar('/', git_remote), -1),
arrayElement(splitByChar('/', project_path), -1)
) = 'rudel'
AND session_date >= today() - 30
AND organization_id = 'abc-user-id'
AND (git_remote != '' OR package_name != '' OR project_path != '')
User
What is the full query for project details now is it this one?
Assistant
Yes, that's the one — it comes from getProjectDetails at line 339–356 in apps/api/src/services/project.service.ts.
User
I am getting this in clickhouse PROJECT_KEY_EXPR
User
[Request interrupted by user]
User
I am getting this in clickhouse: Error
Unknown expression or function identifier PROJECT_KEY_EXPR in scope (SELECT if(count() > 0, any(if(git_remote != '', arrayElement(splitByChar('/', git_remote), -1), arrayElement(splitByChar('/', project_path), -1))), if(position('rudel', '/') > 0, arrayElement(splitByChar('/', 'rudel'), -1), 'rudel')) AS project_display FROM rudel.session_analytics WHERE (organization_id = 'abc-user-id') AND ((project_path = 'rudel') OR (git_remote = 'rudel') OR (PROJECT_KEY_EXPR = 'rudel')) AND ((git_remote != '') OR (package_name != '') OR (project_path != ''))).
Assistant
PROJECT_KEY_EXPR is defined as a const but line 37 uses it inside a regular string literal ('...') instead of a template literal. Let me check:
Assistant
The source looks correct — ${PROJECT_KEY_EXPR} is inside a template literal on line 37. But ClickHouse is receiving the literal string, which means the API is running stale code. Let me check if this was recently changed:
Assistant
That error is coming from the query I showed in my explanation — I wrote PROJECT_KEY_EXPR as a placeholder label, not the expanded expression. I should have expanded it. The actual query the API sends to ClickHouse has it fully substituted.
The real expanded subquery is:
sql
(
SELECT
if(
count() > 0,
any(if(git_remote != '',
arrayElement(splitByChar('/', git_remote), -1),
arrayElement(splitByChar('/', project_path), -1)
)),
if(position('rudel', '/') > 0,
arrayElement(splitByChar('/', 'rudel'), -1),
'rudel'
)
) as project_display
FROM rudel.session_analytics
WHERE organization_id = 'abc-user-id'
AND (
project_path = 'rudel'
OR git_remote = 'rudel'
OR if(git_remote != '', git_remote, if(package_name != '', package_name, project_path)) = 'rudel'
)
AND (git_remote != '' OR package_name != '' OR project_path != '')
)
This substitution happens in TypeScript before the query is ever sent to ClickHouse. The literal string PROJECT_KEY_EXPR never reaches ClickHouse in normal operation.
User
Ok I get this now: Error
Aggregate function any(project_path) AS project_path is found in WHERE in query.
Assistant
This is a ClickHouse alias shadowing issue. The SELECT has any(project_path) as project_path, and PROJECT_DISPLAY_EXPR in the WHERE clause also references the column project_path. ClickHouse resolves the alias first, so it sees an aggregate in the WHERE.
Let me look at the full query and what consumes the result:
Assistant
The fix is to rename the alias so it doesn't shadow the column name. Line 341: any(project_path) as project_path → any(project_path) as raw_project_path, then read it back as row.raw_project_path.
Assistant
Now update the type and the read:
Assistant
Now let me check if any other queries in the file have the same alias shadowing pattern:
Assistant
That one is inside a CTE and the outer query qualifies it as pk.project_path — no shadowing issue there.
The fix is done. Root cause: ClickHouse resolves SELECT aliases before evaluating the WHERE clause, so any(project_path) as project_path caused it to see an aggregate function wherever project_path appeared in PROJECT_DISPLAY_EXPR within WHERE. Renaming the alias to raw_project_path breaks that cycle.
User
What's the new query? want to test it
Assistant
With org = 'your-user-id', pp = 'rudel', days = 30:
sql
SELECT
any(project_path) as raw_project_path,
COUNT(*) as total_sessions,
SUM(ifNull(input_tokens, 0) + ifNull(output_tokens, 0)) as total_tokens,
SUM(ifNull(input_tokens, 0)) as input_tokens_sum,
SUM(ifNull(output_tokens, 0)) as output_tokens_sum,
COUNT(DISTINCT user_id) as contributors_count,
countIf(success_score < 40) as errors_count,
ifNull(round(avgOrNull(actual_duration_min), 2), 0) as avg_session_duration_min,
ifNull(round(avgOrNull(success_score), 2), 0) as success_rate,
round(SUM(actual_duration_min), 2) as total_duration_min
FROM rudel.session_analytics
WHERE if(git_remote != '',
arrayElement(splitByChar('/', git_remote), -1),
arrayElement(splitByChar('/', project_path), -1)
) = (
SELECT
if(
count() > 0,
any(if(git_remote != '',
arrayElement(splitByChar('/', git_remote), -1),
arrayElement(splitByChar('/', project_path), -1)
)),
if(position('rudel', '/') > 0,
arrayElement(splitByChar('/', 'rudel'), -1),
'rudel'
)
) as project_display
FROM rudel.session_analytics
WHERE organization_id = 'your-user-id'
AND (
project_path = 'rudel'
OR git_remote = 'rudel'
OR if(git_remote != '', git_remote, if(package_name != '', package_name, project_path)) = 'rudel'
)
AND (git_remote != '' OR package_name != '' OR project_path != '')
)
AND session_date >= today() - 30
AND organization_id = 'your-user-id'
AND (git_remote != '' OR package_name != '' OR project_path != '')
Replace your-user-id with your actual org/user ID from the organization_id column.