Compare commits

...

1 Commits

Author SHA1 Message Date
HAL9000 f62fd7bd12 fix(acms): normalize context path matching for absolute paths in _path_matches
CI / benchmark-publish (pull_request) Has been skipped
CI / push-validation (pull_request) Successful in 33s
CI / helm (pull_request) Successful in 44s
CI / build (pull_request) Successful in 54s
CI / quality (pull_request) Successful in 1m13s
CI / lint (pull_request) Successful in 1m23s
CI / typecheck (pull_request) Successful in 1m30s
CI / security (pull_request) Successful in 1m31s
CI / benchmark-regression (pull_request) Failing after 55s
CI / e2e_tests (pull_request) Successful in 3m55s
CI / integration_tests (pull_request) Successful in 5m3s
CI / unit_tests (pull_request) Failing after 6m3s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 4s
Fixes issue #10972 where _path_matches() used PurePath.full_match()/match()
which requires the entire path to match. Since fragment metadata stores
absolute paths (e.g. /app/.opencode/skills/SKILL.md) while project context
--exclude-path/--include-path settings produce relative globs (.opencode/*,
docs/*), include/exclude filters were silently ineffective.

Added _matches_any() static helper in execute_phase_context_assembler.py that:
- Tries full_match(pattern) as-is for relative paths and anchored patterns
- Auto-prefixes relative patterns with **/ so they match absolute paths
Updated _matches_pattern() in context_phase_analysis.py with same logic plus
zero-depth compatibility shim.

Added 7 new BDD regression scenarios with @tdd_issue tags:
- 5 in execute_phase_context_assembler_coverage.feature (absolute path matching)
- 1 extra trailing ** glob exclusion test
- 1 in project_context_phase_analysis.feature (phase analysis exclusion)

ISSUES CLOSED: #10972
2026-05-07 12:11:31 +00:00
7 changed files with 132 additions and 9 deletions
+10
View File
@@ -47,6 +47,16 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
and milestone assignment. This eliminates systemic PR merge blockers caused by workers
omitting required items.
- **ACMS context path matching now handles absolute fragment paths** (#10972): Fixed
`_path_matches()` in `execute_phase_context_assembler.py` and `_matches_pattern()` in
`context_phase_analysis.py` to correctly match absolute paths (e.g. `/app/.opencode/skills/SKILL.md`)
against relative glob patterns (e.g. `.opencode/**`, `docs/*`). Previously
`PurePath.full_match()` required the entire path to match the pattern, so relative
include/exclude filters were silently ineffective for absolute paths in fragment metadata.
Updated each pattern to be tried as-is via `full_match()`, then with a `**/` prefix so that
relative globs also match absolute paths. Added BDD regression tests in
`execute_phase_context_assembler_coverage.feature` and `project_context_phase_analysis.feature`.
### Changed
- Restored `benchmark-regression` CI job to `master.yml` with `pull_request` trigger guard
+1
View File
@@ -31,3 +31,4 @@ Below are some of the specific details of various contributions.
* HAL 9000 has contributed comprehensive milestone documentation for v3.6.0 (Advanced Concepts & Deferred Features) and v3.7.0 (TUI Implementation) (PR #9903): split into sub-documents covering context strategies, LLM backends, resource types, A2A rename, container tool execution, scope chain resolution, cost/safety budgets, E2E workflow tests, code review examples, plugin architecture, TUI layout, persona system, reference/command input, session management, configuration, and TuiMaterializer integration.
* HAL 9000 has contributed the LLMTraceRepository data-integrity fix (PR #8185 / issue #7505): replaced the unconditional `session.commit()` in `LLMTraceRepository.save()` with a dual-path implementation that respects the UnitOfWork pattern — flushing only when an external session is provided, and flushing + committing + closing when operating standalone. This eliminates premature transaction commits, loss of rollback capability, and a docstring/implementation mismatch.
* HAL 9000 has contributed the ACMS Index Data Model and File Traversal Engine (PR #9664 / issue #9579): foundational data structures for indexed context entries with hot/warm/cold/archive storage tier classification, tag system, and a timeout-safe chunked file traversal engine for large projects with 10,000+ files.
* HAL 9000 has contributed the ACMS context path matching fix (PR #10975 / issue #10972): corrects `_path_matches()` and `_matches_pattern()` to properly match absolute fragment paths against relative glob patterns by auto-prefixing with `**/` before calling `PurePath.full_match()`, preventing silent inefficacy of include/exclude filters for absolute paths in fragment metadata.
@@ -46,6 +46,31 @@ Feature: Execute-phase context assembler coverage
When epcov I check path matching for "src/foo.py" with exclude "src/secret*"
Then epcov the path should match
@tdd_issue @tdd_issue_10972
Scenario: epcov path matches absolute path against relative include glob
When epcov I check path matching for "/app/.opencode/skills/SKILL.md" with include ".opencode/**"
Then epcov the path should match
@tdd_issue @tdd_issue_10972
Scenario: epcov path matches absolute path against relative exclude glob
When epcov I check path matching for "/app/.opencode/skills/SKILL.md" with exclude ".opencode/**"
Then epcov the path should not match
@tdd_issue @tdd_issue_10972
Scenario: epcov path matches absolute path against relative include glob with wildcard
When epcov I check path matching for "/app/docs/readme.md" with include "docs/*"
Then epcov the path should match
@tdd_issue @tdd_issue_10972
Scenario: epcov path matches absolute path not matching relative include glob
When epcov I check path matching for "/app/src/main.py" with include "docs/*"
Then epcov the path should not match
@tdd_issue @tdd_issue_10972
Scenario: epcov relative path is excluded by trailing ** glob
When epcov I check path matching for "build/debug/output.log" with exclude "build/**"
Then epcov the path should not match
# ---- _resource_matches static method ----
Scenario: epcov resource matches with no rules passes all
@@ -29,3 +29,10 @@ Feature: Project context phase analysis summaries
When I compute project context phase analysis with budget 1000
Then execute phase should have fewer tokens than strategize phase
And apply phase should have fewer or equal tokens than execute phase
@tdd_issue @tdd_issue_10972
Scenario: Absolute path fragments are correctly excluded by relative exclude globs
Given a phase analysis policy with opencode exclude paths
And an absolute path fragment for phase analysis
When I compute project context phase analysis with budget 2000
Then strategize phase should exclude the absolute path fragment
@@ -183,3 +183,54 @@ def step_apply_less_or_equal(context: Any) -> None:
exec_tokens = context.phase_result["phases"]["execute"]["total_tokens"]
apply_tokens = context.phase_result["phases"]["apply"]["total_tokens"]
assert apply_tokens <= exec_tokens
@given("a phase analysis policy with opencode exclude paths")
def step_policy_opencode_exclude(context: Any) -> None:
"""Policy that excludes .opencode/** paths using relative globs."""
context.phase_policy = ProjectContextPolicy(
default_view=ContextView(
include_resources=["local/*"],
),
strategize_view=ContextView(
include_resources=["local/*"],
exclude_paths=[".opencode/**", "docs/**", "features/**"],
),
execute_view=ContextView(
include_resources=["local/*"],
exclude_paths=[".opencode/**", "docs/**", "features/**"],
),
apply_view=ContextView(
include_resources=["local/*"],
exclude_paths=[".opencode/**", "docs/**", "features/**"],
),
)
@given("an absolute path fragment for phase analysis")
def step_absolute_path_fragment(context: Any) -> None:
"""Fragment with an absolute path that should be excluded by relative globs."""
context.phase_fragments = [
TieredFragment(
fragment_id="abs-skill",
content="skill content",
tier=ContextTier.HOT,
resource_id="local/repo-a",
project_name="local/ctx-app",
token_count=50,
metadata={
"path": "/app/.opencode/skills/SKILL.md",
"byte_size": 1000,
},
)
]
@then("strategize phase should exclude the absolute path fragment")
def step_strat_excludes_absolute(context: Any) -> None:
"""Verify that the absolute path fragment is excluded by relative glob patterns."""
strat = context.phase_result["phases"]["strategize"]
assert strat["fragment_count"] == 0, (
f"Expected 0 fragments (absolute path should be excluded by relative glob), "
f"got {strat['fragment_count']}"
)
@@ -31,10 +31,20 @@ def _path_matches(path: str, include_patterns: list[str]) -> bool:
def _matches_pattern(path_obj: PurePosixPath, pattern: str) -> bool:
"""Match with a small compatibility shim for ``**/`` zero-depth cases."""
return path_obj.match(pattern) or (
"**/" in pattern and path_obj.match(pattern.replace("**/", ""))
)
"""Match a path against a glob pattern, handling absolute vs relative paths.
Tries ``full_match()`` with the pattern as-is, then with a ``**/``
prefix so that relative globs (e.g. ``.opencode/*``) correctly match
absolute paths (e.g. ``/app/.opencode/skills/SKILL.md``). Also
handles the ``**/`` zero-depth compatibility shim.
"""
if path_obj.full_match(pattern):
return True
# Auto-prefix with **/ so relative patterns match absolute paths
if not pattern.startswith("**/") and path_obj.full_match(f"**/{pattern}"):
return True
# Zero-depth shim: "**/" in pattern but full_match already tried above
return bool("**/" in pattern and path_obj.full_match(pattern.replace("**/", "")))
def _extract_path(fragment: TieredFragment) -> str:
@@ -72,13 +72,32 @@ class ACMSExecutePhaseContextAssembler(ExecutePhaseContextAssembler):
@staticmethod
def _path_matches(path: str, include: list[str], exclude: list[str]) -> bool:
"""Return whether *path* passes include/exclude path globs."""
"""Return whether *path* passes include/exclude path globs.
Handles both absolute paths (e.g. ``/app/.opencode/skills/SKILL.md``)
and relative paths (e.g. ``src/foo.py``) against relative glob
patterns (e.g. ``.opencode/**``, ``src/**/*.py``).
Each pattern is tried with ``full_match()`` as-is (handles
relative paths and ``**`` patterns). If the pattern is not
already anchored with ``**/``, a second attempt prefixes
``**/`` so that relative globs also match absolute paths.
"""
pure_path = PurePath(path)
if include and not any(pure_path.full_match(pattern) for pattern in include):
def _matches_any(patterns: list[str]) -> bool:
for pattern in patterns:
if pure_path.full_match(pattern):
return True
if not pattern.startswith("**/") and pure_path.full_match(
f"**/{pattern}"
):
return True
return False
return not (
exclude and any(pure_path.full_match(pattern) for pattern in exclude)
)
if include and not _matches_any(include):
return False
return not (exclude and _matches_any(exclude))
@staticmethod
def _resource_matches(