Skip to content

fix(extract): attribute extraction cost to its project#100

Open
serhiizghama wants to merge 2 commits into
agentctxhq:mainfrom
serhiizghama:fix/extraction-cost-project-id
Open

fix(extract): attribute extraction cost to its project#100
serhiizghama wants to merge 2 commits into
agentctxhq:mainfrom
serhiizghama:fix/extraction-cost-project-id

Conversation

@serhiizghama

Copy link
Copy Markdown
Contributor

Closes #66. recordCost upserted the sessions row by session_id alone and never wrote project_id. In a sparse session where the cost row is the first DB write — no SessionStart/UserPromptSubmit injection ever fired, so nothing else set project_id — the cost lands on a project_id IS NULL row. status filters its per-project total by project_id, so the cost silently drops out of the project view it actually belongs to (it still shows under "All projects", so it's mis-attributed rather than lost).

The project id is already derivable a few lines down, so I just resolve it before recordCost and persist it in the upsert. On conflict it's filled with COALESCE(project_id, @projectId) so a value an injection already set is never clobbered. Cost arithmetic and the "All projects" total are untouched.

Added a test in run.test.ts that runs extraction for a session with no prior injection and asserts the resulting row's project_id is the project's id rather than NULL; reverting the fix fails it.

recordCost upserted the sessions row by session_id alone and never wrote
project_id. For a sparse session whose first DB write is the cost row (no
SessionStart/UserPromptSubmit injection ever fired), the cost lands on a
project_id IS NULL row, and status's per-project total filters by
project_id, so the cost is dropped from the project view it belongs to.

Resolve the project id before recording cost and persist it in the upsert,
filling it only when absent (COALESCE) so an injection-set value is never
clobbered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extraction cost is recorded on a session row with no project_id, so per-project status extraction cost can omit it

1 participant