Commit 6766457
Haider
fix: session env reads Layer-1 attrs from latest
Addresses GPT consensus-review finding M2 on PR #938.
`annotateSession` was deriving `de.env.*` session attributes by regex-
parsing the `project_scan` tool's output text via
`detectEnvFromProjectScan()`. Two architectural problems:
1. Layer-1 violation: `project-scan.ts:935` already writes the
authoritative `de.env.dbt_present`, `de.env.dbt_manifest_present`,
`de.env.warehouse_type`, `de.env.tools_detected` onto the tool
span's attributes (via the tracer's metadata-channel lift). The
session rollup ignored that authoritative source and re-parsed the
formatted output text, which is fragile to format drift and can
disagree with the per-span Layer-1 values. This violated the PR's
documented merge rule: Layer 1 (caller/tool-provided) wins over
Layer 2 (derived).
2. Stale-state bug: used `find()` to pick the first project_scan span.
A session that ran project_scan twice — e.g., scan, configure a
new warehouse, scan again — reflected the first scan's state in
the session root, not the latest.
Fix:
- Pick the LAST project_scan span in the toolSpans array (insertion
order = wall-clock order, since spans are pushed in logToolCall).
- For each `de.env.*` key, read the span's Layer-1 attribute first.
Fall back to the text-parse only when the Layer-1 value is absent.
- Text-parse fallback is computed lazily (only runs if at least one
key needs the fallback) so the common case where all four keys hit
Layer 1 skips the regex work entirely.
Verified with 3 cases: Layer-1 wins over conflicting text, text fallback
fills in absent attrs, latest of 2 scans wins.project_scan span1 parent 3cda78f commit 6766457
1 file changed
Lines changed: 43 additions & 8 deletions
Lines changed: 43 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
512 | 547 | | |
513 | 548 | | |
514 | 549 | | |
| |||
0 commit comments