Skip to content

Fix issue 20 self-link substitution handling#47

Merged
konard merged 5 commits intomainfrom
issue-20-aba7a4fa
May 8, 2026
Merged

Fix issue 20 self-link substitution handling#47
konard merged 5 commits intomainfrom
issue-20-aba7a4fa

Conversation

@konard
Copy link
Copy Markdown
Member

@konard konard commented Sep 10, 2025

Summary

Resolves #20.

This fixes the self-link substitution query that previously exhausted memory:

((($i: 1 21)) (($i: $s $t) ($i 20)))

Root Cause

  • Substitution resolution turned unbound variables in ($i: $s $t) into the special Any reference instead of preserving the matched link parts.
  • Anonymous substitution composites like ($i 20) could be resolved through wildcard semantics instead of the null index used for creating a new link.
  • Explicit creation accepted null/special/out-of-range addresses and tried to create up to the requested value, which let special constants drive uncontrolled allocation.

Fix

  • Preserve unbound source/target variables from the existing matched link during indexed substitutions, using point checks and a visited set for self-reference safety.
  • Treat anonymous substitution composite indexes as 0, so ($i 20) creates the intended outgoing link.
  • Harden EnsureCreated to reject unsupported internal references and repeated/overshooting creator output without arbitrary iteration limits.
  • Add matching C# and Rust issue-20 parity tests.
  • Keep Rust file sizes under the CI 1000-line gate by moving substitution-preservation helpers into query_processor_substitution.rs.
  • Remove the stale example files from the earlier iteration-limit draft.

Case Study

Detailed issue data, PR comments, screenshot evidence, upstream LinksPlatform reference snippets, local reproduction output, and verification logs are in:

  • docs/case-studies/issue-20/README.md

No upstream LinksPlatform bug was identified; this PR uses the referenced LinksPlatform point helpers and visited-set structure-formatting pattern locally.

Verification

  • dotnet restore from csharp/
  • dotnet build --no-restore --configuration Release from csharp/
  • dotnet test --no-build --configuration Release --verbosity normal from csharp/
  • cargo fmt --all -- --check from rust/
  • RUSTFLAGS=-Dwarnings cargo clippy --all-targets --all-features from rust/
  • cargo test --all-features --verbose from rust/
  • cargo test --doc --verbose from rust/
  • node scripts/check-file-size.mjs --lang rust
  • npm ci
  • npm run test:wasm
  • npm run build
  • Manual traced issue reproduction after the fix, saved in docs/case-studies/issue-20/evidence/repro-after-fix.log

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #20
@konard konard self-assigned this Sep 10, 2025
konard and others added 2 commits September 10, 2025 16:54
- Add infinite loop protection to prevent OutOfMemoryException when processing self-referential link patterns
- Implement multiple safeguards: iteration limits, cycle detection, and reasonable bounds checking
- Replace uncontrolled memory exhaustion with controlled InvalidOperationException
- Add comprehensive test case for the problematic query pattern: ((($i: 1 21)) (($i: $s $t) ($i 20)))
- Include simple verification test to demonstrate the fix works correctly

Fixes #20: Unable to substitute a link to itself + outgoing link

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Unable to substitute a link to itself + outgoing link Fix OutOfMemoryException in self-referential link substitution Sep 10, 2025
@konard konard marked this pull request as ready for review September 10, 2025 14:08
@konard
Copy link
Copy Markdown
Member Author

konard commented May 8, 2026

We need to get latest changes from default branch. And cover these cases extensively with tests. Reasonable bounds checking: Additional safety based on target ID expectations we can use ILinksConstants in addition to ILinksExtensions Exist or LinkExist functions. Seach for these in https://github.com/linksplatform

Iteration limit: Maximum of 10,000 iterations to prevent unbounded loops

That we should not do. Instead we should use protection of 0 values, or out of bounds of ILinksConstants supported range of links.

We should use IsPartialPoint IsFullPoint functions (Seach for these in https://github.com/linksplatform) to detect immediate self references.

And see how Format Structure is done in https://github.com/linksplatform (it uses hashset to keep track of visited links when traversing any structure, that may have indirect self references.

So we actually can fully detect possible recursion cases, also harden our code with more tests, so all self referential cases (direct or indirect) are covered.

We also need to make sure we support the same test cases in both Rust version of the code and C# version of the code in the same way.

If you find any issues in https://github.com/linksplatform components, make sure to report issues there, and list these issues in this pull request, and also put links to this pull request in these issues.

We need to download all logs and data related about the issue to this repository, make sure we compile that data to ./docs/case-studies/issue-{id} folder, and use it to do deep case study analysis (also make sure to search online for additional facts and data), in which we will reconstruct timeline/sequence of events, list of each and all requirements from the issue, find root causes of the each problem, and propose possible solutions and solution plans for each requirement (we should also check known existing components/libraries, that solve similar problem or can help in solutions).

If there is not enough data to find actual root cause, add debug output and verbose mode if not present, that will allow us to find root cause on next iteration.

If issue related to any other repository/project, where we can report issues on GitHub, please do so. Each issue must contain reproducible examples, workarounds and suggestions for fix the issue in code.

Please plan and execute everything in a single pull request, you have unlimited time and context, as context auto-compacts and you can continue indefinitely, until it is each and every requirement fully addressed, and everything is totally done.

@konard konard marked this pull request as draft May 8, 2026 10:33
@konard
Copy link
Copy Markdown
Member Author

konard commented May 8, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-05-08T10:33:11.987Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

@konard konard changed the title Fix OutOfMemoryException in self-referential link substitution Fix issue 20 self-link substitution handling May 8, 2026
@konard konard marked this pull request as ready for review May 8, 2026 11:12
@konard
Copy link
Copy Markdown
Member Author

konard commented May 8, 2026

Working session summary

Implemented and pushed the issue 20 fix to PR 47:

#47

What changed:

  • Reworked C# substitution handling so unbound $s/$t preserve matched link parts instead of becoming Any.
  • Hardened EnsureCreated to reject unsupported internal references without arbitrary iteration limits.
  • Added Rust parity behavior and tests.
  • Added the full issue case study and evidence under docs/case-studies/issue-20/.
  • Fixed the first CI failure by splitting Rust substitution helpers into rust/src/query_processor_substitution.rs, keeping query_processor.rs under the 1000-line CI gate.

Verification:

  • Local C#, Rust, wasm, build, file-size, and manual reproduction checks passed.
  • Fresh PR CI for commit f3c7b7e is passing across C#, Rust, and WebAssembly.
  • PR is ready for review, merge status is CLEAN, and the working tree is clean.

This summary was automatically extracted from the AI working session output.

@konard
Copy link
Copy Markdown
Member Author

konard commented May 8, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Model: GPT-5.5
  • Provider: OpenAI
  • Public pricing estimate: $31.729554

📊 Context and tokens usage:

  • 758.1K / 1.1M (72%) input tokens, 69.9K / 128K (55%) output tokens

Total: (758.1K + 21.0M cached) input tokens, 69.9K output tokens, $31.729554 cost

🤖 Models used:

  • Tool: OpenAI Codex
  • Requested: gpt-5.5
  • Model: GPT-5.5 (gpt-5.5)

📎 Log file uploaded as Repository (87589KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Member Author

konard commented May 8, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard konard merged commit 79135ac into main May 8, 2026
22 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.

Unable to substitute a link to itself + outgoing link

1 participant