Skip to content

Fix infinite recursion on links that point back to themselves - #336

Merged
dblock merged 1 commit into
codegram:masterfrom
dblock:dblock/self-link-recursion
Nov 22, 2026
Merged

dblock merged 1 commit into
codegram:masterfrom
dblock:dblock/self-link-recursion

Conversation

@dblock

@dblock dblock commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

🤖 This PR was written by an AI (Claude) acting on behalf of @dblock.

Closes #232.

Problem

When a link's resource has a link of the same name pointing to the same URL, for example a sub_nodes collection whose own _links.sub_nodes is itself and whose items are embedded under a different key, api.item.sub_nodes.map(&:name) raised SystemStackError: stack level too deep. Link#each calls respond_to?(@key), and Link#respond_to_missing? (and #delegate_method) followed _resource.sub_nodes to a new Link to the same URL, asked it the same question, and so on forever, fetching the URL on every level.

This is unrelated to Ruby 3; it reproduces on current Ruby.

Fix

  • Link#respond_to_missing? and Link#delegate_method no longer delegate to a Link with the same URL.
  • Link#each raises Hyperclient::SelfReferencingLinkError ("The sub_nodes link at … links back to itself, use _embedded to iterate over embedded items.") instead of recursing. _embedded.<key> still works.
  • Links of the same name pointing to a different URL are still followed as before.

Validation

  • New specs for the self-referencing each, respond_to? and nil-delegation paths, and for a same-name link to a different URL; the self-referencing specs fail without the fix.
  • bundle exec rake locally on Ruby 4.0.9: 174 tests, 32 spinach steps, RuboCop clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_011Gr21htyJfr8XZGHBcPwkW

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Danger Report

No issues found.

View run

@coveralls

coveralls commented Nov 22, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 99.701% (+0.007%) from 99.694% — dblock:dblock/self-link-recursion into codegram:master

When a link's resource has a link of the same name pointing to the same
URL (e.g. a `sub_nodes` collection whose `_links.sub_nodes` is itself),
`Link#respond_to_missing?` and `#delegate_method` followed that link
forever, fetching it on every level until `SystemStackError`. Stop
delegating to a link with the same URL, and have `Link#each` raise
`Hyperclient::SelfReferencingLinkError` pointing to `_embedded` instead.

Closes codegram#232.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Gr21htyJfr8XZGHBcPwkW
@dblock
dblock force-pushed the dblock/self-link-recursion branch from 68c072a to 278d7f8 Compare November 22, 2026 13:51
@dblock
dblock merged commit 3dfd286 into codegram:master Nov 22, 2026
11 checks passed
@dblock
dblock deleted the dblock/self-link-recursion branch November 22, 2026 13:55
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.

Ruby 3 upgrade throws kernel error for the overwritten each method

2 participants