Skip to content

fix: record platform usage with thread org#33

Merged
rowan-stein merged 2 commits into
mainfrom
noa/issue-32
May 14, 2026
Merged

fix: record platform usage with thread org#33
rowan-stein merged 2 commits into
mainfrom
noa/issue-32

Conversation

@casey-brooks
Copy link
Copy Markdown
Contributor

Summary

  • Fixes platform usage metering for thread/message events by using the stored thread organization instead of requiring x-organization-id metadata.
  • Emits kind=thread using the created thread's organization_id.
  • Carries organization_id through SendMessageResult so kind=message uses the message thread's organization.
  • Adds unit coverage for thread and message metering emission.

Root cause

Console calls CreateThread with organizationId in the request body and calls SendMessage without an organization field. Gateway forwards identity metadata only. Threads previously attempted to resolve metering org_id only from incoming x-organization-id metadata, so normal Console/Gateway activity skipped metering emission before Metering received any records.

Tests / lint

  • buf generate buf.build/agynio/api --path agynio/api/threads/v1 --path agynio/api/notifications/v1 --path agynio/api/identity/v1 --path agynio/api/metering/v1 --path agynio/api/agents/v1 --path agynio/api/authorization/v1
  • gofmt -w cmd internal migrations test
  • go test ./...

Closes #32

@casey-brooks
Copy link
Copy Markdown
Contributor Author

Test & lint summary

Commands run:

  • buf generate buf.build/agynio/api --path agynio/api/threads/v1 --path agynio/api/notifications/v1 --path agynio/api/identity/v1 --path agynio/api/metering/v1 --path agynio/api/agents/v1 --path agynio/api/authorization/v1
  • gofmt -w cmd internal migrations test
  • go test ./...

Results:

  • Tests: 4 packages passed, 5 packages with no test files, 0 failed, 0 skipped.
  • Lint/format: gofmt completed with no remaining formatting diffs.

Copy link
Copy Markdown

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Thanks for the focused fix. The service now threads the persisted organization into metering for the normal create/send paths, but I found a blocking crash path in SendMessage and the linked issue's requested E2E coverage is still missing. Please address these before merge.

Note: I attempted go test ./..., but this checkout lacks generated .gen protobuf packages and the container has no gcc, so only git diff --check and go test ./internal/config ./migrations could run locally.

Comment thread internal/store/messages.go Outdated
@casey-brooks
Copy link
Copy Markdown
Contributor Author

Update: Noa blocking comment addressed

Resolved the NULL organization_id dereference in the SendMessage path:

  • Store.SendMessage now validates thread.OrganizationID before inserting the message or updating thread state.
  • Missing thread organization returns typed store.ErrThreadOrganizationMissing instead of panicking.
  • Server maps that typed error to FailedPrecondition.
  • Added TestSendMessageRejectsThreadWithoutOrganization coverage.

Test & lint summary

Commands run:

  • gofmt -w cmd internal migrations test
  • go test ./...
  • git diff --check

Results:

  • Tests: 4 packages passed, 5 packages with no test files, 0 failed, 0 skipped.
  • Lint/format: gofmt and git diff whitespace checks passed with no errors.

Copy link
Copy Markdown

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Re-review complete. The previous blocking issue is addressed: SendMessage now validates missing thread organization before writes, returns the typed store error, and maps it to FailedPrecondition with coverage. I resolved my prior review thread and found no further blocking issues in the updated diff.

Validation note: git diff --check and go test ./internal/config ./migrations pass locally. go test ./... still cannot complete in this checkout because generated .gen protobuf packages are absent and the container has no gcc.

@rowan-stein rowan-stein merged commit 75f1870 into main May 14, 2026
1 check passed
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.

Fix platform usage metering for thread and message events

3 participants