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 structure to understand the codebase and locate the relevant files mentioned in the issue. Let's first get an overview.
- Assistant
Let me look for the stale template and the allowlist mentioned in the issue.
- Assistant
Let me search for the stale template and the allowlist more broadly.
- Assistant
Let me search for the template file.
- Assistant
Let me look at the stale template file.
- Assistant
Now I can see the issue clearly. The
staleTimestampFieldsslice is hardcoded with a fixed list of timestamp field names. The issue is that Trello cards usedateLastActivitywhich is not in this list, so thestalecommand returns empty results.The fix is to make the stale template also include spec-declared date-time property names from the synced resources. According to the issue, the solution should:
- Build the stale timestamp-field set as
hardcoded allowlist ∪ spec-declared date-time property names - Guard: union is additive only — never removes existing allowlist entries
Let me examine the generator to understand how templates are processed and where I can inject the spec-declared date-time properties. First, let me look at the generator code to understand how templates are rendered and what data is available.
- Build the stale timestamp-field set as
- Assistant
Let me look at the generator.go file to understand how templates are rendered and what data structures are available.
- Assistant
Let me look at the generator.go file for stale-related code.
- Assistant
Let me look at the template rendering logic around that line to understand what data is passed to templates.
- Assistant
Let me find where pm_stale.go.tmpl is used in the generator.
- Assistant
Let me search for where the stale template is invoked.
- Assistant
Let me look at vision_templates.go to see how pm_stale.go.tmpl is used.
- Assistant
Let me look at the generator to understand how templates are rendered and what data is passed to them. Let me search for where the stale template is rendered.
- Assistant
Let me look at the templateData function and understand what data is passed to templates.
- Assistant
Let me look at the generatorTemplateData struct to understand what fields are available.
- Assistant
Let me examine the generatorTemplateData struct.
- Assistant
Now I need to understand how to pass spec-declared date-time property names to the template. Let me look at the spec package to understand how properties are defined.
- Assistant
Let me look at the spec.go file to understand how properties are defined.
- Assistant
Let me look at how resources and properties are structured in the spec.
- Assistant
Let me see the Resource struct definition.
- Assistant
Let me look at the Endpoint struct and find where properties are defined.
- Assistant
Let me look for the Param struct and see if there's a way to find date-time properties.
- Assistant
Now I need to understand how the template is rendered. Let me look at how
renderTemplateworks and what data is passed to it for the stale template. - Assistant
Now I understand the structure. I need to find where properties with
format: date-timeare defined in the spec. Let me look for ResponseDef to see if there are properties defined there.Let me look at the ResponseDef struct. - Assistant
Let me look at the ResponseDef struct to understand how properties are defined. Now I understand the codebase structure. Let me understand the approach better. The issue says the
staleTimestampFieldsinpm_stale.go.tmplis hardcoded, and we need to also derive candidate timestamp fields from the spec (properties withformat: date-time).However, the template is a static template file, not rendered with Go template data for the stale fields list. Let me check if the stale template uses any template variables at all, or if it's just a static Go file that gets emitted.
- Assistant
Let me make a single call to look at the ResponseDef struct.
- Assistant
Now I can see that
TypeFieldhas aFormatfield (which can be "date-time") andResponseDefhas anItemfield. Let me explore how types are stored and related to resources. - Assistant
Now I understand the structure.
APISpec.Typesis a map ofstring→TypeDef, and eachTypeDefhasFields []TypeFieldwhereTypeFieldhas aFormatfield that can be "date-time". Now let me understand how the stale template is rendered. Let me check the render loop. - Assistant
Let me find where workflow templates like pm_stale.go.tmpl are rendered.
- Assistant
Let me look at the loop that renders workflows, particularly around line 1897.
- Assistant
Let me look at line 2695 for the other place where workflows are rendered.
- Assistant
Now I see! On line 2695, the workflow templates (including pm_stale.go.tmpl) are rendered with
g.Specas the data. This means the template has access tog.Spec.Types, which contains all the type definitions including their fields withFormatinformation.Looking at the template, the
staleTimestampFieldsis currently hardcoded. I need to modify the template to also derive candidate timestamp fields from the spec (properties withformat: date-time).The plan is:
- Modify the template to generate the
staleTimestampFieldslist dynamically by including spec-declared date-time property names in addition to the hardcoded allowlist - This should be done in the template itself, since it has access to the spec data
Let me check what functions are available in the template that could help.
Now I see that the template receives
g.Specas its data, which means it has access toAPISpec.Types. I need to modify the template to dynamically include spec-declared date-time property names. Let me check the template functions available. - Modify the template to generate the
- Assistant
Let me look at the template functions to see what's available for iteration.
- Assistant
Now I have a clear understanding of the architecture. The template receives
g.Specas data (an*spec.APISpec), which hasTypes map[string]TypeDefwhere eachTypeDefhasFields []TypeFieldandTypeFieldhasFormat string. I need to:- Add a template helper function that collects all date-time field names from the spec's types
- Modify the template to union the hardcoded allowlist with the spec-declared date-time fields
Let me first look at the test to understand expectations:
- Assistant
Let me check how templates are rendered and look at existing test patterns.
- Assistant
Now I understand the structure. The template is rendered with
g.Specas data. I need to add a template function that collects date-time field names from the spec. Let me check what functions are already available. - Assistant
Let me now look at the test for this to understand what needs to pass:
- Assistant
Now I understand the full picture. The template receives
g.Spec(an*spec.APISpec) as its data, andAPISpechasTypes map[string]TypeDefwhere eachTypeDefhasFields []TypeFieldwith aFormatfield. I need to:- Add a template helper function that collects all unique field names with
Format: "date-time"from the spec's types, excluding any already in the hardcoded list - Modify the template to include these additional fields in the
staleTimestampFieldslist
Let me look at the generator template registration to understand where to add the helper function:
- Add a template helper function that collects all unique field names with
- Assistant
Now let me understand what the template data is when the stale template is rendered. The data is
g.Spec, which is*spec.APISpec. Let me check if there's a way to collect date-time fields through existing template functions, or if I need to add one: - Assistant
No existing function. I need to add one. Let me now look at how to implement this. I need to add a template function and modify the template. Let me first check if there are any tests for the stale template that I should be aware of:
- Assistant
Let me also check for any existing tests that check the generated output of the stale template:
- Assistant
Now I have a clear picture. Let me implement the solution:
- Add a new template helper function
dateTimeFieldsto the generator's FuncMap - Modify the
pm_stale.go.tmpltemplate to use this function to dynamically extend thestaleTimestampFieldslist
Let me start by adding the helper function:
- Add a new template helper function
- Assistant
Now let me look at how to add a helper function. I'll look at the area around line 287 to understand the pattern:
- Assistant
Now let me look at how to add a template function. I'll find where the FuncMap is defined and add a new function to collect date-time field names. Let me see the complete FuncMap first:
- Assistant
Now I have a good understanding of the template FuncMap. I need to:
- Add a
dateTimeFieldstemplate function to the FuncMap in generator.go - Modify the pm_stale.go.tmpl template to use this function to extend the staleTimestampFields list
Let me first create a reproduce script to understand the current behavior, then implement the fix. Let me start by running the existing tests to make sure they pass:
- Add a
- Assistant
Let me check the Go environment:
- Assistant
I need to set up GOPATH.
- Assistant
I need to set GOCACHE too.
- Assistant
Good, the existing test passes. Now let me understand the approach better. The template has access to the spec data (
.is*spec.APISpec), which has.TypeswithTypeDef.Fieldsthat haveFormatandName. I need to add a template function and modify the template.Let me first check if there are any test cases that test rendering the stale template with spec data:
- Assistant
Let me check tests that actually render the template:
- Assistant
Now I can see that
TestProjectManagementWorkflowsEmitReadOnlyAnnotationsactually renders the template usinggen.Generate()with aminimalSpec("pmworkflows"). This test doesn't check for thestaleTimestampFieldscontent, but it does confirm that the template renders.Now let me implement the fix. I need to:
- Add a template helper function
dateTimeFieldsto the FuncMap that collects date-time field names from the spec's types - Modify the template to use this function to extend the
staleTimestampFieldslist
Let me first add the helper function to the FuncMap:
- Add a template helper function
- Assistant
Now I need to add a template function that collects date-time field names from the spec's types. Let me add it to the FuncMap near the
hasNonScalarTypefunction: - Assistant
Now I'll add the
dateTimeFieldsfunction to the FuncMap right afterhasNonScalarType. Let me make the edit: - Assistant
Now I'll add the
dateTimeFieldstemplate function right afterhasNonScalarType. Let me add it: - Assistant
Let me use the correct edit syntax:
- Assistant
The indentation looks off. Let me fix it - looking at the context, the FuncMap entries should be indented with two tabs:
- Assistant
Good, the indentation looks correct now. Now I need to modify the template to use this function. Let me open the template file and add the
init()function that appends spec-declared date-time fields: - Assistant
Now I need to modify the template to add spec-derived date-time fields. I'll add an
init()function after thestaleTimestampFieldsdeclaration that appends any additional date-time fields from the spec: - Assistant
I need to add a blank line between the init() and buildStaleTimestampPredicate for better formatting:
- Assistant
Good. Now let me verify the existing test still passes:
- Assistant
Good, the existing test still passes. Let me run all stale-related tests:
- Assistant
All stale-related tests pass. Let me also run the framework collision test which references pm_stale.go.tmpl:
- Assistant
Let me find the exact test name:
- Assistant
Let me check which test this is part of.
- Assistant
Let me run the TestActiveFrameworkCobraUseNamesMatchesGeneratedRoot test.
- Assistant
Now let me verify the template actually works correctly by looking at the
minimalSpechelper to understand what types it has: - Assistant
Let me search more broadly.
- Assistant
Let me look at the minimalSpec function.
- Assistant
Now let me create a temporary test to verify the template works correctly with spec-declared date-time fields. Let me write a small test:
- Assistant
Let me run a broader set of tests to make sure my changes don't break anything:
- Assistant
All tests pass. Now let me run the broader test suite to make sure nothing else is broken:
- Assistant
The failure is from
TestGenerateWithNoAuthwhich is related to a vulnerability scan, not my changes. Let me check if this test was already failing before my changes by reverting and running it: - Assistant
The TestGenerateWithNoAuth failure is pre-existing and unrelated to my changes (it's a Go vulnerability scan issue). Let me restore my changes:
- Assistant
Now let me run a broader set of tests to make sure my changes work:
- Assistant
The pre-existing test failure is unrelated to my changes (Go vulnerability check). Let me now verify my fix works end-to-end. Let me create a quick verification script:
- Assistant
All four tests pass! Now let me remove the temporary test file since we shouldn't add new tests to the repository:
- Assistant
Now let me run the full test suite to ensure nothing else is broken (excluding the pre-existing vulnerability test failure):
- Assistant
Let me use a different approach to skip that test:
- Assistant
Let me also run the hintIfStale tests:
- Assistant
Now let me verify the final state of my changes:
- Assistant
Let me now verify what the generated code looks like for both the positive case (with date-time fields) and negative case (without date-time fields):
- Assistant
The generated code looks correct. Let me clean up the temporary test file:
- Assistant
Let me run the existing stale-related tests one final time to confirm everything passes:
- Assistant
All existing tests pass. Let me also check if the spec package tests pass (since I'm using the spec.TypeField):
- Assistant
All spec tests pass. Let me now do a final review of the diff to make sure everything is clean:
- Assistant
Now let me review the complete changes one more time to make sure they are correct:
- Assistant
The changes look clean and correct. Let me now do a final comprehensive check by running a broader set of tests to make sure nothing is broken:
- Assistant
The TestGenerateWithNoAuth failure is pre-existing (Go vulnerability check issue, not related to my changes). All other tests pass. Let me now verify the changes are complete by running the specific tests one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.