ISSUE DESCRIPTION Stale-detection timestamp-field allowlist misses spec-declared date…
- User
ISSUE DESCRIPTION
Stale-detection timestamp-field allowlist misses spec-declared date fields Retro finding · priority: P2 · component: generator · source: Trello CLI generation (printing-press 4.9.0)
What happened
The generated
internal/cli/pm_stale.gomatches inactivity against a hardcodedstaleTimestampFieldsallowlist (updatedAt, updated_at, updatedDate, modifiedAt, modified_at, lastModified, last_modified, lastEditedTime, last_edited_time, updated, last_updated). Trello cards usedateLastActivity, which is absent. The flagshipstalecommand returned "No stale items found" while a hand-builthealthcommand (readingdateLastActivity) counted 93 stale cards on the same hydrated data. Silent-empty flagship command, no error.Root cause
The stale template hardcodes a timestamp-name allowlist instead of also deriving candidate timestamp fields from the spec (properties with
format: date-time).Durable fix (proposed)
Build the stale timestamp-field set as
hardcoded allowlist ∪ spec-declared date-time property names for the synced resources. Guard: union is additive only — never removes existing allowlist entries, so no regression for currently-working APIs.Test
- Positive: a spec with a
dateLastActivity(format: date-time) card property produces astalethat finds rows older than N days. - Negative: an API using
updated_atis unchanged.
Repro / evidence
trello-pp-cli stale --days 14→ empty;trello-pp-cli health→ 93 stale on the same mirror. Fixed by hand-addingdateLastActivityto the allowlist. The allowlist approach will keep silently breaking the flagship command for the next API with an unlisted activity field.ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusor commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Positive: a spec with a
- Assistant
I'll start by exploring the repository to understand its structure and locate the relevant files mentioned in the issue. Let's first check the current directory and list files.
- Assistant
Let me search for the stale-related files more broadly.
- Assistant
Let me search more specifically for the stale-related files.
- Assistant
Found the stale template file. Let me also look for the staleTimestampFields definition.
- Assistant
Let me examine the stale template file first.
- Assistant
Now I need to understand the generator code that populates this template. Let me look at the generator code and tests.
- Assistant
Let me examine the generator code and the broader context to understand how the template is rendered:
- Assistant
Let me check the test around line 13035 to see the full test.
- Assistant
Now I understand the issue. The problem is that the
staleTimestampFieldsin the template is hardcoded and doesn't include fields from the OpenAPI spec that haveformat: date-time. For example, Trello usesdateLastActivitywhich is not in the hardcoded list.The fix needs to:
- Look at how the generator processes templates
- Add logic to derive timestamp fields from the spec (properties with
format: date-time) - Add these to the hardcoded allowlist when generating the stale command
Let me explore the generator code to understand how templates are processed.
- Assistant
Let me examine the generator.go file to understand how templates are processed and what data is available to them.
- Assistant
Let me examine the generator structure and how templates get their data.
- Assistant
Let me look at what data is passed to the templates.
- Assistant
Let me search for how the stale template is rendered specifically.
- Assistant
Let me look at the context around line 3184 to understand how the stale template is rendered.
- Assistant
Let me search for where pm_stale.go.tmpl is actually rendered.
- Assistant
Let me search for where the stale template is actually rendered.
- Assistant
Let me look at vision_templates.go to see how the stale template is rendered.
- Assistant
Now I need to understand how the template is rendered. Let me search for where the templates are actually executed.
- Assistant
Let me look at line 2698 to see where the stale template is rendered.
- Assistant
Good! I found it. The stale template is rendered at line 2698 with
g.Specas the data. This means the template has access to the full API spec. Now I need to understand what's in the spec and how to access properties withformat: date-time. - Assistant
Let me check the spec structure to understand how date-time fields are represented.
- Assistant
Let me search for how properties are defined in the spec structure.
- Assistant
Let me look at the Property struct more closely.
- Assistant
Let me check the Resource struct to see how properties are stored there.
- Assistant
Let me look at the Resource struct.
- Assistant
Let me check the ResponseDef to see if it contains properties with format information.
- Assistant
Let me look at ResponseDef.
- Assistant
Let me search for how properties are collected or stored.
- Assistant
Let me understand the APISpec and Resources structure better:
- Assistant
Let me check how the OpenAPI parser works to understand what information is available.
- Assistant
Let me look at the openapi parser to understand what information it extracts.
- Assistant
Let me look at how properties are parsed and if they have a Format field.
- Assistant
Now I understand the structure better. The spec has properties with a Format field that can be "date-time". However, I need to understand how to access these properties from the template. Let me check if there's a way to get all properties across all resources.
- Assistant
Let me understand what functions are available to the template and how the template accesses the spec's data. Let me look at the template more carefully - the current template uses
{{.Name}}and{{.Owner}}, so it's rendering against the spec's fields. - Assistant
Let me look at the template functions available and how the spec data gets passed to the template:
- Assistant
Let me look at the template to see how it uses the spec data and what functions are available:
- Assistant
Now I understand the challenge better. The stale template is rendered against
g.Spec(the APISpec). But the hardcoded list in the template is just a Go source code literal. The template can't easily iterate over all resource properties.Let me think about the approach:
- The template is rendered once by the generator to produce a Go source file
- The template receives the APISpec as data
- The template has access to various helper functions
- I need to modify the template to dynamically add spec-declared date-time properties to the list
The template currently has:
var staleTimestampFields = []string{ "updatedAt", "updated_at", ... }I need to make this dynamic. But the template is generating Go code, so I need to be careful. I could add a new template function that extracts date-time properties from the spec and use it in the template to build the list dynamically, or I could have the generator extract these properties and pass them as template data to include in the list.
Looking at the issue description, it's asking for a union approach: hardcoded allowlist plus spec-declared date-time property names for the synced resources.
- Assistant
Let me look at the spec structure to understand how we can extract date-time formatted properties:
- Assistant
Let me look at how response body properties are stored in the spec:
- Assistant
Let me look at how the OpenAPI parser stores format information for properties:
- Assistant
Let me look at
TypeFieldstruct: - Assistant
Now I need to understand how the types/type definitions are stored in the spec:
- Assistant
Now I understand the data model.
TypeFieldhas aFormatfield that can be "date-time", and theAPISpechasTypes map[string]TypeDefwhere eachTypeDefhasFields []TypeField.The fix needs to:
- Add a template function that extracts date-time field names from the spec
- Modify the template to use both the hardcoded list and the spec-derived fields
Let me examine the template more carefully to understand what I need to change:
- Assistant
Let me understand how templates are structured and what data they receive:
- Assistant
Let me understand how to connect resources with their response types and look for date-time fields:
- Assistant
Let me understand how the template renders and what helper functions are available for working with the spec types:
- Assistant
Let me check what fields the spec stores that have format: date-time:
- Assistant
Let me look at a spec file to see how date-time fields are declared:
- Assistant
Let me understand the architecture. The template receives the spec's data. I need to add a helper function to extract date-time field names from the spec and modify the template to include them. Let me first look at how the template is rendered:
- Assistant
Now let me look at how the template function is registered and called. Let me add a helper function to extract date-time field names from the spec and modify the template to use them.
- Assistant
Now I have a clear understanding of the codebase. Let me plan and implement the fix:
Plan:
- Add a
specDateTimeFieldstemplate function to the FuncMap that extracts all field names withformat: date-timefrom the spec'sTypesmap - Modify
pm_stale.go.tmplto include spec-derived date-time fields in addition to the hardcoded allowlist - Update the test to verify spec-derived fields are included
Let me first add the helper function:
- Add a
- Assistant
Now I need to add the
specDateTimeFieldstemplate function. Let me find the right place to add it: - Assistant
Now let me look at how the template renders and understand how to dynamically add fields. The template receives
*spec.APISpecas its data context. I need to add a template function and modify the template. - Assistant
Now I understand the full architecture. Let me implement the fix:
- Add a
specDateTimeFieldstemplate function that extracts date-time formatted property names from the spec's Types - Modify the template to include spec-derived date-time fields in addition to the hardcoded allowlist
- Update the test
Let me first add the helper function to the FuncMap:
- Add a
- Assistant
Now let me look at how the template function enumLiteral works as an example for a function that returns Go string literals:
- Assistant
Now I understand the architecture. Let me implement the fix step by step.
First, I need to add a
specDateTimeFieldstemplate function to the FuncMap, then modify the template to use it. Let me add the function: - Assistant
Now I understand the full picture. Let me implement the fix. I'll:
- Add a
specDateTimeFieldstemplate function that extracts unique date-time field names from the spec'sTypesmap - Modify the template to include spec-derived fields after the hardcoded allowlist (additive only, no duplicates)
- Update the test
Let me first add the function. I'll place it near the other type-related template functions:
- Add a
- Assistant
Let me first check if there's already a function like this or a pattern for filtering:
- Assistant
Now I have a clear understanding. Let me implement the fix step by step.
First, I'll add the
specDateTimeFieldsfunction to the template FuncMap. This function will take the spec'sTypesmap and return a list of field names that haveformat: date-time: - Assistant
Now I need to add the
specDateTimeFieldsfunction to the FuncMap. This function will extract field names from the spec's Types that haveformat: date-time. I'll add it right afterhasNonScalarTypesince it has a similar pattern: - Assistant
Let me fix the file - I accidentally deleted the closing brace. Let me restore the file and start over:
- Assistant
Good, let me now carefully implement the fix. First, I'll add the
specDateTimeFieldstemplate function, then modify the template, and finally update the test. - Assistant
Now let me add the
specDateTimeFieldsfunction afterhasNonScalarType. I'll use the proper heredoc syntax for the edit command: - Assistant
I see there's a duplicate closing brace at line 272. Let me fix that:
- Assistant
There's a duplicate comment line. Let me fix that:
- Assistant
Good, the generator.go file now has the
specDateTimeFieldsfunction added. Now let me check ifsortis already imported: - Assistant
Good,
sortis already imported. Now I need to modify the template to use this function. The template currently receives*spec.APISpecas its data context, so it has access to.Types. Let me also create a function that builds the full union list (hardcoded + spec-derived, deduplicated) and returns it as a Go string literal for template embedding: - Assistant
Now I need to modify the template. The approach is to create a function that builds the full union list (hardcoded + spec-derived) and renders it as a Go
[]stringliteral, then use it in the template. Let me update the generator function to build this merged list and emit it as a Go literal: - Assistant
I notice
exampleLinemight have gotten lost. Let me check: - Assistant
I see
exampleLinegot dropped. Let me add it back: - Assistant
I see there's still an extra
},at line 332. Let me fix this: - Assistant
There's still a duplicate
promotedExampleLine. Let me fix that: - Assistant
There's still a duplicate
commandExampleArgs. Let me fix that: - Assistant
Let me fix the duplicate
currentYear: - Assistant
This is getting messy with all the duplicate lines. Let me reset and start over with a clean approach:
- Assistant
Good. Now let me take a cleaner approach. I'll add just the
specDateTimeFieldsfunction to the FuncMap, then modify the template to use it. The function returns spec-derived date-time field names, and the template appends them to the hardcoded list.Let me add the function right after the existing
hasNonScalarTypefunction (line 271): - Assistant
Let me use a precise approach - replace the exact lines between hasNonScalarType and exampleLine:
- Assistant
Good, the generator.go change looks clean. Let me verify it compiles:
- Assistant
Let me check the Go environment.
- Assistant
Let me check if there's a GOPATH issue or if I need to set it.
- Assistant
Let me set up the Go environment properly.
- Assistant
Let me set HOME and try again.
- Assistant
It compiles. Now I need to modify the template to use the
specDateTimeFieldsfunction. But first, I need to ensure the function only returns fields NOT already in the hardcoded allowlist. Let me update the function to exclude hardcoded fields, and also add a version that does the exclusion: - Assistant
Let me update the function to exclude the hardcoded allowlist entries so we don't get duplicates in the template:
- Assistant
Let me verify the build still works:
- Assistant
Good, the build works. Now I need to modify the template to use the
specDateTimeFieldsfunction. The template receives*spec.APISpecas its data context, so.Typesgives access to the types map. Let me modify the template: - Assistant
Good, the template changes look correct. Now let me update the test to also check for spec-derived date-time fields. Let me look at the test first:
- Assistant
The existing test reads the raw template file. My changes keep all the hardcoded entries in the template, so the existing test should still pass. Let me verify by running it:
- Assistant
The existing test passes. Now I need to add a new test that verifies the spec-derived date-time fields are included in the rendered output. Let me look at how to add a test that renders the template with a spec containing date-time fields:
- Assistant
Now I need to add a test that verifies spec-derived date-time fields are included when the template is rendered. Let me look at how other tests render templates:
- Assistant
Let me look for how tests are structured in the generator test file:
- Assistant
Let me look at how existing tests in the file work to understand the pattern:
- Assistant
Now I can see the testing pattern. Let me find the
minimalSpecfunction to understand how to create a test spec: - Assistant
Let me search more broadly for minimalSpec.
- Assistant
Let me look at the minimalSpec function.
- Assistant
Now I understand the pattern. Let me add a new test that verifies spec-derived date-time fields are included in the rendered stale template. I'll add it right after the existing
TestStaleTemplateCoversCommonTimestampFieldstest: - Assistant
Now I'll add a new test that verifies the template includes spec-derived date-time fields. I'll add it right after
TestStaleTemplateCoversCommonTimestampFields: - Assistant
I see there's a duplicate comment line at 13139-13140. Let me fix that.
- Assistant
Good, the test is added correctly. Now let me run the new test to make sure it passes:
- Assistant
Excellent! The new test passes. Let me also run the original test and other related tests to make sure I didn't break anything:
- Assistant
All related tests pass. Now let me also verify the rendered output looks correct by checking what the template generates:
- Assistant
Let me also verify the rendered output by creating a small test script:
- Assistant
Let me write a quick test within the package to inspect the rendered output:
- Assistant
Let me also add a test for the negative case where a spec uses
updated_at(which is already in the hardcoded list) - the field should not be duplicated: - Assistant
Let me add a test for the negative case (API using
updated_atis unchanged, no duplicates): - Assistant
There's a duplicate comment at 13184-13185. Let me fix that:
- Assistant
Good, now let me run the new duplicate test to verify it passes:
- Assistant
All three tests pass. Now let me also check if there are any golden test files that might be affected by our template change:
- Assistant
Let me also check if there are any golden tests that compare generated output:
- Assistant
No golden files contain staleTimestampFields. Let me also check if there are broader golden tests that might be affected:
- Assistant
Let me check if any golden test cases have date-time fields in their type definitions, as these would now produce different output:
- Assistant
Let me check if the golden-api.yaml has date-time fields in its type definitions:
- Assistant
Let me check if there are golden tests that test the golden-api fixture and whether they include the stale template:
- Assistant
Let me check for golden tests that might be affected:
- Assistant
Let me check for golden tests elsewhere:
- Assistant
Let me check for golden test comparisons:
- Assistant
Let me check if there's a golden test script that might be affected:
- Assistant
Let me check if the golden test script might be affected by our changes:
- Assistant
Let me check if the golden-api test case includes the stale workflow:
- Assistant
Let me check the golden test case definitions:
- Assistant
Let me check the golden test cases directory more carefully.
- Assistant
Let me check the golden-api case to understand its spec and whether it generates the stale template:
- Assistant
Let me check what the command.txt says and whether the golden-api case generates the stale template.
- Assistant
Let me check what archetype the golden-api spec uses and if it generates workflows:
- Assistant
Let me check if the golden expected output includes pm_stale.go:
- Assistant
Let me check the golden-api fixture to see if it has date-time fields in its type definitions:
- Assistant
Good, the golden-api has a
due_atfield with formatdate-time. But since the golden-api doesn't generate the stale template (it's not a project-management archetype), this won't affect golden tests. Let me verify by checking if the golden expected output for this case includes any stale-related files: - Assistant
Let me check if the golden expected output for generate-golden-api has a pm_stale.go file:
- Assistant
Good, no golden stale file exists. Now let me also run a broader set of generator tests to make sure nothing is broken:
- Assistant
All tests pass. Let me now review my changes to make sure they are correct and complete. Let me check the git diff:
- Assistant
Let me review the full diff to make sure everything is correct:
- Assistant
The diff looks clean. Let me now run a broader set of tests to make sure nothing else is broken, including the orphans and load workflow tests:
- Assistant
All tests pass. Let me also check if there are any spec package tests that might be affected:
- Assistant
All tests pass. Let me now do a final review of all my changes to make sure everything is correct and complete:
- Assistant
The changes look clean and correct. Let me also run a broader set of generator tests to make sure nothing else is broken:
- Assistant
The test failure is unrelated to my changes - it's a Go vulnerability check failure (GO-2026-5856) in the standard library. Let me confirm by running just the stale-related tests:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.