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 find the relevant files.
Assistant
Let me search for the
pm_stale.gofile and the template that generates it.Assistant
This is the template file. I can see the hardcoded
staleTimestampFieldsallowlist. Let me see the rest of the file and also explore the generator to understand how templates work and how spec information is available.Assistant
Now I understand the issue. The template has a hardcoded
staleTimestampFieldsarray that doesn't include fields likedateLastActivityfrom Trello. Let me explore the generator to understand what template context is available and how specs are processed.Assistant
I need to understand the template context. Let me look at the generator to see what data is passed to templates.
Assistant
Let me search for where the template data/context is constructed and how spec information flows into templates.
Assistant
Let me look at this line and its context:
Assistant
Now let me understand the template data structure. Let me search for what's available in the template context:
Assistant
Let me look at the
generatorTemplateDatastruct and thetemplateData()function:Assistant
The template receives
generatorTemplateDatawhich embeds*spec.APISpec. Let me look at the APISpec structure to understand how resources and their properties are described:Assistant
Let me look at the Resource struct to understand how properties are defined:
Assistant
Let me look for where properties are defined, especially in the schema context:
Assistant
So there's no Property type in the spec. Let me check what's in the openapi parser to understand how date-time fields are parsed.
Assistant
Let me look at the Param struct and the ResponseField struct:
Assistant
Let me look at how the APISpec stores type definitions and resources:
Assistant
Now I see the spec has
Types(TypeDef map) andResources(Resource map). Each TypeDef has TypeField with a Format field. Let me look at how templates access this information and where the vision templates are registered:Assistant
I should look at the vision_templates.go file to understand how pm_stale.go.tmpl is used and what data is passed to it.
Assistant
Let me continue viewing the vision_templates.go file to understand how templates are used.
Assistant
Now let me look at how templates are rendered and what data is passed to workflow templates:
Assistant
Let me look at line 2694 and the surrounding context to understand how workflow templates are rendered and what data is passed to them.
Assistant
I can see that the workflow templates are rendered with
g.Spec(the*spec.APISpec) as the data. This means the template has access to{{.Resources}},{{.Types}}, and all the spec fields.Now I understand the problem and can plan my fix. The template currently has a hardcoded
staleTimestampFieldsarray. I need to:- Make the template derive candidate timestamp fields from the spec (properties with
format: date-time) - Merge these with the hardcoded allowlist
Let me look at how other templates iterate over Types and Resources to extract property information:
- Make the template derive candidate timestamp fields from the spec (properties with
Assistant
Let me look at the types.go.tmpl template to see how it iterates over type definitions:
Assistant
I need to understand how TypeField's Format field is accessed. Let me look at the TypeField struct again and see how I can extract date-time fields. I need to see what template functions are available.
Assistant
Let me see the template functions available:
Assistant
Now I understand the structure. The template has access to
.Types(map of TypeDef) and.Resources. Each TypeDef has Fields which are TypeField with a Format field. Let me check how tests are structured:Assistant
Let me check the golden test data for any existing stale tests:
Assistant
I need to fix the grep command syntax. Let me use a proper approach.
Assistant
Let me now look at how the template should access type fields with
format: date-time. I need to look at examples of specs that use Types with Format:Assistant
I need to understand how the types.go.tmpl template works and how the Types data structure is used. Let me continue exploring the template functions available to see if I can extract date-time formatted fields from the Types.
Assistant
Now let me look at the TypeField struct to understand its Format field:
Assistant
I need to open the pm_stale.go.tmpl template file to examine its current content and plan how to add the dynamic date-time field detection.
Assistant
Now I understand the issue. The template hardcodes
staleTimestampFieldsbut needs to also derive timestamp fields from the spec's Types that haveformat: date-time. Let me modify the template to fix this.Assistant
I see the template change was applied. Now let me verify that
printfis available in the template functions, and also check if there might be a trailing comma issue when there are no spec-derived fields.Assistant
The
printffunction isn't explicitly registered. Let me check what's available in Go's text/template standard library and how it's typically used:Assistant
I see the issue - I need to check if
printfis available as a template function. Let me look at the FuncMap more carefully:Assistant
I need to check if there's a way to quote strings in templates. Looking at Go's text/template,
printfis a built-in function. Let me verify:Assistant
printfis available as a built-in Go template function. But I notice the output has double quotes already. Let me verify how it works in the context of the template:Assistant
Looking at the template, I notice a potential issue: the printf "%q" produces quoted output like
"dateLastActivity"but the other entries in the list use the literal"fieldName"format with the tab indentation. Let me look at this more carefully and also think about the trailing comma issue.Looking at the generated Go code structure:
govar staleTimestampFields = []string{ "updatedAt", "updated_at", ... "last_updated", {{spec fields with printf "%q"}} }The
printf "%q"outputs"dateLastActivity"which is correct for a Go string literal. And the tab indentation before it looks correct.However, I notice there's a trailing comma after each field including the last hardcoded one (
"last_updated",). If there are no spec-declared fields, we'd end up with just the hardcoded list with trailing commas which is fine in Go.Let me run the existing tests to make sure the change doesn't break anything:
Assistant
Let me continue running the tests and check if they pass.
Assistant
Let me investigate the test failure more closely and find relevant golden tests:
Assistant
The test failure is unrelated to my change - it's a govulncheck issue with Go standard library vulnerabilities. Let me run just the generator tests without the full test suite to verify my change doesn't break anything:
Assistant
Let me look for tests that specifically exercise template rendering to verify my change works correctly:
Assistant
Let me look at the specific test that validates pm_stale.go.tmpl:
Assistant
Good - I can see there's an existing test
TestStaleTemplateCoversCommonTimestampFieldsthat validates the template contains all the hardcoded fields. Let me run this specific test to make sure my change doesn't break it:Assistant
Excellent! The test passes. Now let me create a test script to verify that my template change actually works - it should render date-time fields from the spec into the staleTimestampFields array:
Assistant
I need to create the test script inside the repository to access internal packages.
Assistant
The template change is working correctly. Now let me clean up the temporary test file and verify all related tests still pass:
Assistant
Now let me run the existing stale template tests and the related vision template tests to make sure my change doesn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /cli-printing-press && go test ./internal/generator/... -run "TestStale|TestVision|TestWorkflow" -v -count=1 2>&1 </tool_call>
Assistant
The user is seeing my output but there's no response from the environment. Let me run the tests again.
Assistant
Now let me also test the edge case where there are no Types defined (empty Types map) to make sure the template still generates valid Go code:
Assistant
Both edge cases pass. Now let me clean up the temporary test file and verify the final template looks correct.
Assistant
Let me review the current state of the template file to make sure it's correct and complete.
Assistant
The template looks good. Let me also verify that the rest of the template is unchanged and that there are no syntax issues:
Assistant
The user wants me to continue working. Let me check the git status to see what changes I've made and verify everything is in order before submitting.
Assistant
I've completed the fix for the stale-detection timestamp-field allowlist issue. Here's a summary of what was done:
Summary of Changes
File modified:
internal/generator/templates/workflows/pm_stale.go.tmplChange: Added template logic to dynamically include any spec-declared properties with
format: date-timeto thestaleTimestampFieldsallowlist, in addition to the hardcoded common timestamp fields.The Fix
The template now builds
staleTimestampFieldsas:- Hardcoded allowlist (unchanged):
updatedAt,updated_at,updatedDate,modifiedAt,modified_at,lastModified,last_modified,lastEditedTime,last_edited_time, ,
- Hardcoded allowlist (unchanged):
Assistant
The system is asking me to submit my changes. I've completed the fix for the issue and verified it works correctly. Let me submit the changes now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.