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
Let me start by understanding the repository structure and finding the relevant files mentioned in the issue. The issue is about a stale-detection timestamp-field allowlist in a Go project that generates CLI tools. I need to:
- Explore the repository structure
- Find the
internal/cli/pm_stale.gotemplate or generator - Understand how the
staleTimestampFieldsallowlist is used - Implement the fix to also derive candidate timestamp fields from the spec (properties with
format: date-time)
Let me start by exploring the repository.
Assistant
Let me continue exploring to find the template files and the stale detection code.
Assistant
The user is pointing out that I made an error in my function call. I used
openwith afileparameter, but looking at the available functions,opendoesn't have afileparameter - it takes[FILE]and[LINE_NUMBER]as positional arguments. Let me fix this.Assistant
Let me try using bash to view the file instead:
Assistant
Now I understand the template. I can see the hardcoded
staleTimestampFieldslist. I need to find how the template data is structured so I can add spec-declareddate-timefields to this list. Let me explore the generator code.Assistant
Let me look at the generator code to understand how templates are processed and how the data is structured:
Assistant
Now let me look at the main generator file to understand how the template data is built:
Assistant
This is a large file. Let me look for how the template data (template data struct) is built, specifically what's passed to the
pm_stale.go.tmpltemplate. I need to find where the template rendering happens:Assistant
Now let me look at how the
pm_stale.go.tmpltemplate gets its data. Let me search for how the template's data is built:Assistant
Let me look at the
templateData()function:Assistant
Let me look at the
generatorTemplateDatastruct definition to understand what data is available to templates:Assistant
Now I understand. The
generatorTemplateDataembeds*spec.APISpec. The template has access to the full API spec through.APISpecor directly via fields. Let me look at thespec.APISpectype to understand its structure:Assistant
Now I understand the spec structure. The
APISpechasResourcesandTypes. TheTypesmap containsTypeDefentries that haveFieldswithformatattributes. Let me look at theTypeDefandTypeDefFieldstructures:Assistant
Now I have the full picture. The
TypeFieldstruct has aFormatfield that can contain"date-time". The fix should:- In the template
pm_stale.go.tmpl, derive timestamp field names from the spec's type definitions (any field withformat: date-time) - Combine these with the hardcoded allowlist
Now I need to understand how the template iterates over resources and their types. Let me look at how resources reference types:
- In the template
Assistant
I see the structure. Let me look at the Resource type to understand how it references types:
<tool_call>bash grep -n "type Resource struct|ResponseTypes|ListResponseType|ResponseType" /cli-printing-press/internal/spec/spec.go | head -30
Assistant
I need to continue investigating the Resource struct to understand how resources reference types, which will help me understand how to derive date-time fields from the spec.
Assistant
Now I understand the full picture. The spec has:
APISpec.Resources- map of resourcesAPISpec.Types- map of type definitions- Each
TypeDefhasFieldsof typeTypeField - Each
TypeFieldhasFormat(e.g."date-time")
The
pm_stale.go.tmpltemplate has access to the full spec through the embedded*spec.APISpecingeneratorTemplateData.Now let me look at the existing test infrastructure to understand how tests work:
Assistant
Let me check if there are any golden tests or existing tests that involve the stale template:
Assistant
I need to continue exploring the test file to understand how the stale timestamp fields are tested, and then implement the fix. Let me look at the specific test around line 13035.
Assistant
Now I have a clear picture. The test
TestStaleTemplateCoversCommonTimestampFieldsvalidates that the hardcoded list is present in the template. The fix should:- Modify the template to build the
staleTimestampFieldslist dynamically at compile time by combining the hardcoded allowlist with spec-declareddate-timefields - Since this is a Go template, I need to pass the derived fields as template data
Let me understand how the template data flows. The template is rendered with
generatorTemplateDatawhich embeds*spec.APISpec. So in the template, I can access.Types(or.APISpec.Types) to iterate over type definitions.Let me verify what the template currently receives:
- Modify the template to build the
Assistant
The user is reminding me that I need to include my reasoning BEFORE each tool call. Let me continue investigating how the template is rendered and what data it receives.
I need to find where the pm_stale.go.tmpl template is rendered to understand what data is passed to it. Let me search for where templates are invoked with their data.
Assistant
I need to see where the workflow templates (like
pm_stale.go.tmpl) are rendered. Let me look at lines around 2698 and 2934 since those seem to render workflow templates:Assistant
The workflow templates are rendered with
g.Spec(the*spec.APISpec) as data. This means the template has access to.Typesto iterate over type definitions and find date-time fields.Now let me implement the fix. I'll modify the template to build
staleTimestampFieldsas a union of the hardcoded allowlist and spec-declared date-time fields.Assistant
Now I understand the full picture. The template is rendered with
g.Spec(the*spec.APISpec), so I can access.Typesin the template to find date-time fields. I need to modify thestaleTimestampFieldsvariable definition to include spec-declared date-time fields.Let me implement the fix by modifying the template to add spec-declared date-time fields:
Assistant
The user is telling me there's a syntax error in my edit command. I need to provide the edit command in the correct format. Looking at the function schema, edit requires
LINE_RANGEas<start_line>:<end_line>format. Let me use the correct syntax with the heredoc format.Assistant
- I need to first verify the current state of the template to see what exactly was changed and if there are any issues.
Let me view the full template file to understand the current state and see what needs to be fixed.
Assistant
I can see there's a duplicate comment block from the failed edit. Lines 16-23 and lines 24-32 are nearly identical comment blocks. Let me fix this by rewriting the entire staleTimestampFields section properly:
Assistant
Good, the file has been restored to its original state. Now let me create a proper replacement. I'll use sed to make the change precisely:
Assistant
Now I'll create the replacement text using a script approach that's more reliable:
Assistant
The template has been updated successfully. Now I need to run the existing tests to make sure my changes don't break anything. Let me run the generator tests, particularly the one that tests the stale template.
Assistant
Let me set up the Go environment and run the tests:
Assistant
Check is incomplete. I'll continue by setting up the Go environment variables properly and then run the existing tests to validate my changes.
Assistant
The existing test passes. Now let me run more comprehensive tests to make sure I didn't break anything:
Assistant
Now let me also run tests that might render the template to make sure the template itself is valid Go code after rendering:
Assistant
The test failure is related to
govulncheckfinding a vulnerability in the Go standard library (crypto/tls@go1.26.4), which is not related to my changes. Let me verify by running more targeted tests that specifically test the workflow templates.Assistant
Excellent! All workflow-related tests pass. Now let me write a quick test script to verify that my changes work correctly - specifically that a spec with
dateLastActivityas a date-time field gets included in the generated stale timestamp fields:Assistant
I cannot provide additional thinking before the first token.
Assistant
Let me fix the import path:
Assistant
The user wants me to continue with my task. Let me run the test from within the module directory where internal package imports are allowed:
Assistant
I cannot think action right away as I lack the proper argument structure. Let me run the test:
Assistant
The test file path is relative to the test package. Let me fix it:
Assistant
The test passes. Now let me clean up the temporary test directory and also think about edge cases:
- Duplicate fields: If a spec-declared
date-timefield has the same name as a hardcoded field (likeupdated_at), it should not create a duplicate entry in the generated Go code. Let me check what happens.
- Duplicate fields: If a spec-declared
Assistant
I cannot provide additional thinking before the first token.
Let me run the updated tests to make sure all edge cases pass.
Assistant
All tests pass. Now let me clean up the temporary test directory and verify the final state of changes:
Assistant
Now let me verify the final state of my changes and run the existing tests one more time:
Assistant
Let me run the existing tests to verify my changes don't break anything, then submit.
Assistant
All tests pass. Let me submit my changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.