Skip to content

engine: refuse a systems stock named for the clock - #1088

Merged
bpowers merged 1 commit into
mainfrom
systems-refuse-clock-stock-names
Oct 12, 2026
Merged

bpowers merged 1 commit into
mainfrom
systems-refuse-clock-stock-names

Conversation

@bpowers

@bpowers bpowers commented Oct 12, 2026

Copy link
Copy Markdown
Owner

A systems-format stock named time simulated, but its series took the clock's key in the results, so the CLI printed the clock under time and silently dropped the stock.
The same holds for the other clock names (dt, initial_time, final_time).

The systems reader now refuses such a stock, as a returned error that names the stock as written and its line:

line 1: stock 'Time' has one of the simulation's clock names (time, dt, initial_time, final_time), which a stock cannot take; rename the stock

What counts as a clock name comes from db::is_implicit_global, the rule a patch rename already uses, not a second list.
The check is in the lexer's stock-name validation, which every stock reference passes through and which already knows the line.
Other builtin names (pi, time_step, starttime, stoptime) stay legal: the translator quotes them, so equations read the stock.

With these names refused, the CLI's skip of a stock named time in print_filtered_tsv and print_filtered_tsv_comparison could never fire, so it is removed.
The integration test that pinned the old collision (visible_stocks_includes_time_named_stock) goes with it.
Nothing in test/ names a stock after the clock.

Evidence

  • systems::parser::tests::a_stock_named_for_the_clock_is_refused: every name in db::IMPLICIT_GLOBALS, in lower, upper and title case, at each place a line names a stock (stock-only, with parameters, infinite, flow source, flow destination, flow with no rate), is refused with line 3: and the stock's name. Names that only contain a clock name (time2, time_spent) are accepted.
  • systems::translate::tests::a_stock_named_like_a_builtin_is_read_as_the_stock: takes every zero-argument builtin name and alias and splits them with is_implicit_global. It checks that the clock names are exactly IMPLICIT_GLOBALS and that open_systems refuses each one. Every other name must simulate the same as the model with the stock named a.
  • I ran the CLI by hand: simlin simulate on A(5) > Time @ 1 exits 1 with the message above.

What this does not establish: the CLI has no test harness, so its column printing is covered only by reading the code and the manual run. Formula references to an undeclared time are unchanged: they are undeclared names like any other, as before.

Fixes #440

A systems-format stock named time (or dt, initial_time, final_time)
takes the clock slot's key in the results, where every host reads the
clock by name. The CLI printed the clock under "time" and silently
dropped the stock's series. The importer now refuses such a stock with
an error naming the stock and its line, the same rule a patch rename
keeps; the check reuses db::is_implicit_global rather than a second
list. Other builtin names (pi, time_step, starttime, stoptime) stay
legal, since the translator quotes them and equations read the stock.

The check sits in the lexer's stock-name validation, the one place
every stock reference passes through with its line number. The CLI's
skip of a stock whose canonical name is time is dead now and removed,
as is the integration test that pinned the old collision.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T05:08:27.701555Z 9f98984 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the diff. The lexer check correctly rejects clock-named stocks at every reference site (plain, parameterized, infinite [...], and both flow endpoints), uses the same db::is_implicit_global rule as the patch rename, and names the stock as the user wrote it with the line number. The error message's IMPLICIT_GLOBALS.join(", ") enumeration gives useful guidance, and the removal of the CLI dedup paths in print_filtered_tsv/print_filtered_tsv_comparison is sound now that the parser forbids the collision. The partition in the translate test cross-checks that every IMPLICIT_GLOBALS entry is a zero-arg builtin name and verifies both arms (clock → refused, other → runs as the stock). No blocking issues found.

Overall correctness: correct.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f98984801

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

});
}
}
if crate::db::is_implicit_global(&crate::canonicalize(name)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject clock-named stocks during systems export

When a valid non-systems project, such as one loaded from XMILE or JSON, contains a stock named time, dt, initial_time, or final_time, systems::writer::project_to_systems still formats it as an ordinary stock and returns Ok; simlin_project_serialize_systems therefore reports a successful export. The resulting text now deterministically fails in open_systems at this check, so the writer can emit an artifact its paired reader cannot consume. Add the same representability check to export and return an error, or otherwise ensure writer output remains parseable.

AGENTS.md reference: src/simlin-engine/AGENTS.md:L27-L29

Useful? React with 👍 / 👎.

@bpowers
bpowers merged commit 3f87e90 into main Oct 12, 2026
16 of 19 checks passed
@bpowers
bpowers deleted the systems-refuse-clock-stock-names branch October 12, 2026 13:08
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.

cli: a systems stock named time is dropped from the output

1 participant