Skip to content

fix: route Codex telemetry hooks through wrapper#3116

Merged
danielkov merged 6 commits into
mainfrom
daniel/age-2563-investigation-investigate-async-hook-support-in-codex
May 29, 2026
Merged

fix: route Codex telemetry hooks through wrapper#3116
danielkov merged 6 commits into
mainfrom
daniel/age-2563-investigation-investigate-async-hook-support-in-codex

Conversation

@danielkov
Copy link
Copy Markdown
Contributor

@danielkov danielkov commented May 29, 2026

Summary

  • Route Codex SessionStart, PostToolUse, and Stop hooks through a generated hook_async.sh wrapper so telemetry events return immediately without using unsupported hooks.json async fields.
  • Keep blocking events on hook.sh and update trusted hash generation to match the per-event command path.
  • Add tests for async-wrapper routing, generated wrapper contents, executable ZIP permissions, plus a server changeset.

Linear

Test plan

  • go test ./server/internal/plugins

Summary by cubic

Routes Codex telemetry-only hooks through a background wrapper and adds user_email attribution so events return fast and map to the right user. Also pipes payloads via stdin and refreshes per-event trusted hashes on upgrade to keep telemetry reliable. Addresses AGE-2563.

  • Bug Fixes
    • Routes SessionStart, PostToolUse, and Stop via hook_async.sh; others stay on hook.sh.
    • Adds hook_async.sh that copies stdin, forwards to hook.sh in the background, and exits 0; ensures it’s executable in the ZIP.
    • Adds user_email to the API/payload; hook.sh derives it on SessionStart from local Codex auth, server caches session metadata, resolves user, and applies it across events.
    • Pipes the enriched payload to curl via stdin (--data-binary @-) to avoid ARG_MAX truncation on large events.
    • Computes trusted hashes per event’s command and refreshes existing [hooks.state] trusted_hash during install so upgrades don’t silently drop telemetry.
    • Regenerates OpenAPI/SDK and updates CLI examples to include user_email.

Written for commit 5549aa0. Summary will update on new commits.

Review in cubic

@danielkov danielkov requested a review from a team as a code owner May 29, 2026 16:57
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 29, 2026

AGE-2563

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: 5549aa0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gram-docs-redirect Ready Ready Preview, Comment May 29, 2026 9:00pm

Request Review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc7cf24895

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/internal/plugins/generate.go
@github-actions github-actions Bot added the preview Spawn a preview environment label May 29, 2026
@speakeasybot
Copy link
Copy Markdown
Collaborator

speakeasybot commented May 29, 2026

🚀 Preview Environment (PR #3116)

Preview URL: https://pr-3116.dev.getgram.ai

Component Status Details Updated (UTC)
⏳ Database Pending Waiting for db-init job 2026-05-29 21:09:19.
✅ Images Available Container images ready 2026-05-29 21:09:16.

Gram Preview Bot

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 4 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread .changeset/codex-async-hook-wrapper.md
Comment thread server/internal/plugins/generate.go
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7ba7f6f8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/internal/plugins/generate.go Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 12 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread server/internal/plugins/generate.go Outdated
Comment thread server/internal/hooks/codex_hooks.go Outdated
Comment thread server/internal/plugins/generate.go
- Pipe the enriched Codex hook payload to curl via stdin (--data-binary @-)
  instead of passing it as an argv, avoiding ARG_MAX truncation for large
  PostToolUse events.
- Refresh the trusted_hash on existing Gram-managed [hooks.state] entries
  during install so upgrades that change a hook command (hook.sh ->
  hook_async.sh) don't get flagged as modified and silently stop telemetry.
- Consult the session metadata cache regardless of payload user_email,
  filling each field only when empty, to avoid redundant user lookups.
- Restore the trailing newline on generated openapi3.yaml to fix the
  "Check for dirty files" CI step.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tigation-investigate-async-hook-support-in-codex

# Conflicts:
#	server/internal/plugins/generate.go
- Regenerate the internal SDK and bundled OpenAPI so the codex hook
  user_email field is reflected (Check SDK is up-to-date).
- Replace forbidden t.Skip calls in the install-script regression test
  with require.NoError (forbidigo GG004).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@danielkov danielkov added this pull request to the merge queue May 29, 2026
Merged via the queue into main with commit e8f7b31 May 29, 2026
33 checks passed
@danielkov danielkov deleted the daniel/age-2563-investigation-investigate-async-hook-support-in-codex branch May 29, 2026 21:14
@github-actions github-actions Bot locked and limited conversation to collaborators May 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

preview Spawn a preview environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants