Skip to content

Keep agent Sentry reporting live until shutdown - #3165

Merged
kwakayama merged 3 commits into
mainfrom
agent/sentry-agent-lifecycle
Jul 29, 2026
Merged

Keep agent Sentry reporting live until shutdown#3165
kwakayama merged 3 commits into
mainfrom
agent/sentry-agent-lifecycle

Conversation

@kwakayama

Copy link
Copy Markdown
Contributor

Summary

  • keep agent service application-error reporting active after start readiness
  • move flush/reset cleanup to explicit service shutdown lifecycle
  • make lifecycle composition run later cleanup even when earlier lifecycle stop fails
  • preserve terminal startup failure capture/flush/reset behavior

Validation

  • deno test --allow-all src/agent/service/runtime.test.ts src/agent/hosted/veryfront-cloud-agent-service.test.ts
  • deno fmt --check src/agent/service/runtime.ts src/agent/service/runtime.test.ts src/agent/hosted/veryfront-cloud-agent-service.ts src/agent/hosted/veryfront-cloud-agent-service.test.ts
  • deno lint src/agent/service/runtime.ts src/agent/service/runtime.test.ts src/agent/hosted/veryfront-cloud-agent-service.ts src/agent/hosted/veryfront-cloud-agent-service.test.ts
  • deno check src/agent/hosted/veryfront-cloud-agent-service.ts src/agent/service/runtime.ts src/agent/hosted/veryfront-cloud-agent-service.test.ts src/agent/service/runtime.test.ts
  • deno task typecheck
  • deno task typecheck:consumer

Notes

  • Pre-commit verify:quick was attempted and failed on unrelated existing docs gaps for ./release-assets: missing @example JSDoc and missing docs/api-reference/veryfront/release-assets.md.
  • npm --prefix storybook ci was run once to satisfy the local consumer typecheck prerequisite.

@kwakayama

Copy link
Copy Markdown
Contributor Author

Independent code review for PR #3165

Score: 86/100
Verdict: COMMENT - no BLOCK findings, but two WATCH items before treating this as fully hardened.

Reviewed range: 9008f8c99e491a1cb1d551db163c4653416a9453..3b060743174bad8482be3ac3aa0d74f133a8e311

Spec / blocker fit

The main blocker fix is directionally correct. startAgentService no longer performs readiness-time onFinally flush/reset, so application-error reporting stays installed after server readiness. The new shutdown lifecycle is attached to the runtime lifecycle at src/agent/hosted/veryfront-cloud-agent-service.ts:264-273, and the cleanup path is exact-once guarded at src/agent/hosted/veryfront-cloud-agent-service.ts:161-170. The lifecycle combiner now runs secondary stop() even after primary stop() fails at src/agent/service/runtime.ts:213-228, which preserves the Sentry reset/flush cleanup when detached-run or registration shutdown fails.

BLOCK findings

None.

WATCH findings

  1. [WATCH / MEDIUM] Startup-error cleanup still assumes flush() cannot reject.
    File: src/agent/hosted/veryfront-cloud-agent-service.ts:285-290
    Issue: the shutdown cleanup uses try/finally so reset() always runs after a flush failure (src/agent/hosted/veryfront-cloud-agent-service.ts:167-170), but the startup error path does await applicationErrors.flush(); applicationErrors.reset(); without a finally. If a future application-error lifecycle or test seam returns a rejecting flush, the process can skip reset() and also skip the exit(1) path inside runAgentServiceMain. The current production Sentry lifecycle appears to catch reporter flush failures, so I do not consider this a blocker for the 0.1.1175 fix, but the lifecycle contract itself is not encoded at this call site.
    Fix: mirror the shutdown pattern in onStartupError: capture/log, then try { await applicationErrors.flush(); } finally { applicationErrors.reset(); }; if exit-on-startup-failure must be invariant, catch/log flush failure so cleanup cannot prevent exit(1).

  2. [WATCH / LOW] The sibling public start path still has startup rollback failure masking.
    File: src/agent/hosted/veryfront-cloud-agent-service.ts:214-216
    Issue: this PR adds isolated rollback cleanup for startAgentService via stopRegistrationForStartupFailure() (src/agent/hosted/veryfront-cloud-agent-service.ts:176-187, used at :277-281), but startNodeVeryfrontCloudAgentService still does await registrationLifecycle?.stop?.() directly in its catch. If that stop path later becomes fallible, it can replace the original server/start failure with a cleanup failure. Today registration stop() only clears interval state, so this is a hardening follow-up rather than a merge blocker.
    Fix: reuse stopRegistrationForStartupFailure() in startNodeVeryfrontCloudAgentService too, or document why this public path intentionally keeps the stricter cleanup-failure behavior.

Validation run

  • deno check src/agent/hosted/veryfront-cloud-agent-service.ts src/agent/service/runtime.ts src/agent/hosted/veryfront-cloud-agent-service.test.ts src/agent/service/runtime.test.ts - passed
  • deno test --allow-all src/agent/service/runtime.test.ts src/agent/hosted/veryfront-cloud-agent-service.test.ts - passed, 30 tests
  • deno fmt --check ... on the four touched files - passed
  • deno lint ... on the four touched files - passed
  • deno task typecheck - passed
  • git diff --check 9008f8c99e491a1cb1d551db163c4653416a9453..3b060743174bad8482be3ac3aa0d74f133a8e311 - passed
  • Pattern/security scan over touched files found no hardcoded real secrets; only synthetic test values such as example.*, token-1, and a fake public Sentry DSN.

Note: an explicit lsp_diagnostics tool was not available in this leaf review environment, so I used Deno check plus the full repo typecheck as the type-safety gate.

Attach application-error cleanup to the agent service lifecycle so readiness no longer tears down reporting while the server keeps serving. Startup and rollback cleanup errors are isolated so the original fatal path still reaches the expected exit or rejection.

Constraint: Published agent services return from startup after readiness while the process remains live.
Rejected: Keep runAgentServiceMain success-path cleanup | It flushes and resets the reporter immediately after readiness.
Confidence: high
Scope-risk: narrow
Directive: Keep application-error cleanup owned by service shutdown, and keep cleanup failures from replacing startup failures.
Tested: deno test --allow-all src/agent/hosted/veryfront-cloud-agent-service.test.ts src/agent/service/runtime.test.ts; deno fmt --check touched files; deno lint touched files; deno check touched files; deno task typecheck; deno task typecheck:consumer
Not-tested: Full deno task verify and binary e2e suite were not run; pre-commit verify:quick hit unrelated missing release-assets API docs.
@kwakayama
kwakayama force-pushed the agent/sentry-agent-lifecycle branch from 3b06074 to 53ee22a Compare July 29, 2026 11:20
@kwakayama

Copy link
Copy Markdown
Contributor Author

Re-review for PR #3165 at 53ee22a

Score: 94/100
Verdict: APPROVE - both prior WATCH findings are resolved, and I found no new BLOCK/WATCH issues in the update.

Reviewed range: 9008f8c99e491a1cb1d551db163c4653416a9453..53ee22af4f6c67aaef77875b9a403888be93910d
Incremental range checked: 3b060743174bad8482be3ac3aa0d74f133a8e311..53ee22af4f6c67aaef77875b9a403888be93910d

Prior WATCH resolution

  1. Startup-error cleanup on flush rejection: resolved.
    Evidence: src/agent/hosted/veryfront-cloud-agent-service.ts:288-299 now catches startup flush failures, logs them, and always runs applicationErrors.reset() in finally. The new regression at src/agent/hosted/veryfront-cloud-agent-service.test.ts:472-532 forces flush() to reject and verifies capture, flush, reset, and exit(1) still happen.

  2. Registration rollback masking in startNodeVeryfrontCloudAgentService: resolved.
    Evidence: src/agent/hosted/veryfront-cloud-agent-service.ts:214-220 now routes startup rollback cleanup through stopRegistrationForStartupFailure(), preserving the original startup error if cleanup fails. The new regression at src/agent/hosted/veryfront-cloud-agent-service.test.ts:1013-1083 forces clearInterval() to throw during rollback and asserts the rejected error is still the original invalid-port startup error, not the rollback error.

New test reliability / side effects

The new tests are acceptable:

  • Deno global serve overrides are restored in finally (src/agent/hosted/veryfront-cloud-agent-service.test.ts:522-524).
  • Application-error test seams and log/application-error globals are restored in finally (src/agent/hosted/veryfront-cloud-agent-service.test.ts:528-531).
  • The rollback test restores both globalThis.fetch and globalThis.clearInterval in finally (src/agent/hosted/veryfront-cloud-agent-service.test.ts:1079-1082).
  • The forced clearInterval() failure calls the original clearInterval() before throwing (src/agent/hosted/veryfront-cloud-agent-service.test.ts:1047-1050), so the heartbeat interval is actually cleared and does not leak.
  • Startup-failure tests pass signals: [], avoiding process signal-handler side effects while exercising the intended startup/rollback path.

Validation run

  • deno check src/agent/hosted/veryfront-cloud-agent-service.ts src/agent/service/runtime.ts src/agent/hosted/veryfront-cloud-agent-service.test.ts src/agent/service/runtime.test.ts - passed
  • deno test --allow-all src/agent/service/runtime.test.ts src/agent/hosted/veryfront-cloud-agent-service.test.ts - passed, 32 tests
  • deno fmt --check on the four touched files - passed
  • deno lint on the four touched files - passed
  • deno task typecheck - passed
  • deno task typecheck:consumer - passed
  • git diff --check 9008f8c99e491a1cb1d551db163c4653416a9453..53ee22af4f6c67aaef77875b9a403888be93910d - passed
  • Pattern/security scan over touched files found no hardcoded real secrets; only synthetic test values such as example.*, token-1, and fake public Sentry DSNs.
  • Worktree was clean after validation.

Note: an explicit lsp_diagnostics tool was still unavailable in this review environment, so Deno check, full typecheck, and consumer typecheck were used as the type-safety gates.

@kwakayama
kwakayama marked this pull request as ready for review July 29, 2026 11:23
@kwakayama
kwakayama requested a review from kojiwakayama as a code owner July 29, 2026 11:23

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

Copy link
Copy Markdown

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: 53ee22af4f

ℹ️ 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 src/agent/hosted/veryfront-cloud-agent-service.ts
kojiwakayama
kojiwakayama previously approved these changes Jul 29, 2026
@kwakayama
kwakayama added this pull request to the merge queue Jul 29, 2026
@kojiwakayama
kojiwakayama removed this pull request from the merge queue due to a manual request Jul 29, 2026
Keep service module lifecycle cleanup independent from transport shutdown so application-error flush/reset still runs when Deno, Bun, or Node server shutdown fails.

Constraint: Agent application-error cleanup is attached to service runtime stop, but transports may fail before runtime stop runs.
Rejected: Leave stopRuntime sequenced after successful transport stop only | It skips lifecycle cleanup on server.shutdown, server.stop, or server.close failure.
Confidence: high
Scope-risk: narrow
Directive: Preserve the first shutdown failure while still attempting module lifecycle cleanup exactly once.
Tested: deno test --allow-all src/server/service-server.test.ts; deno test --allow-all src/agent/hosted/veryfront-cloud-agent-service.test.ts src/agent/service/runtime.test.ts; deno fmt --check touched files; deno lint touched files; deno check touched files; deno task typecheck
Not-tested: Full deno task verify and binary e2e suite were not run; prior PR verification noted unrelated release-assets docs gaps.
Track shutdown failure presence separately from the failure value so undefined or null transport/runtime failures are still rethrown after lifecycle cleanup runs.

Constraint: JavaScript allows throwing or rejecting nullish values, and service shutdown must preserve the first failure exactly.
Rejected: Use the failure value itself as the sentinel | undefined and null are valid failure values and were treated as no failure.
Confidence: high
Scope-risk: narrow
Directive: Keep shutdown cleanup independent from transport failures and preserve first-failure identity, including nullish failures.
Tested: deno test --allow-all src/server/service-server.test.ts; deno test --allow-all src/agent/hosted/veryfront-cloud-agent-service.test.ts src/agent/service/runtime.test.ts; deno fmt --check touched files; deno check touched files; deno run --allow-read --allow-run scripts/lint/check-test-typecheck-baseline.ts; deno task lint; deno task typecheck
Not-tested: Full deno task verify and binary e2e suite were not run.
@kwakayama

Copy link
Copy Markdown
Contributor Author

Re-review at 51324d9

Score: 96/100
Verdict: APPROVE — the transport-shutdown cleanup thread and the nullish first-error edge case are resolved; no remaining BLOCK or WATCH findings.

Evidence:

  • stopRuntime() always attempts runtime/application-error cleanup after Deno, Bun, or Node transport shutdown fails.
  • The original transport failure remains authoritative even when cleanup also fails, including null and undefined rejection values.
  • Existing shutdown latches preserve exact-once cleanup.
  • Regression coverage now exercises Deno, Bun, Node, nullish failures, graceful shutdown, startup failure, and cleanup-flush failure.
  • src/server/service-server.test.ts was removed from the obsolete test-typecheck baseline, fixing the CI lint failure.

Validation passed:

  • 41 focused service-server and Agent lifecycle tests
  • deno task lint
  • deno task typecheck
  • consumer typecheck
  • targeted deno check, deno fmt --check, and git diff --check
  • test-typecheck baseline: 94 grandfathered files, 0 new

The inline review thread has been replied to with commit evidence and resolved. The fresh GitHub Actions run is still being monitored separately.

@kwakayama
kwakayama requested a review from kojiwakayama July 29, 2026 11:54
@kwakayama
kwakayama enabled auto-merge July 29, 2026 11:59
kwakayama added a commit that referenced this pull request Jul 29, 2026
Prepare the next stable framework version as a stacked release so the Agent Sentry lifecycle fix can publish after approval without reusing an existing npm version.

Constraint: PR #3165 remains unmerged and this release branch must be based on agent/sentry-agent-lifecycle at 51324d9.

Rejected: Base on main | it would bypass the pending lifecycle fix that this release is intended to publish.

Confidence: high

Scope-risk: narrow

Directive: After PR #3165 merges, retarget this release PR to main before merging.

Tested: npm latest/version-unused checks for veryfront and @veryfront/ext-observability-sentry; GitHub tag/release absence checks for v0.1.1176; jq deno.json version check and VERSION sync assertion; deno fmt --check deno.json src/utils/version-constant.ts; deno check src/utils/version-constant.ts; stable-release-requested.sh returns true against origin/main.

Not-tested: Full release CI and package publishing remain for protected PR CI/release automation; local pre-commit verify:quick is blocked by existing release-assets docs/reference gap.
@kwakayama
kwakayama added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit a226ff4 Jul 29, 2026
28 checks passed
@kwakayama
kwakayama deleted the agent/sentry-agent-lifecycle branch July 29, 2026 12:18
kwakayama added a commit that referenced this pull request Jul 29, 2026
Prepare the next stable framework version on top of the merged Agent Sentry lifecycle fix without reusing an existing npm version.

Constraint: PR #3165 merged into origin/main at a226ff4, so the release branch must now contain only the version bump above main.

Rejected: Keep the old stacked lifecycle commits | they are already represented by the squashed merge on main.

Confidence: high

Scope-risk: narrow

Directive: Keep this release PR limited to the two version files until release automation publishes 0.1.1176.

Tested: jq deno.json version check and VERSION sync assertion; deno fmt --check deno.json src/utils/version-constant.ts; deno check src/utils/version-constant.ts; diff and merge-base validated against origin/main.

Not-tested: Full release CI and package publishing remain for protected PR CI/release automation; local pre-commit verify:quick is blocked by existing release-assets docs/reference gap.
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.

2 participants