Skip to content

Conversation

@daveey
Copy link
Contributor

@daveey daveey commented Jan 15, 2026

Rename ResourceLimitsConfig.limit to min/max for better semantics

TL;DR

Renamed limit to min/max in ResourceLimitsConfig to better represent inventory capacity constraints, and updated all references throughout the codebase.

What changed?

  • Changed ResourceLimitsConfig.limit to min (floor) and max (ceiling) parameters
  • Updated the effective limit calculation formula to: min(max_limit, max(min_limit, sum(modifier_bonus * quantity_held)))
  • Modified C++ implementation in inventory.hpp to support the new min/max semantics
  • Added agent_config() method to CogConfig to centralize agent configuration
  • Updated all references to limit across the codebase to use the new parameters

How to test?

  1. Run the Cogs vs Clips mission to verify inventory limits work correctly
  2. Test dynamic inventory limits with modifiers to ensure they respect both min and max constraints
  3. Verify that existing inventory behavior is preserved in all game modes
  4. Check that the new agent configuration method correctly applies all settings

Why make this change?

This change provides more intuitive and flexible inventory limit semantics:

  • min establishes a floor for capacity even with no modifiers
  • max sets a ceiling that can't be exceeded regardless of modifiers
  • The naming better reflects how these values actually constrain inventory capacity
  • Centralizing agent configuration in CogConfig improves code organization and maintainability

Copy link
Contributor Author

daveey commented Jan 15, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • add-to-merge-queue - adds this PR to the back of the merge queue
  • add-to-merge-queue-as-hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@daveey daveey mentioned this pull request Jan 15, 2026
@daveey daveey changed the base branch from daveey-cg-viz to graphite-base/4876 January 15, 2026 18:57
@daveey daveey force-pushed the graphite-base/4876 branch from 7e49aad to 0bebaae Compare January 15, 2026 18:57
@daveey daveey changed the base branch from graphite-base/4876 to main January 15, 2026 18:57
@daveey daveey changed the title cp refactor(cogames): use agent_config method in CogConfig Jan 15, 2026
@daveey daveey marked this pull request as ready for review January 15, 2026 19:03
@daveey daveey requested a review from sasmith January 15, 2026 19:03
Comment on lines +322 to +324
min_val = resource_limit.get("min", resource_limit.get("limit", 0))
max_val = resource_limit.get("max", 65535)
limit_defs.append(CppLimitDef(resource_ids, min_val, max_val, modifier_ids))
Copy link
Contributor

Choose a reason for hiding this comment

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

Backward compatibility issue: When reading old configs that have limit but not min/max, the code uses limit as min (line 322). This breaks the semantics for configs with modifiers.

Problem: Old config with limit=100 and modifiers that add +50 would give effective limit of 150. After migration, min=100 with +50 modifiers gives max(100, 50) = 100.

Fix: Should migrate limit to max instead of min when modifiers are present:

min_val = resource_limit.get("min", 0)
max_val = resource_limit.get("max", resource_limit.get("limit", 65535))

This preserves the old behavior where limit was effectively a cap that modifiers couldn't exceed.

Suggested change
min_val = resource_limit.get("min", resource_limit.get("limit", 0))
max_val = resource_limit.get("max", 65535)
limit_defs.append(CppLimitDef(resource_ids, min_val, max_val, modifier_ids))
min_val = resource_limit.get("min", 0)
max_val = resource_limit.get("max", resource_limit.get("limit", 65535))
limit_defs.append(CppLimitDef(resource_ids, min_val, max_val, modifier_ids))

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

}
}
// Apply formula: min(max_limit, max(min_limit, modifier_sum))
int effective = std::max(static_cast<int>(min_limit), modifier_sum);
Copy link
Contributor

Choose a reason for hiding this comment

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

Claude, can you change this to use std::clamp?

InventoryQuantity amount;

// Get the effective limit (base + sum of modifier bonuses)
// Get the effective limit: min(max_limit, max(min_limit, sum(modifier_bonus * quantity_held)))
Copy link
Contributor

Choose a reason for hiding this comment

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

The description(s) should also use clamp


struct SharedInventoryLimit {
InventoryQuantity base_limit;
InventoryQuantity min_limit;
Copy link
Contributor

Choose a reason for hiding this comment

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

This all strikes me as a little funky. E.g., why are we at the min_limit if there are no modifiers? It's also pretty easy for ResourceLimitsConfig(min=...) to be confusing, since it definitely suggests that this inventory amount can't be less than the min.

Let's talk about what we're trying to solve?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we renamed "limit" to "capacity" it would be less confusing.

Apply suggested changes
limits={
"hp": ResourceLimitsConfig(min=self.hp_limit, resources=["hp"], modifiers=self.hp_modifiers),
# when hp == 0, the cog can't hold gear or hearts
"gear": ResourceLimitsConfig(max=self.gear_limit, resources=gear, modifiers={"hp": 100}),
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like a hacky way to accomplish this result, but let's ship it and revisit if needed.

@graphite-app
Copy link
Contributor

graphite-app bot commented Jan 15, 2026

Merge activity

  • Jan 15, 11:15 PM UTC: daveey added this pull request to the Graphite merge queue.
  • Jan 15, 11:15 PM UTC: CI is running for this pull request on a draft pull request (#4889) due to your merge queue CI optimization settings.
  • Jan 15, 11:27 PM UTC: Merged by the Graphite merge queue via draft PR: #4889.

graphite-app bot pushed a commit that referenced this pull request Jan 15, 2026
# Rename ResourceLimitsConfig.limit to min/max for better semantics

### TL;DR

Renamed `limit` to `min`/`max` in `ResourceLimitsConfig` to better represent inventory capacity constraints, and updated all references throughout the codebase.

### What changed?

- Changed `ResourceLimitsConfig.limit` to `min` (floor) and `max` (ceiling) parameters
- Updated the effective limit calculation formula to: `min(max_limit, max(min_limit, sum(modifier_bonus * quantity_held)))`
- Modified C++ implementation in `inventory.hpp` to support the new min/max semantics
- Added `agent_config()` method to `CogConfig` to centralize agent configuration
- Updated all references to `limit` across the codebase to use the new parameters

### How to test?

1. Run the Cogs vs Clips mission to verify inventory limits work correctly
2. Test dynamic inventory limits with modifiers to ensure they respect both min and max constraints
3. Verify that existing inventory behavior is preserved in all game modes
4. Check that the new agent configuration method correctly applies all settings

### Why make this change?

This change provides more intuitive and flexible inventory limit semantics:
- `min` establishes a floor for capacity even with no modifiers
- `max` sets a ceiling that can't be exceeded regardless of modifiers
- The naming better reflects how these values actually constrain inventory capacity
- Centralizing agent configuration in `CogConfig` improves code organization and maintainability
@graphite-app graphite-app bot closed this Jan 15, 2026
@graphite-app graphite-app bot deleted the daveey-cog-move branch January 15, 2026 23:27
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.

3 participants