Skip to content

Conversation

@ootakazuhiko
Copy link
Collaborator

背景\nCodeQLの未使用変数指摘(phase6-metricsのgauge未利用)を解消し、メトリクス出力の意図と整合させるため。\n\n## 変更\n- Phase6のqualityメトリクスを保持するスナップショットを追加\n- ObservableGaugeへbatch callbackを登録し、最新値を観測\n- recordQualityMetricsでスナップショットを更新\n\n## ログ\n- 追加ログなし\n\n## テスト\n- 未実施(依存未導入のため)\n\n## 影響\n- Phase6 quality gaugeがrecordQualityMetricsの値を出力するようになる(機能追加のみ)\n\n## ロールバック\n- 本PRをrevert\n\n## 関連Issue\n- #1004\n- #1336

Copilot AI review requested due to automatic review settings January 4, 2026 22:31
@github-actions
Copy link

github-actions bot commented Jan 4, 2026

❓ Code Generation Drift Detection

Status:
Regeneration needed: No


Automated by AE-Framework Codegen

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

Quality Summary

  • Adapters:

  • Formal: n/a

  • Replay: n/a

  • Trace IDs:

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

🔍 Verification Summary

  • Traceability: 6 scenarios
    • Tests: 3 (50%)
    • Impl: 3 (50%)
    • Formal: 3 (50%)
Unlinked (top 5) - Device registration publishes enough pre-keys and emits audit log (id: device-registration-publishes-enough-pre-keys-and-emits-audit-log) test:N/A impl:N/A formal:N/A - Invalid auth tag triggers audit violation for AES-GCM envelopes (id: invalid-auth-tag-triggers-audit-violation-for-aes-gcm-envelopes) test:N/A impl:N/A formal:N/A - Session rotation stays within forward secrecy thresholds (id: session-rotation-stays-within-forward-secrecy-thresholds) test:N/A impl:N/A formal:N/A
Linked examples (up to 3) - Successful reservation (id: successful-reservation) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/specs/formal/tla+/Inventory.tla) - Prevent negative stock (id: prevent-negative-stock) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/specs/formal/tla+/Inventory.tla) - Idempotent by order id (id: idempotent-by-order-id) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/specs/formal/tla+/Inventory.tla)
Hit basis (tests/formal) - Test hits: title=3 id=0 tag=0 - Formal hits: title=0 id=3 tag=0
- Model Check (TLC): 2/8 (25%) modules ok
Non-OK modules (top 5) - KvOnce (log: artifacts/codex/KvOnce.tlc.log.txt) - KvOnceRefinement (log: artifacts/codex/KvOnceRefinement.tlc.log.txt) - KvOnceImpl (log: artifacts/codex/KvOnceImpl.tlc.log.txt) - KvOnce (log: artifacts/codex/KvOnce.tlc.log.txt) - KvOnceRefinement (log: artifacts/codex/KvOnceRefinement.tlc.log.txt)
- Alloy: detected 2 specs (execution skipped) - Contracts: schemas=true conditions=true machine=true - Contracts exec: parseIn=false pre=false post=false parseOut=false

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

CodeX Artifacts Summary

  • • Contract/E2E templates: 1 files (dir: tests/api/generated)
  • • Tests: PBT files=122, BDD features=0
  • • Formal specs: TLA=1, Alloy=1

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR resolves CodeQL unused variable warnings by wiring Phase6 quality gauges to the OpenTelemetry metrics system using batch observable callbacks.

Key changes:

  • Introduced qualitySnapshot object to hold latest quality metric values (coverage, a11yScore, performanceScore)
  • Registered a batch observable callback to observe gauge values from the snapshot
  • Updated recordQualityMetrics to populate the snapshot when metrics are recorded

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +75 to +96
const qualitySnapshot: Partial<Phase6Metrics['quality']> = {};

type Attrs = Record<string, string | number | boolean>;
interface MinimalObservableResult {
observe: (instrument: ObservableGauge | undefined, value: number, attributes?: Attrs) => void;
}

meter.addBatchObservableCallback(
(observableResult) => {
const observer = observableResult as unknown as MinimalObservableResult;
if (typeof qualitySnapshot.coverage === 'number') {
observer.observe(coverageGauge, qualitySnapshot.coverage, { metric: 'coverage' });
}
if (typeof qualitySnapshot.a11yScore === 'number') {
observer.observe(a11yScoreGauge, qualitySnapshot.a11yScore, { metric: 'a11y' });
}
if (typeof qualitySnapshot.performanceScore === 'number') {
observer.observe(performanceScoreGauge, qualitySnapshot.performanceScore, { metric: 'performance' });
}
},
[coverageGauge, a11yScoreGauge, performanceScoreGauge]
);
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

The new batch observable callback functionality (lines 82-96) and the qualitySnapshot updates in recordQualityMetrics (lines 350, 358, 366) lack test coverage. The codebase has comprehensive testing in tests/telemetry/, including tests for enhanced-telemetry.test.ts. Consider adding tests to verify: 1) that the snapshot is correctly updated when recordQualityMetrics is called, 2) that the batch callback correctly observes values from the snapshot, and 3) that the callback handles cases where snapshot values are undefined.

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +93
const observer = observableResult as unknown as MinimalObservableResult;
if (typeof qualitySnapshot.coverage === 'number') {
observer.observe(coverageGauge, qualitySnapshot.coverage, { metric: 'coverage' });
}
if (typeof qualitySnapshot.a11yScore === 'number') {
observer.observe(a11yScoreGauge, qualitySnapshot.a11yScore, { metric: 'a11y' });
}
if (typeof qualitySnapshot.performanceScore === 'number') {
observer.observe(performanceScoreGauge, qualitySnapshot.performanceScore, { metric: 'performance' });
}
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

The batch observable callback lacks error handling. If an error occurs during metric observation (e.g., due to invalid snapshot data or OpenTelemetry API issues), it could cause the callback to fail silently or propagate errors. The similar implementation in enhanced-telemetry.ts (lines 157-204) wraps the callback logic in a try-catch block with error logging. Consider adding the same error handling pattern here.

Suggested change
const observer = observableResult as unknown as MinimalObservableResult;
if (typeof qualitySnapshot.coverage === 'number') {
observer.observe(coverageGauge, qualitySnapshot.coverage, { metric: 'coverage' });
}
if (typeof qualitySnapshot.a11yScore === 'number') {
observer.observe(a11yScoreGauge, qualitySnapshot.a11yScore, { metric: 'a11y' });
}
if (typeof qualitySnapshot.performanceScore === 'number') {
observer.observe(performanceScoreGauge, qualitySnapshot.performanceScore, { metric: 'performance' });
}
try {
const observer = observableResult as unknown as MinimalObservableResult;
if (typeof qualitySnapshot.coverage === 'number') {
observer.observe(coverageGauge, qualitySnapshot.coverage, { metric: 'coverage' });
}
if (typeof qualitySnapshot.a11yScore === 'number') {
observer.observe(a11yScoreGauge, qualitySnapshot.a11yScore, { metric: 'a11y' });
}
if (typeof qualitySnapshot.performanceScore === 'number') {
observer.observe(performanceScoreGauge, qualitySnapshot.performanceScore, { metric: 'performance' });
}
} catch (error) {
console.error('Error observing phase6 quality metrics', error);
}

Copilot uses AI. Check for mistakes.

meter.addBatchObservableCallback(
(observableResult) => {
const observer = observableResult as unknown as MinimalObservableResult;
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

The type casting approach is inconsistent with the existing codebase pattern. This code uses 'as unknown as MinimalObservableResult', but the similar implementation in enhanced-telemetry.ts uses 'as any' for the same purpose (lines 161-194). While both accomplish the same goal, consider using 'as any' to maintain consistency across the codebase, or document why a different approach was chosen here.

Suggested change
const observer = observableResult as unknown as MinimalObservableResult;
const observer = (observableResult as any) as MinimalObservableResult;

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Jan 4, 2026

❓ Code Generation Drift Detection

Status:
Regeneration needed: No


Automated by AE-Framework Codegen

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

🔍 Verification Summary

  • Traceability: 6 scenarios
    • Tests: 3 (50%)
    • Impl: 3 (50%)
    • Formal: 3 (50%)
Unlinked (top 5) - Device registration publishes enough pre-keys and emits audit log (id: device-registration-publishes-enough-pre-keys-and-emits-audit-log) test:N/A impl:N/A formal:N/A - Invalid auth tag triggers audit violation for AES-GCM envelopes (id: invalid-auth-tag-triggers-audit-violation-for-aes-gcm-envelopes) test:N/A impl:N/A formal:N/A - Session rotation stays within forward secrecy thresholds (id: session-rotation-stays-within-forward-secrecy-thresholds) test:N/A impl:N/A formal:N/A
Linked examples (up to 3) - Successful reservation (id: successful-reservation) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/specs/formal/tla+/Inventory.tla) - Prevent negative stock (id: prevent-negative-stock) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/specs/formal/tla+/Inventory.tla) - Idempotent by order id (id: idempotent-by-order-id) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/specs/formal/tla+/Inventory.tla)
Hit basis (tests/formal) - Test hits: title=3 id=0 tag=0 - Formal hits: title=0 id=3 tag=0
- Model Check (TLC): 2/8 (25%) modules ok
Non-OK modules (top 5) - KvOnce (log: artifacts/codex/KvOnce.tlc.log.txt) - KvOnceRefinement (log: artifacts/codex/KvOnceRefinement.tlc.log.txt) - KvOnceImpl (log: artifacts/codex/KvOnceImpl.tlc.log.txt) - KvOnce (log: artifacts/codex/KvOnce.tlc.log.txt) - KvOnceRefinement (log: artifacts/codex/KvOnceRefinement.tlc.log.txt)
- Alloy: detected 2 specs (execution skipped) - Contracts: schemas=true conditions=true machine=true - Contracts exec: parseIn=false pre=false post=false parseOut=false

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

CodeX Artifacts Summary

  • • Contract/E2E templates: 1 files (dir: tests/api/generated)
  • • Tests: PBT files=122, BDD features=0
  • • Formal specs: TLA=1, Alloy=1

@ootakazuhiko ootakazuhiko merged commit ced3d6d into main Jan 4, 2026
78 of 79 checks 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.

2 participants